This commit is contained in:
dotasek 2022-10-31 14:53:50 -04:00
parent 942777da11
commit 5558f0458f
1 changed files with 49 additions and 35 deletions

View File

@ -38,7 +38,6 @@ import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
@ -85,6 +84,8 @@ public class TerminologyCache {
private static final String CAPABILITY_STATEMENT_TITLE = ".capabilityStatement";
private static final String TERMINOLOGY_CAPABILITIES_TITLE = ".terminologyCapabilities";
private SystemNameKeyGenerator systemNameKeyGenerator = new SystemNameKeyGenerator();
public class CacheToken {
@Getter
private String name;
@ -96,13 +97,48 @@ public class TerminologyCache {
private boolean hasVersion;
public void setName(String n) {
String systemName = getSystemNameKeyGenerator().getNameForSystem(n);
if (name == null)
name = n;
else if (!n.equals(name))
name = systemName;
else if (!systemName.equals(name))
name = NAME_FOR_NO_SYSTEM;
}
}
protected SystemNameKeyGenerator getSystemNameKeyGenerator() {
return systemNameKeyGenerator;
}
public class SystemNameKeyGenerator {
public String getNameForSystem(String system) {
if (system.equals("http://snomed.info/sct"))
return "snomed";
if (system.equals("http://www.nlm.nih.gov/research/umls/rxnorm"))
return "rxnorm";
if (system.equals("http://loinc.org"))
return "loinc";
if (system.equals("http://unitsofmeasure.org"))
return "ucum";
if (system.startsWith("http://hl7.org/fhir/sid/"))
return system.substring(24).replace("/", "");
if (system.startsWith("urn:iso:std:iso:"))
return "iso"+system.substring(16).replace(":", "");
if (system.startsWith("http://terminology.hl7.org/CodeSystem/"))
return system.substring(38).replace("/", "").replace('|','X');
if (system.startsWith("http://hl7.org/fhir/"))
return system.substring(20).replace("/", "");
if (system.equals("urn:ietf:bcp:47"))
return "lang";
if (system.equals("urn:ietf:bcp:13"))
return "mimetypes";
if (system.equals("urn:iso:std:iso:11073:10101"))
return "11073";
if (system.equals("http://dicom.nema.org/resources/ontology/DCM"))
return "dicom";
return system.replace("/", "_").replace(":", "_").replace("?", "X").replace("#", "X");
}
}
private class CacheEntry {
private String request;
private boolean persistent;
@ -185,7 +221,7 @@ public class TerminologyCache {
public CacheToken generateValidationToken(ValidationOptions options, Coding code, ValueSet vs) {
CacheToken ct = new CacheToken();
if (code.hasSystem()) {
ct.name = getNameForSystem(code.getSystem());
ct.setName(code.getSystem());
ct.hasVersion = code.hasVersion();
}
else
@ -226,7 +262,7 @@ public class TerminologyCache {
CacheToken ct = new CacheToken();
for (Coding c : code.getCoding()) {
if (c.hasSystem()) {
ct.setName(getNameForSystem(c.getSystem()));
ct.setName(c.getSystem());
ct.hasVersion = c.hasVersion();
}
}
@ -287,53 +323,31 @@ public class TerminologyCache {
if (vs != null) {
for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
if (inc.hasSystem()) {
ct.setName(getNameForSystem(inc.getSystem()));
ct.setName(inc.getSystem());
ct.hasVersion = inc.hasVersion();
}
}
for (ConceptSetComponent inc : vs.getCompose().getExclude()) {
if (inc.hasSystem()) {
ct.setName(getNameForSystem(inc.getSystem()));
ct.setName(inc.getSystem());
ct.hasVersion = inc.hasVersion();
}
}
for (ValueSetExpansionContainsComponent inc : vs.getExpansion().getContains()) {
if (inc.hasSystem()) {
ct.setName(getNameForSystem(inc.getSystem()));
ct.setName(inc.getSystem());
ct.hasVersion = inc.hasVersion();
}
}
}
}
private String getNameForSystem(String system) {
if (system.equals("http://snomed.info/sct"))
return "snomed";
if (system.equals("http://www.nlm.nih.gov/research/umls/rxnorm"))
return "rxnorm";
if (system.equals("http://loinc.org"))
return "loinc";
if (system.equals("http://unitsofmeasure.org"))
return "ucum";
if (system.startsWith("http://hl7.org/fhir/sid/"))
return system.substring(24).replace("/", "");
if (system.startsWith("urn:iso:std:iso:"))
return "iso"+system.substring(16).replace(":", "");
if (system.startsWith("http://terminology.hl7.org/CodeSystem/"))
return system.substring(38).replace("/", "").replace('|','X');
if (system.startsWith("http://hl7.org/fhir/"))
return system.substring(20).replace("/", "");
if (system.equals("urn:ietf:bcp:47"))
return "lang";
if (system.equals("urn:ietf:bcp:13"))
return "mimetypes";
if (system.equals("urn:iso:std:iso:11073:10101"))
return "11073";
if (system.equals("http://dicom.nema.org/resources/ontology/DCM"))
return "dicom";
return system.replace("/", "_").replace(":", "_").replace("?", "X").replace("#", "X");
private String normalizeSystemPath(String path) {
return path.replace("/", "").replace('|','X');
}
public NamedCache getNamedCache(CacheToken cacheToken) {
final String cacheName = cacheToken.name == null ? "null" : cacheToken.name;
@ -687,7 +701,7 @@ public class TerminologyCache {
public void removeCS(String url) {
synchronized (lock) {
String name = getNameForSystem(url);
String name = getSystemNameKeyGenerator().getNameForSystem(url);
if (caches.containsKey(name)) {
caches.remove(name);
}