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: FhirR4.java From synthea with Apache License 2.0 | 6 votes |
/** * 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: TerminologyCache.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
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 #3
Source File: IPatientPatientAttributeMapper.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
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: TerminologyCache.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
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 #5
Source File: FHIRToolingClient.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
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 #6
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
@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 #7
Source File: ServiceRequestBuilder.java From cqf-ruler with Apache License 2.0 | 5 votes |
public ServiceRequestBuilder buildCode(Coding coding) { complexProperty.setCode( new CodeableConceptBuilder() .buildCoding(coding) .build() ); return this; }
Example #8
Source File: FhirEncodersTest.java From bunsen with Apache License 2.0 | 5 votes |
@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 #9
Source File: ICD11Generator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 #10
Source File: MetaTest.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
@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 #11
Source File: Helper.java From cqf-ruler with Apache License 2.0 | 5 votes |
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 #12
Source File: TerminologyCache.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 #13
Source File: ToolingExtensions.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 #14
Source File: CodeableConceptBuilder.java From cqf-ruler with Apache License 2.0 | 5 votes |
public CodeableConceptBuilder buildCoding(Coding coding) { if (!complexProperty.hasCoding()) { complexProperty.setCoding(new ArrayList<>()); } complexProperty.addCoding(coding); return this; }
Example #15
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 #16
Source File: ProfileComparer.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 #17
Source File: RdfParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 #18
Source File: ObjectConverter.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 #19
Source File: ConceptMapEngine.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 #20
Source File: ConceptMapEngine.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 #21
Source File: LoincToDEConvertor.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 #22
Source File: CodeableConceptBuilder.java From cqf-ruler with Apache License 2.0 | 4 votes |
public CodeableConceptBuilder buildCoding(List<Coding> coding) { complexProperty.setCoding(coding); return this; }
Example #23
Source File: FhirChCrlDocumentBundle.java From elexis-3-core with Eclipse Public License 1.0 | 4 votes |
@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 #24
Source File: CodingBuilder.java From cqf-ruler with Apache License 2.0 | 4 votes |
public CodingBuilder() { super(new Coding()); }
Example #25
Source File: ActivityDefinitionBuilder.java From cqf-ruler with Apache License 2.0 | 4 votes |
public ActivityDefinitionBuilder buildBodySite(Coding coding) { complexProperty.getBodySite().add(new CodeableConceptBuilder().buildCoding(coding).build()); return this; }
Example #26
Source File: ActivityDefinitionBuilder.java From cqf-ruler with Apache License 2.0 | 4 votes |
public ActivityDefinitionBuilder buildCode(Coding coding) { complexProperty.getCode().addCoding(coding); return this; }
Example #27
Source File: IPatientPatientAttributeMapper.java From elexis-3-core with Eclipse Public License 1.0 | 4 votes |
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 #28
Source File: FhirR4.java From synthea with Apache License 2.0 | 4 votes |
/** * Add a MedicationAdministration if needed for the given medication. * * @param personEntry The Entry for the Person * @param bundle Bundle to add the MedicationAdministration to * @param encounterEntry Current Encounter entry * @param medication The Medication * @param medicationRequest The related medicationRequest * @return The added Entry */ private static BundleEntryComponent medicationAdministration( BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Medication medication, MedicationRequest medicationRequest) { MedicationAdministration medicationResource = new MedicationAdministration(); medicationResource.setSubject(new Reference(personEntry.getFullUrl())); medicationResource.setContext(new Reference(encounterEntry.getFullUrl())); Code code = medication.codes.get(0); String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI; medicationResource.setMedication(mapCodeToCodeableConcept(code, system)); medicationResource.setEffective(new DateTimeType(new Date(medication.start))); medicationResource.setStatus("completed"); if (medication.prescriptionDetails != null) { JsonObject rxInfo = medication.prescriptionDetails; MedicationAdministrationDosageComponent dosage = new MedicationAdministrationDosageComponent(); // as_needed is false if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) { Quantity dose = new SimpleQuantity() .setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble()); dosage.setDose((SimpleQuantity) dose); if (rxInfo.has("instructions")) { for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) { JsonObject instruction = instructionElement.getAsJsonObject(); dosage.setText(instruction.get("display").getAsString()); } } } if (rxInfo.has("refills")) { SimpleQuantity rate = new SimpleQuantity(); rate.setValue(rxInfo.get("refills").getAsLong()); dosage.setRate(rate); } medicationResource.setDosage(dosage); } if (!medication.reasons.isEmpty()) { // Only one element in list Code reason = medication.reasons.get(0); for (BundleEntryComponent entry : bundle.getEntry()) { if (entry.getResource().fhirType().equals("Condition")) { Condition condition = (Condition) entry.getResource(); // Only one element in list Coding coding = condition.getCode().getCoding().get(0); if (reason.code.equals(coding.getCode())) { medicationResource.addReasonReference().setReference(entry.getFullUrl()); } } } } BundleEntryComponent medicationAdminEntry = newEntry(bundle, medicationResource); return medicationAdminEntry; }
Example #29
Source File: PhenoPacketTestUtil.java From phenopacket-schema with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static CodeableConcept codeableConcept(String system, String id, String label){ return new CodeableConcept().addCoding(new Coding(system, id, label)); }
Example #30
Source File: ICD11Generator.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
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)); } }