Search in sources :

Example 96 with Reference

use of org.hl7.fhir.r4.model.Reference in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7MessageModel method convert.

@Override
public Bundle convert(Message message, MessageEngine engine) {
    Preconditions.checkArgument(message != null, "Input Hl7 message cannot be null");
    Preconditions.checkArgument(engine != null, "MessageEngine cannot be null");
    HL7DataExtractor hl7DTE = new HL7DataExtractor(message);
    HL7MessageData dataSource = new HL7MessageData(hl7DTE);
    Bundle bundle = null;
    // NOTE: We have seen PHI in these exception messages.
    try {
        bundle = engine.transform(dataSource, this.getResources(), new HashMap<>());
        // Bundle is passed by reference and may be modified
        deduplicate(bundle);
        engine.getFHIRContext().validate(bundle);
    } catch (Exception e) {
        // Print stack class and trace without the error message.
        handleException(e);
    }
    return bundle;
}
Also used : HL7DataExtractor(io.github.linuxforhealth.hl7.parsing.HL7DataExtractor) HashMap(java.util.HashMap) Bundle(org.hl7.fhir.r4.model.Bundle) IOException(java.io.IOException) HL7Exception(ca.uhn.hl7v2.HL7Exception)

Example 97 with Reference

use of org.hl7.fhir.r4.model.Reference in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7MessageModel method deduplicate.

// General deduplication utility. Currently only Organizations.
// Bundle is passed by reference and may be modified
private void deduplicate(Bundle bundle) {
    List<BundleEntryComponent> entries = bundle.getEntry();
    Iterator<BundleEntryComponent> i = entries.iterator();
    while (i.hasNext()) {
        // Safe traversal for removal
        BundleEntryComponent entry = i.next();
        // Currently only looking for duplicate Organizations, because their Urls and Id's are created from org data.
        if (entry.getFullUrl().startsWith("Organization/") && duplicateFound(entry, entries)) {
            // Safe removal
            i.remove();
        }
    }
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)

Example 98 with Reference

use of org.hl7.fhir.r4.model.Reference in project BridgeServer2 by Sage-Bionetworks.

the class CRCController method createPatient.

Patient createPatient(Account account) {
    Patient patient = new Patient();
    patient.setActive(true);
    patient.setId(account.getId());
    Identifier identifier = new Identifier();
    identifier.setValue(account.getId());
    identifier.setSystem(USER_ID_VALUE_NS);
    patient.addIdentifier(identifier);
    Coding coding = new Coding();
    coding.setSystem("source");
    coding.setCode("sage");
    Meta meta = new Meta();
    meta.setTag(ImmutableList.of(coding));
    patient.setMeta(meta);
    HumanName name = new HumanName();
    if (isNotBlank(account.getFirstName())) {
        name.addGiven(account.getFirstName());
    }
    if (isNotBlank(account.getLastName())) {
        name.setFamily(account.getLastName());
    }
    patient.addName(name);
    Map<String, String> atts = account.getAttributes();
    if (isNotBlank(atts.get("gender"))) {
        if ("female".equalsIgnoreCase(atts.get("gender"))) {
            patient.setGender(AdministrativeGender.FEMALE);
        } else if ("male".equalsIgnoreCase(atts.get("gender"))) {
            patient.setGender(AdministrativeGender.MALE);
        } else {
            patient.setGender(AdministrativeGender.OTHER);
        }
    } else {
        patient.setGender(AdministrativeGender.UNKNOWN);
    }
    if (isNotBlank(atts.get("dob"))) {
        LocalDate localDate = LocalDate.parse(atts.get("dob"));
        patient.setBirthDate(localDate.toDate());
    }
    Address address = new Address();
    if (isNotBlank(atts.get("address1"))) {
        address.addLine(atts.get("address1"));
    }
    if (isNotBlank(atts.get("address2"))) {
        address.addLine(atts.get("address2"));
    }
    if (isNotBlank(atts.get("city"))) {
        address.setCity(atts.get("city"));
    }
    if (isNotBlank(atts.get("state"))) {
        address.setState(atts.get("state"));
    } else {
        address.setState("NY");
    }
    if (isNotBlank(atts.get("zip_code"))) {
        address.setPostalCode(atts.get("zip_code"));
    }
    patient.addAddress(address);
    if (isNotBlank(atts.get("home_phone"))) {
        ContactPoint contact = new ContactPoint();
        contact.setSystem(ContactPointSystem.PHONE);
        contact.setValue(atts.get("home_phone"));
        patient.addTelecom(contact);
    }
    if (account.getPhone() != null && TRUE.equals(account.getPhoneVerified())) {
        ContactPoint contact = new ContactPoint();
        contact.setSystem(ContactPointSystem.SMS);
        contact.setValue(account.getPhone().getNumber());
        patient.addTelecom(contact);
    }
    if (account.getEmail() != null && TRUE.equals(account.getEmailVerified())) {
        ContactPoint contact = new ContactPoint();
        contact.setSystem(ContactPointSystem.EMAIL);
        contact.setValue(account.getEmail());
        patient.addTelecom(contact);
    }
    Reference ref = new Reference("CUZUCK");
    ref.setDisplay("COVID Recovery Corps");
    ContactComponent contact = new ContactComponent();
    contact.setOrganization(ref);
    patient.addContact(contact);
    return patient;
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) HumanName(org.hl7.fhir.dstu3.model.HumanName) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) Identifier(org.hl7.fhir.dstu3.model.Identifier) Address(org.hl7.fhir.dstu3.model.Address) Coding(org.hl7.fhir.dstu3.model.Coding) Reference(org.hl7.fhir.dstu3.model.Reference) ContactComponent(org.hl7.fhir.dstu3.model.Patient.ContactComponent) Patient(org.hl7.fhir.dstu3.model.Patient) LocalDate(org.joda.time.LocalDate)

Example 99 with Reference

use of org.hl7.fhir.r4.model.Reference in project BridgeServer2 by Sage-Bionetworks.

the class CRCController method addLocation.

/**
 * This is a nice-to-have addition of address information for the location given by an
 * ID in the appointment record. Do not fail the request if this fails, but log enough
 * to troubleshoot if the issue is on our side.
 */
void addLocation(JsonNode node, Account account, String locationId) {
    String cuimcEnv = (account.getDataGroups().contains(TEST_USER_GROUP)) ? "test" : "prod";
    String cuimcUrl = "cuimc." + cuimcEnv + ".location.url";
    String url = bridgeConfig.get(cuimcUrl);
    String reqBody = "id=\"" + locationId + "\"";
    try {
        HttpResponse response = post(url, account, reqBody);
        String resBody = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8.name());
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200 && statusCode != 201) {
            logWarningMessage(locationId, statusCode, resBody);
            return;
        }
        JsonNode bundleJson = BridgeObjectMapper.get().readTree(resBody);
        if (!bundleJson.has("entry") || ((ArrayNode) bundleJson.get("entry")).size() == 0) {
            logWarningMessage(locationId, statusCode, resBody);
            return;
        }
        JsonNode resJson = bundleJson.get("entry").get(0).get("resource");
        if (resJson == null) {
            logWarningMessage(locationId, statusCode, resBody);
            return;
        }
        JsonNode telecom = resJson.get("telecom");
        JsonNode address = resJson.get("address");
        ArrayNode participants = (ArrayNode) node.get("participant");
        if (participants != null) {
            for (int i = 0; i < participants.size(); i++) {
                JsonNode child = participants.get(i);
                ObjectNode actor = (ObjectNode) child.get("actor");
                if (actor != null && actor.has("reference")) {
                    String ref = actor.get("reference").textValue();
                    if (ref.startsWith("Location")) {
                        if (telecom != null) {
                            actor.set("telecom", telecom);
                        }
                        if (address != null) {
                            actor.set("address", address);
                        // addGeocodingInformation(actor);
                        }
                        break;
                    }
                }
            }
        }
    } catch (IOException e) {
        LOG.warn("Error retrieving location, id = " + locationId, e);
        return;
    }
    LOG.info("Location added to appointment record for user " + account.getId());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HttpResponse(org.apache.http.HttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint)

Example 100 with Reference

use of org.hl7.fhir.r4.model.Reference in project cqf-ruler by DBCG.

the class CompositionSectionComponentBuilder method initializeDstu2_1.

@Override
protected void initializeDstu2_1(T theResource) {
    super.initializeDstu2_1(theResource);
    org.hl7.fhir.dstu2016may.model.Composition.SectionComponent section = (org.hl7.fhir.dstu2016may.model.Composition.SectionComponent) theResource;
    section.setTitle(myTitle).setId(getId());
    getEntries().forEach(entry -> section.addEntry(new Reference(entry)));
    if (myText != null) {
        Narrative narrative = new Narrative();
        narrative.setStatusAsString(myText.getStatus());
        narrative.setDivAsString(myText.getText());
        section.setText(narrative);
    }
// no focus
}
Also used : Narrative(org.hl7.fhir.dstu2016may.model.Narrative) Reference(org.hl7.fhir.dstu2016may.model.Reference)

Aggregations

Reference (org.hl7.fhir.r4.model.Reference)351 Test (org.junit.Test)291 ArrayList (java.util.ArrayList)188 Reference (org.hl7.fhir.dstu3.model.Reference)104 Reference (io.adminshell.aas.v3.model.Reference)102 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)89 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)83 Resource (org.hl7.fhir.r4.model.Resource)83 Bundle (org.hl7.fhir.r4.model.Bundle)81 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)80 Coding (org.hl7.fhir.r4.model.Coding)73 List (java.util.List)72 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)69 Observation (org.hl7.fhir.r4.model.Observation)69 FHIRException (org.hl7.fhir.exceptions.FHIRException)67 Test (org.junit.jupiter.api.Test)66 Date (java.util.Date)60 Identifier (org.hl7.fhir.r4.model.Identifier)53 Encounter (org.hl7.fhir.r4.model.Encounter)48 HashMap (java.util.HashMap)45