Hi Jeff,
I was able to got my project up and running with the above classes. I added a couple new fields to let the Patient and Therapist comment on a particular Exercise by adding a couple fields to PatientExercise as below:
@Embed
public class PatientExercise {
int sets = 0;
int reps = 0;
int freq = 0;
int status = Constants.PATIENT_EXERCISE_STATUS_ACTIVE; // 0=active; 1=stopped
@Load Ref<Exercise> exercise = null; // Exercise is an @Entity
@Load Ref<Therapist> assignTherapist = null; // Therapist who trains this Exercise. Therapist is an @Entity
String patientComment = null;
String therapistComment = null;
}
@Entity
@Index
public class Patient {
int age;
String occupation;
List<String> injuredPart = new ArrayList<String>();
@Load Ref<Therapist> currentTherapist; // LIMIT: trained by only 1 therapist at a time. Many to one relationship
List<PatientExercise> assignedExercise = new ArrayList<PatientExercise>(); // Many to many relationship
}
This works fine if Patient and Therapist leave only 1 comment (the highlighted fields above). If I want to capture all comments they leave and display them later in time line, I must associate each of them with Date. For example. I want to add a couple Lists of ExerciseComment to the PatientExercise class as below:
List<ExerciseComment> patientCommentList = new ArrayList<PatientComment>();
List<ExerciseComment> patientCommentList = new ArrayList<PatientComment>();
@Embed
public class ExerciseComment {
String comment;
Date date;
}
My current solution is adding 2 more classes: PatientExerciseComment for Patient's comment and TherapistPatientExerciseComment for THerapist's comment, then add 2 List under Patient as shown below:
@Embed
public class PatientExerciseComment {
@Load Ref<Exercise> exercise = null; // Exercise is an @Entity
@Load Ref<Therapist> reviewee = null; // Therapist who trains this Exercise. Therapist is an @Entity
String comment = null;
Date date;
}
@Embed
public class TherapistPatientExerciseComment {
@Load Ref<Exercise> exercise = null; // Exercise is an @Entity
String comment = null;
Date date;
}
@Entity
@Index
public class Patient {
int age;
String occupation;
List<String> injuredPart = new ArrayList<String>();
@Load Ref<Therapist> currentTherapist; // LIMIT: trained by only 1 therapist at a time. Many to one relationship
List<PatientExercise> assignedExercise = new ArrayList<PatientExercise>(); // Many to many relationship
List<PatientExerciseComment> patientCommentList = new ArrayList<PatientExerciseComment>(); // All of Patient comments
List<TherapistPatientExerciseComment > therapistCommentList = new ArrayList<TherapistPatientExerciseComment >(); // All of Therapist replies
}
With this implementation, I will do the below steps to display Patient's comments on a particular Exercise
1. Find all elements in the patientCommentList with Ref<Exercise>'s Id matches that particular Exercise
2. Sort these based on the Date
And to display Patient and Therapist comments in timeline, I will repeat the above steps for therapistCommentList, then sort of of the combination of 2 List.
I have 2 questions for you:
1. Do you plan to support nesting @Embed collection inside other @Embed collection in the future? Is that the limit of Google datastore?
2. Do you have any suggestion on my solution to make it simpler and quicker to retrieve comments from both Therapist and Patient on a particular Exercise?
Thanks,
Anh