Parse out canonical url version + refactor

This commit is contained in:
dotasek 2022-11-02 16:58:28 -04:00
parent 8e663f3ce9
commit 16a0a08598
3 changed files with 57 additions and 23 deletions

View File

@ -84,6 +84,7 @@ public class TerminologyCache {
private static final String CAPABILITY_STATEMENT_TITLE = ".capabilityStatement"; private static final String CAPABILITY_STATEMENT_TITLE = ".capabilityStatement";
private static final String TERMINOLOGY_CAPABILITIES_TITLE = ".terminologyCapabilities"; private static final String TERMINOLOGY_CAPABILITIES_TITLE = ".terminologyCapabilities";
private SystemNameKeyGenerator systemNameKeyGenerator = new SystemNameKeyGenerator(); private SystemNameKeyGenerator systemNameKeyGenerator = new SystemNameKeyGenerator();
public class CacheToken { public class CacheToken {
@ -109,33 +110,62 @@ public class TerminologyCache {
return systemNameKeyGenerator; return systemNameKeyGenerator;
} }
public class SystemNameKeyGenerator { public class SystemNameKeyGenerator {
public static final String SNOMED_SCT_CODESYSTEM_URL = "http://snomed.info/sct";
public static final String RXNORM_CODESYSTEM_URL = "http://www.nlm.nih.gov/research/umls/rxnorm";
public static final String LOINC_CODESYSTEM_URL = "http://loinc.org";
public static final String UCUM_CODESYSTEM_URL = "http://unitsofmeasure.org";
public static final String HL7_TERMINOLOGY_CODESYSTEM_BASE_URL = "http://terminology.hl7.org/CodeSystem/";
public static final String HL7_SID_CODESYSTEM_BASE_URL = "http://hl7.org/fhir/sid/";
public static final String HL7_FHIR_CODESYSTEM_BASE_URL = "http://hl7.org/fhir/";
public static final String ISO_CODESYSTEM_URN = "urn:iso:std:iso:";
public static final String LANG_CODESYSTEM_URN = "urn:ietf:bcp:47";
public static final String MIMETYPES_CODESYSTEM_URN = "urn:ietf:bcp:13";
public static final String _11073_CODESYSTEM_URN = "urn:iso:std:iso:11073:10101";
public static final String DICOM_CODESYSTEM_URL = "http://dicom.nema.org/resources/ontology/DCM";
public String getNameForSystem(String system) { public String getNameForSystem(String system) {
if (system.equals("http://snomed.info/sct")) System.out.println(system);
if (system.equals(SNOMED_SCT_CODESYSTEM_URL))
return "snomed"; return "snomed";
if (system.equals("http://www.nlm.nih.gov/research/umls/rxnorm")) if (system.equals(RXNORM_CODESYSTEM_URL))
return "rxnorm"; return "rxnorm";
if (system.equals("http://loinc.org")) if (system.equals(LOINC_CODESYSTEM_URL))
return "loinc"; return "loinc";
if (system.equals("http://unitsofmeasure.org")) if (system.equals(UCUM_CODESYSTEM_URL))
return "ucum"; return "ucum";
if (system.startsWith("http://hl7.org/fhir/sid/")) if (system.startsWith(HL7_SID_CODESYSTEM_BASE_URL))
return system.substring(24).replace("/", ""); return getNameForCanonicalURL(HL7_SID_CODESYSTEM_BASE_URL, system);
if (system.startsWith("urn:iso:std:iso:")) if (system.startsWith(ISO_CODESYSTEM_URN))
return "iso"+system.substring(16).replace(":", ""); return "iso"+system.substring(ISO_CODESYSTEM_URN.length()).replace(":", "");
if (system.startsWith("http://terminology.hl7.org/CodeSystem/")) if (system.startsWith(HL7_TERMINOLOGY_CODESYSTEM_BASE_URL))
return system.substring(38).replace("/", "").replace('|','X'); return getNameForCanonicalURL(HL7_TERMINOLOGY_CODESYSTEM_BASE_URL, system);
if (system.startsWith("http://hl7.org/fhir/")) if (system.startsWith(HL7_FHIR_CODESYSTEM_BASE_URL))
return system.substring(20).replace("/", ""); return getNameForCanonicalURL(HL7_FHIR_CODESYSTEM_BASE_URL, system);
if (system.equals("urn:ietf:bcp:47")) if (system.equals(LANG_CODESYSTEM_URN))
return "lang"; return "lang";
if (system.equals("urn:ietf:bcp:13")) if (system.equals(MIMETYPES_CODESYSTEM_URN))
return "mimetypes"; return "mimetypes";
if (system.equals("urn:iso:std:iso:11073:10101")) if (system.equals(_11073_CODESYSTEM_URN))
return "11073"; return "11073";
if (system.equals("http://dicom.nema.org/resources/ontology/DCM")) if (system.equals(DICOM_CODESYSTEM_URL))
return "dicom"; return "dicom";
return system.replace("/", "_").replace(":", "_").replace("?", "X").replace("#", "X"); return system.replace("/", "_").replace(":", "_").replace("?", "X").replace("#", "X");
} }
public String getNameForCanonicalURL(String baseUrl, String fullUrl) {
final String[] subIds = fullUrl.substring(baseUrl.length()).split("\\|");
String baseId = subIds[0].replace("/", "");
if (subIds.length == 2) {
return baseId + "_" + subIds[1];
}
return baseId;
}
} }

View File

@ -33,6 +33,7 @@ import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.MethodSource;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
@ -456,19 +457,22 @@ public class TerminologyCacheTests implements ResourceLoaderTests {
assertEquals("http://dummy.org", extracted); assertEquals("http://dummy.org", extracted);
} }
@Test @ParameterizedTest
public void testCodingWithSystemCacheTokenGenerationWithPipeCharSystem() throws IOException, URISyntaxException { @CsvSource({
"http://terminology.hl7.org/CodeSystem/id|version,id_version",
"http://hl7.org/fhir/id|version,id_version",
"http://hl7.org/fhir/sid/id|version,id_version"
})
public void testCacheTokenGenerationWithCanonicalUrl(String system, String expectedName) throws IOException, URISyntaxException {
TerminologyCache terminologyCache = createTerminologyCache(); TerminologyCache terminologyCache = createTerminologyCache();
ValueSet valueSet = new ValueSet(); ValueSet valueSet = new ValueSet();
Coding coding = new Coding(); Coding coding = new Coding();
coding.setCode("dummyCode"); coding.setSystem(system);
coding.setSystem("http://terminology.hl7.org/CodeSystem/dummy|System");
coding.setVersion("dummyVersion");
TerminologyCache.CacheToken cacheToken = terminologyCache.generateValidationToken(CacheTestUtils.validationOptions, TerminologyCache.CacheToken cacheToken = terminologyCache.generateValidationToken(CacheTestUtils.validationOptions,
coding, valueSet); coding, valueSet);
assertEquals("dummyXSystem", cacheToken.getName()); assertEquals(expectedName, cacheToken.getName());
assertTrue(cacheToken.hasVersion());
} }
} }