Skip to content

Commit

Permalink
Merge pull request #1816 from samply/ratio
Browse files Browse the repository at this point in the history
Add Record for Complex Type Ratio
  • Loading branch information
alexanderkiel authored Jun 24, 2024
2 parents 82022a6 + 4497165 commit 446a745
Show file tree
Hide file tree
Showing 24 changed files with 313 additions and 63 deletions.
2 changes: 1 addition & 1 deletion modules/admin-api/test/blaze/admin_api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@
[#fhir/Coding
{:system #fhir/uri"system-192253"
:code #fhir/code"code-192300"}]}
:subject (type/map->Reference {:reference (str "Patient/" pat-id)})}]))
:subject (type/reference {:reference (str "Patient/" pat-id)})}]))
(range 120)))
(mapv (range 100)))

Expand Down
16 changes: 8 additions & 8 deletions modules/db/test/blaze/db/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@
(with-system-data [{:blaze.db/keys [node]} config]
[[[:put {:fhir/type :fhir/Patient :id "0"
:active true
:name [(type/map->HumanName {:family (apply str (repeat 1000 "a"))})]}]]]
:name [(type/human-name {:family (apply str (repeat 1000 "a"))})]}]]]

(testing "as first clause"
(given (pull-type-query node "Patient" [["family" (apply str (repeat 1000 "a"))]])
Expand All @@ -1419,7 +1419,7 @@
(with-system-data [{:blaze.db/keys [node]} config]
[[[:put {:fhir/type :fhir/Patient :id "0"
:active true
:name [(type/map->HumanName {:family name})]}]]]
:name [(type/human-name {:family name})]}]]]

(testing "as first clause"
(given (pull-type-query node "Patient" [["family" name]])
Expand Down Expand Up @@ -4563,7 +4563,7 @@

(defn- patient-w-identifier [i]
{:fhir/type :fhir/Patient :id (str i)
:identifier [(type/map->Identifier {:value (str i)})]})
:identifier [(type/identifier {:value (str i)})]})

(deftest type-query-identifier-non-matching-test
(st/unstrument)
Expand All @@ -4586,15 +4586,15 @@
[[[:put {:fhir/type :fhir/Patient :id "0"
:active true
:identifier
[(type/map->Identifier {:system system :value "0"})]}]
[(type/identifier {:system system :value "0"})]}]
[:put {:fhir/type :fhir/Patient :id "1"
:active true
:identifier
[(type/map->Identifier {:system system :value "0"})]}]
[(type/identifier {:system system :value "0"})]}]
[:put {:fhir/type :fhir/Patient :id "2"
:active true
:identifier
[(type/map->Identifier {:system system :value "0"})]}]]]
[(type/identifier {:system system :value "0"})]}]]]

(doseq [value (if system ["0" "foo|0"] ["0" "|0"])]
(given (pull-type-query node "Patient" [["identifier" value]])
Expand Down Expand Up @@ -6356,9 +6356,9 @@
(defn- observation-create-op [id]
[:create {:fhir/type :fhir/Observation :id (format "%05d" id)
:category
[(type/map->CodeableConcept
[(type/codeable-concept
{:coding
[(type/map->Coding
[(type/coding
{:system #fhir/uri"system-141902"
:code (type/code (format "%05d" id))})]})]}])

Expand Down
4 changes: 4 additions & 0 deletions modules/fhir-structure/src/blaze/fhir/spec/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@
:fhir/Coding
:fhir/CodeableConcept
:fhir/Quantity
:fhir/Ratio
:fhir/Period
:fhir/Identifier
:fhir/HumanName
Expand Down Expand Up @@ -425,6 +426,7 @@
:fhir.json/Meta
:fhir.json/Attachment
:fhir.json/Quantity
:fhir.json/Ratio
:fhir.json/Period
:fhir.json/Identifier
:fhir.json/HumanName
Expand Down Expand Up @@ -549,6 +551,7 @@
:fhir.xml/Coding
:fhir.xml/CodeableConcept
:fhir.xml/Quantity
:fhir.xml/Ratio
:fhir.xml/Period
:fhir.xml/Identifier
:fhir.xml/HumanName
Expand Down Expand Up @@ -590,6 +593,7 @@
:fhir.cbor/Meta
:fhir.cbor/Attachment
:fhir.cbor/Quantity
:fhir.cbor/Ratio
:fhir.cbor/Period
:fhir.cbor/Identifier
:fhir.cbor/HumanName
Expand Down
5 changes: 5 additions & 0 deletions modules/fhir-structure/src/blaze/fhir/spec/type.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,11 @@
:hash-num 40
:interned (and (nil? id) (p/-interned extension) (nil? value)))

(declare ratio)

(def-complex-type Ratio [^String id extension numerator denominator]
:hash-num 48)

(declare period)

(def-complex-type Period [^String id extension ^:primitive start ^:primitive end]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
:args (s/cat :x any?)
:ret boolean?)

(s/fdef system/date
:args (s/cat :year int? :month (s/? int?) :day (s/? int?))
:ret system/date?)

;; ---- System.DateTime -------------------------------------------------------

(s/fdef system/date-time?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@

#fhir/Quantity{} 56

#fhir/Ratio{} 48

#fhir/Period{} 48

#fhir/Identifier{} 64
Expand Down
10 changes: 9 additions & 1 deletion modules/fhir-structure/test/blaze/fhir/spec/generators.clj
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,15 @@

;; TODO: Range

;; TODO: Ratio
(defn ratio
[& {:keys [id extension numerator denominator]
:or {id (gen/return nil)
extension (extensions)
numerator (nilable (quantity))
denominator (nilable (quantity))}}]
(->> (gen/tuple id extension numerator denominator)
(to-map [:id :extension :numerator :denominator])
(gen/fmap type/ratio)))

;; TODO: RatioRange

Expand Down
28 changes: 28 additions & 0 deletions modules/fhir-structure/test/blaze/fhir/spec/type/system_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,34 @@
nil
#system/date-time"2020"))

(testing "date"
(testing "year"
(are [year date] (= date (system/date year))
1000 #system/date"1000"
2024 #system/date"2024"
9999 #system/date"9999")

(given-thrown (system/date -1)
:message := "Invalid value for Year (valid values 1 - 9999): -1"))

(testing "year-month"
(are [year month date] (= date (system/date year month))
1000 1 #system/date"1000-01"
2024 6 #system/date"2024-06"
9999 12 #system/date"9999-12")

(given-thrown (system/date 2024 0)
:message := "Invalid value for MonthOfYear (valid values 1 - 12): 0"))

(testing "year-month-day"
(are [year month day date] (= date (system/date year month day))
1000 1 1 #system/date"1000-01-01"
2024 6 15 #system/date"2024-06-15"
9999 12 31 #system/date"9999-12-31")

(given-thrown (system/date 2023 2 29)
:message := "Invalid date 'February 29' as '2023' is not a leap year")))

(testing "system equals"
(testing "same precision"
(testing "within date"
Expand Down
Loading

0 comments on commit 446a745

Please sign in to comment.