incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <rnew...@apache.org>
Subject Re: getting list of items spanning a time period
Date Mon, 01 Apr 2013 09:58:44 GMT
I can see that it's easy to use map/reduce to find the answer to 'how
many people were admitted in this time period' and 'how many people
were discharged in this time period'. From there, it's easy to get
'how many people were admitted before this time period' and 'how many
people were discharged after this time period'. If you know all four
numbers, you can calculate the number you seek which is 'how many
people were admitted before this time period and have not been
discharged in this time period'.

map:

map(doc) {
  emit(["admitted", doc.admitted_at], null);
  emit(["discharged", doc.discharged_at || "under_treatment"], null);
}

reduce:

 _count

query with

?startkey=["admitted", <start of time period>]&endkey=["admitted",
<end of time period>]&reduce=true
?startkey=["discharged", <start of time period>]&endkey=["admitted",
<end of time period>]&reduce=true
?startkey=["admitted"]&endkey=["admitted", <start of time period>]&reduce=true
?startkey=["discharged", <end of time period>]&endkey=["discharged",
{}]&reduce=true

This should give 'admitted within period', 'discharged within period',
'admitted before period' and 'discharged after period'.

Is that helpful?

B.



On 1 April 2013 10:47, Manokaran K <mano@smartgrader.com> wrote:
> FYI, am using an 'admission' doc that has an admission_time and a
> discharge_time (null if patient is still under treatment) for each patient.
>
>
> On Mon, Apr 1, 2013 at 3:15 PM, Manokaran K <mano@smartgrader.com> wrote:
>
>>
>> On Mon, Apr 1, 2013 at 3:08 PM, Александр Опак <opak.alexandr@gmail.com>wrote:
>>
>>> Use Cron(http://en.wikipedia.org/wiki/Cron) for this =)
>>>
>>>
>> Thanks for the quick response. Am planning to use a node.js based
>> scheduler. But my question is: is there a simpler way than creating a new
>> document just for tracking patients?
>>
>> thanks
>>
>
>
>
> --
> K Manokaran
> Chief Executive Officer
> MindPlough Analytics Pvt Ltd
> (SmartGrader is the flagship service of MindPlough)
> Mobile: +91 98400 88688

Mime
View raw message