diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d3d15b7..a54283b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -43,17 +43,8 @@ jobs: - name: Sleep to give server time to start run: sleep 90 - - name: Load add-condition-transaction-example-1 - run: curl -X POST -H "Content-type:application/fhir+json;fhirVersion=4.0" -d @fsh-generated/resources/Bundle-add-condition-transaction-example-1.json http://localhost:8080/fhir; - - - name: Query add-condition-transaction-example-1 - run: sleep 10; curl $(cat input/queries/get-flags-associated-with-patient.md) | jq '.id = "QUERY-OUTPUT--add-condition-transaction-example-1"' > input/resources/QUERY-OUTPUT--add-condition-transaction-example-1.json - - - name: Load add-condition-transaction-example-2 - run: curl -X POST -H "Content-type:application/fhir+json;fhirVersion=4.0" -d @fsh-generated/resources/Bundle-add-condition-transaction-example-2.json http://localhost:8080/fhir; \ - - - name: Query add-condition-transaction-example-2 - run: sleep 10; curl $(cat input/queries/get-flags-associated-with-patient.md) | jq '.id = "QUERY-OUTPUT--add-condition-transaction-example-2"' > input/resources/QUERY-OUTPUT--add-condition-transaction-example-2.json + - name: Load examples and run queries to be added to IG + run: ./scripts/run-examples.sh - name: Build IG run: ./_genonce.sh diff --git a/input/queries/add-condition-transaction-example-1.md b/input/queries/add-condition-transaction-example-1.md new file mode 100644 index 0000000..0108957 --- /dev/null +++ b/input/queries/add-condition-transaction-example-1.md @@ -0,0 +1 @@ +Patient?identifier=9912003888&_revinclude=Consent:patient&_revinclude=Flag:patient&_revinclude=Condition:patient diff --git a/input/queries/add-condition-transaction-example-2.md b/input/queries/add-condition-transaction-example-2.md new file mode 100644 index 0000000..0108957 --- /dev/null +++ b/input/queries/add-condition-transaction-example-2.md @@ -0,0 +1 @@ +Patient?identifier=9912003888&_revinclude=Consent:patient&_revinclude=Flag:patient&_revinclude=Condition:patient diff --git a/input/queries/get-flags-associated-with-patient.md b/input/queries/get-flags-associated-with-patient.md deleted file mode 100644 index 43b564b..0000000 --- a/input/queries/get-flags-associated-with-patient.md +++ /dev/null @@ -1 +0,0 @@ -http://localhost:8080/fhir/Patient?identifier=9912003888&_revinclude=Consent:patient&_revinclude=Flag:patient&_revinclude=Condition:patient \ No newline at end of file diff --git a/scripts/run-examples.sh b/scripts/run-examples.sh new file mode 100755 index 0000000..01c45e9 --- /dev/null +++ b/scripts/run-examples.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# TODO The order of the examples may be important depending on the queries. Would there be a tidy way of chaining them and makes the depedancies +# clear, explicit and useful in the guidance? +# Probably makes more sense just to describe the queries and add output in statically, rather trying to combine integrations testing +# into the build of the IG. See if it serves as a useful example... + +SERVER_BASE="http://localhost:8080/fhir/" +HEADERS="Content-type:application/fhir+json;fhirVersion=4.0" + +# TODO - Make the script runnable from any path +SCRIPT_ROOT=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ); + +for EXAMPLE in ./input/fsh/examples/*; do + + # Get the filename from the path + EXAMPLE=$(echo $EXAMPLE | awk -F '/' '{print $5}'); + + # This relies on SUSHI having been ran to generate JSON representations of the resources. + GENERATED=$(echo ./fsh-generated/resources/*${EXAMPLE%.*}*); + + # Sushi will prepend the name of the Resource, which will be used in the server calls. + RESOURCE_NAME=$(echo $GENERATED | awk -F '/' '{print $4}' | awk -F '-' '{print $1}'); + + # Assumption here that Bundle examples will be transactions, guessing it'll fail if not... + # Set RESOURCE_NAME to empty string so post is made to the base server url. + if [ "$RESOURCE_NAME" == "Bundle" ]; then + RESOURCE_NAME="" + fi; + + # Post the resource + curl -X POST -H $HEADERS -d @${GENERATED} $SERVER_BASE$RESOURCE_NAME; + + # Filename of query (minus extension) must match the filename of the example posted. + QUERY=$(cat ./input/queries/${EXAMPLE%.*}*); + + # Run corresponding query, change the ID of the bundle to something readable and output to resources in input to be included in IG build + curl $SERVER_BASE$QUERY | jq '.id = "QUERY-OUTPUT--'${EXAMPLE%.*}'"' > ./input/resources/QUERY-OUTPUT--${EXAMPLE%.*}.json + +done; \ No newline at end of file