org.hl7.fhir.r4.model.Reference Java Examples
The following examples show how to use
org.hl7.fhir.r4.model.Reference.
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: QuestionnaireBuilder.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private boolean instanceOf(TypeRefComponent t, Element obj) { if (t.getWorkingCode().equals("Reference")) { if (!(obj instanceof Reference)) { return false; } else { String url = ((Reference) obj).getReference(); // there are several problems here around profile matching. This process is degenerative, and there's probably nothing we can do to solve it if (url.startsWith("http:") || url.startsWith("https:")) return true; else if (t.hasProfile() && t.getProfile().get(0).getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) return url.startsWith(t.getProfile().get(0).getValue().substring(40)+'/'); else return true; } } else if (t.getWorkingCode().equals("Quantity")) { return obj instanceof Quantity; } else throw new NotImplementedException("Not Done Yet"); }
Example #2
Source File: FhirR4.java From synthea with Apache License 2.0 | 6 votes |
/** * 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: FhirGroupExporterR4.java From synthea with Apache License 2.0 | 6 votes |
/** * Export the patient list as a FHIR Group resource. * @param stop The stop time. * @return FHIR Group resource. */ public static Group export(long stop) { String uuid = UUID.randomUUID().toString(); Group group = new Group(); group.setId(uuid); group.addIdentifier() .setSystem("urn:ietf:rfc:3986") .setValue("urn:uuid:" + uuid); group.setActive(true); group.setType(GroupType.PERSON); group.setActual(true); group.setName("Synthea Patients"); group.setQuantity(patientList.size()); for (String resourceId : patientList) { group.addMember().setEntity(new Reference(FhirR4.getUrlPrefix("Patient") + resourceId)); } return group; }
Example #4
Source File: MeasureOperationsProvider.java From cqf-ruler with Apache License 2.0 | 6 votes |
private void resolveReferences(Resource resource, Parameters parameters, Map<String, Resource> resourceMap) { List<IBase> values; for (BaseRuntimeChildDefinition child : this.measureResourceProvider.getContext().getResourceDefinition(resource).getChildren()) { values = child.getAccessor().getValues(resource); if (values == null || values.isEmpty()) { continue; } else if (values.get(0) instanceof Reference && ((Reference) values.get(0)).getReferenceElement().hasResourceType() && ((Reference) values.get(0)).getReferenceElement().hasIdPart()) { Resource fetchedResource = (Resource) registry .getResourceDao(((Reference) values.get(0)).getReferenceElement().getResourceType()) .read(new IdType(((Reference) values.get(0)).getReferenceElement().getIdPart())); if (!resourceMap.containsKey(fetchedResource.getIdElement().getValue())) { parameters.addParameter(new Parameters.ParametersParameterComponent().setName("resource") .setResource(fetchedResource)); resourceMap.put(fetchedResource.getIdElement().getValue(), fetchedResource); } } } }
Example #5
Source File: ResourceUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 #6
Source File: ObjectConverter.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public static Reference readAsReference(Element item) { Reference r = new Reference(); r.setDisplay(item.getNamedChildValue("display")); r.setReference(item.getNamedChildValue("reference")); r.setType(item.getNamedChildValue("type")); List<Element> identifier = item.getChildrenByName("identifier"); if (identifier.isEmpty() == false) { r.setIdentifier(readAsIdentifier(identifier.get(0))); } return r; }
Example #7
Source File: ObservationDefinitionEntityToFHIRObservationDefinitionTransformer.java From careconnect-reference-implementation with Apache License 2.0 | 5 votes |
public ObservationDefinition transform(final ObservationDefinitionEntity observationDefinitionEntity, FhirContext ctx) { final ObservationDefinition observationDefinition = (ObservationDefinition) ctx.newJsonParser().parseResource(observationDefinitionEntity.getResource()); observationDefinition.setId(observationDefinitionEntity.getId().toString()); if (observationDefinitionEntity.getAbnormalValueSet() != null) { observationDefinition.setAbnormalCodedValueSet( new Reference().setReference(observationDefinitionEntity.getAbnormalValueSet().getUrl()) .setDisplay(observationDefinitionEntity.getAbnormalValueSet().getName()) ); } if (observationDefinitionEntity.getNormalValueSet() != null) { observationDefinition.setNormalCodedValueSet( new Reference().setReference(observationDefinitionEntity.getNormalValueSet().getUrl()) .setDisplay(observationDefinitionEntity.getNormalValueSet().getName()) ); } if (observationDefinitionEntity.getValidValueSet() != null) { observationDefinition.setValidCodedValueSet( new Reference().setReference(observationDefinitionEntity.getValidValueSet().getUrl()) .setDisplay(observationDefinitionEntity.getValidValueSet().getName()) ); } if (observationDefinitionEntity.getCriticalValueSet() != null) { observationDefinition.setCriticalCodedValueSet( new Reference().setReference(observationDefinitionEntity.getCriticalValueSet().getUrl()) .setDisplay(observationDefinitionEntity.getCriticalValueSet().getName()) ); } return observationDefinition; }
Example #8
Source File: PlanDefinitionApplyProvider.java From cqf-ruler with Apache License 2.0 | 5 votes |
@Operation(name = "$apply", idempotent = true, type = PlanDefinition.class) public CarePlan applyPlanDefinition( @IdParam IdType theId, @RequiredParam(name="patient") String patientId, @OptionalParam(name="encounter") String encounterId, @OptionalParam(name="practitioner") String practitionerId, @OptionalParam(name="organization") String organizationId, @OptionalParam(name="userType") String userType, @OptionalParam(name="userLanguage") String userLanguage, @OptionalParam(name="userTaskContext") String userTaskContext, @OptionalParam(name="setting") String setting, @OptionalParam(name="settingContext") String settingContext) throws IOException, JAXBException, FHIRException { PlanDefinition planDefinition = this.planDefintionDao.read(theId); if (planDefinition == null) { throw new IllegalArgumentException("Couldn't find PlanDefinition " + theId); } logger.info("Performing $apply operation on PlanDefinition/" + theId); CarePlanBuilder builder = new CarePlanBuilder(); builder .buildInstantiatesCanonical(planDefinition.getIdElement().getIdPart()) .buildSubject(new Reference(patientId)) .buildStatus(CarePlan.CarePlanStatus.DRAFT); if (encounterId != null) builder.buildEncounter(new Reference(encounterId)); if (practitionerId != null) builder.buildAuthor(new Reference(practitionerId)); if (organizationId != null) builder.buildAuthor(new Reference(organizationId)); if (userLanguage != null) builder.buildLanguage(userLanguage); Session session = new Session(planDefinition, builder, patientId, encounterId, practitionerId, organizationId, userType, userLanguage, userTaskContext, setting, settingContext); return resolveActions(session); }
Example #9
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 #10
Source File: ReferenceBuilder.java From cqf-ruler with Apache License 2.0 | 4 votes |
public ReferenceBuilder() { super(new Reference()); }
Example #11
Source File: IdentifierBuilder.java From cqf-ruler with Apache License 2.0 | 4 votes |
public IdentifierBuilder buildAssigner(Reference assigner) { complexProperty.setAssigner(assigner); return this; }
Example #12
Source File: ServiceRequestBuilder.java From cqf-ruler with Apache License 2.0 | 4 votes |
public ServiceRequestBuilder buildRequester(String requester) { complexProperty.setRequester(new Reference(requester)); return this; }
Example #13
Source File: MeasureReportBuilder.java From cqf-ruler with Apache License 2.0 | 4 votes |
public MeasureReportBuilder buildPatientReference(String patientRef) { this.complexProperty.setSubject(new Reference(patientRef)); return this; }
Example #14
Source File: PlanDefinitionApplyProvider.java From cqf-ruler with Apache License 2.0 | 4 votes |
private void resolveDefinition(Session session, PlanDefinition.PlanDefinitionActionComponent action) { if (action.hasDefinition()) { logger.debug("Resolving definition "+ action.getDefinitionCanonicalType().getValue()); String definition = action.getDefinitionCanonicalType().getValue(); if (definition.startsWith(session.getPlanDefinition().fhirType())) { logger.error("Currently cannot resolve nested PlanDefinitions"); throw new NotImplementedException("Plan Definition refers to sub Plan Definition, this is not yet supported"); } else { Resource result; try { if (action.getDefinitionCanonicalType().getValue().startsWith("#")) { result = this.activityDefinitionApplyProvider.resolveActivityDefinition( (ActivityDefinition) resolveContained(session.getPlanDefinition(), action.getDefinitionCanonicalType().getValue()), session.getPatientId(), session.getPractionerId(), session.getOrganizationId() ); } else { result = this.activityDefinitionApplyProvider.apply( new IdType(CanonicalHelper.getId(action.getDefinitionCanonicalType())), session.getPatientId(), session.getEncounterId(), session.getPractionerId(), session.getOrganizationId(), null, session.getUserLanguage(), session.getUserTaskContext(), session.getSetting(), session.getSettingContext() ); } if (result.getId() == null) { logger.warn("ActivityDefinition %s returned resource with no id, setting one", action.getDefinitionCanonicalType().getId()); result.setId( UUID.randomUUID().toString() ); } session.getCarePlanBuilder() .buildContained(result) .buildActivity( new CarePlanActivityBuilder() .buildReference( new Reference("#"+result.getId()) ) .build() ); } catch (Exception e) { logger.error("ERROR: ActivityDefinition %s could not be applied and threw exception %s", action.getDefinition(), e.toString()); } } } }
Example #15
Source File: FhirR4.java From synthea with Apache License 2.0 | 4 votes |
/** * 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 #16
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 #17
Source File: FhirR4.java From synthea with Apache License 2.0 | 4 votes |
/** * 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 #18
Source File: TestData.java From bunsen with Apache License 2.0 | 4 votes |
/** * 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 #19
Source File: TestData.java From bunsen with Apache License 2.0 | 3 votes |
/** * 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; }