Skip to content

Commit

Permalink
Merge pull request #14 from PATH-Global-Health/fml-wip
Browse files Browse the repository at this point in the history
FHIR Mapping Language Tutorial
  • Loading branch information
citizenrich authored May 7, 2024
2 parents fa93019 + 4a7fa94 commit 8c1c342
Show file tree
Hide file tree
Showing 7 changed files with 646 additions and 0 deletions.
56 changes: 56 additions & 0 deletions input/maps/HIVObservationHIVCondition.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
### @host = http://localhost:8080/matchboxv3/fhir
@host = https://test.ahdis.ch/matchbox/fhir


### Convert FML to StructureMap
POST {{host}}/StructureMap/$convert HTTP/1.1
Content-Type: text/fhir-mapping
Accept: application/fhir+json


< ./HIVObservationHIVCondition.map


### Put it
PUT {{host}}/StructureMap/HIVObservationHIVCondition HTTP/1.1
Content-Type: application/fhir+json
Accept: application/fhir+JSON

< ./StructureMap-HIVObservationHIVCondition.json


# Or, just do this one...

### PUT FML to StructureMap (combined previous 2 steps in one)
PUT {{host}}/StructureMap/HIVObservationHIVCondition HTTP/1.1
Content-Type: text/fhir-mapping
Accept: application/fhir+json

< ./HIVObservationHIVCondition.map


# Then...


### Verify StructureMap is created
GET {{host}}/StructureMap/HIVObservationHIVCondition HTTP/1.1
Accept: application/fhir+JSON



### Transforms
POST {{host}}/StructureMap/$transform?source=https://path-global-health.github.io/MERindicators/StructureMap/HIVObservationHIVCondition
Accept: application/fhir+json;fhirVersion=4.0
Content-Type: application/fhir+json;fhirVersion=4.0

< ./test-data1.json



### Transforms
POST {{host}}/StructureMap/$transform?source=https://path-global-health.github.io/MERindicators/StructureMap/HIVObservationHIVCondition
Accept: application/fhir+json;fhirVersion=4.0
Content-Type: application/fhir+json;fhirVersion=4.0

< ./test-data2.json

53 changes: 53 additions & 0 deletions input/maps/HIVObservationHIVCondition.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
map "https://path-global-health.github.io/MERindicators/StructureMap/HIVObservationHIVCondition" = "HIVObservationHIVCondition"

uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias bund as source
uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias output as target



group HIVObservationHIVCondition(
source src: bund,
target tgt: output
) {

src -> tgt.type = 'collection' "setBundleType";

src.entry as entry -> tgt.entry as tentry then {
entry.resource : Patient as patient -> tentry.resource = patient then {

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'))
-> tgt.entry as newentry, newentry.resource = create("Condition") as cond, uuid() as cid then {
obsentry.resource as obs -> newentry.fullUrl = ( "urn:uuid:" & cid ) then {
//obsentry -> newentry.resource = cond, cond.id = cid "setConditionRes";
obsentry -> cond.id = cid "setCId";
patient -> cond.subject as subject then {
patient -> subject.reference = reference(patient) "setSubjectRef";
} "setSubject";
obsentry -> cond.code as ccode then {
obsentry -> ccode.coding as coding then {
obsentry -> coding.code = '86406008',
coding.display = "HIV Condition Positive",
coding.system = 'http://snomed.info/sct' "setCondSystemCode";
} "setCondCoding";
} "SetCondCode";
obs -> tgt.entry as pentry, pentry.resource = create("Provenance") as prov, uuid() as pid then {
obs -> prov.id = pid "setPId";
obs -> pentry.fullUrl = ( "urn:uuid:" & pid ) "setFullUrl";
obs -> prov.target as ptarg then {
obs -> ptarg.reference = reference(cond) "setTargetRef";
} "setTarget";
obs -> prov.entity as entity then {
obs -> entity.role = "source" "setRole";
obs -> entity.what as pwhat then {
obs -> pwhat.reference = reference(obs) "setWhatRef";
} "setWhat";
} "setEntity";
} "setProvenance";
} "setCondition";
} "getObservation";
} "patientResource";
} "copyPatient";

}


23 changes: 23 additions & 0 deletions input/maps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# How to use this folder

This folder is standalone and dependent on the IG it is in.

Follow the directions below then open `input/maps/HIVObservationHIVCondition.http` in VS Code. Click on:
* Convert FML to StructureMap and Put it or...
* PUT FML to StructureMap which combines the two operations. This converts FML (.map) files to FHIR StructureMaps and PUTs it on the server.
* Verify StructureMap is created
* Transform

The $transform operation will transform the bundle in the payload to an output bundle. In production, the returned bundle would be put on a FHIR server.

## Setup

* The operations use a publicly available server. Please setup a private server with the usual protections before transforming patient data. The open source server used here is the publicly available hosted [Matchbox](https://github.com/ahdis/matchbox) server which is a version of HAPI FHIR Server with additional operations. Standard HAPI FHIR JPA Server does not have the operations needed for this demo.

* Do not post real data. Please use the de-identified examples.

* Install REST Client if using VS Code. Otherwise, use an extension in other editors that can execute .http files.
[VS Marketplace](https://marketplace.visualstudio.com/items?itemName=humao.rest-client)

* It's recommended to install the FHIR Mapping Language extension if using VS Code [VS Marketplace](https://marketplace.visualstudio.com/items?itemName=HealexSystems.fhir-mapping-language-support)

30 changes: 30 additions & 0 deletions input/maps/_convert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

export HEADER1="content-type:application/fhir+json"
export HEADER2="content-type:text/fhir-mapping"
export ACCEPT="accept:application/fhir+json"

export FHIR="https://test.ahdis.ch/matchbox/fhir"
export CONVERT="${FHIR}/StructureMap/$convert"
export MAP="${FHIR}/StructureMap"

# curl --request POST -H 'accept: application/fhir+json' -H 'content-type: text/fhir-mapping' --data-binary @HIVObservationHIVCondition.map --url 'https://test.ahdis.ch/matchbox/fhir/StructureMap/$convert'

function convertput {
# curl -s -X POST -H ${ACCEPT} -H ${HEADER2} --data-binary @${1}.map --url ${CONVERT} | \
# curl -s -X PUT -H ${HEADER1} --data-binary @- --url "${MAP}/${1}" | \
# curl -s -X GET -H ${ACCEPT} --url "${MAP}/${1}" | \
# jq .

curl -s -X POST -H ${ACCEPT} -H ${HEADER2} --data-binary @${1}.map --url ${CONVERT} | jq . > StructureMap-${1}.json
printf "StructureMap created\n"

curl -s -X PUT -H ${HEADER1} --data-binary @StructureMap-${1}.json --url "${MAP}/${1}" | jq .
printf "StructureMap loaded on server\n"

curl -s -X GET -H ${ACCEPT} --url "${MAP}/${1}" | jq .
printf "Confirm StructureMap loaded on server\n"
}

convertput HIVObservationHIVCondition

25 changes: 25 additions & 0 deletions input/maps/_transform.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

export HEADER1="content-type:application/fhir+json"
export ACCEPT="accept:application/fhir+json"

export FHIR="https://test.ahdis.ch/matchbox/fhir"
export TRANSFORM="${FHIR}/StructureMap/${1}/$transform"



curl --request POST "https://test.ahdis.ch/matchbox/fhir/StructureMap/\$transform?source=https://path-global-health.github.io/MERindicators/StructureMap/HIVObservationHIVCondition" \
--data-binary @test-data1.json \
-H "Accept: application/fhir+json" -H "Content-Type: application/fhir+json"



# curl --request POST -H 'accept: application/fhir+json' -H 'content-type: text/fhir+json' --data-binary @test-data1.json --url 'https://test.ahdis.ch/matchbox/fhir/StructureMap/HIVObservationHIVCondition/$transform'

function transform {
curl -s -X POST -H ${ACCEPT} -H ${HEADER1} --data-binary @${2} --url ${TRANSFORM} | jq .
}

transform HIVObservationHIVCondition test-data1.json
# transform HIVObservationHIVCondition test-data2.json

Loading

0 comments on commit 8c1c342

Please sign in to comment.