|
2 | 2 | (:refer-clojure :exclude [str]) |
3 | 3 | (:require |
4 | 4 | [blaze.admin-api.spec] |
5 | | - [blaze.admin-api.validation] |
| 5 | + [blaze.admin-api.validator :as validator] |
| 6 | + [blaze.admin-api.validator.spec] |
6 | 7 | [blaze.anomaly :as ba :refer [if-ok]] |
7 | 8 | [blaze.async.comp :as ac :refer [do-sync]] |
8 | 9 | [blaze.db.impl.index.patient-last-change :as plc] |
|
32 | 33 | [blaze.module :as m] |
33 | 34 | [blaze.spec] |
34 | 35 | [blaze.util :refer [str]] |
35 | | - [clojure.datafy :as datafy] |
36 | 36 | [clojure.spec.alpha :as s] |
37 | 37 | [integrant.core :as ig] |
38 | 38 | [jsonista.core :as j] |
|
42 | 42 | [ring.util.response :as ring] |
43 | 43 | [taoensso.timbre :as log]) |
44 | 44 | (:import |
45 | | - [ca.uhn.fhir.context FhirContext] |
46 | | - [ca.uhn.fhir.context.support DefaultProfileValidationSupport] |
47 | | - [ca.uhn.fhir.parser IParser] |
48 | | - [ca.uhn.fhir.validation FhirValidator] |
49 | 45 | [com.google.common.base CaseFormat] |
50 | 46 | [java.io File] |
51 | | - [java.nio.file Files] |
52 | | - [org.hl7.fhir.common.hapi.validation.support |
53 | | - CommonCodeSystemsTerminologyService |
54 | | - InMemoryTerminologyServerValidationSupport PrePopulatedValidationSupport |
55 | | - ValidationSupportChain] |
56 | | - [org.hl7.fhir.common.hapi.validation.validator FhirInstanceValidator])) |
| 47 | + [java.nio.file Files])) |
57 | 48 |
|
58 | 49 | (set! *warn-on-reflection* true) |
59 | 50 |
|
|
209 | 200 | :details #fhir/CodeableConcept |
210 | 201 | {:text #fhir/string "No allowed profile found."}}]}))) |
211 | 202 |
|
212 | | -(defn- validate [^FhirValidator validator writing-context resource] |
213 | | - (->> ^String (fhir-spec/write-json-as-string writing-context resource) |
214 | | - (.validateWithResult validator) |
215 | | - (.toOperationOutcome) |
216 | | - (datafy/datafy))) |
| 203 | +(defn- validate [validator writing-context resource] |
| 204 | + (->> (fhir-spec/write-json-as-string writing-context resource) |
| 205 | + (validator/validate validator))) |
217 | 206 |
|
218 | 207 | (defn- error-issues [outcome] |
219 | 208 | (update outcome :issue (partial filterv (comp #{"error"} :value :severity)))) |
|
458 | 447 | {:path (str context-path "/__admin") |
459 | 448 | :syntax :bracket})) |
460 | 449 |
|
461 | | -(defn- read-profile [name] |
462 | | - (let [classloader (.getContextClassLoader (Thread/currentThread))] |
463 | | - (with-open [source (.getResourceAsStream classloader name)] |
464 | | - (slurp source)))) |
465 | | - |
466 | | -(defn- profile-validation-support [context] |
467 | | - (let [s (PrePopulatedValidationSupport. context) |
468 | | - parser ^IParser (.newJsonParser ^FhirContext context)] |
469 | | - (run! |
470 | | - (fn [name] |
471 | | - (log/debug "Load profile" name) |
472 | | - (.addResource s (.parseResource parser ^String (read-profile name)))) |
473 | | - ;; The current (IG 1.10.0) profiles, copied from the IG into each module, |
474 | | - ;; plus the frozen legacy (IG 0.1.0) profiles bundled with this module — |
475 | | - ;; so Tasks submitted with either the current or the legacy canonical |
476 | | - ;; validate against a matching profile edition. The 0.1.0 editions are |
477 | | - ;; frozen rather than derived from the current ones, so they keep matching |
478 | | - ;; legacy submissions once the IG diverges from 0.1.0. |
479 | | - ["blaze/db/CodeSystem-ColumnFamily.json" |
480 | | - "blaze/db/CodeSystem-Database.json" |
481 | | - "blaze/db/ValueSet-ColumnFamily.json" |
482 | | - "blaze/db/ValueSet-Database.json" |
483 | | - "blaze/job_scheduler/StructureDefinition-Job.json" |
484 | | - "blaze/job_scheduler/CodeSystem-JobType.json" |
485 | | - "blaze/job_scheduler/CodeSystem-JobOutput.json" |
486 | | - "blaze/job/async_interaction/StructureDefinition-AsyncInteractionJob.json" |
487 | | - "blaze/job/async_interaction/StructureDefinition-AsyncInteractionRequestBundle.json" |
488 | | - "blaze/job/async_interaction/StructureDefinition-AsyncInteractionResponseBundle.json" |
489 | | - "blaze/job/async_interaction/CodeSystem-AsyncInteractionJobOutput.json" |
490 | | - "blaze/job/async_interaction/CodeSystem-AsyncInteractionJobParameter.json" |
491 | | - "blaze/job/compact/CodeSystem-CompactJobOutput.json" |
492 | | - "blaze/job/compact/CodeSystem-CompactJobParameter.json" |
493 | | - "blaze/job/compact/StructureDefinition-CompactJob.json" |
494 | | - "blaze/job/re_index/StructureDefinition-ReIndexJob.json" |
495 | | - "blaze/job/re_index/CodeSystem-ReIndexJobOutput.json" |
496 | | - "blaze/job/re_index/CodeSystem-ReIndexJobParameter.json" |
497 | | - "blaze/admin-api/v0_1_0/CodeSystem-ColumnFamily.json" |
498 | | - "blaze/admin-api/v0_1_0/CodeSystem-Database.json" |
499 | | - "blaze/admin-api/v0_1_0/ValueSet-ColumnFamily.json" |
500 | | - "blaze/admin-api/v0_1_0/ValueSet-Database.json" |
501 | | - "blaze/admin-api/v0_1_0/StructureDefinition-Job.json" |
502 | | - "blaze/admin-api/v0_1_0/CodeSystem-JobType.json" |
503 | | - "blaze/admin-api/v0_1_0/CodeSystem-JobOutput.json" |
504 | | - "blaze/admin-api/v0_1_0/StructureDefinition-AsyncInteractionJob.json" |
505 | | - "blaze/admin-api/v0_1_0/StructureDefinition-AsyncInteractionRequestBundle.json" |
506 | | - "blaze/admin-api/v0_1_0/StructureDefinition-AsyncInteractionResponseBundle.json" |
507 | | - "blaze/admin-api/v0_1_0/CodeSystem-AsyncInteractionJobOutput.json" |
508 | | - "blaze/admin-api/v0_1_0/CodeSystem-AsyncInteractionJobParameter.json" |
509 | | - "blaze/admin-api/v0_1_0/CodeSystem-CompactJobOutput.json" |
510 | | - "blaze/admin-api/v0_1_0/CodeSystem-CompactJobParameter.json" |
511 | | - "blaze/admin-api/v0_1_0/StructureDefinition-CompactJob.json" |
512 | | - "blaze/admin-api/v0_1_0/StructureDefinition-ReIndexJob.json" |
513 | | - "blaze/admin-api/v0_1_0/CodeSystem-ReIndexJobOutput.json" |
514 | | - "blaze/admin-api/v0_1_0/CodeSystem-ReIndexJobParameter.json"]) |
515 | | - s)) |
516 | | - |
517 | | -(defn- create-validator* [] |
518 | | - (let [context (FhirContext/forR4) |
519 | | - _ (.newJsonParser context) |
520 | | - validator (.newValidator context) |
521 | | - chain (doto (ValidationSupportChain.) |
522 | | - (.addValidationSupport (DefaultProfileValidationSupport. context)) |
523 | | - (.addValidationSupport (InMemoryTerminologyServerValidationSupport. context)) |
524 | | - (.addValidationSupport (CommonCodeSystemsTerminologyService. context)) |
525 | | - (.addValidationSupport (profile-validation-support context))) |
526 | | - instanceValidator (FhirInstanceValidator. chain)] |
527 | | - (.registerValidatorModule validator instanceValidator) |
528 | | - validator)) |
529 | | - |
530 | | -(defn- create-validator [] |
531 | | - (try |
532 | | - (create-validator*) |
533 | | - (catch Exception e |
534 | | - (log/error e) |
535 | | - (throw e)))) |
536 | | - |
537 | 450 | (defn- create-job-handler [job-scheduler] |
538 | 451 | (fn [{:keys [body] :as request}] |
539 | 452 | (do-sync [job (js/create-job job-scheduler (jc/canonicalize (iu/strip-meta body)))] |
|
580 | 493 | (ac/completed-future))))) |
581 | 494 |
|
582 | 495 | (defmethod m/pre-init-spec :blaze/admin-api [_] |
583 | | - (s/keys :req-un [:blaze/context-path ::admin-node :blaze.fhir/parsing-context |
584 | | - :blaze.fhir/writing-context :blaze/job-scheduler |
585 | | - ::read-job-handler ::history-job-handler |
586 | | - ::search-type-job-handler ::settings ::features] |
| 496 | + (s/keys :req-un [:blaze/context-path ::admin-node :blaze.admin-api/validator |
| 497 | + :blaze.fhir/parsing-context :blaze.fhir/writing-context |
| 498 | + :blaze/job-scheduler ::read-job-handler |
| 499 | + ::history-job-handler ::search-type-job-handler ::settings |
| 500 | + ::features] |
587 | 501 | :opt [::dbs ::expr/cache ::db-sync-timeout])) |
588 | 502 |
|
589 | 503 | (defmethod ig/init-key :blaze/admin-api |
590 | 504 | [_ {:keys [job-scheduler] :as config}] |
591 | 505 | (log/info "Init Admin endpoint") |
592 | 506 | (reitit.ring/ring-handler |
593 | | - (router (assoc config :validator (create-validator) |
| 507 | + (router (assoc config |
594 | 508 | :create-job-handler (create-job-handler job-scheduler) |
595 | 509 | :pause-job-handler (job-action-handler job-scheduler js/pause-job) |
596 | 510 | :resume-job-handler (job-action-handler job-scheduler js/resume-job) |
|
0 commit comments