org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent Java Examples

The following examples show how to use org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void doServerIncludeCodes(ConceptSetComponent inc, boolean heirarchical, List<ValueSetExpansionParameterComponent> params, List<ValueSet> imports, Parameters expParams) throws FHIRException {
  ValueSetExpansionOutcome vso = context.expandVS(inc, heirarchical);
  if (vso.getError() != null)
    throw new TerminologyServiceException("Unable to expand imported value set: " + vso.getError());
  ValueSet vs = vso.getValueset();
  if (vs.hasVersion())
    if (!existsInParams(params, "version", new UriType(vs.getUrl() + "|" + vs.getVersion())))
      params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "|" + vs.getVersion())));
  for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
    if (!existsInParams(params, p.getName(), p.getValue()))
      params.add(p);
  }
  for (ValueSetExpansionContainsComponent cc : vs.getExpansion().getContains()) {
    addCodeAndDescendents(cc, null, expParams, imports);
  }
}
 
Example #2
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private ValueSet intersectByExpansion(ValueSet lvs, ValueSet rvs) {
  // this is pretty straight forward - we intersect the lists, and build a compose out of the intersection
  ValueSet vs = new ValueSet();
  vs.setStatus(PublicationStatus.DRAFT);
  
  Map<String, ValueSetExpansionContainsComponent> left = new HashMap<String, ValueSetExpansionContainsComponent>();
  scan(lvs.getExpansion().getContains(), left);
  Map<String, ValueSetExpansionContainsComponent> right = new HashMap<String, ValueSetExpansionContainsComponent>();
  scan(rvs.getExpansion().getContains(), right);
  Map<String, ConceptSetComponent> inc = new HashMap<String, ConceptSetComponent>();
  
  for (String s : left.keySet()) {
    if (right.containsKey(s)) {
      ValueSetExpansionContainsComponent cc = left.get(s);
      ConceptSetComponent c = inc.get(cc.getSystem());
      if (c == null) {
        c = vs.getCompose().addInclude().setSystem(cc.getSystem());
        inc.put(cc.getSystem(), c);
      }
      c.addConcept().setCode(cc.getCode()).setDisplay(cc.getDisplay());
    }
  }
  return vs;
}
 
Example #3
Source File: RandomCodeGenerator.java    From synthea with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a random code from the expansion of a ValueSet.
 *
 * @param valueSetUri the URI of the ValueSet
 * @param seed a random seed to ensure reproducibility of this result
 * @return the randomly selected Code
 */
public static Code getCode(String valueSetUri, long seed) {
  if (terminologyClient == null) {
    throw new RuntimeException(
        "Unable to generate code from ValueSet URI: terminology service not configured");
  }
  ValueSetExpansionComponent expansion = expandValueSet(valueSetUri);

  Random random = new Random(seed);
  int randomIndex = random.nextInt(expansion.getTotal());

  ValueSetExpansionContainsComponent contains = expansion.getContains().get(randomIndex);
  validateContains(contains);

  return new Code(contains.getSystem(), contains.getCode(), contains.getDisplay());
}
 
Example #4
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean expansionContainsCode(List<ValueSetExpansionContainsComponent> contains, String system, String code) {
  for (ValueSetExpansionContainsComponent cc : contains) {
    if (system.equals(cc.getSystem()) && code.equals(cc.getCode()))
      return true;
    if (expansionContainsCode(cc.getContains(), system, code))
      return true;
  }
  return false;
}
 
Example #5
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void addCodeAndDescendents(ValueSetExpansionContainsComponent focus, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filters)  throws FHIRException {
  focus.checkNoModifiers("Expansion.contains", "expanding");
  ValueSetExpansionContainsComponent np = addCode(focus.getSystem(), focus.getCode(), focus.getDisplay(), parent, 
       convert(focus.getDesignation()), expParams, focus.getAbstract(), focus.getInactive(), filters);
  for (ValueSetExpansionContainsComponent c : focus.getContains())
    addCodeAndDescendents(focus, np, expParams, filters);
}
 
Example #6
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void excludeCode(String theSystem, String theCode) {
  ValueSetExpansionContainsComponent n = new ValueSet.ValueSetExpansionContainsComponent();
  n.setSystem(theSystem);
  n.setCode(theCode);
  String s = key(n);
  excludeKeys.add(s);
}
 
Example #7
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void copyImportContains(List<ValueSetExpansionContainsComponent> list, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filter) throws FHIRException {
  for (ValueSetExpansionContainsComponent c : list) {
    c.checkNoModifiers("Imported Expansion in Code System", "expanding");
    ValueSetExpansionContainsComponent np = addCode(c.getSystem(), c.getCode(), c.getDisplay(), parent, null, expParams, c.getAbstract(), c.getInactive(), filter);
    copyImportContains(c.getContains(), np, expParams, filter);
  }
}
 
Example #8
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void scan(List<ValueSetExpansionContainsComponent> list, Map<String, ValueSetExpansionContainsComponent> map) {
  for (ValueSetExpansionContainsComponent cc : list) {
    if (cc.hasSystem() && cc.hasCode()) {
      String s = cc.getSystem()+"::"+cc.getCode();
      if (!map.containsKey(s))
        map.put(s,  cc);
    }
    if (cc.hasContains())
      scan(cc.getContains(), map);
  }
}
 
Example #9
Source File: StructureMapUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private Coding buildCoding(String uri, String code) throws FHIRException {
 // if we can get this as a valueSet, we will
 String system = null;
 String display = null;
 ValueSet vs = Utilities.noString(uri) ? null : worker.fetchResourceWithException(ValueSet.class, uri);
 if (vs != null) {
   ValueSetExpansionOutcome vse = worker.expandVS(vs, true, false);
   if (vse.getError() != null)
     throw new FHIRException(vse.getError());
   CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
   for (ValueSetExpansionContainsComponent t : vse.getValueset().getExpansion().getContains()) {
     if (t.hasCode())
       b.append(t.getCode());
     if (code.equals(t.getCode()) && t.hasSystem()) {
       system = t.getSystem();
        display = t.getDisplay();
       break;
     }
      if (code.equalsIgnoreCase(t.getDisplay()) && t.hasSystem()) {
        system = t.getSystem();
        display = t.getDisplay();
        break;
      }
   }
   if (system == null)
     throw new FHIRException("The code '"+code+"' is not in the value set '"+uri+"' (valid codes: "+b.toString()+"; also checked displays)");
 } else
   system = uri;
 ValidationResult vr = worker.validateCode(terminologyServiceOptions, system, code, null);
 if (vr != null && vr.getDisplay() != null)
   display = vr.getDisplay();
 return new Coding().setSystem(system).setCode(code).setDisplay(display);
}
 
Example #10
Source File: RandomCodeGenerator.java    From synthea with Apache License 2.0 5 votes vote down vote up
private static void validateContains(ValueSetExpansionContainsComponent contains) {
  if (contains.getSystem() == null || contains.getCode() == null
      || contains.getDisplay() == null) {
    throw new RuntimeException(
        "ValueSet contains element does not contain system, code and display");
  }
}
 
Example #11
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void excludeCodes(ValueSetExpansionComponent expand, List<ValueSetExpansionParameterComponent> params) {
  for (ValueSetExpansionContainsComponent c : expand.getContains()) {
    excludeCode(c.getSystem(), c.getCode());
  }
}
 
Example #12
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void addToHeirarchy(List<ValueSetExpansionContainsComponent> target, List<ValueSetExpansionContainsComponent> source) {
  for (ValueSetExpansionContainsComponent s : source) {
    target.add(s);
  }
}
 
Example #13
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private String key(ValueSetExpansionContainsComponent c) {
  return key(c.getSystem(), c.getCode());
}