From 33554189a18e6245a1598d4593ef672a0ba0ffee Mon Sep 17 00:00:00 2001 From: James Agnew Date: Sun, 11 Mar 2018 15:46:59 -0500 Subject: [PATCH] More loinc work --- LOINC_NOTES.txt | 5 ++ .../dao/data/ITermCodeSystemVersionDao.java | 4 +- .../jpa/entity/TermCodeSystemVersion.java | 10 ++- .../jpa/term/TerminologyLoaderSvcImpl.java | 13 ++- .../uhn/fhir/jpa/term/loinc/BaseHandler.java | 80 +++++++++++++++++++ .../BaseLoincTop2000LabResultsHandler.java | 36 +++++++++ .../loinc/LoincDocumentOntologyHandler.java | 40 ++-------- .../LoincTop2000LabResultsSiHandler.java | 20 +++++ .../LoincTop2000LabResultsUsHandler.java | 20 +++++ ...minologyLoaderSvcIntegrationDstu3Test.java | 20 ++--- .../term/TerminologyLoaderSvcLoincTest.java | 61 ++++++++++---- .../LOINC_1.6_Top2000CommonLabResultsSI.csv | 10 +++ .../LOINC_1.6_Top2000CommonLabResultsUS.csv | 10 +++ 13 files changed, 263 insertions(+), 66 deletions(-) create mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/BaseHandler.java create mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/BaseLoincTop2000LabResultsHandler.java create mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincTop2000LabResultsSiHandler.java create mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincTop2000LabResultsUsHandler.java create mode 100644 hapi-fhir-jpaserver-base/src/test/resources/loinc/LOINC_1.6_Top2000CommonLabResultsSI.csv create mode 100644 hapi-fhir-jpaserver-base/src/test/resources/loinc/LOINC_1.6_Top2000CommonLabResultsUS.csv diff --git a/LOINC_NOTES.txt b/LOINC_NOTES.txt index 859f6249d09..e5930368ab7 100644 --- a/LOINC_NOTES.txt +++ b/LOINC_NOTES.txt @@ -1,5 +1,6 @@ Database migration: update table TRM_CODESYSTEM_VER drop column RES_VERSION_ID; + drop constraint IDX_CSV_RESOURCEPID_AND_VER from table TRM_CODESYSTEM_VER TODO: In answer lists, figure out what to do with externally defined lists @@ -54,3 +55,7 @@ Document Ontology - Need to define a URI for the document ontology ValueSet. Currently I am using "http://loinc.org/document-ontology-codes" +Top 2000 +- Need to define a URI for both ValueSets. Currently I am using + "http://loinc.org/top-2000-lab-results-us" and + "http://loinc.org/top-2000-lab-results-si" diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermCodeSystemVersionDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermCodeSystemVersionDao.java index b27d625c73e..c53f3bc2db7 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermCodeSystemVersionDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermCodeSystemVersionDao.java @@ -33,7 +33,7 @@ public interface ITermCodeSystemVersionDao extends JpaRepository findByCodeSystemResource(@Param("resource_id") Long theCodeSystemResourcePid); - @Query("SELECT cs FROM TermCodeSystemVersion cs WHERE cs.myResource.myId = :resource_id AND cs.myResourceVersionId = :version_id") - TermCodeSystemVersion findByCodeSystemResourceAndVersion(@Param("resource_id") Long theCodeSystemResourcePid, @Param("version_id") Long theCodeSystemVersionPid); + @Query("SELECT cs FROM TermCodeSystemVersion cs WHERE cs.myCodeSystemHavingThisVersionAsCurrentVersionIfAny.myResource.myId = :resource_id") + TermCodeSystemVersion findCurrentVersionForCodeSystemResourcePid(@Param("resource_id") Long theCodeSystemResourcePid); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java index 88b48afc2bf..c91606fcb40 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java @@ -41,9 +41,9 @@ import javax.persistence.UniqueConstraint; import ca.uhn.fhir.util.CoverageIgnore; //@formatter:off -@Table(name="TRM_CODESYSTEM_VER", uniqueConstraints= { - @UniqueConstraint(name="IDX_CSV_RESOURCEPID_AND_VER", columnNames= {"RES_ID", "RES_VERSION_ID"}) -}) +@Table(name="TRM_CODESYSTEM_VER" + // Note, we used to have a constraint named IDX_CSV_RESOURCEPID_AND_VER (don't reuse this) +) @Entity() //@formatter:on public class TermCodeSystemVersion implements Serializable { @@ -65,6 +65,10 @@ public class TermCodeSystemVersion implements Serializable { @Column(name = "CS_VERSION_ID", nullable = true, updatable = false) private String myCodeSystemVersionId; + @SuppressWarnings("unused") + @OneToOne(mappedBy = "myCurrentVersion", optional = true) + private TermCodeSystem myCodeSystemHavingThisVersionAsCurrentVersionIfAny; + /** * Constructor */ diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcImpl.java index 6338ca30401..1bc4b23a6e2 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcImpl.java @@ -60,7 +60,6 @@ public class TerminologyLoaderSvcImpl implements IHapiTerminologyLoaderSvc { public static final String SCT_FILE_CONCEPT = "Terminology/sct2_Concept_Full_"; public static final String SCT_FILE_DESCRIPTION = "Terminology/sct2_Description_Full-en"; public static final String SCT_FILE_RELATIONSHIP = "Terminology/sct2_Relationship_Full"; - private static final int LOG_INCREMENT = 100000; public static final String LOINC_ANSWERLIST_FILE = "AnswerList_Beta_1.csv"; public static final String LOINC_ANSWERLIST_LINK_FILE = "LoincAnswerListLink_Beta_1.csv"; public static final String LOINC_DOCUMENT_ONTOLOGY_FILE = "DocumentOntology.csv"; @@ -70,7 +69,9 @@ public class TerminologyLoaderSvcImpl implements IHapiTerminologyLoaderSvc { public static final String LOINC_PART_LINK_FILE = "LoincPartLink_Beta_1.csv"; public static final String LOINC_PART_RELATED_CODE_MAPPING_FILE = "PartRelatedCodeMapping_Beta_1.csv"; public static final String LOINC_RSNA_PLAYBOOK_FILE = "LoincRsnaRadiologyPlaybook.csv"; - + public static final String TOP2000_COMMON_LAB_RESULTS_US_FILE = "Top2000CommonLabResultsUS.csv"; + public static final String TOP2000_COMMON_LAB_RESULTS_SI_FILE = "Top2000CommonLabResultsSI.csv"; + private static final int LOG_INCREMENT = 100000; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TerminologyLoaderSvcImpl.class); @Autowired private IHapiTerminologySvc myTermSvc; @@ -249,6 +250,14 @@ public class TerminologyLoaderSvcImpl implements IHapiTerminologyLoaderSvc { handler = new LoincRsnaPlaybookHandler(codeSystemVersion, code2concept, propertyNames, valueSets, conceptMaps); iterateOverZipFile(theZipBytes, LOINC_RSNA_PLAYBOOK_FILE, handler, ',', QuoteMode.NON_NUMERIC); + // Top 2000 Codes - US + handler = new LoincTop2000LabResultsUsHandler(code2concept, valueSets); + iterateOverZipFile(theZipBytes, TOP2000_COMMON_LAB_RESULTS_US_FILE, handler, ',', QuoteMode.NON_NUMERIC); + + // Top 2000 Codes - SI + handler = new LoincTop2000LabResultsSiHandler(code2concept, valueSets); + iterateOverZipFile(theZipBytes, TOP2000_COMMON_LAB_RESULTS_SI_FILE, handler, ',', QuoteMode.NON_NUMERIC); + theZipBytes.clear(); for (Entry next : code2concept.entrySet()) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/BaseHandler.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/BaseHandler.java new file mode 100644 index 00000000000..7a2c3d8dd17 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/BaseHandler.java @@ -0,0 +1,80 @@ +package ca.uhn.fhir.jpa.term.loinc; + +import ca.uhn.fhir.jpa.entity.TermConcept; +import ca.uhn.fhir.jpa.term.IRecordHandler; +import org.hl7.fhir.r4.model.Enumerations; +import org.hl7.fhir.r4.model.ValueSet; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.apache.commons.lang3.StringUtils.isBlank; + +abstract class BaseHandler implements IRecordHandler { + + private final List myValueSets; + private final Map myIdToValueSet = new HashMap<>(); + private final Map myCode2Concept; + + BaseHandler(Map theCode2Concept, List theValueSets) { + myValueSets = theValueSets; + myCode2Concept = theCode2Concept; + } + + void addCodeAsIncludeToValueSet(ValueSet theVs, String theCodeSystemUrl, String theCode, String theDisplayName) { + ValueSet.ConceptSetComponent include = null; + for (ValueSet.ConceptSetComponent next : theVs.getCompose().getInclude()) { + if (next.getSystem().equals(theCodeSystemUrl)) { + include = next; + break; + } + } + if (include == null) { + include = theVs.getCompose().addInclude(); + include.setSystem(theCodeSystemUrl); + } + + boolean found = false; + for (ValueSet.ConceptReferenceComponent next : include.getConcept()) { + if (next.getCode().equals(theCode)) { + found = true; + } + } + if (!found) { + + String displayName = theDisplayName; + if (isBlank(displayName)) { + for (TermConcept next : myCode2Concept.values()) { + if (next.getCode().equals(theCode)) { + displayName = next.getDisplay(); + } + } + } + + include + .addConcept() + .setCode(theCode) + .setDisplay(displayName); + + } + } + + ValueSet getValueSet(String theValueSetId, String theValueSetUri, String theValueSetName) { + ValueSet vs; + if (!myIdToValueSet.containsKey(theValueSetId)) { + vs = new ValueSet(); + vs.setUrl(theValueSetUri); + vs.setId(theValueSetId); + vs.setName(theValueSetName); + vs.setStatus(Enumerations.PublicationStatus.ACTIVE); + myIdToValueSet.put(theValueSetId, vs); + myValueSets.add(vs); + } else { + vs = myIdToValueSet.get(theValueSetId); + } + return vs; + } + + +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/BaseLoincTop2000LabResultsHandler.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/BaseLoincTop2000LabResultsHandler.java new file mode 100644 index 00000000000..a53f406851b --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/BaseLoincTop2000LabResultsHandler.java @@ -0,0 +1,36 @@ +package ca.uhn.fhir.jpa.term.loinc; + +import ca.uhn.fhir.jpa.entity.TermConcept; +import ca.uhn.fhir.jpa.term.IHapiTerminologyLoaderSvc; +import ca.uhn.fhir.jpa.term.IRecordHandler; +import org.apache.commons.csv.CSVRecord; +import org.hl7.fhir.r4.model.ValueSet; + +import java.util.List; +import java.util.Map; + +import static org.apache.commons.lang3.StringUtils.trim; + +public class BaseLoincTop2000LabResultsHandler extends BaseHandler implements IRecordHandler { + + private String myValueSetId; + private String myValueSetUri; + private String myValueSetName; + + public BaseLoincTop2000LabResultsHandler(Map theCode2concept, List theValueSets, String theValueSetId, String theValueSetUri, String theValueSetName) { + super(theCode2concept, theValueSets); + myValueSetId = theValueSetId; + myValueSetUri = theValueSetUri; + myValueSetName = theValueSetName; + } + + @Override + public void accept(CSVRecord theRecord) { + String loincNumber = trim(theRecord.get("LOINC #")); + String displayName = trim(theRecord.get("Long Common Name")); + + ValueSet valueSet = getValueSet(myValueSetId, myValueSetUri, myValueSetName); + addCodeAsIncludeToValueSet(valueSet, IHapiTerminologyLoaderSvc.LOINC_URL, loincNumber, displayName); + } + +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincDocumentOntologyHandler.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincDocumentOntologyHandler.java index 3d51231ee01..4f8d07ae964 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincDocumentOntologyHandler.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincDocumentOntologyHandler.java @@ -13,7 +13,7 @@ import java.util.*; import static org.apache.commons.lang3.StringUtils.trim; -public class LoincDocumentOntologyHandler implements IRecordHandler { +public class LoincDocumentOntologyHandler extends BaseHandler implements IRecordHandler { public static final String DOCUMENT_ONTOLOGY_CODES_VS_ID = "DOCUMENT_ONTOLOGY_CODES_VS"; public static final String DOCUMENT_ONTOLOGY_CODES_VS_URI = "http://loinc.org/document-ontology-codes"; @@ -21,15 +21,12 @@ public class LoincDocumentOntologyHandler implements IRecordHandler { private final Map myCode2Concept; private final TermCodeSystemVersion myCodeSystemVersion; private final Set myPropertyNames; - private final List myValueSets; - private final Map myIdToValueSet = new HashMap<>(); - private final Set myCodesInDocumentOntologyValueSet = new HashSet<>(); public LoincDocumentOntologyHandler(TermCodeSystemVersion theCodeSystemVersion, Map theCode2concept, Set thePropertyNames, List theValueSets) { + super(theCode2concept, theValueSets); myCodeSystemVersion = theCodeSystemVersion; myCode2Concept = theCode2concept; myPropertyNames = thePropertyNames; - myValueSets = theValueSets; } @Override @@ -42,35 +39,10 @@ public class LoincDocumentOntologyHandler implements IRecordHandler { String partName = trim(theRecord.get("PartName")); // RSNA Codes VS - ValueSet vs; - if (!myIdToValueSet.containsKey(DOCUMENT_ONTOLOGY_CODES_VS_ID)) { - vs = new ValueSet(); - vs.setUrl(DOCUMENT_ONTOLOGY_CODES_VS_URI); - vs.setId(DOCUMENT_ONTOLOGY_CODES_VS_ID); - vs.setName(DOCUMENT_ONTOLOGY_CODES_VS_NAME); - vs.setStatus(Enumerations.PublicationStatus.ACTIVE); - myIdToValueSet.put(DOCUMENT_ONTOLOGY_CODES_VS_ID, vs); - myValueSets.add(vs); - } else { - vs = myIdToValueSet.get(DOCUMENT_ONTOLOGY_CODES_VS_ID); - } - - if (!myCodesInDocumentOntologyValueSet.contains(loincNumber)) { - String loincDisplayName= null; - if (myCode2Concept.containsKey(loincNumber)) { - loincDisplayName = myCode2Concept.get(loincNumber).getDisplay(); - } - - vs - .getCompose() - .getIncludeFirstRep() - .setSystem(IHapiTerminologyLoaderSvc.LOINC_URL) - .addConcept() - .setCode(loincNumber) - .setDisplay(loincDisplayName); - myCodesInDocumentOntologyValueSet.add(loincNumber); - } + ValueSet vs = getValueSet(DOCUMENT_ONTOLOGY_CODES_VS_ID, DOCUMENT_ONTOLOGY_CODES_VS_URI, DOCUMENT_ONTOLOGY_CODES_VS_NAME); + addCodeAsIncludeToValueSet(vs, IHapiTerminologyLoaderSvc.LOINC_URL, loincNumber, null); + // Part Properties String loincCodePropName; switch (partTypeName) { case "Document.Kind": @@ -99,4 +71,6 @@ public class LoincDocumentOntologyHandler implements IRecordHandler { } + + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincTop2000LabResultsSiHandler.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincTop2000LabResultsSiHandler.java new file mode 100644 index 00000000000..78f63978261 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincTop2000LabResultsSiHandler.java @@ -0,0 +1,20 @@ +package ca.uhn.fhir.jpa.term.loinc; + +import ca.uhn.fhir.jpa.entity.TermConcept; +import org.hl7.fhir.r4.model.ValueSet; + +import java.util.List; +import java.util.Map; + +public class LoincTop2000LabResultsSiHandler extends BaseLoincTop2000LabResultsHandler { + + public static final String TOP_2000_SI_VS_ID = "TOP_2000_SI_VS_ID"; + public static final String TOP_2000_SI_VS_URI = "http://loinc.org/top-2000-lab-results-si"; + public static final String TOP_2000_SI_VS_NAME = "Top 2000 Lab Results SI"; + + public LoincTop2000LabResultsSiHandler(Map theCode2concept, List theValueSets) { + super(theCode2concept, theValueSets, TOP_2000_SI_VS_ID, TOP_2000_SI_VS_URI, TOP_2000_SI_VS_NAME); + } + + +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincTop2000LabResultsUsHandler.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincTop2000LabResultsUsHandler.java new file mode 100644 index 00000000000..dad256ce4ac --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/loinc/LoincTop2000LabResultsUsHandler.java @@ -0,0 +1,20 @@ +package ca.uhn.fhir.jpa.term.loinc; + +import ca.uhn.fhir.jpa.entity.TermConcept; +import org.hl7.fhir.r4.model.ValueSet; + +import java.util.List; +import java.util.Map; + +public class LoincTop2000LabResultsUsHandler extends BaseLoincTop2000LabResultsHandler { + + public static final String TOP_2000_US_VS_ID = "TOP_2000_LABRESULTS_US"; + public static final String TOP_2000_US_VS_URI = "http://loinc.org/top-2000-lab-results-us"; + public static final String TOP_2000_US_VS_NAME = "Top 2000 Lab Results US"; + + public LoincTop2000LabResultsUsHandler(Map theCode2concept, List theValueSets) { + super(theCode2concept, theValueSets, TOP_2000_US_VS_ID, TOP_2000_US_VS_URI, TOP_2000_US_VS_NAME); + } + + +} diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcIntegrationDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcIntegrationDstu3Test.java index 9b12611608b..c45b4e17ca3 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcIntegrationDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcIntegrationDstu3Test.java @@ -6,11 +6,14 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import java.io.IOException; import java.util.List; public class TerminologyLoaderSvcIntegrationDstu3Test extends BaseJpaDstu3Test { + @Autowired private TerminologyLoaderSvcImpl myLoader; @AfterClass @@ -18,17 +21,14 @@ public class TerminologyLoaderSvcIntegrationDstu3Test extends BaseJpaDstu3Test { TestUtil.clearAllStaticFieldsForUnitTest(); } - @Before - public void beforeInitTest() { - myLoader = new TerminologyLoaderSvcImpl(); - myLoader.setTermSvcForUnitTests(myTermSvc); - } - @Test - @Ignore - public void testLoadAndStoreLoinc() { - List files; -// myLoader.processSnomedCtFiles(files, mySrd); + public void testLoadAndStoreLoinc() throws Exception { + ZipCollectionBuilder files = new ZipCollectionBuilder(); + TerminologyLoaderSvcLoincTest.createLoincBundle(files); + + myLoader.loadLoinc(files.getFiles(), mySrd); + + Thread.sleep(120000); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincTest.java index a65c6ca564c..96d4f130d74 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincTest.java @@ -2,10 +2,7 @@ package ca.uhn.fhir.jpa.term; import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; import ca.uhn.fhir.jpa.entity.TermConcept; -import ca.uhn.fhir.jpa.term.loinc.LoincDocumentOntologyHandler; -import ca.uhn.fhir.jpa.term.loinc.LoincPartHandler; -import ca.uhn.fhir.jpa.term.loinc.LoincPartRelatedCodeMappingHandler; -import ca.uhn.fhir.jpa.term.loinc.LoincRsnaPlaybookHandler; +import ca.uhn.fhir.jpa.term.loinc.*; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.r4.model.CodeSystem; @@ -21,6 +18,7 @@ import org.mockito.Captor; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -60,21 +58,13 @@ public class TerminologyLoaderSvcLoincTest { mySvc = new TerminologyLoaderSvcImpl(); mySvc.setTermSvcForUnitTests(myTermSvc); mySvc.setTermSvcDstu3ForUnitTest(myTermSvcDstu3); - + myFiles = new ZipCollectionBuilder(); } @Test public void testLoadLoinc() throws Exception { - myFiles.addFile("/loinc/", "loinc.csv", TerminologyLoaderSvcImpl.LOINC_FILE); - myFiles.addFile("/loinc/", "hierarchy.csv", TerminologyLoaderSvcImpl.LOINC_HIERARCHY_FILE); - myFiles.addFile("/loinc/", "AnswerList_Beta_1.csv", TerminologyLoaderSvcImpl.LOINC_ANSWERLIST_FILE); - myFiles.addFile("/loinc/", TerminologyLoaderSvcImpl.LOINC_ANSWERLIST_LINK_FILE, TerminologyLoaderSvcImpl.LOINC_ANSWERLIST_LINK_FILE); - myFiles.addFile("/loinc/", TerminologyLoaderSvcImpl.LOINC_PART_FILE, TerminologyLoaderSvcImpl.LOINC_PART_FILE); - myFiles.addFile("/loinc/", TerminologyLoaderSvcImpl.LOINC_PART_LINK_FILE, TerminologyLoaderSvcImpl.LOINC_PART_LINK_FILE); - myFiles.addFile("/loinc/", TerminologyLoaderSvcImpl.LOINC_PART_RELATED_CODE_MAPPING_FILE); - myFiles.addFile("/loinc/", TerminologyLoaderSvcImpl.LOINC_DOCUMENT_ONTOLOGY_FILE); - myFiles.addFile("/loinc/", TerminologyLoaderSvcImpl.LOINC_RSNA_PLAYBOOK_FILE); + createLoincBundle(myFiles); // Actually do the load mySvc.loadLoinc(myFiles.getFiles(), details); @@ -240,14 +230,53 @@ public class TerminologyLoaderSvcLoincTest { assertEquals("US Retroperitoneum", group.getElement().get(0).getTarget().get(0).getDisplay()); assertEquals(Enumerations.ConceptMapEquivalence.EQUAL, group.getElement().get(0).getTarget().get(0).getEquivalence()); + // TOP 2000 - US + vs = valueSets.get(LoincTop2000LabResultsUsHandler.TOP_2000_US_VS_ID); + assertEquals(vs.getName(), LoincTop2000LabResultsUsHandler.TOP_2000_US_VS_NAME); + assertEquals(vs.getUrl(), LoincTop2000LabResultsUsHandler.TOP_2000_US_VS_URI); + assertEquals(1, vs.getCompose().getInclude().size()); + assertEquals(IHapiTerminologyLoaderSvc.LOINC_URL, vs.getCompose().getInclude().get(0).getSystem()); + assertEquals(9, vs.getCompose().getInclude().get(0).getConcept().size()); + assertEquals("2160-0", vs.getCompose().getInclude().get(0).getConcept().get(0).getCode()); + assertEquals("Creatinine [Mass/volume] in Serum or Plasma", vs.getCompose().getInclude().get(0).getConcept().get(0).getDisplay()); + assertEquals("718-7", vs.getCompose().getInclude().get(0).getConcept().get(1).getCode()); + assertEquals("Hemoglobin [Mass/volume] in Blood", vs.getCompose().getInclude().get(0).getConcept().get(1).getDisplay()); + + // TOP 2000 - SI + vs = valueSets.get(LoincTop2000LabResultsSiHandler.TOP_2000_SI_VS_ID); + assertEquals(vs.getName(), LoincTop2000LabResultsSiHandler.TOP_2000_SI_VS_NAME); + assertEquals(vs.getUrl(), LoincTop2000LabResultsSiHandler.TOP_2000_SI_VS_URI); + assertEquals(1, vs.getCompose().getInclude().size()); + assertEquals(IHapiTerminologyLoaderSvc.LOINC_URL, vs.getCompose().getInclude().get(0).getSystem()); + assertEquals(9, vs.getCompose().getInclude().get(0).getConcept().size()); + assertEquals("14682-9", vs.getCompose().getInclude().get(0).getConcept().get(0).getCode()); + assertEquals("Creatinine [Moles/volume] in Serum or Plasma", vs.getCompose().getInclude().get(0).getConcept().get(0).getDisplay()); + assertEquals("718-7", vs.getCompose().getInclude().get(0).getConcept().get(1).getCode()); + assertEquals("Hemoglobin [Mass/volume] in Blood", vs.getCompose().getInclude().get(0).getConcept().get(1).getDisplay()); } - - @AfterClass public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } + static void createLoincBundle(ZipCollectionBuilder theFiles) throws IOException { + theFiles.addFile("/loinc/", "loinc.csv", TerminologyLoaderSvcImpl.LOINC_FILE); + theFiles.addFile("/loinc/", "hierarchy.csv", TerminologyLoaderSvcImpl.LOINC_HIERARCHY_FILE); + theFiles.addFile("/loinc/", "AnswerList_Beta_1.csv", TerminologyLoaderSvcImpl.LOINC_ANSWERLIST_FILE); + theFiles.addFile("/loinc/", TerminologyLoaderSvcImpl.LOINC_ANSWERLIST_LINK_FILE, TerminologyLoaderSvcImpl.LOINC_ANSWERLIST_LINK_FILE); + theFiles.addFile("/loinc/", TerminologyLoaderSvcImpl.LOINC_PART_FILE, TerminologyLoaderSvcImpl.LOINC_PART_FILE); + theFiles.addFile("/loinc/", TerminologyLoaderSvcImpl.LOINC_PART_LINK_FILE, TerminologyLoaderSvcImpl.LOINC_PART_LINK_FILE); + theFiles.addFile("/loinc/", TerminologyLoaderSvcImpl.LOINC_PART_RELATED_CODE_MAPPING_FILE); + theFiles.addFile("/loinc/", TerminologyLoaderSvcImpl.LOINC_DOCUMENT_ONTOLOGY_FILE); + theFiles.addFile("/loinc/", TerminologyLoaderSvcImpl.LOINC_RSNA_PLAYBOOK_FILE); + /* + * Top 2000 files have versions in the filename so don't use the + * constant.. that way this is a better test + */ + theFiles.addFile("/loinc/", "LOINC_1.6_Top2000CommonLabResultsSI.csv"); + theFiles.addFile("/loinc/", "LOINC_1.6_Top2000CommonLabResultsUS.csv"); + } + } diff --git a/hapi-fhir-jpaserver-base/src/test/resources/loinc/LOINC_1.6_Top2000CommonLabResultsSI.csv b/hapi-fhir-jpaserver-base/src/test/resources/loinc/LOINC_1.6_Top2000CommonLabResultsSI.csv new file mode 100644 index 00000000000..326b4184a3d --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/test/resources/loinc/LOINC_1.6_Top2000CommonLabResultsSI.csv @@ -0,0 +1,10 @@ +LOINC #,Long Common Name,Short Name,CLASS,Rank +14682-9,Creatinine [Moles/volume] in Serum or Plasma,Creat SerPl-mCnc,Chem,1 +718-7,Hemoglobin [Mass/volume] in Blood,Hgb Bld-mCnc,HEM/BC,2 +2823-3,Potassium [Moles/volume] in Serum or Plasma,Potassium SerPl-sCnc,Chem,3 +14749-6,Glucose [Moles/volume] in Serum or Plasma,Glucose SerPl-mCnc,Chem,4 +2951-2,Sodium [Moles/volume] in Serum or Plasma,Sodium SerPl-sCnc,Chem,5 +3094-0,Urea nitrogen [Mass/volume] in Serum or Plasma,BUN SerPl-mCnc,Chem,6 +2028-9,"Carbon dioxide, total [Moles/volume] in Serum or Plasma",CO2 SerPl-sCnc,Chem,7 +2075-0,Chloride [Moles/volume] in Serum or Plasma,Chloride SerPl-sCnc,Chem,8 +789-8,Erythrocytes [#/volume] in Blood by Automated count,RBC # Bld Auto,HEM/BC,9 diff --git a/hapi-fhir-jpaserver-base/src/test/resources/loinc/LOINC_1.6_Top2000CommonLabResultsUS.csv b/hapi-fhir-jpaserver-base/src/test/resources/loinc/LOINC_1.6_Top2000CommonLabResultsUS.csv new file mode 100644 index 00000000000..16b77b41e0b --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/test/resources/loinc/LOINC_1.6_Top2000CommonLabResultsUS.csv @@ -0,0 +1,10 @@ +LOINC #,Long Common Name,Short Name,CLASS,Rank +2160-0,Creatinine [Mass/volume] in Serum or Plasma,Creat SerPl-mCnc,Chem,1 +718-7,Hemoglobin [Mass/volume] in Blood,Hgb Bld-mCnc,HEM/BC,2 +2823-3,Potassium [Moles/volume] in Serum or Plasma,Potassium SerPl-sCnc,Chem,3 +2345-7,Glucose [Mass/volume] in Serum or Plasma,Glucose SerPl-mCnc,Chem,4 +2951-2,Sodium [Moles/volume] in Serum or Plasma,Sodium SerPl-sCnc,Chem,5 +3094-0,Urea nitrogen [Mass/volume] in Serum or Plasma,BUN SerPl-mCnc,Chem,6 +2028-9,"Carbon dioxide, total [Moles/volume] in Serum or Plasma",CO2 SerPl-sCnc,Chem,7 +2075-0,Chloride [Moles/volume] in Serum or Plasma,Chloride SerPl-sCnc,Chem,8 +789-8,Erythrocytes [#/volume] in Blood by Automated count,RBC # Bld Auto,HEM/BC,9