Skip to content

Instantly share code, notes, and snippets.

@abcdw
Created May 8, 2020 09:27
Show Gist options
  • Save abcdw/ec49409aa22a44ede6fc1eb79cfe7814 to your computer and use it in GitHub Desktop.
Save abcdw/ec49409aa22a44ede6fc1eb79cfe7814 to your computer and use it in GitHub Desktop.
(ns app.server.core
(:require [clojure.string :as string]
[ironhide.core :as ih]))
(defn -main []
(println "hello"))
(defmethod ih/get-global-sight :ihs/read-only [key args & [ctx]]
[(fn [x] {:ih/ro-value x
:ih/value x})
(fn [x] (:ih/value x))])
{:key-a :k1
:val-a :v1
:key-b :k2
:val-b :v2} <-> {:k1 :v1}
{:keys [:k1 :k2]
:values [:v1 :v2]}
(defmethod ih/get-global-sight :ihs/filter-lower-cased-persons [key args & [ctx]]
[(fn [v] (remove (fn [{x :name}] (= (string/lower-case x) x)) v))
(fn [v] v)])
(-> (ih/execute
#:ih{:direction [:original :target]
:rules [{:original [:person :ihs/filter-lower-cased-persons [:*]]
:target [:person [:*]]}]
:data {:original {:person [{:name "lowercased"} {:name "Uppercased"}]}}})
(assoc :ih/direction [:target :original])
ih/execute)
(def patient-transformer
#:ih{:direction [:form :fhir]
:rules
[{:fhir [:name [:* {:use "official"}] :given [:*]]
:form [:first-name {:ih/sight :ihs/str<->vector :separator "o"} [:*]]}
{:fhir [:name [0 {:use "official"}] :family]
:form [:last-name]}]})
(def transformers
{:patient
patient-transformer
:practitioner
#:ih{:direction [:form :fhir]
:sights #:ihs{:patient-form<->fhir
patient-transformer}
:rules
[{:fhir [:patients [:*] :family-members]
:form [:patients [:*] :ihs/patient-form<->fhir ]}]}})
[[1 2]
[1 2 3]
[1]]
(defn to-fhir [type data]
(->
(ih/execute
(assoc-in (type transformers)
[:ih/data :form] data))
(get-in [:ih/data :fhir])))
(defn to-form [type data]
(->
(ih/execute
(->
(assoc-in (type transformers)
[:ih/data :fhir] data)
(assoc :ih/direction [:fhir :form])))
(get-in [:ih/data :form])))
(def fhir-patient (partial to-fhir :patient))
(def form-patient (partial to-form :patient))
(-> (fhir-patient {:first-name "Bob"
:last-name "Smith"})
form-patient)
(def fhir-practitioner (partial to-fhir :practitioner))
(def form-practitioner (partial to-form :practitioner))
(->
{:patients [{:first-name "Bob"
:last-name "Smith"}
{:first-name "Bob Michael"
:last-name "Smith"}]}
fhir-practitioner
; form-practitioner
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment