|
| 1 | +// name the map and its canonical url |
1 | 2 | map "https://path-global-health.github.io/MERindicators/StructureMap/HIVObservationHIVCondition" = "HIVObservationHIVCondition"
|
2 | 3 |
|
3 |
| -uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias bund as source |
| 4 | +// declare the structure defs used |
| 5 | +uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias input as source |
4 | 6 | uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias output as target
|
5 | 7 |
|
6 | 8 |
|
7 |
| - |
| 9 | +// declare group with local vars (src, tgt) and their aliases |
| 10 | +// anything ending with semicolon is a rule |
8 | 11 | group HIVObservationHIVCondition(
|
9 |
| - source src: bund, |
| 12 | + source src: input, |
10 | 13 | target tgt: output
|
11 | 14 | ) {
|
| 15 | + // set bundle type for the output bundle |
| 16 | + src -> tgt.type = 'transaction' "setBundleType"; |
12 | 17 |
|
13 |
| - src -> tgt.type = 'collection' "setBundleType"; |
14 |
| - |
15 |
| - src.entry as entry -> tgt.entry as tentry then { |
16 |
| - entry.resource : Patient as patient -> tentry.resource = patient then { |
17 |
| - |
18 |
| - src.entry as obsentry where resource.is(Observation) and resource.subject.exists(reference=("Patient/" & patient.id)) and resource.code.exists(coding.exists(system='https://openconceptlab.org/orgs/CIEL/sources/CIEL' and code='160540')) |
19 |
| - -> tgt.entry as newentry, newentry.resource = create("Condition") as cond, uuid() as cid then { |
20 |
| - obsentry.resource as obs -> newentry.fullUrl = ( "urn:uuid:" & cid ) then { |
21 |
| - //obsentry -> newentry.resource = cond, cond.id = cid "setConditionRes"; |
| 18 | + // loop through patients in input bundle |
| 19 | + src.entry as entry -> tgt.entry as tentry |
| 20 | + then { |
| 21 | + entry.resource : Patient as patient -> tentry.resource = patient |
| 22 | + then { |
| 23 | + // for observations of that patient look for art program enrollment |
| 24 | + // create a condition resource in output with uuid |
| 25 | + src.entry as obsentry where resource.is(Observation) |
| 26 | + and resource.subject.exists(reference=("Patient/" & patient.id)) |
| 27 | + and resource.code.exists(coding.exists(system='https://openconceptlab.org/orgs/CIEL/sources/CIEL' and code='160540')) |
| 28 | + -> tgt.entry as newentry, newentry.resource = create("Condition") as cond, uuid() as cid |
| 29 | + then { |
| 30 | + obsentry.resource as obs -> newentry.fullUrl = ( "urn:uuid:" & cid ), |
| 31 | + // var for request bit of resources in transaction bundle |
| 32 | + newentry.request as newrequest |
| 33 | + then { |
22 | 34 | obsentry -> cond.id = cid "setCId";
|
23 |
| - patient -> cond.subject as subject then { |
| 35 | + // setrequest rule for resource in transaction bundle |
| 36 | + // needs to be processed properly before putting on existing data on fhir server |
| 37 | + obsentry -> newrequest.method = "PUT", newrequest.url = "Condition" "setrequest"; |
| 38 | + patient -> cond.subject as subject |
| 39 | + then { |
24 | 40 | patient -> subject.reference = reference(patient) "setSubjectRef";
|
25 | 41 | } "setSubject";
|
26 | 42 | obsentry.effective as effective -> cond.onset = effective "setOnset";
|
27 |
| - obsentry -> cond.code as ccode then { |
28 |
| - obsentry -> ccode.coding as coding then { |
| 43 | + obsentry -> cond.code as ccode |
| 44 | + then { |
| 45 | + obsentry -> ccode.coding as coding |
| 46 | + then { |
29 | 47 | obsentry -> coding.code = '86406008',
|
30 | 48 | coding.display = "HIV Condition Positive",
|
31 | 49 | coding.system = 'http://snomed.info/sct' "setCondSystemCode";
|
32 | 50 | } "setCondCoding";
|
33 | 51 | } "SetCondCode";
|
34 |
| - obs -> tgt.entry as pentry, pentry.resource = create("Provenance") as prov, uuid() as pid then { |
| 52 | + // create provenance resource to document input/output resources links |
| 53 | + obs -> tgt.entry as pentry, pentry.resource = create("Provenance") as prov, uuid() as pid, |
| 54 | + pentry.request as prequest |
| 55 | + then { |
35 | 56 | obs -> prov.id = pid "setPId";
|
36 | 57 | obs -> pentry.fullUrl = ( "urn:uuid:" & pid ) "setFullUrl";
|
37 |
| - obs -> prov.target as ptarg then { |
38 |
| - obs -> ptarg.reference = reference(cond) "setTargetRef"; |
| 58 | + obs -> prequest.method = "PUT", prequest.url = "Provenance" "setrequest"; |
| 59 | + obs -> prov.target as ptarg |
| 60 | + then { |
| 61 | + obs -> ptarg.reference = ( "urn:uuid:" & cid ) "setTargetRef"; |
39 | 62 | } "setTarget";
|
40 |
| - obs -> prov.entity as entity then { |
| 63 | + obs -> prov.entity as entity |
| 64 | + then { |
41 | 65 | obs -> entity.role = "source" "setRole";
|
42 |
| - obs -> entity.what as pwhat then { |
| 66 | + obs -> entity.what as pwhat |
| 67 | + then { |
43 | 68 | obs -> pwhat.reference = reference(obs) "setWhatRef";
|
44 | 69 | } "setWhat";
|
45 | 70 | } "setEntity";
|
|
0 commit comments