couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ken tashiro <presidenttash...@gmail.com>
Subject Re: how to use an included document's key?
Date Thu, 16 Apr 2015 06:17:51 GMT
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
View raw message