-
Notifications
You must be signed in to change notification settings - Fork 20
/
create-maps.sh
executable file
·92 lines (68 loc) · 3.29 KB
/
create-maps.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
set -e
#this script assumes jq is installed See: https://stedolan.github.io/jq/download/
#this script assumes matchboxes is running on localhost at port 8080 See: https://github.com/ahdis/matchbox
#intended to be run after sushi has been run with contents in fsh-generated
### @host = http://localhost:8080/hapi-fhir-jpavalidator/fhir
### @host = http://test.ahdis.ch/hapi-fhir-jpavalidator/fhir
### @host = https://ehealthsuisse.ihe-europe.net/hapi-fhir-jpavalidator/fhir
#HOST="http://127.0.0.1:8080/matchbox/fhir"
#HOST="http://hapi.fhir.org/baseR4"
HOST="https://test.ahdis.ch/matchbox/fhir"
echo "Accessing $HOST/metadata"
### Get capability statement
#curl --request GET $HOST/metadata \
# -H "Accept: application/fhir+json"
#make sure all our structure definitions are loaded up
SDS=( "fsh-generated/resources/StructureDefinition-DDCCOrganization.json" "fsh-generated/resources/StructureDefinition-DDCCImmunizationRecommendation.json" "fsh-generated/resources/StructureDefinition-DDCCImmunization.json" "fsh-generated/resources/StructureDefinition-DDCCPatient.json" "fsh-generated/resources/StructureDefinition-DDCCEventBrand.json" "fsh-generated/resources/StructureDefinition-DDCCCountryOfEvent.json" "fsh-generated/resources/StructureDefinition-DDCCDocumentReferenceQR.json" "fsh-generated/resources/StructureDefinition-DDCCComposition.json" "fsh-generated/resources/StructureDefinition-DDCCCoreDataSet.VS.PoV.json" "fsh-generated/resources/StructureDefinition-DDCCCoreDataSet.VS.CoC.json" "input/resources/StructureDefinition-HC1.json" "input/resources/StructureDefinition-v.json" )
for SD in ${SDS[@]}
do
ID=$(jq -r '.id' $SD)
echo Loading $SD with $ID
curl -sS --request PUT $HOST/StructureDefinition/$ID \
--data-binary @$SD \
-H "Accept: application/fhir+json" -H "Content-Type: application/fhir+json"
done
#transform all fhir mapping language files in a maps-src directory to json structure maps in a maps directory
RDIR="input"
FILES=`ls $RDIR/maps-src/*.map`
SMAPS=( )
for FILE in $FILES
do
NAME=${FILE##*/}
NAME=${NAME%.*}
SMAP="$RDIR/resources/StructureMap-$NAME.json"
SMAPS+=($SMAP)
echo $NAME
echo "Creating StructureMap from FHIR Mapping Language in $FILE to $SMAP"
curl -sS --request PUT $HOST/StructureMap/$NAME \
--data-binary @$FILE \
-H "Accept: application/fhir+json" -H "Content-Type: text/fhir-mapping" \
> $SMAP
done
#transform all ddcc bundle examples with structure maps
EXDIR=$RDIR/resources
mkdir -p $EXDIR
DDCCS=("fsh-generated/resources/Bundle-Example-English.json")
SRC='DDCCDocument'
for SMAP in ${SMAPS[@]}
do
SRCTYPE=$(jq -r '.group[0].input[0].type' $SMAP)
TGTTYPE=$(jq -r '.group[0].input[1].type' $SMAP)
SMURL=$(jq -r '.url' $SMAP)
SMID=$(jq -r '.id' $SMAP)
for DDCC in ${DDCCS[@]}
do
SRCID=$(jq -r '.id' $DDCC)
OUT=$TGTTYPE-$SRCID-From-$SMID.json
if [ $SRCTYPE == $SRC ]; then
echo "Transforming $SRCID instance of $SRC to $TGTTYPE using $SMID"
echo $OUT
curl -sS --request POST "$HOST/StructureMap/\$transform?source=$SMURL" \
--data-binary @$DDCC \
-H "Accept: application/fhir+json" -H "Content-Type: application/fhir+json" \
> $EXDIR/$OUT
fi
done
done
# for SMAP in $SMAPS