RavenDb noob here.. so pardon my ignorance :)
My simplified data model
public class Patient
{
string Name;
List<Problem> Problems;
List<Visit> Visits;
}
public class Problem
{
string Code;
DateTime Date;
}
public class Visit
{
string Code;
DateTime Date;
}
I want to run a query that returns all patients that had any activity within a date range i.e. had a problem diagnosed or a visit occured in the queried date range.
Currently I am getting all patients via streamed query and filtering client side whether a patient qualifies for the date range or not but of course I have to change that.
I could not create index on patient doc since it has the fan out problem. one patient document could spit out 10 dates or 300 dates, I cant know in advance. So raven index dint work for me.
I created a separate document myself called PatientMonthMap (to start with I decided on keeping month to make it easier .. I am assuming int range queries would work better somehow?)
PatientMonthMap has Month as "yyyymm" and patient as "patientId"
The idea being that I could query this document for starting month and ending month and it would give me all patient ids, I can use a Server Transform on that to load the patient documents in question -> that I could then use the Streamed Query to load.
I am populating this document manually when I import new patient data. Patient data never changes in RavenDB, it only changes when I import new data from source DB, import happens nightly or weekly.
So the first question is: Does this make any sense :)
Am I better off using the full date to range query on? Does this yyyyMM (intrange) gives me any benefit?
How do I load "distinct" patient documents on top of this? e.g. a patient may have activity in June and July so his id is repeated in PatientMonthMap
I can replace this strategy with a better technique if you guys have one :)