|
| 1 | +(ns com.eldrix.hermes.importer-test |
| 2 | + (:require |
| 3 | + [clojure.core.async :as async] |
| 4 | + [clojure.java.io :as io] |
| 5 | + [clojure.spec.gen.alpha :as gen] |
| 6 | + [clojure.test :refer [deftest is testing]] |
| 7 | + [com.eldrix.hermes.importer :as importer] |
| 8 | + [com.eldrix.hermes.rf2 :as rf2]) |
| 9 | + (:import (java.time LocalDate))) |
| 10 | + |
| 11 | +(deftest parse-filename |
| 12 | + (testing "nil filename" |
| 13 | + (is (nil? (importer/parse-filename nil)))) |
| 14 | + (testing "concept filename as string" |
| 15 | + (let [{:keys [format version-date content-subtype type country-code identifier component]} (importer/parse-filename "sct2_Concept_Snapshot_INT_20230131.txt")] |
| 16 | + (is (= "Concept" component)) |
| 17 | + (is (= "INT" country-code)) |
| 18 | + (is (= :info.snomed/Concept identifier)) |
| 19 | + (is (= "2" format)) |
| 20 | + (is (= "sct" type)) |
| 21 | + (is (= (LocalDate/of 2023 1 31) version-date)))) |
| 22 | + (testing "description filename as URL" |
| 23 | + (let [{:keys [identifier]} (importer/parse-filename (java.net.URL. "file://Terminology/sct2_Description_Snapshot-en_INT_20230131.txt"))] |
| 24 | + (is (= :info.snomed/Description identifier)))) |
| 25 | + (testing "relationship concrete values filename as file" |
| 26 | + (let [{:keys [identifier]} (importer/parse-filename (io/file "./Terminology/sct2_RelationshipConcreteValues_Snapshot_INT_20230131.txt"))] |
| 27 | + (is (= :info.snomed/RelationshipConcreteValues identifier))))) |
| 28 | + |
| 29 | +(defn import-file |
| 30 | + "Import a SNOMED file" |
| 31 | + [f] |
| 32 | + (let [ch (async/chan)] |
| 33 | + (async/thread |
| 34 | + (importer/process-file f ch) |
| 35 | + (async/close! ch)) |
| 36 | + (async/<!! ch))) |
| 37 | + |
| 38 | +(deftest import-concepts |
| 39 | + (let [{:keys [type parser headings data]} (import-file (io/resource "example-snapshot/Terminology/sct2_Concept_Snapshot_INT_20230131.txt"))] |
| 40 | + (is (= :info.snomed/Concept type)))) |
| 41 | + |
| 42 | +(deftest import-refset |
| 43 | + (let [{:keys [type parser headings data] :as f} (import-file (io/resource "example-snapshot/Refset/Map/der2_iisssccRefset_ExtendedMapSnapshot_INT_20230131.txt"))] |
| 44 | + (is (= :info.snomed/ExtendedMapRefset type)) |
| 45 | + (is (= ["id" "effectiveTime" "active" "moduleId" "refsetId" "referencedComponentId" |
| 46 | + "mapGroup" "mapPriority" "mapRule" "mapAdvice" "mapTarget" |
| 47 | + "correlationId" "mapCategoryId"] headings)))) |
| 48 | + |
| 49 | +(deftest import-custom-refset-nil-values |
| 50 | + (let [{:keys [type parser headings data] :as f} (import-file (io/resource "example-snapshot/Refset/Map/der2_ssRefset_SimpleMapWithDescriptionSnapshot_12345_20241021.txt"))] |
| 51 | + (is (= :info.snomed/SimpleMapRefset type)) |
| 52 | + (is (= ["id" "effectiveTime" "active" "moduleId" "refsetId" "referencedComponentId" |
| 53 | + "mapTarget" "mapTargetDescription"] headings)) |
| 54 | + (is (= ["000d91ce-aae4-4f9e-ad06-51be576becd6" "20241021" |
| 55 | + "1" "195941000112101" "22671000001102" |
| 56 | + "1434181000001106" "ABC01256Q" ""] (first data)) |
| 57 | + "Empty last column should be returned as empty string"))) |
| 58 | + |
| 59 | +(comment |
| 60 | + (require '[clojure.data.csv :as csv]) |
| 61 | + (csv/read-csv "hi\tthere\tand\thow\tare\tyou?\t" :separator \tab) |
| 62 | + (def f (io/resource "example-snapshot/Terminology/sct2_Concept_Snapshot_INT_20230131.txt")) |
| 63 | + (type f) |
| 64 | + (io/as-file f) |
| 65 | + (importer/parse-filename "sct2_Concept.txt") |
| 66 | + (importer/parse-filename (java.net.URL. "https://wibble.com/sct_Concept_Snapshot_INT_20230131.txt")) |
| 67 | + (importer/parse-filename f) |
| 68 | + (importer/parse-filename nil) |
| 69 | + (def ch (async/chan)) |
| 70 | + (async/thread |
| 71 | + (importer/process-file f ch) |
| 72 | + (async/close! ch)) |
| 73 | + (def ch (importer/load-snomed (io/resource "example-snapshot/"))) |
| 74 | + (async/<!! ch) |
| 75 | + |
| 76 | + (gen/sample (rf2/gen-simple-map-refset {:fields [""]}))) |
| 77 | + |
0 commit comments