Created
January 13, 2022 10:22
-
-
Save niquola/398251b2b5831122550edb14cebbb80f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ns innovaccer | |
import #{aidbox aidbox.ops | |
fhir.Patient.search-params | |
fhir.Encounter.search-params} | |
;; here we define sever and include apis | |
server | |
{:apis #{apis aidbox/api}} | |
apis | |
{:zen/tas #{aidbox/api} | |
:routes {"pract" pract-api}} | |
;; this is practitioner profile | |
Practitoner | |
{:zen/tas #{zen/schema} | |
:confirms #{fhir/Practitioner} | |
:keys {:name {:minItems 1}}} | |
patch-subject | |
{:table :user_patients | |
:on {:match-pt [:= [:resource#>> :subject :id] :upt.patient_id] | |
:match-user [:= :upt.user_id (ctx :user :id)]}} | |
;; here is api group for practitioners | |
pract-api | |
{:zen/tas #{aidbox/api} | |
:generate {:metadata {} | |
:openapi {}} | |
:routes | |
;; GET /pract/Patient | |
{"Patient" {:resource/type "Patient" | |
:GET {:operation aidbox.ops/search | |
:params {:name fhir.Patient.search-params/name | |
:_sort {:date fhir.Patient.search-params/sort-name}} | |
:patch-query | |
{:join {:upt {:table :user_patients | |
:on {:match-pt [:= :id :upt.patient_id] | |
:match-user [:= :upt.user_id (ctx :jwt :id)]}}}}}} | |
"Encounter" | |
{:resource/type "Encounter" | |
:GET {:operation aidbox.ops/search | |
:params fhir.Encounter.search-params/params | |
#_{:class fhir.Encounter.search-params/class | |
:subject fhir.Encounter.search-params/subject | |
:practitioner fhir.Encounter.search-params/subject | |
:_include {:subject {:Patient {}}} | |
:_sort {:date fhir.Encounter.search-params/sort-date}} | |
:patch-params | |
{:practitioner (ctx :user :data :practitioner_id)} | |
:patch-query | |
{:join {:upt (when (params :my-param) patch-subject)}} | |
:elements {:mask #{[:identifier :value]} | |
:hide #{[:name]}}} | |
:POST {:operation aidbox.ops/create | |
:profiles #{Pratitioner} | |
:policies {:pt {:engine :sql | |
:query {:from :user_patient | |
:where {:match-user [:= :user_id (ctx :user :id)] | |
:match-pt [:= :patient_id (ctx :resource :subject :id)]}}}} | |
:inject-elements | |
{[:participant {:type {:coding [{:code "ADM" :system "http://terminology.hl7.org/CodeSystem/participant-type"}]}}] | |
{:resourceType "Practitioner" :id (ctx [:user :data :practitioner_id])}}}} | |
GET /smart/Patient/id | |
:from :patient | |
:where {:id [:= :id (ctx :user :patient-id)]} | |
GET /smart/Observation | |
:from :observation | |
:where {:id [:= [:resource#>> :subject :id] (ctx :user :patient-id)]} | |
GET /smart/Observation/id => 404 | |
:from :observation | |
:where {:id [:= [:resource#>> :subject :id] (ctx :user :patient-id)]} | |
POST /smart/Observation => 404 | |
:subject {:id (ctx :usre :patient-id)} => 422/403 | |
PUT /smart/Observation/id => 404 | |
:subject {:id (ctx :usre :patient-id)} => 422/403 | |
{"Observation" {:link [:subject :id]}} | |
GET /pract/Patient | |
;; ??? | |
:join {:x {:table :pt_pr :on | |
[:and | |
[:= :pt_pr.pat_id [:patient.resource#>]] | |
[:= :pt_pr.pr_idd (ctx :user :id)]]} } | |
GET /orgs/Patient (org user.org-ids) | |
"smart" | |
{"Observation" | |
{:GET {:params {:custom {...}} :inject {}} | |
:POST {...} | |
[:id] {:GET {...}}}} | |
* config operation (search params) | |
* access control - safe endpoints | |
* pre-transform (inject patient-id) | |
* post-transform (mask, filter elements) | |
-- low level | |
* describe api | |
* mount and config operations | |
{"Encounter" | |
{:GET {:operation aidbox.ops/search | |
:params fhir.Encounter.search-params/params | |
:patch-params {:practitioner [:user :data :practitioner_id]} | |
:patch-query {:join {:upt (when (params :my-param) patch-subject)}} | |
:elements {:mask #{[:identifier :value]} | |
:hide #{[:name]}}}}} | |
route (middleware) operation (config) | |
encounter-search | |
{:engine zenbox/search | |
:constuctor {:resource "Encounter"} <- config | |
:params {:pid (ctx :user :pid)} <- user | |
:result {}} | |
inject-subject (user.patient-id) | |
GET /prefix/Observation/id?subject=pt-1 | |
?? inject param => subject= user.patient-id | |
patch query => obs.subject.id in (user.patient-id) | |
POST /prefix/Observation | |
?? inject param => subject= user.patient-id | |
check => obs.subject.id should be in user.patient-id | |
additional profile => | |
inject => obs.subject.id = user.patient-id | |
PUT /prefix/Observation/id | |
?? inject param => subject= user.patient-id | |
=> obs.subject.id = user.patient-id | |
operation - params <- mw inject params | |
create-operation (paramaters) | |
generic-operations | |
user -> API (operation) | |
create-rpc | |
configure: resource-type | |
create-obs | |
{:op zenbox/create | |
:resource-type "Observation" | |
:profiles #{} | |
:inject {:subject {:id (ctx :user :patient-id)} | |
:meta {:user (ctx :user :id)}}} | |
{:method xxx/create-obs | |
:params {:value {}}} | |
{:method xxx/create-obs | |
:params {:subject {:id "pt-1"} | |
:meta {:user "u-1"} | |
:value {}}} | |
}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment