From 56c52ab7dd86ca8c4dc5c7455aaa3817b7107d16 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 11 Mar 2022 10:34:18 +1100 Subject: [PATCH 1/3] make fhir version code case independent --- .../src/main/java/org/hl7/fhir/r5/model/Enumerations.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Enumerations.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Enumerations.java index 64de74462..38d4a4a8b 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Enumerations.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Enumerations.java @@ -7293,9 +7293,9 @@ public String toCode(int len) { return new Enumeration(this, FHIRVersion._4_1_0); if ("4.2.0".equals(codeString)) return new Enumeration(this, FHIRVersion._4_2_0); - if ("4.3.0-snapshot1".equals(codeString)) + if ("4.3.0-snapshot1".equalsIgnoreCase(codeString)) return new Enumeration(this, FHIRVersion._4_3_0SNAPSHOT1); - if ("4.3.0-cibuild".equals(codeString)) + if ("4.3.0-cibuild".equalsIgnoreCase(codeString)) return new Enumeration(this, FHIRVersion._4_3_0CIBUILD); if ("4.4.0".equals(codeString)) return new Enumeration(this, FHIRVersion._4_4_0); @@ -7303,9 +7303,9 @@ public String toCode(int len) { return new Enumeration(this, FHIRVersion._4_5_0); if ("4.6.0".equals(codeString)) return new Enumeration(this, FHIRVersion._4_6_0); - if ("5.0.0-snapshot1".equals(codeString)) + if ("5.0.0-snapshot1".equalsIgnoreCase(codeString)) return new Enumeration(this, FHIRVersion._5_0_0SNAPSHOT1); - if ("5.0.0-cibuild".equals(codeString)) + if ("5.0.0-cibuild".equalsIgnoreCase(codeString)) return new Enumeration(this, FHIRVersion._5_0_0CIBUILD); throw new FHIRException("Unknown FHIRVersion code '"+codeString+"'"); } From 6b3d7d4eaac93a1b327a531c2789767f4fa20897 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 11 Mar 2022 10:37:10 +1100 Subject: [PATCH 2/3] infer system when value set has includes --- .../terminologies/ValueSetCheckerSimple.java | 103 +++++++++++------- 1 file changed, 63 insertions(+), 40 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetCheckerSimple.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetCheckerSimple.java index cab2ff611..aeb491319 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetCheckerSimple.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetCheckerSimple.java @@ -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; + Set 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 sys) { if (valueset.hasCompose()) { - if (valueset.getCompose().hasExclude()) { - return null; - } + // not sure what to do with the +// if (valueset.getCompose().hasExclude()) { +// return false; +// } for (ConceptSetComponent vsi : valueset.getCompose().getInclude()) { if (vsi.hasValueSet()) { - return null; - } - if (!vsi.hasSystem()) { - return null; - } - if (vsi.hasFilter()) { - return null; - } - CodeSystem cs = resolveCodeSystem(vsi.getSystem()); - if (cs == null) { - return 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; - } + for (CanonicalType u : vsi.getValueSet()) { + if (!checkForCodeInValueSet(code, u.getValue(), sys)) { + return false; } } - } else { - ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), code); - if (cc != null) { - if (sys == null) { - sys = vsi.getSystem(); - } else if (!sys.equals(vsi.getSystem())) { - return null; + } else if (!vsi.hasSystem()) { + return false; + } + if (vsi.hasSystem()) { + if (vsi.hasFilter()) { + return false; + } + CodeSystem cs = resolveCodeSystem(vsi.getSystem()); + 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) { + sys.add(vsi.getSystem()); + } + } + } else { + ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), code); + if (cc != 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 systems = new ArrayList(); - 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 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 contains, String code, List systems) { + private boolean checkSystems(List contains, String code, Set systems) { for (ValueSetExpansionContainsComponent c: contains) { if (c.getCode().equals(code)) { - if (!systems.contains(c.getSystem())) - systems.add(c.getSystem()); + systems.add(c.getSystem()); } if (c.hasContains()) checkSystems(c.getContains(), code, systems); } + return true; } @Override From ef3aee75f10785e1ef3fac07e566fa2dbae9189c Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 11 Mar 2022 10:37:28 +1100 Subject: [PATCH 3/3] make fhir version code case independent --- .../java/org/hl7/fhir/r4b/model/Enumerations.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/Enumerations.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/Enumerations.java index 4f6d7369a..2910a183b 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/Enumerations.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/Enumerations.java @@ -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(this, FHIRVersion._4_1_0); if ("4.2.0".equals(codeString)) return new Enumeration(this, FHIRVersion._4_2_0); - if ("4.3.0-snapshot1".equals(codeString)) + if ("4.3.0-snapshot1".equalsIgnoreCase(codeString)) return new Enumeration(this, FHIRVersion._4_3_0SNAPSHOT1); - if ("4.3.0-cibuild".equals(codeString)) + if ("4.3.0-cibuild".equalsIgnoreCase(codeString)) return new Enumeration(this, FHIRVersion._4_3_0CIBUILD); throw new FHIRException("Unknown FHIRVersion code '"+codeString+"'"); }