Search in sources :

Example 61 with ContactPoint

use of org.hl7.fhir.r4b.model.ContactPoint in project eCRNow by drajer-health.

the class CdaFhirUtilities method getEmailXml.

public static String getEmailXml(List<ContactPoint> tels) {
    StringBuilder telString = new StringBuilder(200);
    if (tels != null && !tels.isEmpty()) {
        for (ContactPoint tel : tels) {
            if (tel.getSystem() != null && tel.getSystem() == ContactPoint.ContactPointSystem.EMAIL && !StringUtils.isEmpty(tel.getValue())) {
                logger.debug("Found Email address ");
                String use = "";
                telString.append(CdaGeneratorUtils.getXmlForEmail(CdaGeneratorConstants.TEL_EL_NAME, tel.getValue(), use));
            }
        }
    } else {
        logger.debug("Did not find the Email ");
        telString.append(CdaGeneratorUtils.getXmlForNFText(CdaGeneratorConstants.TEL_EL_NAME, CdaGeneratorConstants.NF_NI));
    }
    return telString.toString();
}
Also used : ContactPoint(org.hl7.fhir.r4.model.ContactPoint)

Example 62 with ContactPoint

use of org.hl7.fhir.r4b.model.ContactPoint in project eCRNow by drajer-health.

the class CdaHeaderGenerator method getPractitionerXml.

public static String getPractitionerXml(Practitioner pr) {
    StringBuilder sb = new StringBuilder(500);
    if (pr != null) {
        Identifier npi = CdaFhirUtilities.getIdentifierForSystem(pr.getIdentifier(), CdaGeneratorConstants.FHIR_NPI_URL);
        if (npi != null) {
            sb.append(CdaGeneratorUtils.getXmlForII(CdaGeneratorConstants.AUTHOR_NPI_AA, npi.getValue()));
        } else {
            sb.append(CdaGeneratorUtils.getXmlForII(CdaGeneratorConstants.AUTHOR_NPI_AA));
        }
        sb.append(CdaFhirUtilities.getAddressXml(pr.getAddress()));
        sb.append(CdaFhirUtilities.getTelecomXml(pr.getTelecom(), false));
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.ASSIGNED_PERSON_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.NAME_EL_NAME));
        List<HumanName> hns = pr.getName();
        sb.append(CdaFhirUtilities.getNameXml(hns));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.NAME_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ASSIGNED_PERSON_EL_NAME));
    } else {
        sb.append(CdaGeneratorUtils.getXmlForII(CdaGeneratorConstants.AUTHOR_NPI_AA));
        List<Address> addrs = null;
        sb.append(CdaFhirUtilities.getAddressXml(addrs));
        List<ContactPoint> cps = null;
        sb.append(CdaFhirUtilities.getTelecomXml(cps, false));
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.ASSIGNED_PERSON_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.NAME_EL_NAME));
        List<HumanName> hns = null;
        sb.append(CdaFhirUtilities.getNameXml(hns));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.NAME_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ASSIGNED_PERSON_EL_NAME));
    }
    return sb.toString();
}
Also used : HumanName(org.hl7.fhir.r4.model.HumanName) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Identifier(org.hl7.fhir.r4.model.Identifier) Address(org.hl7.fhir.r4.model.Address)

Example 63 with ContactPoint

use of org.hl7.fhir.r4b.model.ContactPoint in project eCRNow by drajer-health.

the class CdaFhirUtilitiesTest method testGetTelecomXml.

@Test
public void testGetTelecomXml() {
    List<ContactPoint> cps = new ArrayList<ContactPoint>();
    ContactPoint cp1 = new ContactPoint();
    cp1.setUse(ContactPointUse.HOME);
    cp1.setSystem(ContactPointSystem.PHONE);
    cp1.setValue("1234567890");
    cps.add(cp1);
    ContactPoint cp2 = new ContactPoint();
    cp2.setUse(ContactPointUse.MOBILE);
    cp2.setSystem(ContactPointSystem.PHONE);
    cp2.setValue("0987654321");
    cps.add(cp2);
    ContactPoint cp3 = new ContactPoint();
    cp3.setUse(ContactPointUse.WORK);
    cp3.setSystem(ContactPointSystem.EMAIL);
    cp3.setValue("a@b.com");
    cps.add(cp3);
    String result = CdaFhirUtilities.getTelecomXml(cps, false);
    assertTrue(result.contains("(123)456-7890"));
    assertTrue(result.contains("(098)765-4321"));
    assertFalse(result.contains("a@b.com"));
    String result2 = CdaFhirUtilities.getTelecomXml(cps, true);
    assertTrue(result2.contains("(123)456-7890"));
    assertFalse(result2.contains("(098)765-4321"));
    assertFalse(result2.contains("a@b.com"));
}
Also used : ContactPoint(org.hl7.fhir.r4.model.ContactPoint) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 64 with ContactPoint

use of org.hl7.fhir.r4b.model.ContactPoint in project gpconnect-demonstrator by nhsconnect.

the class AppointmentResourceProvider method appointmentResourceConverterToAppointmentDetail.

/**
 * fhir resource Appointment to AppointmentDetail
 *
 * @param appointment Resource
 * @return populated AppointmentDetail
 */
private AppointmentDetail appointmentResourceConverterToAppointmentDetail(Appointment appointment) {
    appointmentValidation.validateAppointmentExtensions(appointment.getExtension());
    if (appointmentValidation.appointmentDescriptionTooLong(appointment)) {
        throwUnprocessableEntity422_InvalidResourceException("Appointment description cannot be greater then " + APPOINTMENT_DESCRIPTION_LENGTH + " characters");
    }
    AppointmentDetail appointmentDetail = new AppointmentDetail();
    Long id = appointment.getIdElement().getIdPartAsLong();
    appointmentDetail.setId(id);
    appointmentDetail.setLastUpdated(getLastUpdated(appointment.getMeta().getLastUpdated()));
    List<Extension> cnlExtension = appointment.getExtensionsByUrl(SystemURL.SD_EXTENSION_GPC_APPOINTMENT_CANCELLATION_REASON);
    if (cnlExtension != null && !cnlExtension.isEmpty()) {
        IBaseDatatype value = cnlExtension.get(0).getValue();
        if (null == value) {
            throwInvalidRequest400_BadRequestException("Cancellation reason missing.");
        }
        appointmentDetail.setCancellationReason(value.toString());
    }
    appointmentDetail.setStatus(appointment.getStatus().toString().toLowerCase(Locale.UK));
    appointmentDetail.setMinutesDuration(appointment.getMinutesDuration());
    appointmentDetail.setPriority(appointment.getPriority());
    appointmentDetail.setStartDateTime(appointment.getStart());
    appointmentDetail.setEndDateTime(appointment.getEnd());
    List<Long> slotIds = new ArrayList<>();
    for (Reference slotReference : appointment.getSlot()) {
        // #200 check slots for absolute references
        checkReferenceIsRelative(slotReference.getReference());
        try {
            String here = slotReference.getReference().substring("Slot/".length());
            Long slotId = new Long(here);
            slotIds.add(slotId);
        } catch (NumberFormatException ex) {
            throwUnprocessableEntity422_InvalidResourceException(String.format("The slot reference value data type for %s is not valid.", slotReference.getReference()));
        }
    }
    appointmentDetail.setSlotIds(slotIds);
    if (appointmentValidation.appointmentCommentTooLong(appointment)) {
        throwUnprocessableEntity422_InvalidResourceException("Appointment comment cannot be greater than " + APPOINTMENT_COMMENT_LENGTH + " characters");
    }
    appointmentDetail.setComment(appointment.getComment());
    appointmentDetail.setDescription(appointment.getDescription());
    for (AppointmentParticipantComponent participant : appointment.getParticipant()) {
        if (participant.getActor() != null) {
            String participantReference = participant.getActor().getReference();
            String actorIdString = participantReference.substring(participantReference.lastIndexOf("/") + 1);
            Long actorId;
            if (actorIdString.equals("null")) {
                actorId = null;
            } else {
                actorId = Long.valueOf(actorIdString);
            }
            if (participantReference.contains("Patient/")) {
                appointmentDetail.setPatientId(actorId);
            } else if (participantReference.contains("Practitioner/")) {
                appointmentDetail.setPractitionerId(actorId);
            } else if (participantReference.contains("Location/")) {
                appointmentDetail.setLocationId(actorId);
            }
        } else {
            throwUnprocessableEntity422_InvalidResourceException("Participant Actor cannot be null");
        }
    }
    if (appointment.getCreated() != null) {
        Date created = appointment.getCreated();
        appointmentDetail.setCreated(created);
    }
    // #200 check extensions for absolute references
    List<Extension> extensions = appointment.getExtension();
    for (Extension extension : extensions) {
        try {
            Reference reference = (Reference) extension.getValue();
            if (reference != null) {
                checkReferenceIsRelative(reference.getReference());
            }
        } catch (ClassCastException ex) {
        }
    }
    List<Resource> contained = appointment.getContained();
    if (contained != null && !contained.isEmpty()) {
        Resource org = contained.get(0);
        Organization bookingOrgRes = (Organization) org;
        BookingOrgDetail bookingOrgDetail = new BookingOrgDetail();
        appointmentValidation.validateBookingOrganizationValuesArePresent(bookingOrgRes);
        bookingOrgDetail.setName(bookingOrgRes.getName());
        // #198 add system and optional use type. Pick system phone if > 1 and available otherwise use the one supplied
        Iterator<ContactPoint> iter = bookingOrgRes.getTelecom().iterator();
        ContactPoint telecom = bookingOrgRes.getTelecomFirstRep();
        while (iter.hasNext()) {
            ContactPoint thisTelecom = iter.next();
            if (thisTelecom.getSystem() == ContactPoint.ContactPointSystem.PHONE) {
                telecom = thisTelecom;
                break;
            }
        }
        bookingOrgDetail.setTelephone(telecom.getValue());
        bookingOrgDetail.setSystem(telecom.getSystem().toString());
        if (telecom.getUse() != null && !telecom.getUse().toString().trim().isEmpty()) {
            bookingOrgDetail.setUsetype(telecom.getUse().toString());
        }
        if (!bookingOrgRes.getIdentifier().isEmpty()) {
            bookingOrgDetail.setOrgCode(bookingOrgRes.getIdentifierFirstRep().getValue());
            String system = bookingOrgRes.getIdentifierFirstRep().getSystem();
            // check that organization identifier system is https://fhir.nhs.uk/Id/ods-organization-code
            if (system != null && !system.trim().isEmpty()) {
                if (!system.equals(ID_ODS_ORGANIZATION_CODE)) {
                    throwUnprocessableEntity422_InvalidResourceException("Appointment organisation identifier system must be an ODS code!");
                }
            } else {
                throwUnprocessableEntity422_InvalidResourceException("Appointment organisation identifier system must be populated!");
            }
        }
        bookingOrgDetail.setAppointmentDetail(appointmentDetail);
        appointmentDetail.setBookingOrganization(bookingOrgDetail);
        // 1.2.7
        appointmentDetail.setServiceCategory(appointment.getServiceCategory().getText());
        appointmentDetail.setServiceType(appointment.getServiceTypeFirstRep().getText());
    }
    return appointmentDetail;
}
Also used : AppointmentParticipantComponent(org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent) IBaseDatatype(org.hl7.fhir.instance.model.api.IBaseDatatype) AppointmentDetail(uk.gov.hscic.model.appointment.AppointmentDetail) BookingOrgDetail(uk.gov.hscic.model.appointment.BookingOrgDetail)

Example 65 with ContactPoint

use of org.hl7.fhir.r4b.model.ContactPoint in project gpconnect-demonstrator by nhsconnect.

the class AppointmentResourceProvider method appointmentDetailToAppointmentResourceConverter.

/**
 * AppointmentDetail to fhir resource Appointment
 *
 * @param appointmentDetail
 * @return Appointment Resource
 */
private Appointment appointmentDetailToAppointmentResourceConverter(AppointmentDetail appointmentDetail) {
    Appointment appointment = new Appointment();
    String appointmentId = String.valueOf(appointmentDetail.getId());
    String versionId = String.valueOf(appointmentDetail.getLastUpdated().getTime());
    String resourceType = appointment.getResourceType().toString();
    IdType id = new IdType(resourceType, appointmentId, versionId);
    appointment.setId(id);
    appointment.getMeta().setVersionId(versionId);
    appointment.getMeta().setLastUpdated(appointmentDetail.getLastUpdated());
    appointment.getMeta().addProfile(SystemURL.SD_GPC_APPOINTMENT);
    Extension extension = new Extension(SystemURL.SD_EXTENSION_GPC_APPOINTMENT_CANCELLATION_REASON, new StringType(appointmentDetail.getCancellationReason()));
    appointment.addExtension(extension);
    // #157 derive delivery channel from slot
    List<Long> sids = appointmentDetail.getSlotIds();
    ScheduleDetail scheduleDetail = null;
    if (sids.size() > 0) {
        // get the first slot but it should not matter because for multi slot appts the deliveryChannel is always the same
        SlotDetail slotDetail = slotSearch.findSlotByID(sids.get(0));
        String deliveryChannel = slotDetail.getDeliveryChannelCode();
        if (deliveryChannel != null && !deliveryChannel.trim().isEmpty()) {
            Extension deliveryChannelExtension = new Extension(SystemURL.SD_EXTENSION_GPC_DELIVERY_CHANNEL, new CodeType(deliveryChannel));
            appointment.addExtension(deliveryChannelExtension);
        }
        scheduleDetail = scheduleSearch.findScheduleByID(slotDetail.getScheduleReference());
    }
    // practitioner role extension here
    // lookup the practitioner
    Long practitionerID = appointmentDetail.getPractitionerId();
    if (practitionerID != null) {
        // #195 we need to get this detail from the schedule not the practitioner table
        if (scheduleDetail != null) {
            Coding roleCoding = new Coding(SystemURL.VS_GPC_PRACTITIONER_ROLE, scheduleDetail.getPractitionerRoleCode(), scheduleDetail.getPractitionerRoleDisplay());
            Extension practitionerRoleExtension = new Extension(SystemURL.SD_EXTENSION_GPC_PRACTITIONER_ROLE, new CodeableConcept().addCoding(roleCoding));
            appointment.addExtension(practitionerRoleExtension);
        }
    }
    switch(appointmentDetail.getStatus().toLowerCase(Locale.UK)) {
        case "pending":
            appointment.setStatus(AppointmentStatus.PENDING);
            break;
        case "booked":
            appointment.setStatus(AppointmentStatus.BOOKED);
            break;
        case "arrived":
            appointment.setStatus(AppointmentStatus.ARRIVED);
            break;
        case "fulfilled":
            appointment.setStatus(AppointmentStatus.FULFILLED);
            break;
        case "cancelled":
            appointment.setStatus(AppointmentStatus.CANCELLED);
            break;
        case "noshow":
            appointment.setStatus(AppointmentStatus.NOSHOW);
            break;
        default:
            appointment.setStatus(AppointmentStatus.PENDING);
            break;
    }
    appointment.setStart(appointmentDetail.getStartDateTime());
    appointment.setEnd(appointmentDetail.getEndDateTime());
    // #218 Date time formats
    appointment.getStartElement().setPrecision(TemporalPrecisionEnum.SECOND);
    appointment.getEndElement().setPrecision(TemporalPrecisionEnum.SECOND);
    List<Reference> slotResources = new ArrayList<>();
    for (Long slotId : appointmentDetail.getSlotIds()) {
        slotResources.add(new Reference("Slot/" + slotId));
    }
    appointment.setSlot(slotResources);
    if (appointmentDetail.getPriority() != null) {
        appointment.setPriority(appointmentDetail.getPriority());
    }
    appointment.setComment(appointmentDetail.getComment());
    appointment.setDescription(appointmentDetail.getDescription());
    appointment.addParticipant().setActor(new Reference("Patient/" + appointmentDetail.getPatientId())).setStatus(ParticipationStatus.ACCEPTED);
    appointment.addParticipant().setActor(new Reference("Location/" + appointmentDetail.getLocationId())).setStatus(ParticipationStatus.ACCEPTED);
    if (null != appointmentDetail.getPractitionerId()) {
        appointment.addParticipant().setActor(new Reference("Practitioner/" + appointmentDetail.getPractitionerId())).setStatus(ParticipationStatus.ACCEPTED);
    }
    if (null != appointmentDetail.getCreated()) {
        appointment.setCreated(appointmentDetail.getCreated());
    }
    if (null != appointmentDetail.getBookingOrganization()) {
        // add extension with reference to contained item
        String reference = "#1";
        Reference orgRef = new Reference(reference);
        Extension bookingOrgExt = new Extension(SystemURL.SD_CC_APPOINTMENT_BOOKINGORG, orgRef);
        appointment.addExtension(bookingOrgExt);
        BookingOrgDetail bookingOrgDetail = appointmentDetail.getBookingOrganization();
        Organization bookingOrg = new Organization();
        bookingOrg.setId(reference);
        bookingOrg.getNameElement().setValue(bookingOrgDetail.getName());
        // #198 org phone now persists usetype and system
        ContactPoint orgTelecom = bookingOrg.getTelecomFirstRep();
        orgTelecom.setValue(bookingOrgDetail.getTelephone());
        try {
            orgTelecom.setSystem(ContactPointSystem.fromCode(bookingOrgDetail.getSystem().toLowerCase()));
            if (bookingOrgDetail.getUsetype() != null && !bookingOrgDetail.getUsetype().trim().isEmpty()) {
                orgTelecom.setUse(ContactPointUse.fromCode(bookingOrgDetail.getUsetype().toLowerCase()));
            }
        } catch (FHIRException ex) {
        // Logger.getLogger(AppointmentResourceProvider.class.getName()).log(Level.SEVERE, null, ex);
        }
        bookingOrg.getMeta().addProfile(SystemURL.SD_GPC_ORGANIZATION);
        if (null != bookingOrgDetail.getOrgCode()) {
            bookingOrg.getIdentifierFirstRep().setSystem(SystemURL.ID_ODS_ORGANIZATION_CODE).setValue(bookingOrgDetail.getOrgCode());
        }
        // add contained booking organization resource
        appointment.getContained().add(bookingOrg);
    }
    // if bookingOrganization
    appointment.setMinutesDuration(appointmentDetail.getMinutesDuration());
    // 1.2.7 set service category from schedule type description
    appointment.setServiceCategory(new CodeableConcept().setText(scheduleDetail.getTypeDescription()));
    // 1.2.7 set service type from slot type description
    appointment.addServiceType(new CodeableConcept().setText(slotSearch.findSlotByID(sids.get(0)).getTypeDisply()));
    return appointment;
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException) BookingOrgDetail(uk.gov.hscic.model.appointment.BookingOrgDetail) ScheduleDetail(uk.gov.hscic.model.appointment.ScheduleDetail) SlotDetail(uk.gov.hscic.model.appointment.SlotDetail)

Aggregations

ContactPoint (org.hl7.fhir.r4.model.ContactPoint)56 Test (org.junit.Test)28 Address (org.hl7.fhir.r4.model.Address)18 Identifier (org.hl7.fhir.r4.model.Identifier)17 HumanName (org.hl7.fhir.r4.model.HumanName)16 PersonAttribute (org.openmrs.PersonAttribute)15 NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 ContactPoint (org.hl7.fhir.dstu3.model.ContactPoint)14 Test (org.junit.jupiter.api.Test)14 ArrayList (java.util.ArrayList)12 Organization (org.hl7.fhir.r4.model.Organization)12 ProviderAttribute (org.openmrs.ProviderAttribute)11 HashSet (java.util.HashSet)10 IdType (org.hl7.fhir.dstu3.model.IdType)9 Patient (org.hl7.fhir.r4.model.Patient)9 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)7 ContactDetail (org.hl7.fhir.r5.model.ContactDetail)6 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)6 HashMap (java.util.HashMap)5 Base64 (org.apache.commons.codec.binary.Base64)5