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

The following examples show how to use org.hl7.fhir.r4.model.CodeableConcept. 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: 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 #2
Source File: FhirR4.java    From synthea with Apache License 2.0 6 votes vote down vote up
/**
 * Map the JsonObject for a Supply into a FHIR SupplyDelivery and add it to the Bundle.
 *
 * @param personEntry    The Person entry.
 * @param bundle         Bundle to add to.
 * @param supply         The supplied object to add.
 * @param encounter      The encounter during which the supplies were delivered
 * @return The added Entry.
 */
private static BundleEntryComponent supplyDelivery(BundleEntryComponent personEntry,
        Bundle bundle, HealthRecord.Supply supply, Encounter encounter) {
 
  SupplyDelivery supplyResource = new SupplyDelivery();
  supplyResource.setStatus(SupplyDeliveryStatus.COMPLETED);
  supplyResource.setPatient(new Reference(personEntry.getFullUrl()));
  
  CodeableConcept type = new CodeableConcept();
  type.addCoding()
    .setCode("device")
    .setDisplay("Device")
    .setSystem("http://terminology.hl7.org/CodeSystem/supply-item-type");
  supplyResource.setType(type);
  
  SupplyDeliverySuppliedItemComponent suppliedItem = new SupplyDeliverySuppliedItemComponent();
  suppliedItem.setItem(mapCodeToCodeableConcept(supply.codes.get(0), SNOMED_URI));
  suppliedItem.setQuantity(new Quantity(supply.quantity));
  
  supplyResource.setSuppliedItem(suppliedItem);
  
  supplyResource.setOccurrence(convertFhirDateTime(supply.start, true));
  
  return newEntry(bundle, supplyResource);
}
 
Example #3
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 #4
Source File: OperationOutcomeUtilities.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static OperationOutcomeIssueComponent convertToIssue(ValidationMessage message, OperationOutcome op) {
  OperationOutcomeIssueComponent issue = new OperationOutcome.OperationOutcomeIssueComponent();
  issue.setCode(convert(message.getType()));
  
  if (message.getLocation() != null) {
    // message location has a fhirPath in it. We need to populate the expression
    issue.addExpression(message.getLocation());
  }
  // pass through line/col if they're present
  if (message.getLine() != 0)
    issue.addExtension().setUrl(ToolingExtensions.EXT_ISSUE_LINE).setValue(new IntegerType(message.getLine()));
  if (message.getCol() != 0)
    issue.addExtension().setUrl(ToolingExtensions.EXT_ISSUE_COL).setValue(new IntegerType(message.getCol()));
  issue.setSeverity(convert(message.getLevel()));
  CodeableConcept c = new CodeableConcept();
  c.setText(message.getMessage());
  issue.setDetails(c);
  if (message.getSource() != null) {
    issue.getExtension().add(ToolingExtensions.makeIssueSource(message.getSource()));
  }
  return issue;
}
 
Example #5
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 #6
Source File: IPatientPatientAttributeMapper.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void mapMaritalStatus(Patient source, IPatient target) {
	CodeableConcept maritalStatus = source.getMaritalStatus();
	if (maritalStatus != null && !maritalStatus.getCoding().isEmpty()) {
		String code = maritalStatus.getCoding().get(0).getCode();
		target.setMaritalStatus(MaritalStatus.byFhirCodeSafe(code));
	}
}
 
Example #7
Source File: LibraryBuilder.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
public LibraryBuilder buildType(LibraryType libraryType) {
    CodeableConcept codeableConcept =
            new CodeableConceptBuilder().buildCoding(
                new CodingBuilder()
                        .buildCode(libraryType.getSystem(), libraryType.toCode(), libraryType.getDisplay())
                        .build()
            ).build();
    complexProperty.setType(codeableConcept);

    return this;
}
 
Example #8
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 #9
Source File: OperationOutcomeBuilder.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
public OperationOutcomeBuilder buildIssue(String severity, String code, String details)
{
    complexProperty.addIssue(
            new OperationOutcome.OperationOutcomeIssueComponent()
                    .setSeverity(OperationOutcome.IssueSeverity.fromCode(severity))
                    .setCode(OperationOutcome.IssueType.fromCode(code))
                    .setDetails(new CodeableConcept().setText(details))
    );

    return this;
}
 
Example #10
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 #11
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static String renderCodeable(CodeableConcept units) {
  if (units == null || units.isEmpty())
    return "";
  String v = renderCoding(units.getCoding());
  if (units.hasText())
    v = v + " " +Utilities.escapeXml(units.getText());
  return v;
}
 
Example #12
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static String renderDEUnits(Type units) {
  if (units == null || units.isEmpty())
    return "";
  if (units instanceof CodeableConcept)
    return renderCodeable((CodeableConcept) units);
  else
    return "<a href=\""+Utilities.escapeXml(((Reference) units).getReference())+"\">"+Utilities.escapeXml(((Reference) units).getReference())+"</a>";
    
}
 
Example #13
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void setAllowableUnits(ElementDefinition eld, CodeableConcept cc) {
  for (Extension e : eld.getExtension()) 
    if (e.getUrl().equals(EXT_ALLOWABLE_UNITS)) {
      e.setValue(cc);
      return;
    }
  eld.getExtension().add(new Extension().setUrl(EXT_ALLOWABLE_UNITS).setValue(cc));
}
 
Example #14
Source File: StructureMapUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private Type generateFixedValue(StructureMapGroupRuleTargetComponent tgt) {
  if (!allParametersFixed(tgt))
    return null;
  if (!tgt.hasTransform())
    return null;
  switch (tgt.getTransform()) {
  case COPY: return tgt.getParameter().get(0).getValue(); 
  case TRUNCATE: return null; 
  //case ESCAPE: 
  //case CAST: 
  //case APPEND: 
  case TRANSLATE: return null; 
//case DATEOP, 
//case UUID, 
//case POINTER, 
//case EVALUATE, 
  case CC: 
    CodeableConcept cc = new CodeableConcept();
    cc.addCoding(buildCoding(tgt.getParameter().get(0).getValue(), tgt.getParameter().get(1).getValue()));
    return cc;
  case C: 
    return buildCoding(tgt.getParameter().get(0).getValue(), tgt.getParameter().get(1).getValue());
  case QTY: return null; 
//case ID, 
//case CP, 
  default:
    return null;
  }
}
 
Example #15
Source File: ObjectConverter.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static CodeableConcept readAsCodeableConcept(Element element) {
  CodeableConcept cc = new CodeableConcept();
  List<Element> list = new ArrayList<Element>();
  element.getNamedChildren("coding", list);
  for (Element item : list)
    cc.addCoding(readAsCoding(item));
  cc.setText(element.getNamedChildValue("text"));
  return cc;
}
 
Example #16
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 #17
Source File: FhirChCrlDocumentBundle.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void createBundle(){
	try {
		Date now = new Date();
		
		this.bundle = new Bundle();
		bundle.setId("BundleFromPractitioner");
		bundle.setMeta(new Meta().setLastUpdated(now).setProfile(Collections.singletonList(
			new CanonicalType("http://fhir.ch/ig/ch-crl/StructureDefinition/ch-crl-bundle"))));
		bundle.setType(BundleType.DOCUMENT);
		
		BundleEntryComponent compositionEntry = bundle.addEntry();
		Composition composition = new Composition();
		compositionEntry.setResource(composition);
		composition.setId("CompFromPractitioner");
		composition.setMeta(new Meta().setLastUpdated(now)
			.setProfile(Collections.singletonList(new CanonicalType(
				"http://fhir.ch/ig/ch-crl/StructureDefinition/ch-crl-composition"))));
		composition.setStatus(CompositionStatus.FINAL);
		composition.setType(new CodeableConcept(
			new Coding("http://loinc.org", "72134-0", "Cancer event report")));
		composition.setDate(now);
		composition.setTitle("Report to the Cancer Registry");
		
		BundleEntryComponent subjectEntry = bundle.addEntry();
		IFhirTransformer<Patient, IPatient> patientTransformer =
			(IFhirTransformer<Patient, IPatient>) FhirTransformersHolder
				.getTransformerFor(Patient.class, IPatient.class);
		Patient subject = patientTransformer.getFhirObject(patient)
			.orElseThrow(() -> new IllegalStateException("Could not create subject"));
		subject.getExtension().clear();
		fixAhvIdentifier(subject);
		
		subjectEntry.setResource(subject);
		
		BundleEntryComponent practitionerEntry = bundle.addEntry();
		IFhirTransformer<Practitioner, IMandator> practitionerTransformer =
			(IFhirTransformer<Practitioner, IMandator>) FhirTransformersHolder
				.getTransformerFor(Practitioner.class, IMandator.class);
		Practitioner practitioner = practitionerTransformer.getFhirObject(author)
			.orElseThrow(() -> new IllegalStateException("Could not create autor"));
		practitioner.getExtension().clear();
		practitioner.getIdentifier().clear();
		practitionerEntry.setResource(practitioner);
		
		BundleEntryComponent documentReferenceEntry = bundle.addEntry();
		DocumentReference documentReference = new DocumentReference();
		documentReferenceEntry.setResource(documentReference);
		documentReference.setId(document.getId());
		DocumentReferenceContentComponent content = documentReference.addContent();
		content.setAttachment(new Attachment().setContentType("application/pdf")
			.setData(IOUtils.toByteArray(document.getContent())));
		
		composition.setSubject(new Reference(subject));
		composition.setAuthor(Collections.singletonList(new Reference(practitioner)));
		SectionComponent section = composition.addSection();
		section.addEntry(new Reference(documentReference));
	} catch (IOException e) {
		LoggerFactory.getLogger(getClass()).error("Error creating FHIR bundle", e);
		throw new IllegalStateException("Error creating FHIR bundle", e);
	}
}
 
Example #18
Source File: IPatientPatientAttributeMapper.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
private void mapMaritalStatus(IPatient source, Patient target) {
	MaritalStatus maritalStatus = source.getMaritalStatus();
	if (maritalStatus != null) {
		target.setMaritalStatus(new CodeableConcept().addCoding(new Coding().setCode(maritalStatus.getFhirCode())));
	}
}
 
Example #19
Source File: CodeableConceptBuilder.java    From cqf-ruler with Apache License 2.0 4 votes vote down vote up
public CodeableConceptBuilder() {
    super(new CodeableConcept());
}
 
Example #20
Source File: IdentifierBuilder.java    From cqf-ruler with Apache License 2.0 4 votes vote down vote up
public IdentifierBuilder buildType(CodeableConcept type) {
    complexProperty.setType(type);
    return this;
}
 
Example #21
Source File: FhirR4.java    From synthea with Apache License 2.0 4 votes vote down vote up
/**
 * Map the given Observation with attachment element to a FHIR Media resource, and add it to the
 * given Bundle.
 *
 * @param personEntry    The Entry for the Person
 * @param bundle         Bundle to add the Media to
 * @param encounterEntry Current Encounter entry
 * @param obs   The Observation to map to FHIR and add to the bundle
 * @return The added Entry
 */
private static BundleEntryComponent media(BundleEntryComponent personEntry, Bundle bundle,
    BundleEntryComponent encounterEntry, Observation obs) {
  org.hl7.fhir.r4.model.Media mediaResource =
      new org.hl7.fhir.r4.model.Media();

  // Hard code as Image since we don't anticipate using video or audio any time soon
  Code mediaType = new Code("http://terminology.hl7.org/CodeSystem/media-type", "image", "Image");

  if (obs.codes != null && obs.codes.size() > 0) {
    List<CodeableConcept> reasonList = obs.codes.stream()
        .map(code -> mapCodeToCodeableConcept(code, SNOMED_URI)).collect(Collectors.toList());
    mediaResource.setReasonCode(reasonList);
  }
  mediaResource.setType(mapCodeToCodeableConcept(mediaType, MEDIA_TYPE_URI));
  mediaResource.setStatus(MediaStatus.COMPLETED);
  mediaResource.setSubject(new Reference(personEntry.getFullUrl()));
  mediaResource.setEncounter(new Reference(encounterEntry.getFullUrl()));

  Attachment content = (Attachment) obs.value;
  org.hl7.fhir.r4.model.Attachment contentResource = new org.hl7.fhir.r4.model.Attachment();
  
  contentResource.setContentType(content.contentType);
  contentResource.setLanguage(content.language);
  if (content.data != null) {
    contentResource.setDataElement(new org.hl7.fhir.r4.model.Base64BinaryType(content.data));
  }
  contentResource.setUrl(content.url);
  contentResource.setSize(content.size);
  contentResource.setTitle(content.title);
  if (content.hash != null) {
    contentResource.setHashElement(new org.hl7.fhir.r4.model.Base64BinaryType(content.hash));
  }
  
  mediaResource.setWidth(content.width);
  mediaResource.setHeight(content.height);

  mediaResource.setContent(contentResource);

  return newEntry(bundle, mediaResource);
}
 
Example #22
Source File: FhirR4.java    From synthea with Apache License 2.0 4 votes vote down vote up
/**
 * Create an entry for the given Claim, which references a Medication.
 *
 * @param person         The person being prescribed medication
 * @param personEntry     Entry for the person
 * @param bundle          The Bundle to add to
 * @param encounterEntry  The current Encounter
 * @param claim           the Claim object
 * @param medicationEntry The Entry for the Medication object, previously created
 * @return the added Entry
 */
private static BundleEntryComponent medicationClaim(
    Person person, BundleEntryComponent personEntry,
    Bundle bundle, BundleEntryComponent encounterEntry, Claim claim,
    BundleEntryComponent medicationEntry) {
  
  org.hl7.fhir.r4.model.Claim claimResource = new org.hl7.fhir.r4.model.Claim();
  org.hl7.fhir.r4.model.Encounter encounterResource =
      (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();

  claimResource.setStatus(ClaimStatus.ACTIVE);
  CodeableConcept type = new CodeableConcept();
  type.getCodingFirstRep()
    .setSystem("http://terminology.hl7.org/CodeSystem/claim-type")
    .setCode("pharmacy");
  claimResource.setType(type);
  claimResource.setUse(org.hl7.fhir.r4.model.Claim.Use.CLAIM);

  // Get the insurance info at the time that the encounter occurred.
  InsuranceComponent insuranceComponent = new InsuranceComponent();
  insuranceComponent.setSequence(1);
  insuranceComponent.setFocal(true);
  insuranceComponent.setCoverage(new Reference().setDisplay(claim.payer.getName()));
  claimResource.addInsurance(insuranceComponent);

  // duration of encounter
  claimResource.setBillablePeriod(encounterResource.getPeriod());
  claimResource.setCreated(encounterResource.getPeriod().getEnd());

  claimResource.setPatient(new Reference(personEntry.getFullUrl()));
  claimResource.setProvider(encounterResource.getServiceProvider());

  // set the required priority
  CodeableConcept priority = new CodeableConcept();
  priority.getCodingFirstRep()
    .setSystem("http://terminology.hl7.org/CodeSystem/processpriority")
    .setCode("normal");
  claimResource.setPriority(priority);

  // add item for encounter
  claimResource.addItem(new ItemComponent(new PositiveIntType(1),
        encounterResource.getTypeFirstRep())
      .addEncounter(new Reference(encounterEntry.getFullUrl())));

  // add prescription.
  claimResource.setPrescription(new Reference(medicationEntry.getFullUrl()));

  Money moneyResource = new Money();
  moneyResource.setValue(claim.getTotalClaimCost());
  moneyResource.setCurrency("USD");
  claimResource.setTotal(moneyResource);

  return newEntry(bundle, claimResource);
}
 
Example #23
Source File: TestData.java    From bunsen with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a FHIR Condition for testing purposes.
 */
public static Condition newCondition() {

  Condition condition = new Condition();

  // Condition based on example from FHIR:
  // https://www.hl7.org/fhir/condition-example.json.html
  condition.setId("Condition/example");

  condition.setLanguage("en_US");

  // Narrative text
  Narrative narrative = new Narrative();
  narrative.setStatusAsString("generated");
  narrative.setDivAsString("This data was generated for test purposes.");
  XhtmlNode node = new XhtmlNode();
  node.setNodeType(NodeType.Text);
  node.setValue("Severe burn of left ear (Date: 24-May 2012)");
  condition.setText(narrative);

  condition.setSubject(new Reference("Patient/example").setDisplay("Here is a display for you."));

  condition.setVerificationStatus(Condition.ConditionVerificationStatus.CONFIRMED);

  // Condition code
  CodeableConcept code = new CodeableConcept();
  code.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("39065001")
      .setDisplay("Severe");
  condition.setSeverity(code);

  // Severity code
  CodeableConcept severity = new CodeableConcept();
  severity.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("24484000")
      .setDisplay("Burn of ear")
      .setUserSelected(true);
  condition.setSeverity(severity);

  // Onset date time
  DateTimeType onset = new DateTimeType();
  onset.setValueAsString("2012-05-24");
  condition.setOnset(onset);

  return condition;
}
 
Example #24
Source File: PhenoPacketTestUtil.java    From phenopacket-schema with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static CodeableConcept codeableConcept(String system, String id, String label){
    return new CodeableConcept().addCoding(new Coding(system, id, label));
}
 
Example #25
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 #26
Source File: TestData.java    From bunsen with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a FHIR medication request for testing purposes.
 */
public static MedicationRequest newMedRequest() {

  MedicationRequest medReq = new MedicationRequest();

  medReq.setId("test-med");

  // Medication code
  CodeableConcept med = new CodeableConcept();
  med.addCoding()
      .setSystem("http://www.nlm.nih.gov/research/umls/rxnorm")
      .setCode("582620")
      .setDisplay("Nizatidine 15 MG/ML Oral Solution [Axid]");

  med.setText("Nizatidine 15 MG/ML Oral Solution [Axid]");

  medReq.setMedication(med);

  Annotation annotation = new Annotation();

  annotation.setText("Test medication note.");

  annotation.setAuthor(
      new Reference("Provider/example")
          .setDisplay("Example provider."));

  medReq.addNote(annotation);

  return medReq;
}
 
Example #27
Source File: IWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 votes vote down vote up
public ValidationResult validateCode(ValidationOptions options, CodeableConcept code, ValueSet vs);