Merge pull request #762 from hapifhir/gg-202203-vs-system

Gg 202203 vs system
This commit is contained in:
Grahame Grieve 2022-03-11 11:30:33 +11:00 committed by GitHub
commit a73b501469
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 138 additions and 115 deletions

View File

@ -6169,9 +6169,9 @@ The primary difference between a medication statement and a medication administr
return _4_1_0;
if ("4.2.0".equals(codeString))
return _4_2_0;
if ("4.3.0-snapshot1".equals(codeString))
if ("4.3.0-snapshot1".equalsIgnoreCase(codeString))
return _4_3_0SNAPSHOT1;
if ("4.3.0-cibuild".equals(codeString))
if ("4.3.0-cibuild".equalsIgnoreCase(codeString))
return _4_3_0CIBUILD;
throw new FHIRException("Unknown FHIRVersion code '"+codeString+"'");
}
@ -6434,9 +6434,9 @@ public String toCode(int len) {
return FHIRVersion._4_1_0;
if ("4.2.0".equals(codeString))
return FHIRVersion._4_2_0;
if ("4.3.0-snapshot1".equals(codeString))
if ("4.3.0-snapshot1".equalsIgnoreCase(codeString))
return FHIRVersion._4_3_0SNAPSHOT1;
if ("4.3.0-cibuild".equals(codeString))
if ("4.3.0-cibuild".equalsIgnoreCase(codeString))
return FHIRVersion._4_3_0CIBUILD;
throw new IllegalArgumentException("Unknown FHIRVersion code '"+codeString+"'");
}
@ -6498,9 +6498,9 @@ public String toCode(int len) {
return new Enumeration<FHIRVersion>(this, FHIRVersion._4_1_0);
if ("4.2.0".equals(codeString))
return new Enumeration<FHIRVersion>(this, FHIRVersion._4_2_0);
if ("4.3.0-snapshot1".equals(codeString))
if ("4.3.0-snapshot1".equalsIgnoreCase(codeString))
return new Enumeration<FHIRVersion>(this, FHIRVersion._4_3_0SNAPSHOT1);
if ("4.3.0-cibuild".equals(codeString))
if ("4.3.0-cibuild".equalsIgnoreCase(codeString))
return new Enumeration<FHIRVersion>(this, FHIRVersion._4_3_0CIBUILD);
throw new FHIRException("Unknown FHIRVersion code '"+codeString+"'");
}

View File

@ -7293,9 +7293,9 @@ public String toCode(int len) {
return new Enumeration<FHIRVersion>(this, FHIRVersion._4_1_0);
if ("4.2.0".equals(codeString))
return new Enumeration<FHIRVersion>(this, FHIRVersion._4_2_0);
if ("4.3.0-snapshot1".equals(codeString))
if ("4.3.0-snapshot1".equalsIgnoreCase(codeString))
return new Enumeration<FHIRVersion>(this, FHIRVersion._4_3_0SNAPSHOT1);
if ("4.3.0-cibuild".equals(codeString))
if ("4.3.0-cibuild".equalsIgnoreCase(codeString))
return new Enumeration<FHIRVersion>(this, FHIRVersion._4_3_0CIBUILD);
if ("4.4.0".equals(codeString))
return new Enumeration<FHIRVersion>(this, FHIRVersion._4_4_0);
@ -7303,9 +7303,9 @@ public String toCode(int len) {
return new Enumeration<FHIRVersion>(this, FHIRVersion._4_5_0);
if ("4.6.0".equals(codeString))
return new Enumeration<FHIRVersion>(this, FHIRVersion._4_6_0);
if ("5.0.0-snapshot1".equals(codeString))
if ("5.0.0-snapshot1".equalsIgnoreCase(codeString))
return new Enumeration<FHIRVersion>(this, FHIRVersion._5_0_0SNAPSHOT1);
if ("5.0.0-cibuild".equals(codeString))
if ("5.0.0-cibuild".equalsIgnoreCase(codeString))
return new Enumeration<FHIRVersion>(this, FHIRVersion._5_0_0CIBUILD);
throw new FHIRException("Unknown FHIRVersion code '"+codeString+"'");
}

View File

@ -33,8 +33,10 @@ package org.hl7.fhir.r5.terminologies;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.NoTerminologyServiceException;
@ -544,71 +546,92 @@ public class ValueSetCheckerSimple extends ValueSetWorker implements ValueSetChe
private String systemForCodeInValueSet(String code) {
String sys = null;
if (valueset.hasCompose()) {
if (valueset.getCompose().hasExclude()) {
Set<String> sys = new HashSet<>();
if (!scanForCodeInValueSet(code, sys)) {
return null;
}
if (sys.size() != 1) {
return null;
} else {
return sys.iterator().next();
}
}
private boolean scanForCodeInValueSet(String code, Set<String> sys) {
if (valueset.hasCompose()) {
// not sure what to do with the
// if (valueset.getCompose().hasExclude()) {
// return false;
// }
for (ConceptSetComponent vsi : valueset.getCompose().getInclude()) {
if (vsi.hasValueSet()) {
return null;
for (CanonicalType u : vsi.getValueSet()) {
if (!checkForCodeInValueSet(code, u.getValue(), sys)) {
return false;
}
if (!vsi.hasSystem()) {
return null;
}
} else if (!vsi.hasSystem()) {
return false;
}
if (vsi.hasSystem()) {
if (vsi.hasFilter()) {
return null;
return false;
}
CodeSystem cs = resolveCodeSystem(vsi.getSystem());
if (cs == null) {
return null;
}
if (cs != null) {
if (vsi.hasConcept()) {
for (ConceptReferenceComponent cc : vsi.getConcept()) {
boolean match = cs.getCaseSensitive() ? cc.getCode().equals(code) : cc.getCode().equalsIgnoreCase(code);
if (match) {
if (sys == null) {
sys = vsi.getSystem();
} else if (!sys.equals(vsi.getSystem())) {
return null;
}
sys.add(vsi.getSystem());
}
}
} else {
ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), code);
if (cc != null) {
if (sys == null) {
sys = vsi.getSystem();
} else if (!sys.equals(vsi.getSystem())) {
return null;
sys.add(vsi.getSystem());
}
}
} else {
if (vsi.hasConcept()) {
for (ConceptReferenceComponent cc : vsi.getConcept()) {
boolean match = cc.getCode().equals(code);
if (match) {
sys.add(vsi.getSystem());
}
}
}
}
}
}
} else if (valueset.hasExpansion()) {
// Retrieve a list of all systems associated with this code in the expansion
List<String> systems = new ArrayList<String>();
checkSystems(valueset.getExpansion().getContains(), code, systems);
if (systems.size()==1)
sys = systems.get(0);
if (!checkSystems(valueset.getExpansion().getContains(), code, sys)) {
return false;
}
}
return true;
}
return sys;
private boolean checkForCodeInValueSet(String code, String uri, Set<String> sys) {
ValueSetCheckerSimple vs = getVs(uri);
return vs.scanForCodeInValueSet(code, sys);
}
/*
* Recursively go through all codes in the expansion and for any coding that matches the specified code, add the system for that coding
* to the passed list.
*/
private void checkSystems(List<ValueSetExpansionContainsComponent> contains, String code, List<String> systems) {
private boolean checkSystems(List<ValueSetExpansionContainsComponent> contains, String code, Set<String> systems) {
for (ValueSetExpansionContainsComponent c: contains) {
if (c.getCode().equals(code)) {
if (!systems.contains(c.getSystem()))
systems.add(c.getSystem());
}
if (c.hasContains())
checkSystems(c.getContains(), code, systems);
}
return true;
}
@Override