Skip to content

Commit

Permalink
Implement the delete-history Command
Browse files Browse the repository at this point in the history
Closes: #1382
  • Loading branch information
alexanderkiel committed Sep 16, 2024
1 parent 3ec5807 commit 4018f3a
Show file tree
Hide file tree
Showing 84 changed files with 1,691 additions and 419 deletions.
4 changes: 2 additions & 2 deletions .github/scripts/admin-api/async-job.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ AUTHORED_ON_ISO=$(echo "$JOB" | jq -r '.authoredOn')
AUTHORED_ON_EPOCH_SECONDS=$($DATE_CMD -d "$AUTHORED_ON_ISO" +%s)
NOW_EPOCH_SECONDS=$($DATE_CMD +%s)
if ((NOW_EPOCH_SECONDS - AUTHORED_ON_EPOCH_SECONDS < 10)); then
echo "OK 👍: the authoredOn dateTime is set and current"
echo " the authoredOn dateTime is set and current"
else
echo "Fail 😞: the authoredOn dateTime is $AUTHORED_ON_ISO, but should be a current dateTime"
echo "🆘 the authoredOn dateTime is $AUTHORED_ON_ISO, but should be a current dateTime"
exit 1
fi

Expand Down
8 changes: 4 additions & 4 deletions .github/scripts/authenticated-request.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ fi
BASE="http://localhost:8080/fhir"

if [ "200" = "$(curl -s --oauth2-bearer "$ACCESS_TOKEN" -o /dev/null -w '%{response_code}' "$BASE")" ]; then
echo "OK 👍: successful authenticated system search request"
echo " successful authenticated system search request"
else
echo "Fail 😞: failed authenticated system search request"
echo "🆘 failed authenticated system search request"
exit 1
fi

if [ "200" = "$(curl -s --oauth2-bearer "$ACCESS_TOKEN" -H "Content-Type: application/fhir+json" -d @.github/openid-auth-test/batch-bundle.json "$BASE" | jq -r '.entry[].response.status')" ]; then
echo "OK 👍: successful authenticated batch request"
echo " successful authenticated batch request"
else
echo "Fail 😞: failed authenticated batch request"
echo "🆘 failed authenticated batch request"
exit 1
fi
16 changes: 8 additions & 8 deletions .github/scripts/batch-metadata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ RESULT=$(curl -sH "Content-Type: application/fhir+json" -d "$(bundle)" "$BASE")

RESOURCE_TYPE="$(echo "$RESULT" | jq -r .resourceType)"
if [ "$RESOURCE_TYPE" = "Bundle" ]; then
echo "OK 👍: the resource type is Bundle"
echo " the resource type is Bundle"
else
echo "Fail 😞: the resource type is $RESOURCE_TYPE, expected Bundle"
echo "🆘 the resource type is $RESOURCE_TYPE, expected Bundle"
exit 1
fi

BUNDLE_TYPE="$(echo "$RESULT" | jq -r .type)"
if [ "$BUNDLE_TYPE" = "batch-response" ]; then
echo "OK 👍: the bundle type is batch-response"
echo " the bundle type is batch-response"
else
echo "Fail 😞: the bundle type is $BUNDLE_TYPE, expected batch-response"
echo "🆘 the bundle type is $BUNDLE_TYPE, expected batch-response"
exit 1
fi

RESPONSE_STATUS="$(echo "$RESULT" | jq -r .entry[].response.status)"
if [ "$RESPONSE_STATUS" = "200" ]; then
echo "OK 👍: the response status is 200"
echo " the response status is 200"
else
echo "Fail 😞: the response status is $RESPONSE_STATUS, expected 200"
echo "🆘 the response status is $RESPONSE_STATUS, expected 200"
exit 1
fi

RESPONSE_RESOURCE_TYPE="$(echo "$RESULT" | jq -r .entry[].resource.resourceType)"
if [ "$RESPONSE_RESOURCE_TYPE" = "CapabilityStatement" ]; then
echo "OK 👍: resource type is CapabilityStatement"
echo " resource type is CapabilityStatement"
else
echo "Fail 😞: resource type was $RESPONSE_RESOURCE_TYPE but should be CapabilityStatement"
echo "🆘 resource type was $RESPONSE_RESOURCE_TYPE but should be CapabilityStatement"
exit 1
fi
16 changes: 8 additions & 8 deletions .github/scripts/batch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@ RESULT=$(curl -sH "Content-Type: application/fhir+json" -d "$(bundle)" "$BASE")

RESOURCE_TYPE="$(echo "$RESULT" | jq -r .resourceType)"
if [ "$RESOURCE_TYPE" = "Bundle" ]; then
echo "OK 👍: the resource type is Bundle"
echo " the resource type is Bundle"
else
echo "Fail 😞: the resource type is $RESOURCE_TYPE, expected Bundle"
echo "🆘 the resource type is $RESOURCE_TYPE, expected Bundle"
exit 1
fi

BUNDLE_TYPE="$(echo "$RESULT" | jq -r .type)"
if [ "$BUNDLE_TYPE" = "batch-response" ]; then
echo "OK 👍: the bundle type is batch-response"
echo " the bundle type is batch-response"
else
echo "Fail 😞: the bundle type is $BUNDLE_TYPE, expected batch-response"
echo "🆘 the bundle type is $BUNDLE_TYPE, expected batch-response"
exit 1
fi

RESPONSE_STATUS="$(echo "$RESULT" | jq -r .entry[].response.status)"
if [ "$RESPONSE_STATUS" = "200" ]; then
echo "OK 👍: the response status is 200"
echo " the response status is 200"
else
echo "Fail 😞: the response status is $RESPONSE_STATUS, expected 200"
echo "🆘 the response status is $RESPONSE_STATUS, expected 200"
exit 1
fi

RESPONSE_PATIENT_ID="$(echo "$RESULT" | jq -r .entry[].resource.id)"
if [ "$RESPONSE_PATIENT_ID" = "$PATIENT_ID" ]; then
echo "OK 👍: patient id's match"
echo " patient id's match"
else
echo "Fail 😞: response patient id was $RESPONSE_PATIENT_ID but should be $PATIENT_ID"
echo "🆘 response patient id was $RESPONSE_PATIENT_ID but should be $PATIENT_ID"
exit 1
fi
4 changes: 2 additions & 2 deletions .github/scripts/cancel-async.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test "after cancel issue code" "$(echo "$RESPONSE" | jq -r '.issue[0].code')" "n

DIAGNOSTICS="$(curl -s -H 'Accept: application/fhir+json' "$STATUS_URL" | jq -r '.issue[0].diagnostics')"
if [[ "$DIAGNOSTICS" =~ The\ asynchronous\ request\ with\ id\ \`[A-Z0-9]+\`\ is\ cancelled. ]]; then
echo "OK 👍: the diagnostics message is right"
echo " the diagnostics message is right"
else
echo "Fail 😞: the diagnostics message is $DIAGNOSTICS, expected /The asynchronous request with id \`[A-Z0-9]\+\` is cancelled./"
echo "🆘 the diagnostics message is $DIAGNOSTICS, expected /The asynchronous request with id \`[A-Z0-9]\+\` is cancelled./"
fi
4 changes: 2 additions & 2 deletions .github/scripts/chaining-without-referential-integrity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ curl -sXPUT -d '{"resourceType" : "Patient", "id": "0", "gender": "male"}' -H 'C
RESULT="$(curl -sH 'Prefer: handling=strict' -H 'Accept: application/fhir+json' "$BASE/Observation?patient.gender=male&_summary=count" | jq -r '.total')"

if [ "$RESULT" = "1" ]; then
echo "OK 👍: chaining works"
echo " chaining works"
else
echo "Fail 😞: chaining doesn't work"
echo "🆘 chaining doesn't work"
exit 1
fi
2 changes: 1 addition & 1 deletion .github/scripts/check-date-search.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ size() {
if [ "$DOWNLOAD_SIZE" = "$COUNT_SIZE" ]; then
echo "$DOWNLOAD_SIZE"
else
echo "Fail 😞: the download size is $DOWNLOAD_SIZE, expected $COUNT_SIZE"
echo "🆘 the download size is $DOWNLOAD_SIZE, expected $COUNT_SIZE"
exit 1
fi
}
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/check-referential-integrity-enforced.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ENFORCED=$(curl -s http://localhost:8080/fhir/metadata | jq -r 'isempty(.rest[].resource[].referencePolicy[] | select(. == "enforced")) | not')

if [ "true" = "$ENFORCED" ]; then
echo "OK 👍"
echo ""
else
echo "Fail 😞"
exit 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ENFORCED=$(curl -s http://localhost:8080/fhir/metadata | jq -r 'isempty(.rest[].resource[].referencePolicy[] | select(. == "enforced")) | not')

if [ "false" = "$ENFORCED" ]; then
echo "OK 👍"
echo ""
else
echo "Fail 😞"
exit 1
Expand Down
8 changes: 4 additions & 4 deletions .github/scripts/conditional-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ STATUS=$(curl -sH "Content-Type: application/fhir+json" \
-d "$(bundle)" "$BASE" | jq -r '.entry[].response.status')

if [ "$STATUS" = "201" ]; then
echo "OK 👍: first attempt created the Organization"
echo " first attempt created the Organization"
else
echo "Fail 😞: status was ${STATUS} but should be 201"
echo "🆘 status was ${STATUS} but should be 201"
exit 1
fi

STATUS=$(curl -sH "Content-Type: application/fhir+json" \
-d "$(bundle)" "$BASE" | jq -r '.entry[].response.status')

if [ "$STATUS" = "200" ]; then
echo "OK 👍: second attempt returned the already created Organization"
echo " second attempt returned the already created Organization"
else
echo "Fail 😞: status was ${STATUS} but should be 200"
echo "🆘 status was ${STATUS} but should be 200"
exit 1
fi
95 changes: 95 additions & 0 deletions .github/scripts/delete-history.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash -e

#
# This script does the following:
#
# * creates a patient
# * updates that patient to create a second version
# * expects the history to contain two entries
# * deletes the history of the patient
# * expects the history to contain only the current entry
# * expects a versioned read of the deleted history entry to return 404
# * expects the type history doesn't contain the deleted history entry
# * expects the system history doesn't contain the deleted history entry
#

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
. "$SCRIPT_DIR/util.sh"

BASE="http://localhost:8080/fhir"

patient() {
cat <<END
{
"resourceType": "Patient",
"id": "$1",
"gender": "$2"
}
END
}

create() {
curl -sfH "Content-Type: application/fhir+json" -d "{\"resourceType\": \"Patient\"}" "$BASE/Patient"
}

update() {
echo "▶️update patient"
curl -XPUT -sfH "Content-Type: application/fhir+json" -d @- -o /dev/null "$BASE/Patient/$1"
}

get_instance_history() {
curl -sH "Accept: application/fhir+json" "$BASE/Patient/$1/_history"
}

get_type_history() {
curl -sH "Accept: application/fhir+json" "$BASE/Patient/_history"
}

get_system_history() {
curl -sH "Accept: application/fhir+json" "$BASE/_history"
}

delete_history() {
echo "▶️delete history"
curl -XDELETE -sf -o /dev/null "$BASE/Patient/$1/_history"
}

vread() {
curl -sH "Accept: application/fhir+json" -w '%{response_code}' -o /dev/null "$BASE/Patient/$1/_history/$2"
}

echo "▶️create patient"
PATIENT_ID=$(create | jq -r '.id')

# update the patient to create a second version
patient "$PATIENT_ID" "male" | update "$PATIENT_ID"

# expect the history to contain two entries
HISTORY="$(get_instance_history "$PATIENT_ID")"
test "instance history total" "$(echo "$HISTORY" | jq -r .total)" "2"
ENTRY_1_VID="$(echo "$HISTORY" | jq -r '.entry[0].resource.meta.versionId')"
ENTRY_2_VID="$(echo "$HISTORY" | jq -r '.entry[1].resource.meta.versionId')"

# delete the history of the patient
delete_history "$PATIENT_ID"

# expect the history to contain only the current entry
HISTORY="$(get_instance_history "$PATIENT_ID")"
test "instance history total" "$(echo "$HISTORY" | jq -r .total)" "1"
test "instance history entry versionId" "$(echo "$HISTORY" | jq -r '.entry[0].resource.meta.versionId')" "$ENTRY_1_VID"
test "instance history entry gender" "$(echo "$HISTORY" | jq -r '.entry[0].resource.gender')" "male"

# expect a versioned read of the deleted history entry to return 404
test "read deleted history entry status code" "$(vread "$PATIENT_ID" "$ENTRY_2_VID")" "404"

# expect the type history doesn't contain the deleted history entry
HISTORY="$(get_type_history)"
test "type history first entry resource id" "$(echo "$HISTORY" | jq -r '.entry[0].resource.id')" "$PATIENT_ID"
test "type history first entry resource versionId" "$(echo "$HISTORY" | jq -r '.entry[0].resource.meta.versionId')" "$ENTRY_1_VID"
test_not_equal "type history second entry resource id" "$(echo "$HISTORY" | jq -r '.entry[1].resource.id')" "$PATIENT_ID"

# expect the system history doesn't contain the deleted history entry
HISTORY="$(get_system_history)"
test "system history first entry resource id" "$(echo "$HISTORY" | jq -r '.entry[0].resource.id')" "$PATIENT_ID"
test "system history first entry resource versionId" "$(echo "$HISTORY" | jq -r '.entry[0].resource.meta.versionId')" "$ENTRY_1_VID"
test_not_equal "system history second entry resource id" "$(echo "$HISTORY" | jq -r '.entry[1].resource.id')" "$PATIENT_ID"
20 changes: 10 additions & 10 deletions .github/scripts/delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,42 @@ PATIENT_HISTORY=$(curl -s "$BASE/Patient/$PATIENT_ID/_history")

TOTAL=$(echo "$PATIENT_HISTORY" | jq .total)
if [ "$TOTAL" = "1" ]; then
echo "OK 👍: patient history has one entry"
echo " patient history has one entry"
else
echo "Fail 😞: patient history has $TOTAL entries"
echo "🆘 patient history has $TOTAL entries"
exit 1
fi

METHOD=$(echo "$PATIENT_HISTORY" | jq -r .entry[].request.method)
if [ "$METHOD" = "DELETE" ]; then
echo "OK 👍: patient history entry has method DELETE"
echo " patient history entry has method DELETE"
else
echo "Fail 😞: patient history entry has method $METHOD"
echo "🆘 patient history entry has method $METHOD"
exit 1
fi

STATUS=$(echo "$PATIENT_HISTORY" | jq -r .entry[].response.status)
if [ "$STATUS" = "204" ]; then
echo "OK 👍: patient history entry has status 204"
echo " patient history entry has status 204"
else
echo "Fail 😞: patient history entry has status $STATUS"
echo "🆘 patient history entry has status $STATUS"
exit 1
fi

PATIENT_STATUS=$(curl -is "$BASE/Patient/$PATIENT_ID" -o /dev/null -w '%{response_code}')
if [ "$PATIENT_STATUS" = "410" ]; then
echo "OK 👍: patient status is HTTP/1.1 410 Gone"
echo " patient status is HTTP/1.1 410 Gone"
else
echo "Fail 😞: patient status is $PATIENT_STATUS"
echo "🆘 patient status is $PATIENT_STATUS"
exit 1
fi

PATIENT_OUTCOME=$(curl -s "$BASE/Patient/$PATIENT_ID")

CODE=$(echo "$PATIENT_OUTCOME" | jq -r .issue[].code)
if [ "$CODE" = "deleted" ]; then
echo "OK 👍: patient outcome has code deleted"
echo " patient outcome has code deleted"
else
echo "Fail 😞: patient outcome has code $CODE"
echo "🆘 patient outcome has code $CODE"
exit 1
fi
20 changes: 10 additions & 10 deletions .github/scripts/download-resources-query-sort.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ blazectl --no-progress --server "$BASE" download "$TYPE" -q "_sort=$SORT&$QUERY"

SIZE=$(wc -l "$FILE_NAME_PREFIX-get.ndjson" | xargs | cut -d ' ' -f1)
if [ "$EXPECTED_SIZE" = "$SIZE" ]; then
echo "OK 👍: download size matches for GET request"
echo " download size matches for GET request"
else
echo "Fail 😞: download size was ${SIZE} but should be ${EXPECTED_SIZE} for GET request"
echo "🆘 download size was ${SIZE} but should be ${EXPECTED_SIZE} for GET request"
rm "$FILE_NAME_PREFIX-get.ndjson"
exit 1
fi
Expand All @@ -22,19 +22,19 @@ blazectl --server "$BASE" download "$TYPE" -p -q "_sort=$SORT&$QUERY" -o "$FILE_

SIZE=$(wc -l "$FILE_NAME_PREFIX-post.ndjson" | xargs | cut -d ' ' -f1)
if [ "$EXPECTED_SIZE" = "$SIZE" ]; then
echo "OK 👍: download size matches for POST request"
echo " download size matches for POST request"
else
echo "Fail 😞: download size was ${SIZE} but should be ${EXPECTED_SIZE} for POST request"
echo "🆘 download size was ${SIZE} but should be ${EXPECTED_SIZE} for POST request"
rm "$FILE_NAME_PREFIX-get.ndjson"
rm "$FILE_NAME_PREFIX-post.ndjson"
exit 1
fi

if [ "$(diff "$FILE_NAME_PREFIX-get.ndjson" "$FILE_NAME_PREFIX-post.ndjson")" = "" ]; then
echo "OK 👍: both downloads are identical"
echo " both downloads are identical"
rm "$FILE_NAME_PREFIX-post.ndjson"
else
echo "Fail 😞: the GET and the POST download differ"
echo "🆘 the GET and the POST download differ"
rm "$FILE_NAME_PREFIX-get.ndjson"
rm "$FILE_NAME_PREFIX-post.ndjson"
exit 1
Expand All @@ -45,9 +45,9 @@ if [[ "$SORT" == "_id" ]]; then
IDS=$(cat "$FILE_NAME_PREFIX-get.ndjson" | jq -r '.id')
IDS_SORT=$(echo "$IDS" | sort)
if [ "$IDS" = "$IDS_SORT" ]; then
echo "OK 👍: resources are sorted by id"
echo " resources are sorted by id"
else
echo "Fail 😞: resources are not sorted by id"
echo "🆘 resources are not sorted by id"
exit 1
fi

Expand All @@ -63,9 +63,9 @@ elif [[ "$SORT" == "_lastUpdated" || "$SORT" == "-_lastUpdated" ]]; then
LAST_UPDATED_SORT=$(echo "$LAST_UPDATED" | sort)
fi
if [ "$LAST_UPDATED" = "$LAST_UPDATED_SORT" ]; then
echo "OK 👍: resources are sorted by lastUpdated"
echo " resources are sorted by lastUpdated"
else
echo "Fail 😞: resources are not sorted by lastUpdated"
echo "🆘 resources are not sorted by lastUpdated"
echo "$LAST_UPDATED"
exit 1
fi
Expand Down
Loading

0 comments on commit 4018f3a

Please sign in to comment.