|
| 1 | +#!/bin/bash -e |
| 2 | + |
| 3 | +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" |
| 4 | +. "$SCRIPT_DIR/util.sh" |
| 5 | + |
| 6 | +patient-valid-no-profile() { |
| 7 | +cat <<END |
| 8 | +{ |
| 9 | + "resourceType": "Patient" |
| 10 | +} |
| 11 | +END |
| 12 | +} |
| 13 | + |
| 14 | +patient-invalid-with-profile() { |
| 15 | +cat <<END |
| 16 | +{ |
| 17 | + "resourceType": "Patient", |
| 18 | + "meta": { |
| 19 | + "profile": "http://example.org/url-114730" |
| 20 | + } |
| 21 | +} |
| 22 | +END |
| 23 | +} |
| 24 | + |
| 25 | +patient-valid-with-profile() { |
| 26 | +cat <<END |
| 27 | +{ |
| 28 | + "resourceType": "Patient", |
| 29 | + "active": true, |
| 30 | + "meta": { |
| 31 | + "profile": "http://example.org/url-114730" |
| 32 | + } |
| 33 | +} |
| 34 | +END |
| 35 | +} |
| 36 | + |
| 37 | +patient-valid-with-profile-as-bundle() { |
| 38 | +cat <<END |
| 39 | +{ |
| 40 | + "resourceType": "Patient", |
| 41 | + "active": true, |
| 42 | + "meta": { |
| 43 | + "profile": "http://example.org/url-114730" |
| 44 | + } |
| 45 | +} |
| 46 | +END |
| 47 | +} |
| 48 | + |
| 49 | +bundle-valid-patient-with-profile() { |
| 50 | +cat <<END |
| 51 | +{ |
| 52 | + "resourceType": "Bundle", |
| 53 | + "type": "transaction", |
| 54 | + "entry": [ |
| 55 | + { |
| 56 | + "resource": $(patient-valid-with-profile), |
| 57 | + "request": { |
| 58 | + "method": "POST", |
| 59 | + "url": "/Patient" |
| 60 | + } |
| 61 | + } |
| 62 | + ] |
| 63 | +} |
| 64 | +END |
| 65 | +} |
| 66 | + |
| 67 | +structure-definition-patient() { |
| 68 | +cat <<END |
| 69 | +{ |
| 70 | + "resourceType": "StructureDefinition", |
| 71 | + "name": "Patient-profile-1", |
| 72 | + "status": "active", |
| 73 | + "kind": "resource", |
| 74 | + "abstract": false, |
| 75 | + "url": "http://example.org/url-114730", |
| 76 | + "type": "Patient", |
| 77 | + "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Patient", |
| 78 | + "derivation": "constraint", |
| 79 | + "differential": { |
| 80 | + "element": [ |
| 81 | + { |
| 82 | + "id": "patient-active-rule", |
| 83 | + "path": "Patient.active", |
| 84 | + "mustSupport": true, |
| 85 | + "min": 1 |
| 86 | + } |
| 87 | + ] |
| 88 | + } |
| 89 | +} |
| 90 | +END |
| 91 | +} |
| 92 | + |
| 93 | +BASE="http://localhost:8080/fhir" |
| 94 | + |
| 95 | +echo "1: testing before Patient profile created" |
| 96 | + |
| 97 | +echo "testing valid patient without profile" |
| 98 | +RESULT_NO_PROFILE=$(patient-valid-no-profile | curl -s -H 'Accept: application/fhir+json' -H "Content-Type: application/fhir+json" -d @- "$BASE/Patient") |
| 99 | +test "resource type" "$(echo "$RESULT_NO_PROFILE" | jq -r .resourceType)" "Patient" |
| 100 | + |
| 101 | +echo "testing invalid patient with profile" |
| 102 | +RESULT_INVALID_WITH_PROFILE=$(patient-invalid-with-profile | curl -s -H 'Accept: application/fhir+json' -H "Content-Type: application/fhir+json" -d @- "$BASE/Patient") |
| 103 | +test "resource type" "$(echo "$RESULT_INVALID_WITH_PROFILE" | jq -r .resourceType)" "OperationOutcome" |
| 104 | +test "issue diagnostics" "$(echo "$RESULT_INVALID_WITH_PROFILE" | jq -r .issue[0].diagnostics)" "Profile reference 'http://example.org/url-114730' has not been checked because it could not be found" |
| 105 | + |
| 106 | +echo "testing valid patient with profile" |
| 107 | +RESULT_VALID_WITH_PROFILE=$(patient-valid-with-profile | curl -s -H 'Accept: application/fhir+json' -H "Content-Type: application/fhir+json" -d @- "$BASE/Patient") |
| 108 | +test "resource type" "$(echo "$RESULT_VALID_WITH_PROFILE" | jq -r .resourceType)" "OperationOutcome" |
| 109 | +test "issue diagnostics" "$(echo "$RESULT_VALID_WITH_PROFILE" | jq -r .issue[0].diagnostics)" "Profile reference 'http://example.org/url-114730' has not been checked because it could not be found" |
| 110 | + |
| 111 | +echo "testing valid patient with profile as bundle" |
| 112 | +RESULT_BUNDLE_VALID_WITH_PROFILE=$(bundle-valid-patient-with-profile | curl -s -H 'Accept: application/fhir+json' -H "Content-Type: application/fhir+json" -d @- "$BASE") |
| 113 | +test "resource type" "$(echo "$RESULT_VALID_WITH_PROFILE" | jq -r .resourceType)" "OperationOutcome" |
| 114 | +test "issue diagnostics" "$(echo "$RESULT_VALID_WITH_PROFILE" | jq -r .issue[0].diagnostics)" "Profile reference 'http://example.org/url-114730' has not been checked because it could not be found" |
| 115 | + |
| 116 | +echo "2: creating the patient profile" |
| 117 | +RESULT_STRUCTURE_DEFINITION=$(structure-definition-patient | curl -s -H 'Accept: application/fhir+json' -H "Content-Type: application/fhir+json" -d @- "$BASE/StructureDefinition") |
| 118 | +test "resource type" "$(echo "$RESULT_STRUCTURE_DEFINITION" | jq -r .resourceType)" "StructureDefinition" |
| 119 | +STRUCTURE_DEFINITION_ID=$(echo "$RESULT_STRUCTURE_DEFINITION" | jq -r .id) |
| 120 | + |
| 121 | +sleep 1 |
| 122 | +echo "3: testing after Patient profile created" |
| 123 | +echo "testing valid patient without profile" |
| 124 | +RESULT_NO_PROFILE=$(patient-valid-no-profile | curl -s -H 'Accept: application/fhir+json' -H "Content-Type: application/fhir+json" -d @- "$BASE/Patient") |
| 125 | +test "resource type" "$(echo "$RESULT_NO_PROFILE" | jq -r .resourceType)" "Patient" |
| 126 | + |
| 127 | +echo "testing invalid patient with profile" |
| 128 | +RESULT_INVALID_WITH_PROFILE=$(patient-invalid-with-profile | curl -s -H 'Accept: application/fhir+json' -H "Content-Type: application/fhir+json" -d @- "$BASE/Patient") |
| 129 | +test "resource type" "$(echo "$RESULT_INVALID_WITH_PROFILE" | jq -r .resourceType)" "OperationOutcome" |
| 130 | +test "issue diagnostics" "$(echo "$RESULT_INVALID_WITH_PROFILE" | jq -r .issue[0].diagnostics)" "Patient.active: minimum required = 1, but only found 0 (from http://example.org/url-114730)" |
| 131 | + |
| 132 | +echo "testing valid patient with profile" |
| 133 | +RESULT_VALID_WITH_PROFILE=$(patient-valid-with-profile | curl -s -H 'Accept: application/fhir+json' -H "Content-Type: application/fhir+json" -d @- "$BASE/Patient") |
| 134 | +test "resource type" "$(echo "$RESULT_VALID_WITH_PROFILE" | jq -r .resourceType)" "Patient" |
| 135 | + |
| 136 | +echo "testing valid patient with profile as bundle" |
| 137 | +RESULT_BUNDLE_VALID_WITH_PROFILE=$(bundle-valid-patient-with-profile | curl -s -H 'Accept: application/fhir+json' -H "Content-Type: application/fhir+json" -d @- "$BASE") |
| 138 | +echo "$RESULT_BUNDLE_VALID_WITH_PROFILE" |
| 139 | +test "resource type" "$(echo "$RESULT_BUNDLE_VALID_WITH_PROFILE" | jq -r .resourceType)" "Bundle" |
| 140 | +test "response status" "$(echo "$RESULT_BUNDLE_VALID_WITH_PROFILE" | jq -r .entry[0].response.status)" "201" |
| 141 | + |
| 142 | +sleep 1 |
| 143 | +echo "4: deleting Patient profile and testing invalid again" |
| 144 | +RESULT_STRUCTURE_DEFINITION_DELETE=$(structure-definition-patient | curl -s -X DELETE -H 'Accept: application/fhir+json' -H "Content-Type: application/fhir+json" -d @- "$BASE/StructureDefinition/$STRUCTURE_DEFINITION_ID") |
| 145 | +test "delete response is empty" "$RESULT_STRUCTURE_DEFINITION_DELETE" "" |
| 146 | + |
| 147 | +echo "testing invalid patient with profile" |
| 148 | +RESULT_INVALID_WITH_PROFILE=$(patient-invalid-with-profile | curl -s -H 'Accept: application/fhir+json' -H "Content-Type: application/fhir+json" -d @- "$BASE/Patient") |
| 149 | +test "resource type" "$(echo "$RESULT_INVALID_WITH_PROFILE" | jq -r .resourceType)" "OperationOutcome" |
| 150 | +test "issue diagnostics" "$(echo "$RESULT_INVALID_WITH_PROFILE" | jq -r .issue[0].diagnostics)" "Profile reference 'http://example.org/url-114730' has not been checked because it could not be found" |
0 commit comments