Search in sources :

Example 6 with CodeableConcept

use of org.hl7.fhir.r5.model.CodeableConcept 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)

Example 7 with CodeableConcept

use of org.hl7.fhir.r5.model.CodeableConcept in project gpconnect-demonstrator by nhsconnect.

the class ScheduleResourceProvider method scheduleDetailToScheduleResourceConverter.

private Schedule scheduleDetailToScheduleResourceConverter(ScheduleDetail scheduleDetail) {
    Schedule schedule = new Schedule();
    String resourceId = String.valueOf(scheduleDetail.getId());
    String versionId = String.valueOf(scheduleDetail.getLastUpdated().getTime());
    String resourceType = schedule.getResourceType().toString();
    IdType id = new IdType(resourceType, resourceId, versionId);
    schedule.setId(id);
    schedule.getMeta().setVersionId(versionId);
    schedule.getMeta().setLastUpdated(scheduleDetail.getLastUpdated());
    if (scheduleDetail.getPractitionerId() != null) {
        schedule.addActor(new Reference("Practitioner/" + scheduleDetail.getPractitionerId()));
    }
    if (scheduleDetail.getPractitionerRoleCode() != 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));
        schedule.addExtension(practitionerRoleExtension);
    }
    // # 194
    // Identifier identifier = new Identifier();
    // identifier.setSystem(SystemURL.ID_GPC_SCHEDULE_IDENTIFIER);
    // identifier.setValue(scheduleDetail.getIdentifier());
    // schedule.addIdentifier(identifier);
    Coding coding = new Coding().setSystem(SystemURL.HL7_VS_C80_PRACTICE_CODES).setCode(scheduleDetail.getTypeCode()).setDisplay(scheduleDetail.getTypeDescription());
    CodeableConcept codableConcept = new CodeableConcept().addCoding(coding);
    codableConcept.setText(scheduleDetail.getTypeDescription());
    schedule.addActor(new Reference("Location/" + scheduleDetail.getLocationId()));
    Period period = new Period();
    period.setStart(scheduleDetail.getStartDateTime());
    period.setEnd(scheduleDetail.getEndDateTime());
    schedule.setPlanningHorizon(period);
    // 1.2.7 remove comment
    // schedule.setComment(scheduleDetail.getComment());
    // 1.2.7 add schedule type description as service category
    schedule.setServiceCategory(new CodeableConcept().setText(scheduleDetail.getTypeDescription()));
    return schedule;
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Coding(org.hl7.fhir.dstu3.model.Coding) Reference(org.hl7.fhir.dstu3.model.Reference) Schedule(org.hl7.fhir.dstu3.model.Schedule) Period(org.hl7.fhir.dstu3.model.Period) IdType(org.hl7.fhir.dstu3.model.IdType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 8 with CodeableConcept

use of org.hl7.fhir.r5.model.CodeableConcept in project gpconnect-demonstrator by nhsconnect.

the class PatientResourceProvider method createContact.

// patientDetailsToMinimalPatient
/**
 * add a set of contact details into the patient record NB these are
 * Contacts (related people etc) not contactpoints (telecoms)
 *
 * @param patient fhirResource object
 */
private void createContact(Patient patient) {
    // relationships
    Patient.ContactComponent contact = new ContactComponent();
    for (String relationship : new String[] { "Emergency contact", "Next of kin", "Daughter" }) {
        CodeableConcept crelationship = new CodeableConcept();
        crelationship.setText(relationship);
        contact.addRelationship(crelationship);
    }
    // contact address
    Address address = new Address();
    address.addLine("Trevelyan Square");
    address.addLine("Boar Ln");
    address.setPostalCode("LS1 6AE");
    address.setType(AddressType.PHYSICAL);
    address.setUse(AddressUse.HOME);
    contact.setAddress(address);
    // gender
    contact.setGender(AdministrativeGender.FEMALE);
    // telecom
    ContactPoint telecom = new ContactPoint();
    telecom.setSystem(ContactPointSystem.PHONE);
    telecom.setUse(ContactPointUse.MOBILE);
    telecom.setValue("07777123123");
    contact.addTelecom(telecom);
    // Name
    HumanName name = new HumanName();
    name.addGiven("Jane");
    name.setFamily("Jackson");
    List<StringType> prefixList = new ArrayList<>();
    prefixList.add(new StringType("Miss"));
    name.setPrefix(prefixList);
    name.setText("JACKSON Jane (Miss)");
    name.setUse(NameUse.OFFICIAL);
    contact.setName(name);
    patient.addContact(contact);
}
Also used : ContactComponent(org.hl7.fhir.dstu3.model.Patient.ContactComponent) ContactComponent(org.hl7.fhir.dstu3.model.Patient.ContactComponent)

Example 9 with CodeableConcept

use of org.hl7.fhir.r5.model.CodeableConcept in project gpconnect-demonstrator by nhsconnect.

the class OrganizationResourceProvider method getValidContact.

private ContactDetail getValidContact() {
    HumanName orgCtName = new HumanName();
    orgCtName.setUse(NameUse.USUAL);
    orgCtName.setFamily("FamilyName");
    Coding coding = new Coding().setSystem(SystemURL.VS_CC_ORG_CT_ENTITYTYPE).setDisplay("ADMIN");
    CodeableConcept orgCtPurpose = new CodeableConcept().addCoding(coding);
    ContactDetail orgContact = new ContactDetail();
    orgContact.setNameElement(orgCtName.getFamilyElement());
    orgContact.addTelecom(getValidTelecom());
    return orgContact;
}
Also used : ContactDetail(org.hl7.fhir.dstu3.model.ContactDetail) HumanName(org.hl7.fhir.dstu3.model.HumanName) Coding(org.hl7.fhir.dstu3.model.Coding) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 10 with CodeableConcept

use of org.hl7.fhir.r5.model.CodeableConcept in project gpconnect-demonstrator by nhsconnect.

the class SlotResourceProvider method slotDetailToSlotResourceConverter.

private Slot slotDetailToSlotResourceConverter(SlotDetail slotDetail) {
    Slot slot = new Slot();
    Date lastUpdated = slotDetail.getLastUpdated() == null ? new Date() : slotDetail.getLastUpdated();
    String resourceId = String.valueOf(slotDetail.getId());
    String versionId = String.valueOf(lastUpdated.getTime());
    IdType id = new IdType(resourceId);
    slot.setId(id);
    slot.getMeta().setVersionId(versionId);
    slot.getMeta().addProfile(SystemURL.SD_GPC_SLOT);
    slot.setSchedule(new Reference("Schedule/" + slotDetail.getScheduleReference()));
    slot.setStart(slotDetail.getStartDateTime());
    slot.setEnd(slotDetail.getEndDateTime());
    // #218 Date time formats
    slot.getStartElement().setPrecision(TemporalPrecisionEnum.SECOND);
    slot.getEndElement().setPrecision(TemporalPrecisionEnum.SECOND);
    switch(slotDetail.getFreeBusyType().toLowerCase(Locale.UK)) {
        case "free":
            slot.setStatus(SlotStatus.FREE);
            break;
        default:
            slot.setStatus(SlotStatus.BUSY);
            break;
    }
    String deliveryChannelCode = slotDetail.getDeliveryChannelCode();
    ArrayList<Extension> al = new ArrayList<>();
    if (deliveryChannelCode != null && !deliveryChannelCode.trim().isEmpty()) {
        Extension deliveryChannelExtension = new Extension(SystemURL.SD_EXTENSION_GPC_DELIVERY_CHANNEL, new CodeType(deliveryChannelCode));
        al.add(deliveryChannelExtension);
    }
    slot.setExtension(al);
    // 1.2.7 add slot type description as service type
    slot.addServiceType(new CodeableConcept().setText(slotDetail.getTypeDisply()));
    return slot;
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) Slot(org.hl7.fhir.dstu3.model.Slot) CodeType(org.hl7.fhir.dstu3.model.CodeType) Date(java.util.Date) IdType(org.hl7.fhir.dstu3.model.IdType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Aggregations

CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)16 Coding (org.hl7.fhir.dstu3.model.Coding)12 Reference (org.hl7.fhir.dstu3.model.Reference)8 IdType (org.hl7.fhir.dstu3.model.IdType)5 ArrayList (java.util.ArrayList)4 Extension (org.hl7.fhir.dstu3.model.Extension)4 Date (java.util.Date)3 Period (org.hl7.fhir.dstu3.model.Period)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 Outcome (org.monarchinitiative.loinc2hpocore.codesystems.Outcome)3 SlotDetail (uk.gov.hscic.model.appointment.SlotDetail)3 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)2 AllergyIntolerance (org.hl7.fhir.dstu3.model.AllergyIntolerance)2 ContactDetail (org.hl7.fhir.dstu3.model.ContactDetail)2 DateTimeType (org.hl7.fhir.dstu3.model.DateTimeType)2 HumanName (org.hl7.fhir.dstu3.model.HumanName)2 Identifier (org.hl7.fhir.dstu3.model.Identifier)2 Location (org.hl7.fhir.dstu3.model.Location)2 Narrative (org.hl7.fhir.dstu3.model.Narrative)2 OperationOutcomeIssueComponent (org.hl7.fhir.dstu3.model.OperationOutcome.OperationOutcomeIssueComponent)2