Search in sources :

Example 81 with Reference

use of org.hl7.fhir.dstu2.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 82 with Reference

use of org.hl7.fhir.dstu2.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 83 with Reference

use of org.hl7.fhir.dstu2.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 84 with Reference

use of org.hl7.fhir.dstu2.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 85 with Reference

use of org.hl7.fhir.dstu2.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)363 Test (org.junit.Test)305 ArrayList (java.util.ArrayList)210 Reference (org.hl7.fhir.dstu3.model.Reference)156 Reference (io.adminshell.aas.v3.model.Reference)118 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)91 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)85 Resource (org.hl7.fhir.r4.model.Resource)85 Test (org.junit.jupiter.api.Test)85 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)84 List (java.util.List)84 Bundle (org.hl7.fhir.r4.model.Bundle)82 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)80 Coding (org.hl7.fhir.r4.model.Coding)76 Observation (org.hl7.fhir.r4.model.Observation)69 FHIRException (org.hl7.fhir.exceptions.FHIRException)67 Date (java.util.Date)62 Identifier (org.hl7.fhir.r4.model.Identifier)58 Collectors (java.util.stream.Collectors)53 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)49