couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Giovanni P <fiat...@gmail.com>
Subject Re: how to use an included document's key?
Date Thu, 16 Apr 2015 11:35:03 GMT
I don't know if I understood it correctly. Why would you need two queries
for fetching the current prescription and the last prescription? You can do
limit=2 and get the current and the last prescriptions at the same time.

But I suppose that your problem with the 2 queries is that you're doing one
query for fetching the patient document, with his basic information, and
then a query to check if it has prescriptions and what they are.

If so, you only need a view that emits

[patient_id, 1] -- patient document
[patient_id, 0, prescription_date] -- prescription document
[patient_id, 0, prescription_date] -- prescription document
[patient_id, 0, prescription_date] -- prescription document
[patient_id, 0, prescription_date] -- prescription document

For example. Then you can query this view with
?include_docs=true&descending=true and get all the data at once.

Sorry if I misunderstood your problem.

On Thu, Apr 16, 2015 at 3:17 AM, ken tashiro <presidenttashiro@gmail.com>
wrote:

> Thank you again, Giovanni.
>
> > Depending on what exactly you are doing, you could perhaps add
> everything as
> > one document, using update functions to prevent the roundtrip?
>
> I am a pharmacist in Japan, and trying to make a database of prescription.
> In Japan, almost 100% of all prescriptions are electrically processed with
> a common data format.But this format is revised every two years,so I chose
> a schema-free database.
>
> Since Japan has experienced several disasters, couchDB seems
> to be suitable for storing patient medical records.(when internet access is
> unavailable, store in a local couchDB, when available, replicate to cloud.)
>
> I want to manage information about the prescription such that
> "this drug is newly prescribed(phase=1)",
> "this drug is used continuously(phase=2)"
> or "this drug is NOT prescribed today but prescribed in the last
> prescription(phase=3)"
> and add to prescription data.
>
> So I made two map functions.
> First,
> key is  [pharmacy_code,patient_code,drug_code,date],
> value is phase,
> and descending=true and limit=1,
> If prescription is submitted, my program does this query for each drug.
> If phase =1 then add {"optional_information": {drug_code: {"phase":"2"} } }
> If phase =2 then add {"optional_information": {drug_code: {"phase":"2"} } }
> If phase =3 then add {"optional_information": {drug_code: {"phase":"1"} } }
> If result = null  then add {"optional_information": {drug_code:
> {"phase":"1"} } }
>
> Next,
> key is  [pharmacy_code,patient_code,prescriber_code,date],
> value is [drug_code],
> and descending=true and limit=1,
> If prescription is submitted, my program does this query once.
> If there is a drug prescribed in the last prescription but not in the
> current prescription, then add {"optional_information": {drug_code:
> {"phase":"3"} } }
>
> Now if I add the last prescription's document id in the current
> prescription's
> document (this needs one query anyway), I wonder if I can get the list of
> drugs
> in the last prescription without adding "optional_information",but it
> is impossible,
> instead I should learn using update function, am I correct?
>
> ken tashiro
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message