Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include System Operations in the Capability Statement #2424

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/scripts/check-capability-statement.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ test "format" "$(echo "$CAPABILITY_STATEMENT" | jq -r '.format | join(",")')" "a
test "Operation Measure \$evaluate-measure Definition" "$(echo "$CAPABILITY_STATEMENT" | jq -r '.rest[0].resource[] | select(.type == "Measure") .operation[] | select(.name == "evaluate-measure") | .definition')" "http://hl7.org/fhir/OperationDefinition/Measure-evaluate-measure"
test "Operation Patient \$everything Definition" "$(echo "$CAPABILITY_STATEMENT" | jq -r '.rest[0].resource[] | select(.type == "Patient") .operation[] | select(.name == "everything") | .definition')" "http://hl7.org/fhir/OperationDefinition/Patient-everything"
test "Operation Patient \$everything Documentation" "$(echo "$CAPABILITY_STATEMENT" | jq -r '.rest[0].resource[] | select(.type == "Patient") .operation[] | select(.name == "everything") | .documentation')" "Returns all resources from the patient compartment of one concrete patient including the patient. Has a fix limit of 10,000 resources if paging isn't used. Paging is supported when the _count parameter is used. No other params are supported."

test "Operation \$totals Documentation" "$(echo "$CAPABILITY_STATEMENT" | jq -r '.rest[0].operation[] | select(.name == "totals") | .documentation')" "Retrieves the total counts of resources available by resource type."
168 changes: 91 additions & 77 deletions modules/rest-api/src/blaze/rest_api/capabilities_handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -137,79 +137,93 @@
structure-definition-repo
search-system-handler
transaction-handler-active?
history-system-handler]
history-system-handler
operations]
:as config}]
{:fhir/type :fhir/CapabilityStatement
:status #fhir/code"active"
:experimental false
:publisher "The Samply Community"
:copyright copyright
:kind #fhir/code"instance"
:date (type/dateTime release-date)
:software
{:name "Blaze"
:version version
:releaseDate (type/dateTime release-date)}
:implementation
{:description "Blaze"}
:fhirVersion #fhir/code"4.0.1"
:format
[#fhir/code"application/fhir+json"
#fhir/code"application/fhir+xml"]
:rest
[{:mode #fhir/code"server"
:resource
(into
[]
(keep (partial capability-resource config))
(sdr/resources structure-definition-repo))
:interaction
(cond-> []
(some? search-system-handler)
(conj {:code #fhir/code"search-system"})
(some? transaction-handler-active?)
(conj {:code #fhir/code"transaction"} {:code #fhir/code"batch"})
(some? history-system-handler)
(conj {:code #fhir/code"history-system"}))
:searchParam
[{:name "_id"
:type "token"
:definition "http://hl7.org/fhir/SearchParameter/Resource-id"}
{:name "_lastUpdated"
:type "date"
:definition "http://hl7.org/fhir/SearchParameter/Resource-lastUpdated"}
{:name "_profile"
:type "uri"
:definition "http://hl7.org/fhir/SearchParameter/Resource-profile"}
{:name "_security"
:type "token"
:definition "http://hl7.org/fhir/SearchParameter/Resource-security"}
{:name "_source"
:type "uri"
:definition "http://hl7.org/fhir/SearchParameter/Resource-source"}
{:name "_tag"
:type "token"
:definition "http://hl7.org/fhir/SearchParameter/Resource-tag"}
{:name "_list"
:type "special"}
{:name "_has"
:type "special"}
{:name "_include"
:type "special"}
{:name "_revinclude"
:type "special"}
{:name "_count"
:type "number"
:documentation "The number of resources returned per page"}
{:name "_elements"
:type "special"}
{:name "_sort"
:type "special"
:documentation "Only `_id`, `_lastUpdated` and `-_lastUpdated` are supported at the moment."}
{:name "_summary"
:type "token"
:documentation "Only `count` is supported at the moment."}]
:compartment ["http://hl7.org/fhir/CompartmentDefinition/patient"]}]})
(let [operations (into
[]
(keep
(fn [{:blaze.rest-api.operation/keys
[code def-uri system-handler documentation]}]
(when system-handler
(cond-> {:name code
:definition (type/canonical def-uri)}
documentation
(assoc :documentation (type/->Markdown documentation))))))
operations)]
{:fhir/type :fhir/CapabilityStatement
:status #fhir/code"active"
:experimental false
:publisher "The Samply Community"
:copyright copyright
:kind #fhir/code"instance"
:date (type/dateTime release-date)
:software
{:name "Blaze"
:version version
:releaseDate (type/dateTime release-date)}
:implementation
{:description "Blaze"}
:fhirVersion #fhir/code"4.0.1"
:format
[#fhir/code"application/fhir+json"
#fhir/code"application/fhir+xml"]
:rest
[(cond->
{:mode #fhir/code"server"
:resource
(into
[]
(keep (partial capability-resource config))
(sdr/resources structure-definition-repo))
:interaction
(cond-> []
(some? search-system-handler)
(conj {:code #fhir/code"search-system"})
(some? transaction-handler-active?)
(conj {:code #fhir/code"transaction"} {:code #fhir/code"batch"})
(some? history-system-handler)
(conj {:code #fhir/code"history-system"}))
:searchParam
[{:name "_id"
:type "token"
:definition "http://hl7.org/fhir/SearchParameter/Resource-id"}
{:name "_lastUpdated"
:type "date"
:definition "http://hl7.org/fhir/SearchParameter/Resource-lastUpdated"}
{:name "_profile"
:type "uri"
:definition "http://hl7.org/fhir/SearchParameter/Resource-profile"}
{:name "_security"
:type "token"
:definition "http://hl7.org/fhir/SearchParameter/Resource-security"}
{:name "_source"
:type "uri"
:definition "http://hl7.org/fhir/SearchParameter/Resource-source"}
{:name "_tag"
:type "token"
:definition "http://hl7.org/fhir/SearchParameter/Resource-tag"}
{:name "_list"
:type "special"}
{:name "_has"
:type "special"}
{:name "_include"
:type "special"}
{:name "_revinclude"
:type "special"}
{:name "_count"
:type "number"
:documentation "The number of resources returned per page"}
{:name "_elements"
:type "special"}
{:name "_sort"
:type "special"
:documentation "Only `_id`, `_lastUpdated` and `-_lastUpdated` are supported at the moment."}
{:name "_summary"
:type "token"
:documentation "Only `count` is supported at the moment."}]
:compartment ["http://hl7.org/fhir/CompartmentDefinition/patient"]}
(seq operations) (assoc :operation operations))]}))

(defn- build-terminology-capabilities-base
[{:keys [version release-date]}]
Expand Down Expand Up @@ -280,11 +294,11 @@
:blaze.db/search-param-registry]
:opt-un
[:blaze/context-path
::search-system-handler
::transaction-handler-active?
::history-system-handler
::resource-patterns
::operations
::rest-api/search-system-handler
::rest-api/transaction-handler-active?
::rest-api/history-system-handler
::rest-api/resource-patterns
::rest-api/operations
:blaze.db/enforce-referential-integrity
:blaze.db/allow-multiple-delete
:blaze/terminology-service]))
Expand Down
3 changes: 3 additions & 0 deletions modules/rest-api/src/blaze/rest_api/spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
(s/def ::rest-api/transaction-handler
fn?)

(s/def ::rest-api/transaction-handler-active?
boolean?)

(s/def ::rest-api/history-system-handler
fn?)

Expand Down
72 changes: 64 additions & 8 deletions modules/rest-api/test/blaze/rest_api/capabilities_handler_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@

(def ^:private minimal-search-system-config
(assoc-in minimal-config [::rest-api/capabilities-handler :search-system-handler]
::search-system))
(fn [_])))

(deftest minimal-search-system-config-test
(with-handler [handler minimal-search-system-config]
Expand All @@ -228,7 +228,7 @@

(def ^:private minimal-history-system-config
(assoc-in minimal-config [::rest-api/capabilities-handler :history-system-handler]
::history-system))
(fn [_])))

(deftest minimal-history-system-config-test
(with-handler [handler minimal-history-system-config]
Expand Down Expand Up @@ -319,7 +319,7 @@
[:rest 0 :resource 0 :searchParam (search-param "value-quantity") :documentation]
:= #fhir/markdown"Decimal values are truncated at two digits after the decimal point.")))

(def ^:private one-operation-config
(def ^:private one-type-operation-config
(update minimal-config ::rest-api/capabilities-handler assoc
:resource-patterns
[#:blaze.rest-api.resource-pattern
Expand All @@ -337,16 +337,16 @@
:type-handler (fn [_])
:instance-handler (fn [_])}]))

(deftest one-operation-test
(with-handler [handler one-operation-config]
(deftest one-type-operation-test
(with-handler [handler one-type-operation-config]
(given (:body @(handler {}))
:fhir/type := :fhir/CapabilityStatement
[:rest 0 :resource 0 :type] := #fhir/code"Measure"
[:rest 0 :resource 0 :operation 0 :name] := "evaluate-measure"
[:rest 0 :resource 0 :operation 0 :definition] :=
#fhir/canonical"http://hl7.org/fhir/OperationDefinition/Measure-evaluate-measure")))

(def ^:private one-operation-documentation-config
(def ^:private one-type-operation-documentation-config
(update minimal-config ::rest-api/capabilities-handler assoc
:resource-patterns
[#:blaze.rest-api.resource-pattern
Expand All @@ -365,8 +365,8 @@
:instance-handler (fn [_])
:documentation "documentation-161800"}]))

(deftest one-operation-documentation-test
(with-handler [handler one-operation-documentation-config]
(deftest one-type-operation-documentation-test
(with-handler [handler one-type-operation-documentation-config]
(given (:body @(handler {}))
:fhir/type := :fhir/CapabilityStatement
[:rest 0 :resource 0 :type] := #fhir/code"Measure"
Expand All @@ -375,6 +375,62 @@
#fhir/canonical"http://hl7.org/fhir/OperationDefinition/Measure-evaluate-measure"
[:rest 0 :resource 0 :operation 0 :documentation] := #fhir/markdown"documentation-161800")))

(def ^:private one-system-operation-config
(update minimal-config ::rest-api/capabilities-handler assoc
:operations
[#:blaze.rest-api.operation
{:code "totals"
:def-uri "https://samply.github.io/blaze/fhir/OperationDefinition/totals"
:affects-state false
:resource-types ["Resource"]
:system-handler (fn [_])}
#:blaze.rest-api.operation
{:code "evaluate-measure"
:def-uri
"http://hl7.org/fhir/OperationDefinition/Measure-evaluate-measure"
:resource-types ["Measure"]
:type-handler (fn [_])
:instance-handler (fn [_])
:documentation "documentation-161800"}]))

(deftest one-system-operation-test
(with-handler [handler one-system-operation-config]
(given (:body @(handler {}))
:fhir/type := :fhir/CapabilityStatement
[:rest 0 :operation count] := 1
[:rest 0 :operation 0 :name] := "totals"
[:rest 0 :operation 0 :definition] :=
#fhir/canonical"https://samply.github.io/blaze/fhir/OperationDefinition/totals")))

(def ^:private one-system-operation-documentation-config
(update minimal-config ::rest-api/capabilities-handler assoc
:operations
[#:blaze.rest-api.operation
{:code "totals"
:def-uri "https://samply.github.io/blaze/fhir/OperationDefinition/totals"
:affects-state false
:resource-types ["Resource"]
:system-handler (fn [_])
:documentation "documentation-141700"}
#:blaze.rest-api.operation
{:code "evaluate-measure"
:def-uri
"http://hl7.org/fhir/OperationDefinition/Measure-evaluate-measure"
:resource-types ["Measure"]
:type-handler (fn [_])
:instance-handler (fn [_])
:documentation "documentation-161800"}]))

(deftest one-system-operation-documentation-test
(with-handler [handler one-system-operation-documentation-config]
(given (:body @(handler {}))
:fhir/type := :fhir/CapabilityStatement
[:rest 0 :operation count] := 1
[:rest 0 :operation 0 :name] := "totals"
[:rest 0 :operation 0 :definition] :=
#fhir/canonical"https://samply.github.io/blaze/fhir/OperationDefinition/totals"
[:rest 0 :operation 0 :documentation] := #fhir/markdown"documentation-141700")))

(def ^:private terminology-service-config
(-> minimal-config
(assoc-in
Expand Down
Loading