Skip to content

Commit

Permalink
script the generation of the examples/queries
Browse files Browse the repository at this point in the history
  • Loading branch information
declankieran committed Jan 31, 2024
1 parent a36d225 commit 0ab24e6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
13 changes: 2 additions & 11 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions input/queries/add-condition-transaction-example-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Patient?identifier=9912003888&_revinclude=Consent:patient&_revinclude=Flag:patient&_revinclude=Condition:patient
1 change: 1 addition & 0 deletions input/queries/add-condition-transaction-example-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Patient?identifier=9912003888&_revinclude=Consent:patient&_revinclude=Flag:patient&_revinclude=Condition:patient
1 change: 0 additions & 1 deletion input/queries/get-flags-associated-with-patient.md

This file was deleted.

40 changes: 40 additions & 0 deletions scripts/run-examples.sh
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 0ab24e6

Please sign in to comment.