org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent Java Examples

The following examples show how to use org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent. 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: ISO21090Importer.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void generateValueSet(EnumValueSet evs) throws Exception {
  ValueSet bvs = ctxt.fetchResource(ValueSet.class, evs.template);
  if (bvs == null)
    throw new Exception("Did not find template value set "+evs.template);
  ValueSet vs = bvs.copy();
  vs.getCompose().getInclude().clear();
  vs.getIdentifier().clear();
  vs.setName("ISO 20190 "+evs.name+" Enumeration");
  vs.setId(evs.name);
  vs.setUrl("http://hl7.org/fhir/iso21090/ValueSet/"+vs.getId());
  vs.setDate(new Date());
  vs.setExperimental(false);
  ConceptSetComponent inc = vs.getCompose().addInclude().setSystem(evs.system);
  for (String code : evs.codes) {
    inc.addConcept().setCode(code);
  }
  new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream("c:\\temp\\iso21090\\ValueSet-"+evs.name+".xml"), vs);
}
 
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: ValueSetsTest.java    From bunsen with Apache License 2.0 6 votes vote down vote up
private static void checkValueSet(ValueSet valueSet, String url, String version) {

    Assert.assertNotNull(
        MessageFormat.format("Could not find value set for url {0} and version {1}", url, version),
        valueSet);

    Assert.assertEquals(url, valueSet.getUrl());
    Assert.assertEquals(version, valueSet.getVersion());

    ConceptSetComponent inclusion = valueSet.getCompose().getIncludeFirstRep();

    Assert.assertEquals("urn:cerner:system", inclusion.getSystem());
    Assert.assertEquals("1", inclusion.getVersion());
    Assert.assertEquals("a", inclusion.getConceptFirstRep().getCode());

    Assert.assertEquals(1, valueSet.getCompose().getInclude().size());
  }
 
Example #4
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private String determineCacheId(ValueSet vs, boolean heirarchical) throws Exception {
  // just the content logical definition is hashed
  ValueSet vsid = new ValueSet();
  vsid.setCompose(vs.getCompose());
  JsonParser parser = new JsonParser();
  parser.setOutputStyle(OutputStyle.NORMAL);
  ByteArrayOutputStream b = new ByteArrayOutputStream();
  parser.compose(b, vsid);
  b.close();
  String s = new String(b.toByteArray(), Constants.CHARSET_UTF8);
  // any code systems we can find, we add these too. 
  for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
    CodeSystem cs = fetchCodeSystem(inc.getSystem());
    if (cs != null) {
      String css = cacheValue(cs);
      s = s + css;
    }
  }
  s = s + "-" + Boolean.toString(heirarchical);
  String r = Integer.toString(s.hashCode());
  //    TextFile.stringToFile(s, Utilities.path(cache, r+".id.json"));
  return r;
}
 
Example #5
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private String getIncSummary(ConceptSetComponent cc) {
  CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
  for (UriType vs : cc.getValueSet()) {
    b.append(vs.asStringValue());
  }
  String vsd =
    b.length() > 0 ? " where the codes are in the value sets (" + b.toString() + ")" : "";
  String system = cc.getSystem();
  if (cc.hasConcept()) {
    return Integer.toString(cc.getConcept().size()) + " codes from " + system + vsd;
  }
  if (cc.hasFilter()) {
    String s = "";
    for (ConceptSetFilterComponent f : cc.getFilter()) {
      if (!Utilities.noString(s)) {
        s = s + " & ";
      }
      s = s + f.getProperty() + " " + f.getOp().toCode() + " " + f.getValue();
    }
    return "from " + system + " where " + s + vsd;
  }
  return "All codes from " + system + vsd;
}
 
Example #6
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean mergeIntoExisting(List<ConceptSetComponent> include, ConceptSetComponent inc) {
  for (ConceptSetComponent dst : include) {
    if (Base.compareDeep(dst,  inc, false))
      return true; // they're actually the same
    if (dst.getSystem().equals(inc.getSystem())) {
      if (inc.hasFilter() || dst.hasFilter()) {
        return false; // just add the new one as a a parallel
      } else if (inc.hasConcept() && dst.hasConcept()) {
        for (ConceptReferenceComponent cc : inc.getConcept()) {
          boolean found = false;
          for (ConceptReferenceComponent dd : dst.getConcept()) {
            if (dd.getCode().equals(cc.getCode()))
              found = true;
            if (found) {
              if (cc.hasDisplay() && !dd.hasDisplay())
                dd.setDisplay(cc.getDisplay());
              break;
            }
          }
          if (!found)
            dst.getConcept().add(cc.copy());
        }
      } else
        dst.getConcept().clear(); // one of them includes the entire code system 
    }
  }
  return false;
}
 
Example #7
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private Integer countMembership(ValueSet vs) {
  int count = 0;
  if (vs.hasExpansion())
    count = count + conceptCount(vs.getExpansion().getContains());
  else {
    if (vs.hasCompose()) {
      if (vs.getCompose().hasExclude()) {
        try {
          ValueSetExpansionOutcome vse = context.expandVS(vs, true, false);
          count = 0;
          count += conceptCount(vse.getValueset().getExpansion().getContains());
          return count;
        } catch (Exception e) {
          return null;
        }
      }
      for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
        if (inc.hasFilter())
          return null;
        if (!inc.hasConcept())
          return null;
        count = count + inc.getConcept().size();
      }
    }
  }
  return count;
}
 
Example #8
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean IsNotFixedExpansion(ValueSet vs) {
  if (vs.hasCompose())
    return false;


  // it's not fixed if it has any includes that are not version fixed
  for (ConceptSetComponent cc : vs.getCompose().getInclude()) {
    if (cc.hasValueSet())
      return true;
    if (!cc.hasVersion())
      return true;
  }
  return false;
}
 
Example #9
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public ValueSetExpansionComponent expandVS(ConceptSetComponent inc, boolean heirachical)
  throws TerminologyServiceException {
  ValueSet vs = new ValueSet();
  vs.setCompose(new ValueSetComposeComponent());
  vs.getCompose().getInclude().add(inc);
  ValueSetExpansionOutcome vse = expandVS(vs, true, heirachical);
  ValueSet valueset = vse.getValueset();
  if (valueset == null) {
    throw new TerminologyServiceException("Error Expanding ValueSet: " + vse.getError());
  }
  return valueset.getExpansion();
}
 
Example #10
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public ValidationResult validateCode(String system, String code, String display,
  ConceptSetComponent vsi) {
  try {
    ValueSet vs = new ValueSet();
    vs.setUrl(Utilities.makeUuidUrn());
    vs.getCompose().addInclude(vsi);
    return verifyCodeExternal(vs,
      new Coding().setSystem(system).setCode(code).setDisplay(display), true);
  } catch (Exception e) {
    return new ValidationResult(IssueSeverity.FATAL,
      "Error validating code \"" + code + "\" in system \"" + system + "\": " + e.getMessage());
  }
}
 
Example #11
Source File: ValidationSupportSTU3.java    From synthea with Apache License 2.0 4 votes vote down vote up
@Override
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem,
    String theCode, String theDisplay, String theValueSetUrl) {
  IssueSeverity severity = IssueSeverity.WARNING;
  String message = "Unsupported CodeSystem";

  if (isCodeSystemSupported(theContext, theCodeSystem)) {
    severity = IssueSeverity.ERROR;
    message = "Code not found";

    CodeSystem cs = codeSystemMap.get(theCodeSystem);
    for (ConceptDefinitionComponent def : cs.getConcept()) {
      if (def.getCode().equals(theCode)) {
        if (def.getDisplay() != null && theDisplay != null) {
          if (def.getDisplay().equals(theDisplay)) {
            severity = IssueSeverity.INFORMATION;
            message = "Validated Successfully";
          } else {
            severity = IssueSeverity.WARNING;
            message = "Validated Code; Display mismatch";
          }
        } else {
          severity = IssueSeverity.WARNING;
          message = "Validated Code; No display";
        }
      }
    }
  }

  ValueSet vs = fetchValueSet(theContext, theValueSetUrl);
  if (vs != null && vs.hasCompose() && vs.getCompose().hasExclude()) {
    for (ConceptSetComponent exclude : vs.getCompose().getExclude()) {
      if (exclude.getSystem().equals(theCodeSystem) && exclude.hasConcept()) {
        for (ConceptReferenceComponent concept : exclude.getConcept()) {
          if (concept.getCode().equals(theCode)) {
            severity = IssueSeverity.ERROR;
            message += "; Code Excluded from ValueSet";
          }
        }
      }
    }
  }

  return new CodeValidationResult(severity, message);
}
 
Example #12
Source File: ValidationSupportSTU3.java    From synthea with Apache License 2.0 4 votes vote down vote up
@Override
public ValueSet.ValueSetExpansionComponent expandValueSet(FhirContext theContext,
    ConceptSetComponent theInclude) {
  return null;
}
 
Example #13
Source File: ValueSets.java    From bunsen with Apache License 2.0 4 votes vote down vote up
@Override
protected void addToValueSet(ValueSet valueSet, Dataset<Value> values) {

  ValueSetComposeComponent composeComponent = valueSet.getCompose();
  ConceptSetComponent currentInclusion = null;
  ConceptReferenceComponent concept = null;

  List<Value> sortedValues = values.sort("system", "version", "value").collectAsList();

  // Workaround for the decoder producing an immutable array by replacing it with a mutable one
  composeComponent.setInclude(new ArrayList<>(composeComponent.getInclude()));
  for (Value value: sortedValues) {

    if (currentInclusion == null
        || !value.getSystem().equals(currentInclusion.getSystem())
        || !value.getVersion().equals(currentInclusion.getVersion())) {

      // Find a matching inclusion
      for (ConceptSetComponent candidate: composeComponent.getInclude()) {

        if (value.getSystem().equals(candidate.getSystem())
            && value.getVersion().equals(candidate.getVersion())) {

          currentInclusion = candidate;

          // Workaround for the decoder producing an immutable array by replacing it with a
          // mutable one
          currentInclusion.setConcept(new ArrayList<>(currentInclusion.getConcept()));
        }
      }

      // No matching inclusion found, so add one
      if (currentInclusion == null) {

        currentInclusion = composeComponent.addInclude();

        currentInclusion.setSystem(value.getSystem());
        currentInclusion.setVersion(value.getVersion());

        concept = null;
      }
    }

    // Create concept if not exists
    if (concept == null || !value.getValue().equals(concept.getCode())) {

      concept = currentInclusion.addConcept();
      concept.setCode(value.getValue());
    }
  }
}
 
Example #14
Source File: ValueSets.java    From bunsen with Apache License 2.0 4 votes vote down vote up
private static Iterator<Value> expandValuesIterator(ValueSet valueSet) {

    List<Value> values = new ArrayList<>();

    ValueSetComposeComponent compose = valueSet.getCompose();

    for (ConceptSetComponent inclusion: compose.getInclude()) {

      for (ConceptReferenceComponent concept: inclusion.getConcept()) {

        Value value = new Value();

        value.setValueSetUri(valueSet.getUrl());
        value.setValueSetVersion(valueSet.getVersion());

        value.setSystem(inclusion.getSystem());
        value.setVersion(inclusion.getVersion());

        value.setValue(concept.getCode());

        values.add(value);
      }
    }

    return values.iterator();
  }
 
Example #15
Source File: ValueSets.java    From bunsen with Apache License 2.0 4 votes vote down vote up
@Override
public Row call(Row valueSetRow) throws Exception {

  ValueSet valueSet = (ValueSet) converter.rowToResource(valueSetRow);

  ValueSet valueSetWithoutConcepts = valueSet.copy();

  List<ConceptSetComponent> updatedInclusions = new ArrayList<>();

  for (ConceptSetComponent inclusion: valueSet.getCompose().getInclude()) {

    ConceptSetComponent inclusionWithoutConcepts = inclusion.copy();

    inclusionWithoutConcepts.setConcept(new ArrayList<>());
    updatedInclusions.add(inclusionWithoutConcepts);
  }

  valueSetWithoutConcepts.getCompose().setInclude(updatedInclusions);

  return converter.resourceToRow(valueSetWithoutConcepts);
}
 
Example #16
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private boolean generateComposition(ResourceContext rcontext, XhtmlNode x, ValueSet vs, boolean header) throws FHIRException, IOException {
 boolean hasExtensions = false;
  List<String> langs = new ArrayList<String>();

  if (header) {
    XhtmlNode h = x.h2();
    h.addText(vs.getName());
    addMarkdown(x, vs.getDescription());
    if (vs.hasCopyrightElement())
      generateCopyright(x, vs);
  }
  XhtmlNode p = x.para();
  p.tx("This value set includes codes from the following code systems:");

  XhtmlNode ul = x.ul();
  XhtmlNode li;
  for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
    hasExtensions = genInclude(rcontext, ul, inc, "Include", langs) || hasExtensions;
  }
  for (ConceptSetComponent exc : vs.getCompose().getExclude()) {
    hasExtensions = genInclude(rcontext, ul, exc, "Exclude", langs) || hasExtensions;
  }

  // now, build observed languages

  if (langs.size() > 0) {
    Collections.sort(langs);
    x.para().b().tx("Additional Language Displays");
    XhtmlNode t = x.table( "codes");
    XhtmlNode tr = t.tr();
    tr.td().b().tx("Code");
    for (String lang : langs)
      tr.td().b().addText(describeLang(lang));
    for (ConceptSetComponent c : vs.getCompose().getInclude()) {
      for (ConceptReferenceComponent cc : c.getConcept()) {
        addLanguageRow(cc, t, langs);
      }
    }
  }

  return hasExtensions;
}
 
Example #17
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public static void addVSComment(ConceptSetComponent nc, String comment) {
  if (!StringUtils.isBlank(comment))
    nc.getExtension().add(Factory.newExtension(EXT_VS_COMMENT, Factory.newString_(comment), true));   
}
 
Example #18
Source File: ValidationSupportProvider.java    From careconnect-reference-implementation with Apache License 2.0 3 votes vote down vote up
public ValueSetExpansionComponent expandValueSet(ConceptSetComponent theInclude) {

    ValueSetExpansionComponent retVal = new ValueSetExpansionComponent();


    return retVal;
  }
 
Example #19
Source File: IWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 2 votes vote down vote up
/**
 * Validation of a code - consult the terminology service 
 * to see whether it is known. If known, return a description of it
 * Also, check whether it's in the provided value set fragment (for supported systems with no value set definition)
 * 
 * note: always return a result, with either an error or a code description, or both (e.g. known code, but not in the value set)
 *  
 * corresponds to 2 terminology service calls: $validate-code and $lookup
 * 
 * @param system
 * @param code
 * @param display
 * @return
 */
public ValidationResult validateCode(String system, String code, String display, ConceptSetComponent vsi);
 
Example #20
Source File: IWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 2 votes vote down vote up
/**
 * Value set expanion inside the internal expansion engine - used 
 * for references to supported system (see "supportsSystem") for
 * which there is no value set. 
 * 
 * @param inc
 * @return
 * @throws FHIRException 
 */
public ValueSetExpansionComponent expandVS(ConceptSetComponent inc, boolean heiarchical) throws TerminologyServiceException;
 
Example #21
Source File: ITerminologyServices.java    From org.hl7.fhir.core with Apache License 2.0 2 votes vote down vote up
/**
 * Test the value set fragment (system | codes | filters). 
 */
public boolean checkVS(ConceptSetComponent vsi, String system, String code);
 
Example #22
Source File: ITerminologyServices.java    From org.hl7.fhir.core with Apache License 2.0 2 votes vote down vote up
/**
 * Expand the value set fragment (system | codes | filters). Note that this 
 * might fail if the expansion is very large. If the expansion fails, then the 
 * checkVS will be called instead
 */
public ValueSetExpansionComponent expandVS(ConceptSetComponent inc) throws Exception;