Skip to content

Commit d627e2b

Browse files
committed
Fix Consent Resource policyRule Property
The problem was that the property `policyRule` comes after the property `policy` in the list of element definitions. Both have the same prefix and `policy` is a BackboneElement. The function separate-element-definitions* used string prefix on path as termination condition, so `policyRule` was counted as member of `policy`. I just added a `.` to make the prefix check robust. Closes: #2700
1 parent ce70854 commit d627e2b

File tree

3 files changed

+113
-2
lines changed

3 files changed

+113
-2
lines changed

modules/fhir-structure/src/blaze/fhir/spec/resource.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
(nil? ed)
5151
{:types (assoc types parent-type out)}
5252

53-
(not (str/starts-with? path parent-type))
53+
(not (str/starts-with? path (str parent-type ".")))
5454
{:types (assoc types parent-type out) :more all}
5555

5656
(backbone-element-definition? ed)

modules/fhir-structure/test/blaze/fhir/spec/generators.clj

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,73 @@
572572
[identifier (gen/vector (identifier))
573573
status (rare-nil (code))
574574
input (gen/vector (task-input))])
575+
576+
(defn consent-policy
577+
[& {:keys [id extension authority uri]
578+
:or {id (often-nil id-value)
579+
extension (extensions)
580+
authority (nilable (uri))
581+
uri (nilable (uri))}}]
582+
(->> (gen/tuple id extension authority uri)
583+
(to-map [:id :extension :authority :uri])
584+
(fhir-type :fhir.Consent/policy)))
585+
586+
(defn consent-verification
587+
[& {:keys [id extension verified verifiedWith verificationDate]
588+
:or {id (often-nil id-value)
589+
extension (extensions)
590+
verified (boolean)
591+
verifiedWith (nilable (reference))
592+
verificationDate (nilable (dateTime))}}]
593+
(->> (gen/tuple id extension verified verifiedWith verificationDate)
594+
(to-map [:id :extension :verified :verifiedWith :verificationDate])
595+
(fhir-type :fhir.Consent/verification)))
596+
597+
(defn consent-provision-actor
598+
[& {:keys [id extension role reference]
599+
:or {id (often-nil id-value)
600+
extension (extensions)
601+
role (codeable-concept)
602+
reference (reference)}}]
603+
(->> (gen/tuple id extension role reference)
604+
(to-map [:id :extension :role :reference])
605+
(fhir-type :fhir.Consent.provision/actor)))
606+
607+
(defn consent-provision-data
608+
[& {:keys [id extension meaning reference]
609+
:or {id (often-nil id-value)
610+
extension (extensions)
611+
meaning (code)
612+
reference (reference)}}]
613+
(->> (gen/tuple id extension meaning reference)
614+
(to-map [:id :extension :meaning :reference])
615+
(fhir-type :fhir.Consent.provision/data)))
616+
617+
(defn consent-provision
618+
[& {:keys [id extension type period actor action securityLabel purpose class
619+
code dataPeriod data]
620+
:or {id (often-nil id-value)
621+
extension (extensions)
622+
type (nilable (code))
623+
period (nilable (period))
624+
actor (gen/vector (consent-provision-actor))
625+
action (gen/vector (codeable-concept))
626+
securityLabel (gen/vector (coding))
627+
purpose (gen/vector (coding))
628+
class (gen/vector (coding))
629+
code (gen/vector (codeable-concept))
630+
dataPeriod (nilable (blaze.fhir.spec.generators/period))
631+
data (gen/vector (consent-provision-data))}}]
632+
(->> (gen/tuple id extension type period actor action securityLabel purpose
633+
class code dataPeriod data)
634+
(to-map [:id :extension :type :period :actor :action :securityLabel
635+
:purpose :class :code :dataPeriod :data :provision])
636+
(fhir-type :fhir.Consent/provision)))
637+
638+
(def-resource-gen consent
639+
[identifier (gen/vector (identifier))
640+
status (code)
641+
policy (gen/vector (consent-policy))
642+
policyRule (nilable (codeable-concept))
643+
verification (gen/vector (consent-verification))
644+
provision (nilable (consent-provision {:provision (gen/vector (consent-provision))}))])

modules/fhir-structure/test/blaze/fhir/spec_test.clj

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4155,7 +4155,8 @@
41554155
:input
41564156
[{:fhir/type :fhir.Task/input
41574157
:value #fhir/code"code-173329"}]})
4158-
{:resourceType "Task" :input [{:valueCode "code-173329"}]})))))
4158+
{:resourceType "Task"
4159+
:input [{:valueCode "code-173329"}]})))))
41594160

41604161
(deftest library-test
41614162
(testing "summary parsing"
@@ -4166,3 +4167,43 @@
41664167
(and
41674168
(->> library :meta :tag (some fu/subsetted?))
41684169
(not-any? :data (:content library))))))))
4170+
4171+
(deftest consent-test
4172+
(testing "round-trip"
4173+
(testing "JSON"
4174+
(satisfies-prop 20
4175+
(prop/for-all [consent (fg/consent)]
4176+
(= (->> (write-json consent)
4177+
(parse-json "Consent"))
4178+
consent))))
4179+
4180+
(testing "XML"
4181+
(satisfies-prop 20
4182+
(prop/for-all [consent (fg/consent)]
4183+
(= (-> consent
4184+
fhir-spec/unform-xml
4185+
fhir-spec/conform-xml)
4186+
consent))))
4187+
4188+
(testing "CBOR"
4189+
(satisfies-prop 20
4190+
(prop/for-all [consent (fg/consent)]
4191+
(= (->> (write-cbor consent)
4192+
(parse-cbor "Consent"))
4193+
consent)))))
4194+
4195+
(testing "parsing"
4196+
(testing "JSON"
4197+
(are [json fhir] (= fhir (write-parse-json "Consent" json))
4198+
{:resourceType "Consent"
4199+
:policyRule {}}
4200+
{:fhir/type :fhir/Consent
4201+
:policyRule #fhir/CodeableConcept{}})))
4202+
4203+
(testing "writing"
4204+
(testing "JSON"
4205+
(is (= (write-read-json
4206+
{:fhir/type :fhir/Consent
4207+
:policyRule #fhir/CodeableConcept{}})
4208+
{:resourceType "Consent"
4209+
:policyRule {}})))))

0 commit comments

Comments
 (0)