org.hl7.fhir.r4.model.Coding Java Examples

The following examples show how to use org.hl7.fhir.r4.model.Coding. 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: StructureMapUtilities.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
private String describeTransformCCorC(StructureMapGroupRuleTargetComponent tgt) throws FHIRException {
  if (tgt.getParameter().size() < 2)
    return null;
  Type p1 = tgt.getParameter().get(0).getValue();
  Type p2 = tgt.getParameter().get(1).getValue();
  if (p1 instanceof IdType || p2 instanceof IdType)
    return null;
  if (!(p1 instanceof PrimitiveType) || !(p2 instanceof PrimitiveType))
    return null;
  String uri = ((PrimitiveType) p1).asStringValue();
  String code = ((PrimitiveType) p2).asStringValue();
  if (Utilities.noString(uri))
    throw new FHIRException("Describe Transform, but the uri is blank");
  if (Utilities.noString(code))
    throw new FHIRException("Describe Transform, but the code is blank");
  Coding c = buildCoding(uri, code);
  return NarrativeGenerator.describeSystem(c.getSystem())+"#"+c.getCode()+(c.hasDisplay() ? "("+c.getDisplay()+")" : "");
}
 
Example #2
Source File: FHIRToolingClient.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public ConceptMap updateClosure(String name, Coding coding) {
  Parameters params = new Parameters();
  params.addParameter().setName("name").setValue(new StringType(name));
  params.addParameter().setName("concept").setValue(coding);
  List<Header> headers = null;
  ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()),
      utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers);
  result.addErrorStatus(410);//gone
  result.addErrorStatus(404);//unknown
  result.addErrorStatus(405);
  result.addErrorStatus(422);//Unprocessable Entity
  result.addSuccessStatus(200);
  result.addSuccessStatus(201);
  if(result.isUnsuccessfulRequest()) {
    throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload());
  }
  return (ConceptMap) result.getPayload();
}
 
Example #3
Source File: TerminologyCache.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public CacheToken generateValidationToken(ValidationOptions options, Coding code, ValueSet vs) {
  CacheToken ct = new CacheToken();
  if (code.hasSystem())
    ct.name = getNameForSystem(code.getSystem());
  else
    ct.name = NAME_FOR_NO_SYSTEM;
  JsonParser json = new JsonParser();
  json.setOutputStyle(OutputStyle.PRETTY);
  ValueSet vsc = getVSEssense(vs);
  try {
    ct.request = "{\"code\" : "+json.composeString(code, "code")+", \"valueSet\" :"+(vsc == null ? "null" : json.composeString(vsc))+(options == null ? "" : ", "+options.toJson())+"}";
  } catch (IOException e) {
    throw new Error(e);
  }
  ct.key = String.valueOf(hashNWS(ct.request));
  return ct;
}
 
Example #4
Source File: TerminologyCache.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public CacheToken generateValidationToken(ValidationOptions options, CodeableConcept code, ValueSet vs) {
  CacheToken ct = new CacheToken();
  for (Coding c : code.getCoding()) {
    if (c.hasSystem())
      ct.setName(getNameForSystem(c.getSystem()));
  }
  JsonParser json = new JsonParser();
  json.setOutputStyle(OutputStyle.PRETTY);
  ValueSet vsc = getVSEssense(vs);
  try {
    ct.request = "{\"code\" : "+json.composeString(code, "codeableConcept")+", \"valueSet\" :"+json.composeString(vsc)+(options == null ? "" : ", "+options.toJson())+"}";
  } catch (IOException e) {
    throw new Error(e);
  }
  ct.key = String.valueOf(hashNWS(ct.request));
  return ct;
}
 
Example #5
Source File: FhirR4.java    From synthea with Apache License 2.0 6 votes vote down vote up
/**
 * Helper function to convert a Code into a CodeableConcept. Takes an optional system, which
 * replaces the Code.system in the resulting CodeableConcept if not null.
 *
 * @param from   The Code to create a CodeableConcept from.
 * @param system The system identifier, such as a URI. Optional; may be null.
 * @return The converted CodeableConcept
 */
private static CodeableConcept mapCodeToCodeableConcept(Code from, String system) {
  CodeableConcept to = new CodeableConcept();
  system = system == null ? null : ExportHelper.getSystemURI(system);
  from.system = ExportHelper.getSystemURI(from.system);

  if (from.display != null) {
    to.setText(from.display);
  }

  Coding coding = new Coding();
  coding.setCode(from.code);
  coding.setDisplay(from.display);
  if (from.system == null) {
    coding.setSystem(system);
  } else {
    coding.setSystem(from.system);
  }

  to.addCoding(coding);

  return to;
}
 
Example #6
Source File: IPatientPatientAttributeMapper.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private void mapRelatedContacts(IPatient source, Patient target) {
	List<ContactComponent> contacts = new ArrayList<>();

	IPerson legalGuardian = source.getLegalGuardian();
	if (legalGuardian != null) {
		ContactComponent _legalGuardian = new ContactComponent();

		CodeableConcept addCoding = new CodeableConcept().addCoding(new Coding().setCode("N"));
		_legalGuardian.setRelationship(Collections.singletonList(addCoding));
		_legalGuardian.setId(legalGuardian.getId());
		List<HumanName> humanNames = contactHelper.getHumanNames(legalGuardian);
		_legalGuardian.setName((!humanNames.isEmpty()) ? humanNames.get(0) : null);
		List<Address> addresses = contactHelper.getAddresses(legalGuardian);
		_legalGuardian.setAddress((!addresses.isEmpty()) ? addresses.get(0) : null);
		AdministrativeGender gender = contactHelper.getGender(legalGuardian.getGender());
		_legalGuardian.setGender(gender);
		List<ContactPoint> contactPoints = contactHelper.getContactPoints(legalGuardian);
		_legalGuardian.setTelecom(contactPoints);

		contacts.add(_legalGuardian);
	}

	target.setContact(contacts);
}
 
Example #7
Source File: ObjectConverter.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static Coding readAsCoding(Element item) {
  Coding c = new Coding();
  c.setSystem(item.getNamedChildValue("system"));
  c.setVersion(item.getNamedChildValue("version"));
  c.setCode(item.getNamedChildValue("code"));
  c.setDisplay(item.getNamedChildValue("display"));
  return c;
}
 
Example #8
Source File: LoincToDEConvertor.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private CodeableConcept makeUnits(String text, String ucum) {
	if (Utilities.noString(text) && Utilities.noString(ucum))
		return null;
	CodeableConcept cc = new CodeableConcept();
	cc.setText(text);
	cc.getCoding().add(new Coding().setCode(ucum).setSystem("http://unitsofmeasure.org"));
	return cc;
}
 
Example #9
Source File: ConceptMapEngine.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public Coding translate(Coding source, String url) throws FHIRException {
  ConceptMap cm = context.fetchResource(ConceptMap.class, url);
  if (cm == null)
    throw new FHIRException("Unable to find ConceptMap '"+url+"'");
  if (source.hasSystem()) 
    return translateBySystem(cm, source.getSystem(), source.getCode());
  else
    return translateByJustCode(cm, source.getCode());
}
 
Example #10
Source File: ConceptMapEngine.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private Coding translateByJustCode(ConceptMap cm, String code) throws FHIRException {
  SourceElementComponent ct = null;
  ConceptMapGroupComponent cg = null;
  for (ConceptMapGroupComponent g : cm.getGroup()) {
    for (SourceElementComponent e : g.getElement()) {
      if (code.equals(e.getCode())) {
        if (e != null)
          throw new FHIRException("Unable to process translate "+code+" because multiple candidate matches were found in concept map "+cm.getUrl());
        ct = e;
        cg = g;
      }
    }
  }
  if (ct == null)
    return null;
  TargetElementComponent tt = null;
  for (TargetElementComponent t : ct.getTarget()) {
    if (!t.hasDependsOn() && !t.hasProduct() && isOkEquivalence(t.getEquivalence())) {
      if (tt != null)
        throw new FHIRException("Unable to process translate "+code+" because multiple targets were found in concept map "+cm.getUrl());
      tt = t;       
    }
  }
  if (tt == null)
    return null;
  return new Coding().setSystem(cg.getTarget()).setVersion(cg.getTargetVersion()).setCode(tt.getCode()).setDisplay(tt.getDisplay());
}
 
Example #11
Source File: RdfParserBase.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
protected void decorateCoding(Complex t, Coding element) {
	if (!element.hasSystem())
		return;
	if ("http://snomed.info/sct".equals(element.getSystem())) {
		t.prefix("sct", "http://snomed.info/sct/");
		t.predicate("a", "sct:"+element.getCode());
	} else if ("http://snomed.info/sct".equals(element.getSystem())) {
		t.prefix("loinc", "http://loinc.org/rdf#");
		t.predicate("a", "loinc:"+element.getCode());
	}  
}
 
Example #12
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private List<Coding> mergeCodings(List<Coding> left, List<Coding> right) {
  List<Coding> result = new ArrayList<Coding>();
  result.addAll(left);
  for (Coding c : right) {
    boolean found = false;
    for (Coding ct : left)
      if (Utilities.equals(c.getSystem(), ct.getSystem()) && Utilities.equals(c.getCode(), ct.getCode()))
        found = true;
    if (!found)
      result.add(c);
  }
  return result;
}
 
Example #13
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 #14
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void setExtension(Element focus, String url, Coding c) {
  for (Extension e : focus.getExtension()) 
    if (e.getUrl().equals(url)) {
      e.setValue(c);
      return;
    }
  focus.getExtension().add(new Extension().setUrl(url).setValue(c));    
}
 
Example #15
Source File: TerminologyCache.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public String summary(CodeableConcept code) {
  StringBuilder b = new StringBuilder();
  b.append("{");
  boolean first = true;
  for (Coding c : code.getCoding()) {
    if (first) first = false; else b.append(",");
    b.append(summary(c));
  }
  b.append("}: \"");
  b.append(code.getText());
  b.append("\"");
  return b.toString();
}
 
Example #16
Source File: MetaTest.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Test
public void testMetaSecurity() {
  Meta meta = new Meta();
  Coding coding = meta.addSecurity().setSystem(TEST_SYSTEM).setCode(TEST_CODE);
  Assertions.assertTrue(meta.hasSecurity());
  Assertions.assertNotNull(meta.getSecurity());
  Assertions.assertNotNull(meta.getSecurity(TEST_SYSTEM, TEST_CODE));
  Assertions.assertEquals(1, meta.getSecurity().size());
  Assertions.assertEquals(meta.getSecurity().get(0), meta.getSecurity(TEST_SYSTEM, TEST_CODE));
  Assertions.assertEquals(meta.getSecurityFirstRep(), meta.getSecurity(TEST_SYSTEM, TEST_CODE));
  Assertions.assertEquals(coding, meta.getSecurity(TEST_SYSTEM, TEST_CODE));
}
 
Example #17
Source File: ICD11Generator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void processIndexTerm(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent cc, JsonObject child) {
  String s = readString(child, "label");
  if (s != null) {
    if (!s.equals(cc.getDisplay())) {
      cc.addDesignation().setValue(s).setUse(new Coding().setSystem("http://id.who.int/icd11/mms/designation").setCode("term"));        
    }
  }    
}
 
Example #18
Source File: FhirEncodersTest.java    From bunsen with Apache License 2.0 5 votes vote down vote up
@Test
public void coding() {

  Coding expectedCoding = condition.getSeverity().getCodingFirstRep();
  Coding actualCoding = decodedCondition.getSeverity().getCodingFirstRep();

  // Codings are a nested array, so we explode them into a table of the coding
  // fields so we can easily select and compare individual fields.
  Dataset<Row> severityCodings = conditionsDataset
      .select(functions.explode(conditionsDataset.col("severity.coding"))
          .alias("coding"))
      .select("coding.*") // Pull all fields in the coding to the top level.
      .cache();

  Assert.assertEquals(expectedCoding.getCode(),
      severityCodings.select("code").head().get(0));
  Assert.assertEquals(expectedCoding.getCode(),
      actualCoding.getCode());

  Assert.assertEquals(expectedCoding.getSystem(),
      severityCodings.select("system").head().get(0));
  Assert.assertEquals(expectedCoding.getSystem(),
      actualCoding.getSystem());

  Assert.assertEquals(expectedCoding.getUserSelected(),
      severityCodings.select("userSelected").head().get(0));
  Assert.assertEquals(expectedCoding.getUserSelected(),
      actualCoding.getUserSelected());

  Assert.assertEquals(expectedCoding.getDisplay(),
      severityCodings.select("display").head().get(0));
  Assert.assertEquals(expectedCoding.getDisplay(),
      actualCoding.getDisplay());
}
 
Example #19
Source File: Helper.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
public static OperationOutcome createErrorOutcome(String display) {
    Coding code = new Coding().setDisplay(display);
    return new OperationOutcome().addIssue(
            new OperationOutcome.OperationOutcomeIssueComponent()
                    .setSeverity(OperationOutcome.IssueSeverity.ERROR)
                    .setCode(OperationOutcome.IssueType.PROCESSING)
                    .setDetails(new CodeableConcept().addCoding(code))
    );
}
 
Example #20
Source File: ServiceRequestBuilder.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
public ServiceRequestBuilder buildCode(Coding coding) {
    complexProperty.setCode(
            new CodeableConceptBuilder()
                    .buildCoding(coding)
                    .build()
    );
    return  this;
}
 
Example #21
Source File: CodeableConceptBuilder.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
public CodeableConceptBuilder buildCoding(Coding coding) {
    if (!complexProperty.hasCoding()) {
        complexProperty.setCoding(new ArrayList<>());
    }

    complexProperty.addCoding(coding);
    return this;
}
 
Example #22
Source File: ConceptMapEngine.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private Coding translateBySystem(ConceptMap cm, String system, String code) {
  throw new Error("Not done yet");
}
 
Example #23
Source File: RdfParserBase.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
protected void decorateCodeableConcept(Complex t, CodeableConcept element) {
	for (Coding c : element.getCoding())
		decorateCoding(t, c);
}
 
Example #24
Source File: StructureMapUtilities.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
private Coding buildCoding(Type value1, Type value2) {
  return new Coding().setSystem(((PrimitiveType) value1).asStringValue()).setCode(((PrimitiveType) value2).asStringValue()) ;
}
 
Example #25
Source File: CodingUtilities.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public static boolean matches(Coding coding, String system, String code) {
  if (coding == null)
    return false;
  return code.equals(coding.getCode()) && system.equals(coding.getSystem());
}
 
Example #26
Source File: CodingUtilities.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public static String present(Coding coding) {
  if (coding == null)
    return "";
  return coding.getSystem()+"::"+coding.getCode();
}
 
Example #27
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private static String renderCoding(List<Coding> codes) {
  CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
  for (Coding c : codes)
    b.append(renderCoding(c));
  return b.toString();
}
 
Example #28
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private static String renderCoding(Coding code) {
  if (code == null || code.isEmpty())
    return "";
  else
    return "<span title=\""+Utilities.escapeXml(code.getSystem())+"\">"+Utilities.escapeXml(code.getCode())+"</span>";
}
 
Example #29
Source File: TerminologyCache.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public String summary(Coding code) {
  return code.getSystem()+"#"+code.getCode()+": \""+code.getDisplay()+"\"";
}
 
Example #30
Source File: ICD11Generator.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void addDesignation(String v, org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent cc, String system, String code) {
  if (v != null) {
    cc.addDesignation().setValue(v.replace("\r", "").replace("\n", "")).setUse(new Coding().setSystem(system).setCode(code));
  }
}