Skip to content

Instantly share code, notes, and snippets.

@mput
Created July 30, 2021 10:38
Show Gist options
  • Save mput/823a471396fcbb584c9bffb4ca5724dc to your computer and use it in GitHub Desktop.
Save mput/823a471396fcbb584c9bffb4ca5724dc to your computer and use it in GitHub Desktop.
{ns test.mapper_test
import #{zhir}
test-mapping
{:zen/tags #{zhir/mapping}
:t zhir/build-object
:steps [{:t zhir/const
:value "ExplanationOfBenefit"
:to [:resourceType]}
{:t zhir/get
:from [:transaction_id]
:to [:id]}
{:t zhir/build-object
:to [:patient]
:steps [{:t zhir/const
:value "Patient"
:to [:resourceType]}]}
{:t zhir/build-vector
:to [:identifier]
:steps [{:t zhir/build-object
:steps [{:t zhir/get
:from [:transaction_id]
:to [:value]}
{:t zhir/const
:value "transactionid"
:to [:system]}]}]}]}
test-for-err
{:zen/tags #{zhir/mapping}
:t zhir/build-object
:steps [{:t zhir/get
:from [:seq]
:to [:sequence]
:actions [{:action zhir.actions/coerce
:type :int}]}
{:t zhir/build-object
:to [:identifier]
:steps [{:t zhir/get
:from [:trans_id]
:to [:id]
:actions [{:action zhir.actions/coerce
:type :int}]}
{:t zhir/const
:to [:num]
:value "1"
:actions [{:action zhir.actions/coerce
:type :int}]}
{:t zhir/const
:to [:num_err]
:value "b1"
:actions [{:action zhir.actions/coerce
:type :int}]}]}
{:t zhir/build-vector
:to [:diags]
:steps [{:t zhir/build-object
:steps [{:t zhir/get
:from [:diag_1]
:to [:value]}
{:t zhir/get
:from [:diag_1_seq]
:to [:seq]
:actions [{:action zhir.actions/coerce
:type :int}]}]}
{:t zhir/build-object
:steps [{:t zhir/get
:from [:diag_2]
:to [:value]}
{:t zhir/get
:from [:diag_2_seq]
:to [:seq]
:actions [{:action zhir.actions/coerce
:type :int}]}]}]}
{:t zhir/map-flatten
:from [:items]
:to [:item-int]
:step {:t zhir/build-object
:steps [{:t zhir/get
:from [:items :*idx :n]
:to [:nint]
:actions [{:action zhir.actions/coerce
:type :int}]}]}}]}
deep-split
{:zen/tags #{zhir/mapping}
:t zhir/build-object
:steps [{:t zhir/map-flatten
:from [:items]
:to [:item]
:step {:t zhir/build-object
:steps [{:t zhir/get
:from [:sys]
:to [:system]}
{:t zhir/get
:from [:items :*idx :sub]
:to [:subtype]}
{:t zhir/map-flatten
:from [:items :*idx :diags]
:to [:smth]
:step {:t zhir/build-object
:steps [{:t zhir/get
:from [:items :*idx :diags :*idx :cod]
:to [:code]
:actions [{:action zhir.actions/coerce
:type :int}]}]}}]}}]}
actions-on-maps
{:zen/tags #{zhir/mapping}
:t zhir/build-object
:steps [{:t zhir/map-flatten
:from [:items]
:to [:items-flat]
:step {:t zhir/get
:from [:items :*idx :s]
:actions [{:action zhir.actions/coerce
:type :int}]}}
{:t zhir/map-flatten
:from [:items]
:to [:item-sorted]
:step {:t zhir/build-object
:steps [{:t zhir/get
:from [:items :*idx :s]
:to [:sequence]}]}
:actions [{:action zhir.actions/sort-by
:path [:sequence]}]}
{:t zhir/map-flatten
:from [:items]
:to [:item-sorted-int]
:step {:t zhir/build-object
:steps [{:t zhir/get
:from [:items :*idx :s]
:to [:sequence]
:actions [{:action zhir.actions/coerce
:type :int}]}]}
:actions [{:action zhir.actions/sort-by
:path [:sequence]}]}
{:t zhir/map-flatten
:from [:items]
:to [:min-seq]
:step {:t zhir/get
:from [:items :*idx :s]
:actions [{:action zhir.actions/coerce
:type :int}]}
:actions [{:action zhir.actions/min}]}
{:t zhir/map-flatten
:from [:items]
:to [:min-seq-error]
:step {:t zhir/get
:from [:items :*idx :se]
:actions [{:action zhir.actions/coerce
:type :int}]}
;; :actions [{:action zhir.actions/min}]
}
]
}
apply
{:zen/tags #{zhir/mapping}
:t zhir/build-object
:steps [{:t zhir/get
:from [:copay]
:to [:patient-copay]
:actions [{:action zhir.actions/coerce
:type :decimal}]}
{:t zhir/apply
:operation :plus
:to [:patient-share]
:step {:t zhir/build-vector
:steps [{:t zhir/get
:from [:copay]
:actions [{:action zhir.actions/coerce
:type :decimal}]}
{:t zhir/get
:from [:cob]
:actions [{:action zhir.actions/coerce
:type :decimal}]}]}}
{:t zhir/apply
:operation :minus
:to [:total]
:step {:t zhir/build-vector
:steps [{:t zhir/get-from-result
:value :patient-share}
{:t zhir/get
:from [:disc]
:actions [{:action zhir.actions/coerce
:type :decimal}]}]}}]}
simple-get
{:zen/tags #{zhir/mapping}
:t zhir/build-vector
:steps [{:t zhir/get
:from [:cob]
:actions [{:action zhir.actions/coerce
:type :decimal}]}]}
empty-hashmap
{:zen/tags #{zhir/mapping}
:t zhir/build-object
:steps []}
min-action
{:zen/tags #{zhir/mapping}
:t zhir/build-vector
:actions [{:action zhir.actions/min}]
:steps [{:t zhir/get
:from [:a]}
{:t zhir/get
:from [:b]}]}
map-to-action
{:zen/tags #{zhir/mapping}
:t zhir/get
:from [:a]
:actions [{:action zhir.actions/map-to
:m {"P" "active"}}]}
incomplete
{:zen/tags #{zhir/mapping}
:t zhir/build-vector
:actions [{:action zhir.actions/skip-nils}]
:steps [{:t zhir/build-object
:actions [{:action zhir.actions/skip-incomplete}]
:steps [{:t zhir/const
:value "system"
:to [:system]}
{:t zhir/get
:from [:unk]
:to [:value]}]}
{:t zhir/build-object
:actions [{:action zhir.actions/skip-incomplete}
{:action zhir.actions/required}]
:steps [{:t zhir/const
:value "system"
:to [:system]}
{:t zhir/get
:from [:a]
:to [:value]}]}]}
actions-on-vector
{:zen/tags #{zhir/mapping}
:t zhir/build-vector
:actions [{:action zhir.actions/set-indexes
:path [:seq]}]
:steps [{:t zhir/build-object
:steps [{:t zhir/get
:from [:a]
:to [:val]}]}
{:t zhir/build-object
:steps [{:t zhir/get
:from [:b]
:to [:val]}]}]}
item
{:zen/tags #{zhir/mapping}
:t zhir/build-object
:steps [{:t zhir/get
:from [:a]
:to [:val]}]}
items
{:zen/tags #{zhir/mapping}
:t zhir/build-vector
:steps [item item]}
Amount
{:zen/tags #{zhir/macro}
:params [:category-system :category-code :amount-value]
:mapping {:t zhir/build-object
:steps
[{:t zhir/build-object
:to [:category]
:steps
[{:t zhir/build-vector
:to [:coding]
:steps
[{:t zhir/build-object
:steps [{:t zhir/macro-destination
:to [:system]
:source-params :category-system}
{:t zhir/macro-destination
:to [:code]
:source-params :category-code}]}]}]}
{:t zhir/build-object
:to [:amount]
:steps
[{:t zhir/macro-destination
:to [:value]
:actions [{:action zhir.actions/coerce
:type :decimal}]
:source-params :amount-value}
{:t zhir/const
:to [:currency]
:value "USD"}]}]}}
macro-test
{:zen/tags #{zhir/mapping}
:t zhir/build-vector
:steps [{:t zhir/macroexpand
:macro Amount
:args {:category-system "https://payment"
:category-code 1
:amount-value {:t zhir/get
:from [:payer-payment]}}}
{:t zhir/macroexpand
:macro Amount
:args {:category-system "https://cob"
:category-code 2
:amount-value {:t zhir/get
:from [:cob]
;; You could shadow actions.
:actions [{:action zhir.actions/coerce
:type :int}]}}}]}
supporting-info-category-code-multiple
{:zen/tags #{zhir/macro}
:params [:category-system :category-code
:first-system :first-code
:second-system :second-code
:system :code]
:mapping {:t zhir/build-object
:actions [{:action zhir.actions/skip-incomplete}]
:steps
[{:t zhir/build-object
:to [:category]
:steps
[{:t zhir/build-vector
:to [:coding]
:steps
[{:t zhir/build-object
:steps [{:t zhir/macro-destination
:to [:system]
:source-params :category-system}
{:t zhir/macro-destination
:to [:code]
:source-params :category-code}]}]}]}
{:t zhir/build-object
:to [:code]
:actions [{:action zhir.actions/skip-incomplete}]
:steps
[{:t zhir/build-vector
:to [:coding]
:actions [{:action zhir.actions/skip-nils}]
:steps
[{:t zhir/build-object
:actions [{:action zhir.actions/skip-incomplete}]
:steps [{:t zhir/macro-destination
:to [:system]
:source-params :first-system}
{:t zhir/macro-destination
:to [:code]
:source-params :first-code}]}
{:t zhir/build-object
:actions [{:action zhir.actions/skip-incomplete}]
:steps [{:t zhir/macro-destination
:to [:system]
:source-params :second-system}
{:t zhir/macro-destination
:to [:code]
:source-params :second-code}]}]}]}
{:t zhir/macro-destination
:to [:_for-all-items]
:source-params :_for-all-items}]}}
category-multiple-usage
{:t zhir/macroexpand
:macro supporting-info-category-code-multiple
:args {:category-system "https://wellnecity.com/fhir/wellnecity/codesystem/rx-information-category"
:category-code "formulary-indicator"
:first-system "https://wellnecity.com/fhir/wellnecity/codesystem/formulary-indicator"
:first-code {:t zhir/get
:from [:formulary_flag]
:actions [{:action zhir.actions/map-to
:m {"F" "in-formulary"
"N" "not-in-formulary"
"*default" "not-in-formulary"}}]}
:second-system "https://wellnecity.com/fhir/ascend/codesystem/formulary-indicator"
:second-code {:t zhir/get
:from [:formulary_flag]}
:_for-all-items true}}
rearrange-sequence-elements
{:zen/tags #{zhir/mapping}
:t zhir/get
:actions [{:action zhir.actions/rearrange-sequence-elements}]
:from [:test]}
CodeableConcept
{:zen/tags #{zhir/macro}
:params [:system :code]
:mapping {:t zhir/build-object
:steps [{:t zhir/build-vector
:to [:coding]
:steps
[{:t zhir/build-object
:steps [{:t zhir/macro-destination
:to [:system]
:source-params :system}
{:t zhir/macro-destination
:to [:code]
:source-params :code}]}]}]}}
category-with-amount
{:zen/tags #{zhir/macro}
:params [:category-system :category-code :amount-value]
:mapping {:t zhir/build-object
:steps
[{:t zhir/macroexpand
:macro CodeableConcept
:to [:category]
:args {:system {:t zhir/macro-destination
:source-params :category-system}
:code {:t zhir/macro-destination
:source-params :category-code}}}
{:t zhir/build-object
:to [:amount]
:steps
[{:t zhir/macro-destination
:to [:value]
:actions [{:action zhir.actions/coerce
:type :decimal}]
:source-params :amount-value}
{:t zhir/const
:to [:currency]
:value "USD"}]}]}}
macro-in-macro
{:zen/tags #{zhir/mapping}
:t zhir/macroexpand
:macro category-with-amount
:args {:category-system "some-category"
:category-code "cat6"
:amount-value {:t zhir/get
:from [:test]}}}
get-name
{:zen/mapping #{zhir/mapping}
:t zhir/get
:from [:given]}
identity-transformation
{:zen/mapping #{zhir/mapping}
:t zhir/build-object
:steps [{:t zhir/const
:to [:name]
:value "Rich"}
{:t zhir/identity
:to [:last]
:step get-name}]}
cond-test
{:t zhir/cond
:steps [{:t zhir/get
:from [:dispatcher]
:actions [{:action zhir.actions/map-to
:m {"a" :a
"*default" false}}]}
{:t zhir/const
:value 1}
{:t zhir/get
:from [:dispatcher]
:actions [{:action zhir.actions/map-to
:m {"b" :b
"*default" false}}]}
{:t zhir/const
:value 2}
{:t zhir/const
:value true}
{:t zhir/const
:value 3}]}
cond-test-error
{:t zhir/cond
:steps [{:t zhir/get
:from [:dispatcher]
:actions [{:action zhir.actions/map-to
:m {"a" :a}}]}
{:t zhir/const
:value 1}
{:t zhir/get
:from [:dispatcher]
:actions [{:action zhir.actions/map-to
:m {"b" :b}}]}
{:t zhir/const
:value 2}]}
or
{:t zhir/or
:steps [{:t zhir/get
:from [:a]}
{:t zhir/get
:from [:b]}]}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment