org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent Java Examples

The following examples show how to use org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent. 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: ValidationSupportR4.java    From synthea with Apache License 2.0 6 votes vote down vote up
@Override
public LookupCodeResult lookupCode(FhirContext theContext, String theSystem, String theCode) {
  if (isCodeSystemSupported(theContext, theSystem)) {
    LookupCodeResult result = new LookupCodeResult();
    result.setSearchedForSystem(theSystem);
    result.setSearchedForCode(theCode);
    result.setFound(false);

    CodeSystem cs = codeSystemMap.get(theSystem);
    for (ConceptDefinitionComponent def : cs.getConcept()) {
      if (def.getCode().equals(theCode)) {
        result.setCodeDisplay(def.getDisplay());
        result.setFound(true);
        return result;
      }
    }
  }
  return LookupCodeResult.notFound(theSystem, theCode);
}
 
Example #2
Source File: DefaultProfileValidationSupportStu3AsR4.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
private CodeValidationResult testIfConceptIsInListInner(List<ConceptDefinitionComponent> conceptList, boolean theCaseSensitive, String code) {
    CodeValidationResult retVal = null;
    for (ConceptDefinitionComponent next : conceptList) {
        String nextCandidate = next.getCode();
        if (theCaseSensitive == false) {
            nextCandidate = nextCandidate.toUpperCase();
        }
        if (nextCandidate.equals(code)) {
            retVal = new CodeValidationResult(next);
            break;
        }

        // recurse
        retVal = testIfConceptIsInList(code, next.getConcept(), theCaseSensitive);
        if (retVal != null) {
            break;
        }
    }

    return retVal;
}
 
Example #3
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static boolean isDeprecated(CodeSystem cs, ConceptDefinitionComponent def)  {
  try {
    for (ConceptPropertyComponent p : def.getProperty()) {
      if (p.getCode().equals("status") && p.hasValue() && p.hasValueCodeType() && p.getValueCodeType().getCode().equals("deprecated"))
        return true;
      // this, though status should also be set
      if (p.getCode().equals("deprecationDate") && p.hasValue() && p.getValue() instanceof DateTimeType) 
        return ((DateTimeType) p.getValue()).before(new DateTimeType(Calendar.getInstance()));
      // legacy  
      if (p.getCode().equals("deprecated") && p.hasValue() && p.getValue() instanceof BooleanType) 
        return ((BooleanType) p.getValue()).getValue();
    }
    return false;
  } catch (FHIRException e) {
    return false;
  }
}
 
Example #4
Source File: ValueSet10_40.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
static public void processConcept(List<ValueSet.ConceptDefinitionComponent> concepts, ConceptDefinitionComponent cs, CodeSystem srcCS) throws FHIRException {
    org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent ct = new org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent();
    concepts.add(ct);
    ct.setCode(cs.getCode());
    ct.setDisplay(cs.getDisplay());
    ct.setDefinition(cs.getDefinition());
    if (CodeSystemUtilities.isNotSelectable(srcCS, cs))
        ct.setAbstract(true);
    for (org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionDesignationComponent csd : cs.getDesignation()) {
        org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionDesignationComponent cst = new org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionDesignationComponent();
        cst.setLanguage(csd.getLanguage());
        cst.setUse(VersionConvertor_10_40.convertCoding(csd.getUse()));
        cst.setValue(csd.getValue());
    }
    for (ConceptDefinitionComponent csc : cs.getConcept()) processConcept(ct.getConcept(), csc, srcCS);
}
 
Example #5
Source File: ValueSet10_40.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
static public void processConcept(List<ConceptDefinitionComponent> concepts, org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent cs, CodeSystem tgtcs) throws FHIRException {
    org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent ct = new org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent();
    concepts.add(ct);
    ct.setCode(cs.getCode());
    ct.setDisplay(cs.getDisplay());
    ct.setDefinition(cs.getDefinition());
    if (cs.getAbstract())
        CodeSystemUtilities.setNotSelectable(tgtcs, ct);
    for (org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionDesignationComponent csd : cs.getDesignation()) {
        org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionDesignationComponent cst = new org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionDesignationComponent();
        cst.setLanguage(csd.getLanguage());
        cst.setUse(VersionConvertor_10_40.convertCoding(csd.getUse()));
        cst.setValue(csd.getValue());
    }
    for (org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent csc : cs.getConcept()) processConcept(ct.getConcept(), csc, tgtcs);
}
 
Example #6
Source File: ValueSetCheckerSimple.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean codeInConceptIsAFilter(CodeSystem cs, ConceptSetFilterComponent f, String code) {
  if (code.equals(f.getProperty()))
    return true;
 ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), f.getValue());
 if (cc == null)
   return false;
 cc = findCodeInConcept(cc.getConcept(), code);
 return cc != null;
}
 
Example #7
Source File: DefaultProfileValidationSupportStu3AsR4.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
private CodeValidationResult testIfConceptIsInList(String theCode, List<ConceptDefinitionComponent> conceptList, boolean theCaseSensitive) {
    String code = theCode;
    if (theCaseSensitive == false) {
        code = code.toUpperCase();
    }

    return testIfConceptIsInListInner(conceptList, theCaseSensitive, code);
}
 
Example #8
Source File: DefaultProfileValidationSupportStu3AsR4.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
private void addConcepts(ConceptSetComponent theInclude, ValueSetExpansionComponent theRetVal, Set<String> theWantCodes, List<ConceptDefinitionComponent> theConcepts) {
    for (ConceptDefinitionComponent next : theConcepts) {
        if (theWantCodes.isEmpty() || theWantCodes.contains(next.getCode())) {
            theRetVal
                    .addContains()
                    .setSystem(theInclude.getSystem())
                    .setCode(next.getCode())
                    .setDisplay(next.getDisplay());
        }
        addConcepts(theInclude, theRetVal, theWantCodes, next.getConcept());
    }
}
 
Example #9
Source File: VersionConvertor_10_40.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static org.hl7.fhir.dstu2.model.ValueSet.ValueSetCodeSystemComponent convertCodeSystem(org.hl7.fhir.r4.model.CodeSystem src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.dstu2.model.ValueSet.ValueSetCodeSystemComponent tgt = new org.hl7.fhir.dstu2.model.ValueSet.ValueSetCodeSystemComponent();
    copyElement(src, tgt);
    if (src.hasUrlElement())
        tgt.setSystemElement(convertUri(src.getUrlElement()));
    if (src.hasVersionElement())
        tgt.setVersionElement(convertString(src.getVersionElement()));
    if (src.hasCaseSensitiveElement())
        tgt.setCaseSensitiveElement(convertBoolean(src.getCaseSensitiveElement()));
    for (ConceptDefinitionComponent cc : src.getConcept()) tgt.addConcept(convertCodeSystemConcept(src, cc));
    return tgt;
}
 
Example #10
Source File: CountryCodesConverter.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void poplang(Element e, ConceptDefinitionComponent cc) {
  for (Element el : XMLUtil.getNamedChildren(e, "short-name")) {
    if (!el.getAttribute("lang3code").equals("eng")) {
      String l2 = lang3To2(el.getAttribute("lang3code"));
      if (l2 != null)
        cc.addDesignation().setLanguage(l2).setValue(el.getTextContent());
    }
  }
}
 
Example #11
Source File: ValueSetCheckerSimple.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ConceptDefinitionComponent findCodeInConcept(List<ConceptDefinitionComponent> concept, String code) {
  for (ConceptDefinitionComponent cc : concept) {
    if (code.equals(cc.getCode()))
      return cc;
    ConceptDefinitionComponent c = findCodeInConcept(cc.getConcept(), code);
    if (c != null)
      return c;
  }
  return null;
}
 
Example #12
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ConceptDefinitionComponent getConceptForCode(List<ConceptDefinitionComponent> clist, String code) {
  for (ConceptDefinitionComponent c : clist) {
    if (code.equals(c.getCode()))
      return c;
    ConceptDefinitionComponent v = getConceptForCode(c.getConcept(), code);
    if (v != null)
      return v;
  }
  return null;
}
 
Example #13
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static boolean isNotSelectable(CodeSystem cs, ConceptDefinitionComponent def) {
  for (ConceptPropertyComponent p : def.getProperty()) {
    if (p.getCode().equals("notSelectable") && p.hasValue() && p.getValue() instanceof BooleanType) 
      return ((BooleanType) p.getValue()).getValue();
  }
  return false;
}
 
Example #14
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void setNotSelectable(CodeSystem cs, ConceptDefinitionComponent concept) throws FHIRFormatError {
  defineNotSelectableProperty(cs);
  ConceptPropertyComponent p = getProperty(concept, "notSelectable");
  if (p != null)
    p.setValue(new BooleanType(true));
  else
    concept.addProperty().setCode("notSelectable").setValue(new BooleanType(true));    
}
 
Example #15
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void setStatus(CodeSystem cs, ConceptDefinitionComponent concept, ConceptStatus status) throws FHIRFormatError {
  defineStatusProperty(cs);
  ConceptPropertyComponent p = getProperty(concept, "status");
  if (p != null)
    p.setValue(new CodeType(status.toCode()));
  else
    concept.addProperty().setCode("status").setValue(new CodeType(status.toCode()));    
}
 
Example #16
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static boolean isInactive(CodeSystem cs, ConceptDefinitionComponent def) throws FHIRException {
  for (ConceptPropertyComponent p : def.getProperty()) {
    if (p.getCode().equals("status") && p.hasValueStringType()) 
      return "inactive".equals(p.getValueStringType());
  }
  return false;
}
 
Example #17
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static String getCodeDefinition(List<ConceptDefinitionComponent> list, String code) {
  for (ConceptDefinitionComponent c : list) {
    if (c.hasCode() &&  c.getCode().equals(code))
      return c.getDefinition();
    String s = getCodeDefinition(c.getConcept(), code);
    if (s != null)
      return s;
  }
  return null;
}
 
Example #18
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static ConceptDefinitionComponent findCode(List<ConceptDefinitionComponent> list, String code) {
  for (ConceptDefinitionComponent c : list) {
    if (c.getCode().equals(code))
      return c;
    ConceptDefinitionComponent s = findCode(c.getConcept(), code);
    if (s != null)
      return s;
  }
  return null;
}
 
Example #19
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static List<String> getOtherChildren(CodeSystem cs, ConceptDefinitionComponent c) {
  List<String> res = new ArrayList<String>();
  for (ConceptPropertyComponent p : c.getProperty()) {
    if ("parent".equals(p.getCode())) {
      res.add(p.getValue().primitiveValue());
    }
  }
  return res;
}
 
Example #20
Source File: IWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public ValidationResult(IssueSeverity severity, String message, ConceptDefinitionComponent definition) {
  this.severity = severity;
  this.message = message;
  this.definition = definition;
}
 
Example #21
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);
}
 
Example #22
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public static void setDeprecated(CodeSystem cs, ConceptDefinitionComponent concept, DateTimeType date) throws FHIRFormatError {
  setStatus(cs, concept, ConceptStatus.Deprecated);
  defineDeprecatedProperty(cs);
  concept.addProperty().setCode("deprecationDate").setValue(date);    
}
 
Example #23
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public static boolean isInactive(CodeSystem cs, String code) throws FHIRException {
  ConceptDefinitionComponent def = findCode(cs.getConcept(), code);
  if (def == null)
    return true;
  return isInactive(cs, def);
}
 
Example #24
Source File: CountryCodesConverter.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void execute() throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
    Document src = load();
    CodeSystem cs1 = new CodeSystem();
    CodeSystem cs2 = new CodeSystem();
    CodeSystem cs3 = new CodeSystem();
    setMetadata(src, cs1, "iso3166", "urn:iso:std:iso:3166", "", "");
    setMetadata(src, cs2, "iso3166-2", "urn:iso:std:iso:3166:-2", "Part2", " Part 2");
    cs1.addProperty().setCode("canonical").setDescription("The 2 letter code that identifies the same country (so 2/3/numeric codes can be aligned)").setType(PropertyType.CODE);
    cs2.addProperty().setCode("country").setDescription("The 2 letter code that identifies the country for the subdivision").setType(PropertyType.CODE);
    for (Element e : XMLUtil.getNamedChildren(src.getDocumentElement(), "country")) {
      System.out.println(e.getAttribute("id"));
      String c2 = XMLUtil.getNamedChildText(e, "alpha-2-code");
      String c3 = XMLUtil.getNamedChildText(e, "alpha-3-code");
      String cN = XMLUtil.getNamedChildText(e, "numeric-code");
      Element n = XMLUtil.getNamedChildByAttribute(e, "short-name", "lang3code", "eng");
      if (n == null)
        n = XMLUtil.getNamedChildByAttribute(e, "short-name-upper-case", "lang3code", "eng");
      if (n == null)
        continue;
      String name = n.getTextContent();
      n = XMLUtil.getNamedChildByAttribute(e, "full-name", "lang3code", "eng");
      if (n == null)
        n = XMLUtil.getNamedChildByAttribute(e, "full-name-upper-case", "lang3code", "eng");
      if (n == null)
        n = XMLUtil.getNamedChildByAttribute(e, "short-name", "lang3code", "eng");
      if (n == null)
        n = XMLUtil.getNamedChildByAttribute(e, "short-name-upper-case", "lang3code", "eng");
      String desc = n.getTextContent();
      ConceptDefinitionComponent cc = cs1.addConcept();
      cc.setCode(c2);
      cc.setDisplay(name);
      cc.setDefinition(desc);
      poplang(e, cc);
      if (c3 != null) {
        cc = cs1.addConcept();
        cc.setCode(c3);
        cc.setDisplay(name);
        cc.setDefinition(desc);
        cc.addProperty().setCode("canonical").setValue(new CodeType(c2));
        poplang(e, cc);
      }
      if (cN != null) {
        cc = cs1.addConcept();
        cc.setCode(cN);
        cc.setDisplay(name);
        cc.setDefinition(desc);
        cc.addProperty().setCode("canonical").setValue(new CodeType(c2));
        poplang(e, cc);
      }
      for (Element sd : XMLUtil.getNamedChildren(e, "subdivision")) {
        cc = cs2.addConcept();
        cc.setCode(XMLUtil.getNamedChildText(sd, "subdivision-code"));
        Element l = XMLUtil.getNamedChild(sd, "subdivision-locale");
        cc.setDisplay(XMLUtil.getNamedChildText(l, "subdivision-locale-name"));
        cc.addProperty().setCode("country").setValue(new CodeType(c2));            
      }
    }
    cs1.setCount(cs1.getConcept().size());
    cs2.setCount(cs2.getConcept().size());
    throw new Error("Needs revisiting");
//    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "4.0.1", "package", "CodeSstem-iso3166.json")), cs1);
//    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "3.0.2", "package", "CodeSstem-iso3166.json")), cs1); // format hasn't changed
//    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "4.0.1", "package", "CodeSstem-iso3166-2.json")), cs2);
//    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "3.0.2", "package", "CodeSstem-iso3166-2.json")), cs2); // format hasn't changed
  }
 
Example #25
Source File: IWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public ConceptDefinitionComponent asConceptDefinition() {
  return definition;
}
 
Example #26
Source File: IWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public ValidationResult(ConceptDefinitionComponent definition) {
  this.definition = definition;
}
 
Example #27
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private ValidationResult validateOnServer(ValueSet vs, Parameters pin) throws FHIRException {
  if (vs != null)
    pin.addParameter().setName("valueSet").setResource(vs);
  for (ParametersParameterComponent pp : pin.getParameter())
    if (pp.getName().equals("profile"))
      throw new Error("Can only specify profile in the context");
  if (expParameters == null)
    throw new Error("No ExpansionProfile provided");
  pin.addParameter().setName("profile").setResource(expParameters);
  txLog.clearLastId();
  Parameters pOut;
  if (vs == null)
    pOut = txClient.validateCS(pin);
  else
    pOut = txClient.validateVS(pin);
  boolean ok = false;
  String message = "No Message returned";
  String display = null;
  TerminologyServiceErrorClass err = TerminologyServiceErrorClass.UNKNOWN;
  for (ParametersParameterComponent p : pOut.getParameter()) {
    if (p.getName().equals("result"))
      ok = ((BooleanType) p.getValue()).getValue().booleanValue();
    else if (p.getName().equals("message"))
      message = ((StringType) p.getValue()).getValue();
    else if (p.getName().equals("display"))
      display = ((StringType) p.getValue()).getValue();
    else if (p.getName().equals("cause")) {
      try {
        IssueType it = IssueType.fromCode(((StringType) p.getValue()).getValue());
        if (it == IssueType.UNKNOWN)
          err = TerminologyServiceErrorClass.UNKNOWN;
        else if (it == IssueType.NOTSUPPORTED)
          err = TerminologyServiceErrorClass.VALUESET_UNSUPPORTED;
      } catch (FHIRException e) {
      }
    }
  }
  if (!ok)
    return new ValidationResult(IssueSeverity.ERROR, message, err).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
  else if (message != null && !message.equals("No Message returned")) 
    return new ValidationResult(IssueSeverity.WARNING, message, new ConceptDefinitionComponent().setDisplay(display)).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
  else if (display != null)
    return new ValidationResult(new ConceptDefinitionComponent().setDisplay(display)).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
  else
    return new ValidationResult(new ConceptDefinitionComponent()).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
}
 
Example #28
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public static boolean hasCSComment(ConceptDefinitionComponent c) {
  return findStringExtension(c, EXT_CS_COMMENT);    
}
 
Example #29
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public static String getCSComment(ConceptDefinitionComponent c) {
  return readStringExtension(c, EXT_CS_COMMENT);    
}
 
Example #30
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public static void addCSComment(ConceptDefinitionComponent nc, String comment) {
  if (!StringUtils.isBlank(comment))
    nc.getExtension().add(Factory.newExtension(EXT_CS_COMMENT, Factory.newString_(comment), true));   
}