Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6D8F4F602 for ; Mon, 1 Apr 2013 09:58:49 +0000 (UTC) Received: (qmail 69751 invoked by uid 500); 1 Apr 2013 09:58:48 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 69694 invoked by uid 500); 1 Apr 2013 09:58:47 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 69653 invoked by uid 99); 1 Apr 2013 09:58:47 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Apr 2013 09:58:47 +0000 Received: from localhost (HELO mail-la0-f45.google.com) (127.0.0.1) (smtp-auth username rnewson, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Apr 2013 09:58:46 +0000 Received: by mail-la0-f45.google.com with SMTP id er20so1986948lab.18 for ; Mon, 01 Apr 2013 02:58:44 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.130.129 with SMTP id oe1mr1731988lbb.69.1364810324646; Mon, 01 Apr 2013 02:58:44 -0700 (PDT) Received: by 10.112.25.201 with HTTP; Mon, 1 Apr 2013 02:58:44 -0700 (PDT) In-Reply-To: References: Date: Mon, 1 Apr 2013 10:58:44 +0100 Message-ID: Subject: Re: getting list of items spanning a time period From: Robert Newson To: "user@couchdb.apache.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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=3D["admitted", ]&endkey=3D["admitted", ]&reduce=3Dtrue ?startkey=3D["discharged", ]&endkey=3D["admitted", ]&reduce=3Dtrue ?startkey=3D["admitted"]&endkey=3D["admitted", ]&redu= ce=3Dtrue ?startkey=3D["discharged", ]&endkey=3D["discharged", {}]&reduce=3Dtrue 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 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 patien= t. > > > On Mon, Apr 1, 2013 at 3:15 PM, Manokaran K wrote: > >> >> On Mon, Apr 1, 2013 at 3:08 PM, =D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0= =BD=D0=B4=D1=80 =D0=9E=D0=BF=D0=B0=D0=BA wrote: >> >>> Use Cron(http://en.wikipedia.org/wiki/Cron) for this =3D) >>> >>> >> 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 ne= w >> 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