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

The following examples show how to use org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent. 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 5 votes vote down vote up
private void excludeCodes(ConceptSetComponent exc, List<ValueSetExpansionParameterComponent> params, String ctxt) throws FHIRException {
  exc.checkNoModifiers("Compose.exclude", "expanding");
  if (exc.hasSystem() && exc.getConcept().size() == 0 && exc.getFilter().size() == 0) {
    excludeSystems.add(exc.getSystem());
  }

  if (exc.hasValueSet())
    throw new Error("Processing Value set references in exclude is not yet done in "+ctxt);
  // importValueSet(imp.getValue(), params, expParams);

  CodeSystem cs = context.fetchCodeSystem(exc.getSystem());
  if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(exc.getSystem())) {
    ValueSetExpansionOutcome vse = context.expandVS(exc, false);
    ValueSet valueset = vse.getValueset();
    if (valueset == null)
      throw new TerminologyServiceException("Error Expanding ValueSet: "+vse.getError());
    excludeCodes(valueset.getExpansion(), params);
    return;
  }

  for (ConceptReferenceComponent c : exc.getConcept()) {
    excludeCode(exc.getSystem(), c.getCode());
  }

  if (exc.getFilter().size() > 0)
    throw new NotImplementedException("not done yet");
}
 
Example #2
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 #3
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public static void addVSComment(ConceptReferenceComponent nc, String comment) {
  if (!StringUtils.isBlank(comment))
    nc.getExtension().add(Factory.newExtension(EXT_VS_COMMENT, Factory.newString_(comment), true));   
}
 
Example #4
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 #5
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 #6
Source File: ValidationSupportR4.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);
}