Thank you for your advice,Matthieu.

> An other solution (I think that's what Giovanni points out) is to
> _not_ put phases in the prescription:
>
> - When you have a new prescription, just write it to the database
>
> - To know the current phase, retrieve the 2 last doc for each
> prescriber (you can use your second query here). Since you already put
> the current prescription, this will give you the current and the last,
> and then you diff in your application. For each drug you know if it
> was there in the previous prescription or not, so you can derive phase
> for each drug. I'm not 100% sure, but you could even build a _reduce
> that creates the result for you here.
>
> Now with this you may have a problem of consistency: if one of your
> databases has the 2 last documents, but another database isn't
> perfectly synced, both databases may not give you the same output.
> This is kind of expected since your phases span multiple documents. If
> you have the last prescription id in the current prescription though,
> you at least know if you lack any of them (but you can't do anything
> without first syncing)

I was not careful about consistency.
Surely I should think about it.

ken tashiro

Reply via email to