Update loader to ensure that ConceptMap and ValueSet Ids are unique for each version loaded.

This commit is contained in:
ianmarshall 2020-09-25 08:51:53 -04:00
parent 5fe46be41c
commit 2bceacd9a6
13 changed files with 27 additions and 23 deletions

View File

@ -64,9 +64,6 @@ public class BaseJpaResourceProviderCodeSystemDstu3 extends JpaResourceProviderD
IValidationSupport.LookupCodeResult result; IValidationSupport.LookupCodeResult result;
if (theVersion != null) { if (theVersion != null) {
result = dao.lookupCode(theCode, new UriType(theSystem.getValue() + "|" + theVersion), theCoding, theRequestDetails); result = dao.lookupCode(theCode, new UriType(theSystem.getValue() + "|" + theVersion), theCoding, theRequestDetails);
} else if (theCoding != null && theCoding.hasVersion()) {
Coding codingWithVersion = new Coding(theCoding.getSystem() + "|" + theCoding.getVersion(), theCoding.getCode(), theCoding.getDisplay());
result = dao.lookupCode(theCode, theSystem, codingWithVersion, theRequestDetails);
} else { } else {
result = dao.lookupCode(theCode, theSystem, theCoding, theRequestDetails); result = dao.lookupCode(theCode, theSystem, theCoding, theRequestDetails);
} }
@ -104,12 +101,6 @@ public class BaseJpaResourceProviderCodeSystemDstu3 extends JpaResourceProviderD
if (theVersion != null) { if (theVersion != null) {
theSystem = new UriType(theSystem.asStringValue() + "|" + theVersion.toString()); theSystem = new UriType(theSystem.asStringValue() + "|" + theVersion.toString());
} }
if (theCodingA != null && theCodingA.hasVersion()) {
theCodingA.setSystem(theCodingA.getSystemElement().asStringValue() + "|" + theCodingA.getVersion());
}
if (theCodingB != null && theCodingB.hasVersion()) {
theCodingB.setSystem(theCodingB.getSystemElement().asStringValue() + "|" + theCodingB.getVersion());
}
result = dao.subsumes(theCodeA, theCodeB, theSystem, theCodingA, theCodingB, theRequestDetails); result = dao.subsumes(theCodeA, theCodeB, theSystem, theCodingA, theCodingB, theRequestDetails);
return (Parameters) result.toParameters(theRequestDetails.getFhirContext()); return (Parameters) result.toParameters(theRequestDetails.getFhirContext());
} finally { } finally {

View File

@ -52,7 +52,7 @@ public abstract class BaseLoincHandler implements IRecordHandler {
private final List<ValueSet> myValueSets; private final List<ValueSet> myValueSets;
private final Map<String, ValueSet> myIdToValueSet = new HashMap<>(); private final Map<String, ValueSet> myIdToValueSet = new HashMap<>();
private final Map<String, TermConcept> myCode2Concept; private final Map<String, TermConcept> myCode2Concept;
private final Properties myUploadProperties; final Properties myUploadProperties;
BaseLoincHandler(Map<String, TermConcept> theCode2Concept, List<ValueSet> theValueSets, List<ConceptMap> theConceptMaps, Properties theUploadProperties) { BaseLoincHandler(Map<String, TermConcept> theCode2Concept, List<ValueSet> theValueSets, List<ConceptMap> theConceptMaps, Properties theUploadProperties) {
myValueSets = theValueSets; myValueSets = theValueSets;
@ -191,6 +191,8 @@ public abstract class BaseLoincHandler implements IRecordHandler {
String version = null; String version = null;
if (isNotBlank(theVersionPropertyName)) { if (isNotBlank(theVersionPropertyName)) {
version = myUploadProperties.getProperty(theVersionPropertyName); version = myUploadProperties.getProperty(theVersionPropertyName);
} else {
version = myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode());
} }
ValueSet vs; ValueSet vs;

View File

@ -31,6 +31,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CONCEPTMAP_VERSION;
import static org.apache.commons.lang3.StringUtils.trim; import static org.apache.commons.lang3.StringUtils.trim;
public class BaseLoincTop2000LabResultsHandler extends BaseLoincHandler implements IRecordHandler { public class BaseLoincTop2000LabResultsHandler extends BaseLoincHandler implements IRecordHandler {
@ -41,7 +42,7 @@ public class BaseLoincTop2000LabResultsHandler extends BaseLoincHandler implemen
public BaseLoincTop2000LabResultsHandler(Map<String, TermConcept> theCode2concept, List<ValueSet> theValueSets, String theValueSetId, String theValueSetUri, String theValueSetName, List<ConceptMap> theConceptMaps, Properties theUploadProperties) { public BaseLoincTop2000LabResultsHandler(Map<String, TermConcept> theCode2concept, List<ValueSet> theValueSets, String theValueSetId, String theValueSetUri, String theValueSetName, List<ConceptMap> theConceptMaps, Properties theUploadProperties) {
super(theCode2concept, theValueSets, theConceptMaps, theUploadProperties); super(theCode2concept, theValueSets, theConceptMaps, theUploadProperties);
myValueSetId = theValueSetId; myValueSetId = theValueSetId + "-" + myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode());
myValueSetUri = theValueSetUri; myValueSetUri = theValueSetUri;
myValueSetName = theValueSetName; myValueSetName = theValueSetName;
} }

View File

@ -50,7 +50,7 @@ public class LoincAnswerListHandler extends BaseLoincHandler {
public void accept(CSVRecord theRecord) { public void accept(CSVRecord theRecord) {
// this is the code for the list (will repeat) // this is the code for the list (will repeat)
String answerListId = trim(theRecord.get("AnswerListId")); String answerListId = trim(theRecord.get("AnswerListId")) + "-" + myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode());
String answerListName = trim(theRecord.get("AnswerListName")); String answerListName = trim(theRecord.get("AnswerListName"));
String answerListOid = trim(theRecord.get("AnswerListOID")); String answerListOid = trim(theRecord.get("AnswerListOID"));
String externallyDefined = trim(theRecord.get("ExtDefinedYN")); String externallyDefined = trim(theRecord.get("ExtDefinedYN"));

View File

@ -33,6 +33,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CONCEPTMAP_VERSION;
import static org.apache.commons.lang3.StringUtils.trim; import static org.apache.commons.lang3.StringUtils.trim;
public class LoincDocumentOntologyHandler extends BaseLoincHandler implements IRecordHandler { public class LoincDocumentOntologyHandler extends BaseLoincHandler implements IRecordHandler {
@ -57,7 +58,8 @@ public class LoincDocumentOntologyHandler extends BaseLoincHandler implements IR
String partName = trim(theRecord.get("PartName")); String partName = trim(theRecord.get("PartName"));
// RSNA Codes VS // RSNA Codes VS
ValueSet vs = getValueSet(DOCUMENT_ONTOLOGY_CODES_VS_ID, DOCUMENT_ONTOLOGY_CODES_VS_URI, DOCUMENT_ONTOLOGY_CODES_VS_NAME, null); ValueSet vs = getValueSet(DOCUMENT_ONTOLOGY_CODES_VS_ID + "-" + myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()),
DOCUMENT_ONTOLOGY_CODES_VS_URI, DOCUMENT_ONTOLOGY_CODES_VS_NAME, null);
addCodeAsIncludeToValueSet(vs, ITermLoaderSvc.LOINC_URI, loincNumber, null); addCodeAsIncludeToValueSet(vs, ITermLoaderSvc.LOINC_URI, loincNumber, null);
// Part Properties // Part Properties

View File

@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CONCEPTMAP_VERSION;
import static org.apache.commons.lang3.StringUtils.trim; import static org.apache.commons.lang3.StringUtils.trim;
public class LoincGroupFileHandler extends BaseLoincHandler implements IRecordHandler { public class LoincGroupFileHandler extends BaseLoincHandler implements IRecordHandler {
@ -43,7 +44,7 @@ public class LoincGroupFileHandler extends BaseLoincHandler implements IRecordHa
@Override @Override
public void accept(CSVRecord theRecord) { public void accept(CSVRecord theRecord) {
//"ParentGroupId","GroupId","Group","Archetype","Status","VersionFirstReleased" //"ParentGroupId","GroupId","Group","Archetype","Status","VersionFirstReleased"
String parentGroupId = trim(theRecord.get("ParentGroupId")); String parentGroupId = trim(theRecord.get("ParentGroupId")) + "-" + myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode());
String groupId = trim(theRecord.get("GroupId")); String groupId = trim(theRecord.get("GroupId"));
String groupName = trim(theRecord.get("Group")); String groupName = trim(theRecord.get("Group"));
@ -55,7 +56,7 @@ public class LoincGroupFileHandler extends BaseLoincHandler implements IRecordHa
// Create group to set its name (terms are added in a different // Create group to set its name (terms are added in a different
// handler) // handler)
getValueSet(groupId, VS_URI_PREFIX + groupId, groupName, null); getValueSet(groupId, VS_URI_PREFIX + groupId + "-" + myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()), groupName, null);
} }

View File

@ -31,6 +31,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CONCEPTMAP_VERSION;
import static org.apache.commons.lang3.StringUtils.trim; import static org.apache.commons.lang3.StringUtils.trim;
public class LoincGroupTermsFileHandler extends BaseLoincHandler implements IRecordHandler { public class LoincGroupTermsFileHandler extends BaseLoincHandler implements IRecordHandler {
@ -42,7 +43,7 @@ public class LoincGroupTermsFileHandler extends BaseLoincHandler implements IRec
@Override @Override
public void accept(CSVRecord theRecord) { public void accept(CSVRecord theRecord) {
//"Category","GroupId","Archetype","LoincNumber","LongCommonName" //"Category","GroupId","Archetype","LoincNumber","LongCommonName"
String groupId = trim(theRecord.get("GroupId")); String groupId = trim(theRecord.get("GroupId")) + "-" + myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode());
String loincNumber = trim(theRecord.get("LoincNumber")); String loincNumber = trim(theRecord.get("LoincNumber"));
ValueSet valueSet = getValueSet(groupId, LoincGroupFileHandler.VS_URI_PREFIX + groupId, null, null); ValueSet valueSet = getValueSet(groupId, LoincGroupFileHandler.VS_URI_PREFIX + groupId, null, null);

View File

@ -32,6 +32,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CONCEPTMAP_VERSION;
import static org.apache.commons.lang3.StringUtils.trim; import static org.apache.commons.lang3.StringUtils.trim;
public class LoincIeeeMedicalDeviceCodeHandler extends BaseLoincHandler implements IRecordHandler { public class LoincIeeeMedicalDeviceCodeHandler extends BaseLoincHandler implements IRecordHandler {
@ -61,7 +62,7 @@ public class LoincIeeeMedicalDeviceCodeHandler extends BaseLoincHandler implemen
String targetCodeSystemUri = ITermLoaderSvc.IEEE_11073_10101_URI; String targetCodeSystemUri = ITermLoaderSvc.IEEE_11073_10101_URI;
addConceptMapEntry( addConceptMapEntry(
new ConceptMapping() new ConceptMapping()
.setConceptMapId(LOINC_IEEE_CM_ID) .setConceptMapId(LOINC_IEEE_CM_ID + "-" + myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()))
.setConceptMapUri(LOINC_IEEE_CM_URI) .setConceptMapUri(LOINC_IEEE_CM_URI)
.setConceptMapName(LOINC_IEEE_CM_NAME) .setConceptMapName(LOINC_IEEE_CM_NAME)
.setSourceCodeSystem(sourceCodeSystemUri) .setSourceCodeSystem(sourceCodeSystemUri)

View File

@ -31,11 +31,12 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CONCEPTMAP_VERSION;
import static org.apache.commons.lang3.StringUtils.trim; import static org.apache.commons.lang3.StringUtils.trim;
public class LoincImagingDocumentCodeHandler extends BaseLoincHandler implements IRecordHandler { public class LoincImagingDocumentCodeHandler extends BaseLoincHandler implements IRecordHandler {
public static final String VS_ID = "loinc-imaging-document-codes"; public final String VS_ID = "loinc-imaging-document-codes" + "-" + myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode());
public static final String VS_URI = "http://loinc.org/vs/loinc-imaging-document-codes"; public static final String VS_URI = "http://loinc.org/vs/loinc-imaging-document-codes";
public static final String VS_NAME = "LOINC Imaging Document Codes"; public static final String VS_NAME = "LOINC Imaging Document Codes";

View File

@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CONCEPTMAP_VERSION;
import static org.apache.commons.lang3.StringUtils.trim; import static org.apache.commons.lang3.StringUtils.trim;
public class LoincParentGroupFileHandler extends BaseLoincHandler implements IRecordHandler { public class LoincParentGroupFileHandler extends BaseLoincHandler implements IRecordHandler {
@ -41,7 +42,7 @@ public class LoincParentGroupFileHandler extends BaseLoincHandler implements IRe
@Override @Override
public void accept(CSVRecord theRecord) { public void accept(CSVRecord theRecord) {
// "ParentGroupId","ParentGroup","Status" // "ParentGroupId","ParentGroup","Status"
String parentGroupId = trim(theRecord.get("ParentGroupId")); String parentGroupId = trim(theRecord.get("ParentGroupId")) + "-" + myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode());
String parentGroupName = trim(theRecord.get("ParentGroup")); String parentGroupName = trim(theRecord.get("ParentGroup"));
getValueSet(parentGroupId, LoincGroupFileHandler.VS_URI_PREFIX + parentGroupId, parentGroupName, null); getValueSet(parentGroupId, LoincGroupFileHandler.VS_URI_PREFIX + parentGroupId, parentGroupName, null);

View File

@ -33,6 +33,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CONCEPTMAP_VERSION;
import static org.apache.commons.lang3.StringUtils.defaultString; import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.apache.commons.lang3.StringUtils.trim; import static org.apache.commons.lang3.StringUtils.trim;
@ -128,7 +129,7 @@ public class LoincPartRelatedCodeMappingHandler extends BaseLoincHandler impleme
addConceptMapEntry( addConceptMapEntry(
new ConceptMapping() new ConceptMapping()
.setConceptMapId(loincPartMapId) .setConceptMapId(loincPartMapId + "-" + myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()))
.setConceptMapUri(loincPartMapUri) .setConceptMapUri(loincPartMapUri)
.setConceptMapName(loincPartMapName) .setConceptMapName(loincPartMapName)
.setSourceCodeSystem(ITermLoaderSvc.LOINC_URI) .setSourceCodeSystem(ITermLoaderSvc.LOINC_URI)

View File

@ -31,6 +31,7 @@ import org.hl7.fhir.r4.model.ValueSet;
import java.util.*; import java.util.*;
import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CONCEPTMAP_VERSION;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.commons.lang3.StringUtils.trim; import static org.apache.commons.lang3.StringUtils.trim;
@ -174,7 +175,7 @@ public class LoincRsnaPlaybookHandler extends BaseLoincHandler implements IRecor
if (isNotBlank(rid)) { if (isNotBlank(rid)) {
addConceptMapEntry( addConceptMapEntry(
new ConceptMapping() new ConceptMapping()
.setConceptMapId(LoincPartRelatedCodeMappingHandler.LOINC_PART_TO_RID_PART_MAP_ID) .setConceptMapId(LoincPartRelatedCodeMappingHandler.LOINC_PART_TO_RID_PART_MAP_ID + "-" + myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()))
.setConceptMapUri(LoincPartRelatedCodeMappingHandler.LOINC_PART_TO_RID_PART_MAP_URI) .setConceptMapUri(LoincPartRelatedCodeMappingHandler.LOINC_PART_TO_RID_PART_MAP_URI)
.setConceptMapName(LoincPartRelatedCodeMappingHandler.LOINC_PART_TO_RID_PART_MAP_NAME) .setConceptMapName(LoincPartRelatedCodeMappingHandler.LOINC_PART_TO_RID_PART_MAP_NAME)
.setSourceCodeSystem(ITermLoaderSvc.LOINC_URI) .setSourceCodeSystem(ITermLoaderSvc.LOINC_URI)
@ -191,7 +192,7 @@ public class LoincRsnaPlaybookHandler extends BaseLoincHandler implements IRecor
if (isNotBlank(rpid)) { if (isNotBlank(rpid)) {
addConceptMapEntry( addConceptMapEntry(
new ConceptMapping() new ConceptMapping()
.setConceptMapId(LoincPartRelatedCodeMappingHandler.LOINC_TERM_TO_RPID_PART_MAP_ID) .setConceptMapId(LoincPartRelatedCodeMappingHandler.LOINC_TERM_TO_RPID_PART_MAP_ID + "-" + myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode()))
.setConceptMapUri(LoincPartRelatedCodeMappingHandler.LOINC_TERM_TO_RPID_PART_MAP_URI) .setConceptMapUri(LoincPartRelatedCodeMappingHandler.LOINC_TERM_TO_RPID_PART_MAP_URI)
.setConceptMapName(LoincPartRelatedCodeMappingHandler.LOINC_TERM_TO_RPID_PART_MAP_NAME) .setConceptMapName(LoincPartRelatedCodeMappingHandler.LOINC_TERM_TO_RPID_PART_MAP_NAME)
.setSourceCodeSystem(ITermLoaderSvc.LOINC_URI) .setSourceCodeSystem(ITermLoaderSvc.LOINC_URI)

View File

@ -29,11 +29,12 @@ import org.hl7.fhir.r4.model.ValueSet;
import java.util.*; import java.util.*;
import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_CONCEPTMAP_VERSION;
import static org.apache.commons.lang3.StringUtils.trim; import static org.apache.commons.lang3.StringUtils.trim;
public class LoincUniversalOrderSetHandler extends BaseLoincHandler implements IRecordHandler { public class LoincUniversalOrderSetHandler extends BaseLoincHandler implements IRecordHandler {
public static final String VS_ID = "loinc-universal-order-set"; public final String VS_ID = "loinc-universal-order-set" + "-" + myUploadProperties.getProperty(LOINC_CONCEPTMAP_VERSION.getCode());
public static final String VS_URI = "http://loinc.org/vs/loinc-universal-order-set"; public static final String VS_URI = "http://loinc.org/vs/loinc-universal-order-set";
public static final String VS_NAME = "LOINC Universal Order Set"; public static final String VS_NAME = "LOINC Universal Order Set";