|
2 | 2 |
|
3 | 3 | # issues an async request and inspects the resulting job |
4 | 4 |
|
5 | | -SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" |
6 | | -. "$SCRIPT_DIR/../util.sh" |
| 5 | +script_dir="$(dirname "$(readlink -f "$0")")" |
| 6 | +. "$script_dir/../util.sh" |
7 | 7 |
|
8 | 8 | if [[ "$OSTYPE" == "darwin"* ]]; then |
9 | 9 | DATE_CMD="gdate" |
10 | 10 | else |
11 | 11 | DATE_CMD="date" |
12 | 12 | fi |
13 | 13 |
|
14 | | -BASE="http://localhost:8080/fhir" |
15 | | -HEADERS=$(curl -s -H 'Prefer: respond-async' -H 'Accept: application/fhir+json' -o /dev/null -D - "$BASE/Observation?code=http://loinc.org|8310-5&_summary=count") |
16 | | -JOB_ID=$(echo "$HEADERS" | grep -i content-location | tr -d '\r' | cut -d '/' -f6) |
| 14 | +base="http://localhost:8080/fhir" |
| 15 | +headers=$(curl -s -H 'Prefer: respond-async' -H 'Accept: application/fhir+json' -o /dev/null -D - "$base/Observation?code=http://loinc.org|8310-5&_summary=count") |
| 16 | +job_id=$(echo "$headers" | grep -i content-location | tr -d '\r' | cut -d '/' -f6) |
17 | 17 |
|
18 | 18 | # wait to fetch the completed job |
19 | 19 | sleep 1 |
20 | | -JOB=$(curl -s -H 'Accept: application/fhir+json' "$BASE/__admin/Task/$JOB_ID") |
| 20 | +job=$(curl -s -H 'Accept: application/fhir+json' "$base/__admin/Task/$job_id") |
21 | 21 |
|
22 | | -test "profile URL" "$(echo "$JOB" | jq -r '.meta.profile[]')" "https://samply.github.io/blaze/fhir/StructureDefinition/AsyncInteractionJob" |
23 | | -test "status" "$(echo "$JOB" | jq -r '.status')" "completed" |
| 22 | +test "profile URL" "$(echo "$job" | jq -r '.meta.profile[]')" "https://samply.github.io/blaze/fhir/StructureDefinition/AsyncInteractionJob" |
| 23 | +test "status" "$(echo "$job" | jq -r '.status')" "completed" |
24 | 24 |
|
25 | | -AUTHORED_ON_ISO=$(echo "$JOB" | jq -r '.authoredOn') |
26 | | -AUTHORED_ON_EPOCH_SECONDS=$($DATE_CMD -d "$AUTHORED_ON_ISO" +%s) |
27 | | -NOW_EPOCH_SECONDS=$($DATE_CMD +%s) |
28 | | -if ((NOW_EPOCH_SECONDS - AUTHORED_ON_EPOCH_SECONDS < 10)); then |
| 25 | +authored_on_iso=$(echo "$job" | jq -r '.authoredOn') |
| 26 | +authored_on_epoch_seconds=$($DATE_CMD -d "$authored_on_iso" +%s) |
| 27 | +now_epoch_seconds=$($DATE_CMD +%s) |
| 28 | +if ((now_epoch_seconds - authored_on_epoch_seconds < 10)); then |
29 | 29 | echo "✅ the authoredOn dateTime is set and current" |
30 | 30 | else |
31 | | - echo "🆘 the authoredOn dateTime is $AUTHORED_ON_ISO, but should be a current dateTime" |
| 31 | + echo "🆘 the authoredOn dateTime is $authored_on_iso, but should be a current dateTime" |
32 | 32 | exit 1 |
33 | 33 | fi |
34 | 34 |
|
35 | | -PARAMETER_URI="https://samply.github.io/blaze/fhir/CodeSystem/AsyncInteractionJobParameter" |
| 35 | +parameter_uri="https://samply.github.io/blaze/fhir/CodeSystem/AsyncInteractionJobParameter" |
36 | 36 |
|
37 | 37 | input_expr() { |
38 | | - echo ".input[] | select(.type.coding[] | select(.system == \"$PARAMETER_URI\" and .code == \"$1\"))" |
| 38 | + echo ".input[] | select(.type.coding[] | select(.system == \"$parameter_uri\" and .code == \"$1\"))" |
39 | 39 | } |
40 | 40 |
|
41 | | -test "t" "$(echo "$JOB" | jq -r "$(input_expr "t") | .valueUnsignedInt")" "1" |
| 41 | +test "t" "$(echo "$job" | jq -r "$(input_expr "t") | .valueUnsignedInt")" "1" |
42 | 42 |
|
43 | | -OUTPUT_URI="https://samply.github.io/blaze/fhir/CodeSystem/AsyncInteractionJobOutput" |
| 43 | +output_uri="https://samply.github.io/blaze/fhir/CodeSystem/AsyncInteractionJobOutput" |
44 | 44 |
|
45 | 45 | output_expr() { |
46 | | - echo ".output[] | select(.type.coding[] | select(.system == \"$OUTPUT_URI\" and .code == \"$1\"))" |
| 46 | + echo ".output[] | select(.type.coding[] | select(.system == \"$output_uri\" and .code == \"$1\"))" |
47 | 47 | } |
48 | 48 |
|
49 | | -PROCESSING_DURATION="$(echo "$JOB" | jq "$(output_expr "processing-duration") | .valueQuantity")" |
50 | | -test "processing-duration unit system" "$(echo "$PROCESSING_DURATION" | jq -r .system)" "http://unitsofmeasure.org" |
51 | | -test "processing-duration unit code" "$(echo "$PROCESSING_DURATION" | jq -r .code)" "s" |
| 49 | +processing_duration="$(echo "$job" | jq "$(output_expr "processing-duration") | .valueQuantity")" |
| 50 | +test "processing-duration unit system" "$(echo "$processing_duration" | jq -r .system)" "http://unitsofmeasure.org" |
| 51 | +test "processing-duration unit code" "$(echo "$processing_duration" | jq -r .code)" "s" |
52 | 52 |
|
53 | 53 | # History |
54 | | -JOB_HISTORY=$(curl -s -H 'Accept: application/fhir+json' "$BASE/__admin/Task/$JOB_ID/_history") |
55 | | - |
56 | | -test "history resource type" "$(echo "$JOB_HISTORY" | jq -r '.resourceType')" "Bundle" |
57 | | -test "history bundle type" "$(echo "$JOB_HISTORY" | jq -r '.type')" "history" |
58 | | -test "history total" "$(echo "$JOB_HISTORY" | jq -r '.total')" "3" |
59 | | -test "history 0 status" "$(echo "$JOB_HISTORY" | jq -r '.entry[0].resource.status')" "completed" |
60 | | -test "history 1 status" "$(echo "$JOB_HISTORY" | jq -r '.entry[1].resource.status')" "in-progress" |
61 | | -test "history 2 status" "$(echo "$JOB_HISTORY" | jq -r '.entry[2].resource.status')" "ready" |
| 54 | +job_history=$(curl -s -H 'Accept: application/fhir+json' "$base/__admin/Task/$job_id/_history") |
| 55 | + |
| 56 | +test "history resource type" "$(echo "$job_history" | jq -r '.resourceType')" "Bundle" |
| 57 | +test "history bundle type" "$(echo "$job_history" | jq -r '.type')" "history" |
| 58 | +test "history total" "$(echo "$job_history" | jq -r '.total')" "3" |
| 59 | +test "history 0 status" "$(echo "$job_history" | jq -r '.entry[0].resource.status')" "completed" |
| 60 | +test "history 1 status" "$(echo "$job_history" | jq -r '.entry[1].resource.status')" "in-progress" |
| 61 | +test "history 2 status" "$(echo "$job_history" | jq -r '.entry[2].resource.status')" "ready" |
0 commit comments