Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
|||
# objectify/1 takes an array of atomic values as inputs, and packages
|
||||
# these into an object with keys specified by the "headers" array and
|
||||
# values obtained by trimming string values, replacing empty strings
|
||||
# by null, and converting strings to numbers if possible.
|
||||
def objectify(headers):
|
||||
def tonumberq: tonumber? // .;
|
||||
def trimq: if type == "string" then sub("^ +";"") | sub(" +$";"") else . end;
|
||||
def tonullq: if . == "" then null else . end;
|
||||
. as $in
|
||||
| reduce range(0; headers|length) as $i
|
||||
({}; .[headers[$i]] = ($in[$i] | trimq | tonumberq | tonullq) );
|
||||
|
||||
def csv2jsonHelper:
|
||||
.[0] as $headers
|
||||
| reduce (.[1:][] | select(length > 0) ) as $row
|
||||
([]; . + [ $row|objectify($headers) ]);
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# output {LAST_VISIT}
|
||||
def LAST_VISIT($patient_id):
|
||||
{LAST_VISIT: (map(select( .PATIENT_ID == $patient_id).VISIT_DATE) | max)};
|
||||
|
||||
# output {SCORE_SUM, SCORE_AVG}
|
||||
def SCORE_SUMMARY($patient_id):
|
||||
map(select( .PATIENT_ID == $patient_id).SCORE)
|
||||
| {SCORE_SUM: add, count: length}
|
||||
| {SCORE_SUM, SCORE_AVG: (if .SCORE_SUM and .count > 0 then .SCORE_SUM/.count else null end)};
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
# Read the two tables:
|
||||
INDEX($patients | [splits("\n")] | map(split(",")) | csv2jsonHelper[]; .PATIENT_ID) as $patients
|
||||
| ($visits | [splits("\n")] | map(split(",")) | csv2jsonHelper) as $visits
|
||||
# Construct the new table:
|
||||
| $visits
|
||||
| map(.PATIENT_ID as $PATIENT_ID
|
||||
| {$PATIENT_ID} +
|
||||
($visits | {LASTNAME: $patients[$PATIENT_ID|tostring]} + LAST_VISIT($PATIENT_ID) + SCORE_SUMMARY($PATIENT_ID)))
|
||||
# ... but display it as a sequence of JSON objects
|
||||
| .[]
|
||||
Loading…
Add table
Add a link
Reference in a new issue