diff --git a/.github/scripts/batch.sh b/.github/scripts/batch.sh index a40c1f031..348981245 100755 --- a/.github/scripts/batch.sh +++ b/.github/scripts/batch.sh @@ -4,9 +4,10 @@ # This script creates a patient and tries to retrieve it through a batch request. # +BASE="http://localhost:8080/fhir" PATIENT_ID=$(curl -sH "Content-Type: application/fhir+json" \ -d '{"resourceType": "Patient"}' \ - "http://localhost:8080/fhir/Patient" | jq -r .id) + "$BASE/Patient" | jq -r .id) bundle() { cat < /dev/null +create-library "$LIBRARY_URI" "$DATA" | post "$BASE" "Library" > /dev/null -MEASURE_ID=$(create-measure "$MEASURE_URI" "$LIBRARY_URI" | post "Measure" | jq -r .id) -REPORT=$(evaluate-measure "$MEASURE_ID") +MEASURE_ID=$(create-measure "$MEASURE_URI" "$LIBRARY_URI" | post "$BASE" "Measure" | jq -r .id) +REPORT=$(evaluate-measure "$BASE" "$MEASURE_ID") COUNT=$(echo "$REPORT" | jq -r ".group[0].population[0].count") if [ "$COUNT" = "$EXPECTED_COUNT" ]; then @@ -129,7 +130,7 @@ else fi LIST_ID=$(echo "$REPORT" | jq -r '.group[0].population[0].subjectResults.reference | split("/")[1]') -PATIENT_BUNDLE=$(fetch-patients "$LIST_ID") +PATIENT_BUNDLE=$(fetch-patients "$BASE" "$LIST_ID") ID_COUNT=$(echo "$PATIENT_BUNDLE" | jq -r ".entry[].resource.id" | sort -u | wc -l | xargs | cut -d ' ' -f1) if [ "$ID_COUNT" = "$EXPECTED_COUNT" ]; then diff --git a/.github/scripts/evaluate-measure.sh b/.github/scripts/evaluate-measure.sh index 5e287d389..8244adaa9 100755 --- a/.github/scripts/evaluate-measure.sh +++ b/.github/scripts/evaluate-measure.sh @@ -73,13 +73,14 @@ create-measure() { } post() { - curl -sH "Content-Type: application/fhir+json" -d @- "http://localhost:8080/fhir/$1" + curl -sH "Content-Type: application/fhir+json" -d @- "$1/$2" } evaluate-measure() { - curl -s "http://localhost:8080/fhir/Measure/$1/\$evaluate-measure?periodStart=2000&periodEnd=2030" + curl -s "$1/Measure/$2/\$evaluate-measure?periodStart=2000&periodEnd=2030" } +BASE="http://localhost:8080/fhir" FILE=$1 EXPECTED_COUNT=$2 @@ -87,10 +88,10 @@ DATA=$(base64 "$FILE" | tr -d '\n') LIBRARY_URI=$(uuidgen | tr '[:upper:]' '[:lower:]') MEASURE_URI=$(uuidgen | tr '[:upper:]' '[:lower:]') -create-library "$LIBRARY_URI" "$DATA" | post "Library" > /dev/null +create-library "$LIBRARY_URI" "$DATA" | post "$BASE" "Library" > /dev/null -MEASURE_ID=$(create-measure "$MEASURE_URI" "$LIBRARY_URI" | post "Measure" | jq -r .id) -REPORT=$(evaluate-measure "$MEASURE_ID") +MEASURE_ID=$(create-measure "$MEASURE_URI" "$LIBRARY_URI" | post "$BASE" "Measure" | jq -r .id) +REPORT=$(evaluate-measure "$BASE" "$MEASURE_ID") COUNT=$(echo "$REPORT" | jq -r ".group[0].population[0].count") if [ "$COUNT" = "$EXPECTED_COUNT" ]; then diff --git a/.github/scripts/evaluate-patient-q1-measure.sh b/.github/scripts/evaluate-patient-q1-measure.sh index 5b48fe40b..076c9f9fd 100755 --- a/.github/scripts/evaluate-patient-q1-measure.sh +++ b/.github/scripts/evaluate-patient-q1-measure.sh @@ -68,24 +68,25 @@ create-measure() { } post() { - curl -sH "Content-Type: application/fhir+json" -d @- "http://localhost:8080/fhir/$1" + curl -sH "Content-Type: application/fhir+json" -d @- "$1/$2" } evaluate-measure() { - curl -s "http://localhost:8080/fhir/Measure/$1/\$evaluate-measure?periodStart=2000&periodEnd=2030&subject=$2" + curl -s "$1/Measure/$2/\$evaluate-measure?periodStart=2000&periodEnd=2030&subject=$3" } +BASE="http://localhost:8080/fhir" FILE="modules/operation-measure-evaluate-measure/test/blaze/fhir/operation/evaluate_measure/q1-query.cql" DATA=$(base64 "$FILE" | tr -d '\n') LIBRARY_URI=$(uuidgen | tr '[:upper:]' '[:lower:]') MEASURE_URI=$(uuidgen | tr '[:upper:]' '[:lower:]') -create-library "$LIBRARY_URI" "$DATA" | post "Library" > /dev/null +create-library "$LIBRARY_URI" "$DATA" | post "$BASE" "Library" > /dev/null -MEASURE_ID=$(create-measure "$MEASURE_URI" "$LIBRARY_URI" | post "Measure" | jq -r .id) +MEASURE_ID=$(create-measure "$MEASURE_URI" "$LIBRARY_URI" | post "$BASE" "Measure" | jq -r .id) -MALE_PATIENT_ID=$(curl -s 'http://localhost:8080/fhir/Patient?gender=male&_count=1' | jq -r '.entry[].resource.id') -COUNT=$(evaluate-measure "$MEASURE_ID" "$MALE_PATIENT_ID" | jq -r ".group[0].population[0].count") +MALE_PATIENT_ID=$(curl -s "$BASE/Patient?gender=male&_count=1" | jq -r '.entry[].resource.id') +COUNT=$(evaluate-measure "$BASE" "$MEASURE_ID" "$MALE_PATIENT_ID" | jq -r ".group[0].population[0].count") if [ "$COUNT" = "1" ]; then echo "Success: count ($COUNT) equals the expected count" else @@ -93,8 +94,8 @@ else exit 1 fi -FEMALE_PATIENT_ID=$(curl -s 'http://localhost:8080/fhir/Patient?gender=female&_count=1' | jq -r '.entry[].resource.id') -COUNT=$(evaluate-measure "$MEASURE_ID" "$FEMALE_PATIENT_ID" | jq -r ".group[0].population[0].count") +FEMALE_PATIENT_ID=$(curl -s "$BASE/Patient?gender=female&_count=1" | jq -r ".entry[].resource.id") +COUNT=$(evaluate-measure "$BASE" "$MEASURE_ID" "$FEMALE_PATIENT_ID" | jq -r ".group[0].population[0].count") if [ "$COUNT" = "0" ]; then echo "Success: count ($COUNT) equals the expected count" else diff --git a/.github/scripts/revinclude.sh b/.github/scripts/revinclude.sh index 333a7d3f7..c4ad7f0ff 100755 --- a/.github/scripts/revinclude.sh +++ b/.github/scripts/revinclude.sh @@ -1,11 +1,11 @@ #!/bin/bash -e -BASE=http://localhost:8080/fhir -EXPECTED_NUM_PATIENTS=$(curl -s "${BASE}/Patient?_summary=count" | jq -r .total) -EXPECTED_NUM_OBSERVATIONS=$(curl -s "${BASE}/Observation?_summary=count" | jq -r .total) -EXPECTED_NUM_CONDITIONS=$(curl -s "${BASE}/Condition?_summary=count" | jq -r .total) -EXPECTED_NUM_ENCOUNTERS=$(curl -s "${BASE}/Encounter?_summary=count" | jq -r .total) -EXPECTED_NUM_PROCEDURES=$(curl -s "${BASE}/Procedure?_summary=count" | jq -r .total) +BASE="http://localhost:8080/fhir" +EXPECTED_NUM_PATIENTS=$(curl -s "$BASE/Patient?_summary=count" | jq -r .total) +EXPECTED_NUM_OBSERVATIONS=$(curl -s "$BASE/Observation?_summary=count" | jq -r .total) +EXPECTED_NUM_CONDITIONS=$(curl -s "$BASE/Condition?_summary=count" | jq -r .total) +EXPECTED_NUM_ENCOUNTERS=$(curl -s "$BASE/Encounter?_summary=count" | jq -r .total) +EXPECTED_NUM_PROCEDURES=$(curl -s "$BASE/Procedure?_summary=count" | jq -r .total) blazectl --server $BASE download Patient -q '_revinclude=Observation:subject&_revinclude=Condition:subject&_revinclude=Procedure:subject&_revinclude=Encounter:subject' -o output.ndjson diff --git a/.github/scripts/search-compartment.sh b/.github/scripts/search-compartment.sh index 0328d188c..a718fd903 100755 --- a/.github/scripts/search-compartment.sh +++ b/.github/scripts/search-compartment.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -BASE=http://localhost:8080/fhir +BASE="http://localhost:8080/fhir" PATIENT_ID=$(curl -s "$BASE/Patient?identifier=http://hl7.org/fhir/sid/us-ssn|999-82-5655" | jq -r '.entry[].resource.id') OBSERVATION_COUNT=$(curl -s "$BASE/Patient/$PATIENT_ID/Observation?_summary=count" | jq .total) diff --git a/.github/scripts/search-observation-profile.sh b/.github/scripts/search-observation-profile.sh index 3a9d7e0e2..83c9d92c1 100755 --- a/.github/scripts/search-observation-profile.sh +++ b/.github/scripts/search-observation-profile.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -BASE=http://localhost:8080/fhir +BASE="http://localhost:8080/fhir" LAB_COUNT=$(curl -s "$BASE/Observation?_profile=http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab&_summary=count" | jq -r .total) if [ "$LAB_COUNT" = "27218" ]; then diff --git a/.github/scripts/search-patient-last-updated.sh b/.github/scripts/search-patient-last-updated.sh index c5c033d3e..b61c4c2bd 100755 --- a/.github/scripts/search-patient-last-updated.sh +++ b/.github/scripts/search-patient-last-updated.sh @@ -6,9 +6,9 @@ # The script assumes that Blaze contains at least some patients that were # imported before this script runs. -BASE=http://localhost:8080/fhir +BASE="http://localhost:8080/fhir" NOW=$(date +%Y-%m-%dT%H:%M:%S) -PATIENT_COUNT=$(curl -sH 'Prefer: handling=strict' "${BASE}/Patient?_lastUpdated=gt$NOW&_summary=count" | jq -r .total) +PATIENT_COUNT=$(curl -sH 'Prefer: handling=strict' "$BASE/Patient?_lastUpdated=gt$NOW&_summary=count" | jq -r .total) if [ $PATIENT_COUNT -eq 0 ]; then echo "Success: no patents are updated after $NOW" diff --git a/.github/scripts/transaction-rw.sh b/.github/scripts/transaction-rw.sh index c979a3e63..b36cb2093 100755 --- a/.github/scripts/transaction-rw.sh +++ b/.github/scripts/transaction-rw.sh @@ -4,6 +4,7 @@ # This script creates and reads a patient in a single transaction. # +BASE="http://localhost:8080/fhir" PATIENT_ID="e42a47bb-a371-4cf5-9f17-51e59c1f612a" bundle() { @@ -32,8 +33,7 @@ cat < handle type/type name (str "/" id)))) (defn- evaluate-stratum-expression [context subject-handle name] diff --git a/modules/operation-measure-evaluate-measure/test/blaze/fhir/operation/evaluate_measure/cql_test.clj b/modules/operation-measure-evaluate-measure/test/blaze/fhir/operation/evaluate_measure/cql_test.clj index 2a8ad8fa1..f82abc30d 100644 --- a/modules/operation-measure-evaluate-measure/test/blaze/fhir/operation/evaluate_measure/cql_test.clj +++ b/modules/operation-measure-evaluate-measure/test/blaze/fhir/operation/evaluate_measure/cql_test.clj @@ -108,6 +108,10 @@ (is (false? (cql/evaluate-individual-expression context patient "InInitialPopulation"))))))) +(def two-value-eval + (fn [_ _ _] ["1" "2"])) + + (deftest calc-strata-test (testing "failing eval" (with-system-data [{:blaze.db/keys [node] :blaze.test/keys [clock]} @@ -121,7 +125,21 @@ (with-redefs [expr/eval (failing-eval "msg-221825")] (given (cql/calc-strata context "" "") ::anom/category := ::anom/fault - ::anom/message := "msg-221825")))))) + ::anom/message := "msg-221825"))))) + + (testing "multiple values" + (with-system-data [{:blaze.db/keys [node] :blaze.test/keys [clock]} + mem-node-system] + [[[:put {:fhir/type :fhir/Patient :id "0"}]]] + (let [context {:db (d/db node) + :now (now clock) + :library (compile-library node) + :subject-type "Patient" + :report-type "population"}] + (with-redefs [expr/eval two-value-eval] + (given (cql/calc-strata context "" "expr-133506") + ::anom/category := ::anom/incorrect + ::anom/message := "CQL expression `expr-133506` returned more than one value for resource `Patient/0`.")))))) (deftest calc-individual-strata-test diff --git a/modules/rest-api/src/blaze/rest_api/capabilities.clj b/modules/rest-api/src/blaze/rest_api/capabilities.clj index bc8e55ee7..199d78681 100644 --- a/modules/rest-api/src/blaze/rest_api/capabilities.clj +++ b/modules/rest-api/src/blaze/rest_api/capabilities.clj @@ -108,7 +108,7 @@ :copyright #fhir/markdown"Copyright 2019 - 2021 The Samply Community\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." :kind #fhir/code"instance" - :date #fhir/dateTime"2021-11-26" + :date #fhir/dateTime"2021-11-30" :software {:name "Blaze" :version version} diff --git a/perf-test/gatling/pom.xml b/perf-test/gatling/pom.xml index b29d7a627..50e74a5af 100644 --- a/perf-test/gatling/pom.xml +++ b/perf-test/gatling/pom.xml @@ -5,7 +5,7 @@ samply.blaze gatling - 0.13.3 + 0.13.4 1.8 diff --git a/pom.xml b/pom.xml index cfd753f8a..071b2ed10 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 samply blaze - 0.13.3 + 0.13.4 blaze A FHIR Store with internal, fast CQL Evaluation Engine diff --git a/src/blaze/handler/health.clj b/src/blaze/handler/health.clj index 56b776500..0c4329051 100644 --- a/src/blaze/handler/health.clj +++ b/src/blaze/handler/health.clj @@ -1,16 +1,18 @@ (ns blaze.handler.health (:require + [blaze.async.comp :as ac] [integrant.core :as ig] [ring.util.response :as ring] [taoensso.timbre :as log])) -(defn- handler [_] +(def ^:private response (-> (ring/response "OK") - (ring/content-type "text/plain"))) + (ring/content-type "text/plain") + (ac/completed-future))) (defmethod ig/init-key :blaze.handler/health [_ _] (log/info "Init health handler") - handler) + (constantly response)) diff --git a/src/blaze/system.clj b/src/blaze/system.clj index 53a2724ce..0e763b4ea 100644 --- a/src/blaze/system.clj +++ b/src/blaze/system.clj @@ -87,7 +87,7 @@ (def ^:private root-config - {:blaze/version "0.13.3" + {:blaze/version "0.13.4" :blaze/clock {} diff --git a/test/blaze/handler/health_test.clj b/test/blaze/handler/health_test.clj new file mode 100644 index 000000000..d20002bee --- /dev/null +++ b/test/blaze/handler/health_test.clj @@ -0,0 +1,32 @@ +(ns blaze.handler.health-test + (:require + [blaze.handler.health] + [blaze.test-util :refer [with-system]] + [clojure.spec.test.alpha :as st] + [clojure.test :as test :refer [deftest]] + [juxt.iota :refer [given]] + [taoensso.timbre :as log])) + + +(st/instrument) +(log/set-level! :trace) + + +(defn- fixture [f] + (st/instrument) + (f) + (st/unstrument)) + + +(test/use-fixtures :each fixture) + + +(def system + {:blaze.handler/health {}}) + + +(deftest handler-test + (with-system [{handler :blaze.handler/health} system] + (given @(handler {}) + :status := 200 + :body := "OK")))