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

The following examples show how to use org.hl7.fhir.dstu3.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: ValidationSupportSTU3.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: CareConnectProfileValidationSupport.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) {
  logD("CareConnect testIfConceptIsInListInner: code=" + code);
  CodeValidationResult retVal = null;
  for (ConceptDefinitionComponent next : conceptList) {
    // KGM
    logD("CareConnect testIfConceptIsInListInner NextCode = "+next.getCode());
    String nextCandidate = next.getCode();
    if (theCaseSensitive == false) {
      nextCandidate = nextCandidate.toUpperCase();
    }
    if (nextCandidate.equals(code)) {
      logD("The Code "+code+" is in the list");
      retVal = new CodeValidationResult(next);
      break;
    }

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

  return retVal;
}
 
Example #3
Source File: ValueSet10_30.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.dstu3.model.CodeSystem.ConceptDefinitionComponent ct = new org.hl7.fhir.dstu3.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.dstu3.model.CodeSystem.ConceptDefinitionDesignationComponent cst = new org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionDesignationComponent();
        cst.setLanguage(csd.getLanguage());
        cst.setUse(VersionConvertor_10_30.convertCoding(csd.getUse()));
        cst.setValue(csd.getValue());
    }
    for (org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent csc : cs.getConcept()) processConcept(ct.getConcept(), csc, tgtcs);
}
 
Example #4
Source File: ValueSet10_30.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.dstu3.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_30.convertCoding(csd.getUse()));
        cst.setValue(csd.getValue());
    }
    for (ConceptDefinitionComponent csc : cs.getConcept()) processConcept(ct.getConcept(), csc, srcCS);
}
 
Example #5
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private ValidationResult verifyCodeInExpansion(ValueSet vs, String system, String code,
  String display) {
  ValueSetExpansionContainsComponent cc = findCode(vs.getExpansion().getContains(), code);
  if (cc == null) {
    return new ValidationResult(IssueSeverity.ERROR,
      "Unknown Code " + code + " in " + vs.getUrl());
  }
  if (display == null) {
    return new ValidationResult(
      new ConceptDefinitionComponent().setCode(code).setDisplay(cc.getDisplay()));
  }
  if (cc.hasDisplay()) {
    if (display.equalsIgnoreCase(cc.getDisplay())) {
      return new ValidationResult(
        new ConceptDefinitionComponent().setCode(code).setDisplay(cc.getDisplay()));
    }
    return new ValidationResult(IssueSeverity.WARNING,
      "Display Name for " + code + " must be '" + cc.getDisplay() + "'",
      new ConceptDefinitionComponent().setCode(code).setDisplay(cc.getDisplay()));
  }
  return null;
}
 
Example #6
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private ValidationResult loadFromCache(String fn) throws FileNotFoundException, IOException {
  if (fn == null) {
    return null;
  }
  if (!(new File(fn).exists())) {
    return null;
  }
  String cnt = TextFile.fileToString(fn);
  if (cnt.startsWith("!error: ")) {
    return new ValidationResult(IssueSeverity.ERROR, cnt.substring(8));
  } else if (cnt.startsWith("!warning: ")) {
    return new ValidationResult(IssueSeverity.ERROR, cnt.substring(10));
  } else {
    return new ValidationResult(new ConceptDefinitionComponent().setDisplay(cnt));
  }
}
 
Example #7
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private String cacheValue(CodeSystem cs) throws IOException {
  CodeSystem csid = new CodeSystem();
  csid.setId(cs.getId());
  csid.setVersion(cs.getVersion());
  csid.setContent(cs.getContent());
  csid.setHierarchyMeaning(CodeSystemHierarchyMeaning.GROUPEDBY);
  for (ConceptDefinitionComponent cc : cs.getConcept()) {
    csid.getConcept().add(processCSConcept(cc));
  }
  JsonParser parser = new JsonParser();
  parser.setOutputStyle(OutputStyle.NORMAL);
  ByteArrayOutputStream b = new ByteArrayOutputStream();
  parser.compose(b, csid);
  b.close();
  return new String(b.toByteArray(), Constants.CHARSET_UTF8);
}
 
Example #8
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private int countConcepts(List<ConceptDefinitionComponent> list) {
  int count = list.size();
  for (ConceptDefinitionComponent c : list)
    if (c.hasConcept())
      count = count + countConcepts(c.getConcept());
  return count;
}
 
Example #9
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void addLanguageRow(ConceptDefinitionComponent c, XhtmlNode t, List<String> langs) {
  XhtmlNode tr = t.tr();
  tr.td().addText(c.getCode());
  for (String lang : langs) {
    ConceptDefinitionDesignationComponent d = null;
    for (ConceptDefinitionDesignationComponent designation : c.getDesignation()) {
      if (lang.equals(designation.getLanguage()))
        d = designation;
    }
    tr.td().addText(d == null ? "" : d.getValue());
  }
}
 
Example #10
Source File: VersionConvertor_10_30.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.dstu3.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 #11
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void scanLangs(ConceptDefinitionComponent c, List<String> langs) {
  for (ConceptDefinitionDesignationComponent designation : c.getDesignation()) {
    String lang = designation.getLanguage();
    if (langs != null && !langs.contains(lang))
      langs.add(lang);
  }
  for (ConceptDefinitionComponent g : c.getConcept())
    scanLangs(g, langs);
}
 
Example #12
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean conceptsHaveComments(ConceptDefinitionComponent c) {
  if (ToolingExtensions.hasCSComment(c))
    return true;
  for (ConceptDefinitionComponent g : c.getConcept())
    if (conceptsHaveComments(g))
      return true;
  return false;
}
 
Example #13
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean conceptsHaveDisplay(ConceptDefinitionComponent c) {
  if (c.hasDisplay())
    return true;
  for (ConceptDefinitionComponent g : c.getConcept())
    if (conceptsHaveDisplay(g))
      return true;
  return false;
}
 
Example #14
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean conceptsHaveDeprecated(CodeSystem cs, ConceptDefinitionComponent c) {
  if (CodeSystemUtilities.isDeprecated(cs, c))
    return true;
  for (ConceptDefinitionComponent g : c.getConcept())
    if (conceptsHaveDeprecated(cs, g))
      return true;
  return false;
}
 
Example #15
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ConceptDefinitionComponent getConceptForCode(List<ConceptDefinitionComponent> list, String code) {
  for (ConceptDefinitionComponent c : list) {
  if (code.equals(c.getCode()))
    return c;
    ConceptDefinitionComponent v = getConceptForCode(c.getConcept(), code);
    if (v != null)
      return v;
  }
  return null;
}
 
Example #16
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ConceptDefinitionComponent getConceptForCodeFromExpansion(List<ValueSetExpansionContainsComponent> list, String code) {
  for (ValueSetExpansionContainsComponent c : list) {
    if (code.equals(c.getCode())) {
      ConceptDefinitionComponent res = new ConceptDefinitionComponent();
      res.setCode(c.getCode());
      res.setDisplay(c.getDisplay());
      return res;
    }
    ConceptDefinitionComponent v = getConceptForCodeFromExpansion(c.getContains(), code);
    if (v != null)
      return v;
  }
  return null;
}
 
Example #17
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean codeExistsInValueSet(CodeSystem cs, String code) {
  for (ConceptDefinitionComponent c : cs.getConcept()) {
    if (inConcept(code, c))
      return true;
  }
  return false;
}
 
Example #18
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean inConcept(String code, ConceptDefinitionComponent c) {
  if (c.hasCodeElement() && c.getCode().equals(code))
    return true;
  for (ConceptDefinitionComponent g : c.getConcept()) {
    if (inConcept(code, g))
      return true;
  }
  return false;
}
 
Example #19
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ConceptDefinitionComponent processCSConcept(ConceptDefinitionComponent cc) {
  ConceptDefinitionComponent ccid = new ConceptDefinitionComponent();
  ccid.setCode(cc.getCode());
  ccid.setDisplay(cc.getDisplay());
  for (ConceptDefinitionComponent cci : cc.getConcept()) {
    ccid.getConcept().add(processCSConcept(cci));
  }
  return ccid;
}
 
Example #20
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ValidationResult verifyCodeInCodeSystem(CodeSystem cs, String system, String code,
  String display) throws Exception {
  ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), code);
  if (cc == null) {
    if (cs.getContent().equals(CodeSystem.CodeSystemContentMode.COMPLETE)) {
      return new ValidationResult(IssueSeverity.ERROR,
        "Unknown Code " + code + " in " + cs.getUrl());
    } else if (!cs.getContent().equals(CodeSystem.CodeSystemContentMode.NOTPRESENT)) {
      return new ValidationResult(IssueSeverity.WARNING,
        "Unknown Code " + code + " in partial code list of " + cs.getUrl());
    } else {
      return verifyCodeExternal(null,
        new Coding().setSystem(system).setCode(code).setDisplay(display), false);
    }
  }
  //
  //        return new ValidationResult(IssueSeverity.WARNING, "A definition was found for "+cs.getUrl()+", but it has no codes in the definition");
  //      return new ValidationResult(IssueSeverity.ERROR, "Unknown Code "+code+" in "+cs.getUrl());
  if (display == null) {
    return new ValidationResult(cc);
  }
  CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
  if (cc.hasDisplay()) {
    b.append(cc.getDisplay());
    if (display.equalsIgnoreCase(cc.getDisplay())) {
      return new ValidationResult(cc);
    }
  }
  for (ConceptDefinitionDesignationComponent ds : cc.getDesignation()) {
    b.append(ds.getValue());
    if (display.equalsIgnoreCase(ds.getValue())) {
      return new ValidationResult(cc);
    }
  }
  return new ValidationResult(IssueSeverity.WARNING,
    "Display Name for " + code + " must be one of '" + b.toString() + "'", cc);
}
 
Example #21
Source File: BaseWorkerContext.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 #22
Source File: SNOMEDUKMockValidationSupport.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) {
  logD("SNOMEDMOCK testIfConceptIsInList: {} code="+ theCode);


  String code = theCode;
  if (theCaseSensitive == false) {
    code = code.toUpperCase();
  }

  return testIfConceptIsInListInner(conceptList, theCaseSensitive, code);
}
 
Example #23
Source File: SNOMEDUKMockValidationSupport.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
private CodeValidationResult testIfConceptIsInListInner(List<ConceptDefinitionComponent> conceptList, boolean theCaseSensitive, String code) {
  logD("SNOMEDMOCK testIfConceptIsInListInner: code=" + code);

  /* This is a mock and we will do a basic check (is the code Numeric!
  return positive if numeric else false */


  CodeValidationResult retVal = null;

    if (isNumeric(code)) {
        ConceptDefinitionComponent concept = new ConceptDefinitionComponent();
        concept.setCode(code);
        retVal = new CodeValidationResult(concept);
    }
  /* Ignore the list for now KGM Dec 2017 TODO
  for (ConceptDefinitionComponent next : conceptList) {
    // KGM
    logD("SNOMEDMOCK testIfConceptIsInListInner NextCode = "+next.getCode());
    String nextCandidate = next.getCode();



  }
  */

  return retVal;
}
 
Example #24
Source File: CareConnectProfileValidationSupport.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) {
  logD("CareConnect testIfConceptIsInList: {} code="+ theCode);

  String code = theCode;
  if (theCaseSensitive == false) {
    code = code.toUpperCase();
  }

  return testIfConceptIsInListInner(conceptList, theCaseSensitive, code);
}
 
Example #25
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.getCode().equals(code))
      return c.getDefinition();
    String s = getCodeDefinition(c.getConcept(), code);
    if (s != null)
      return s;
  }
  return null;
}
 
Example #26
Source File: NUCCConvertor.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void processLine(CodeSystem cs, String[] values) throws FHIRFormatError {
  if (!values[1].equals(last[0])) {
    last[1] = "";
    last[0] = values[1];
    concepts[0] = new ConceptDefinitionComponent();
    cs.getConcept().add(concepts[0]);
    concepts[0].setDisplay(values[1]);
    concepts[0].setCode("base-"+Integer.toString(cs.getConcept().size()));
    CodeSystemUtilities.setNotSelectable(cs, concepts[0]);
  }
  if (!values[2].equals(last[1])) {
    last[1] = values[2];
    concepts[1] = new ConceptDefinitionComponent();
    concepts[0].getConcept().add(concepts[1]);
    concepts[1].setCode(values[0]);
    concepts[1].setDisplay(values[2]);
    concepts[1].setDefinition(values[4]);
    if (values.length > 5 && !Utilities.noString(values[5]))
      ToolingExtensions.addCSComment(concepts[1], values[5]);
  } else if (!Utilities.noString(values[3])) {
    ConceptDefinitionComponent cc = new ConceptDefinitionComponent();
    concepts[1].getConcept().add(cc);
    cc.setCode(values[0]);
    cc.setDisplay(values[3]);
    cc.setDefinition(values[4]);
    if (values.length > 5 && !Utilities.noString(values[5]))
      ToolingExtensions.addCSComment(cc, values[5]);
  }
}
 
Example #27
Source File: ICPC2Importer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void processClass(Element cls, Map<String, ConceptDefinitionComponent> concepts, CodeSystem define) throws FHIRFormatError {
  ConceptDefinitionComponent concept = new ConceptDefinitionComponent();
  concept.setCode(cls.getAttribute("code"));
  concept.setDefinition(getRubric(cls, "preferred"));
  String s = getRubric(cls, "shortTitle");
  if (s != null && !s.equals(concept.getDefinition()))
    concept.addDesignation().setUse(new Coding().setSystem("http://hl7.org/fhir/sid/icpc2/rubrics").setCode("shortTitle")).setValue(s);
  s = getRubric(cls, "inclusion");
  if (s != null)
    concept.addDesignation().setUse(new Coding().setSystem("http://hl7.org/fhir/sid/icpc2/rubrics").setCode("inclusion")).setValue(s);
  s = getRubric(cls, "exclusion");
  if (s != null)
    concept.addDesignation().setUse(new Coding().setSystem("http://hl7.org/fhir/sid/icpc2/rubrics").setCode("exclusion")).setValue(s);
  s = getRubric(cls, "criteria");
  if (s != null)
    concept.addDesignation().setUse(new Coding().setSystem("http://hl7.org/fhir/sid/icpc2/rubrics").setCode("criteria")).setValue(s);
  s = getRubric(cls, "consider");
  if (s != null)
    concept.addDesignation().setUse(new Coding().setSystem("http://hl7.org/fhir/sid/icpc2/rubrics").setCode("consider")).setValue(s);
  s = getRubric(cls, "note");
  if (s != null)
    concept.addDesignation().setUse(new Coding().setSystem("http://hl7.org/fhir/sid/icpc2/rubrics").setCode("note")).setValue(s);
  
  concepts.put(concept.getCode(), concept);
  List<Element> children = new ArrayList<Element>(); 
  XMLUtil.getNamedChildren(cls, "SubClass", children);
  if (children.size() > 0)
    CodeSystemUtilities.setNotSelectable(define, concept);
  
  Element parent = XMLUtil.getNamedChild(cls, "SuperClass");
  if (parent == null) {
    define.addConcept(concept);
  } else {
    ConceptDefinitionComponent p = concepts.get(parent.getAttribute("code"));
    p.getConcept().add(concept);
  }
}
 
Example #28
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static boolean isDeprecated(CodeSystem cs, ConceptDefinitionComponent def) {
  for (ConceptPropertyComponent p : def.getProperty()) {
    if (p.getCode().equals("deprecated") && p.hasValue() && p.getValue() instanceof BooleanType) 
      return ((BooleanType) p.getValue()).getValue();
    if (p.getCode().equals("deprecationDate") && p.hasValue() && p.getValue() instanceof DateTimeType) 
      return ((DateTimeType) p.getValue()).before(new DateTimeType());
  }
  return false;
}
 
Example #29
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 #30
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ConceptDefinitionComponent findCode(String code, List<ConceptDefinitionComponent> list) {
  for (ConceptDefinitionComponent t : list) {
    if (code.equals(t.getCode()))
      return t;
    ConceptDefinitionComponent c = findCode(code, t.getConcept());
    if (c != null)
      return c;
  }
  return null;
}