Search in sources :

Example 1 with Practitioner

use of org.hl7.fhir.dstu3.model.Practitioner in project gpconnect-demonstrator by nhsconnect.

the class AppointmentResourceProvider method appointmentDetailToAppointmentResourceConverter.

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 IdType(appointmentDetail.getCancellationReason()));
    appointment.addExtension(extension);
    Identifier identifier = new Identifier();
    identifier.setSystem(SystemURL.ID_GPC_APPOINTMENT_IDENTIFIER).setValue(String.valueOf(appointmentDetail.getId()));
    appointment.addIdentifier(identifier);
    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;
    }
    Coding coding = new Coding().setSystem(SystemURL.HL7_VS_C80_PRACTICE_CODES).setCode(String.valueOf(appointmentDetail.getTypeCode())).setDisplay(appointmentDetail.getTypeDisplay());
    CodeableConcept codableConcept = new CodeableConcept().addCoding(coding);
    codableConcept.setText(appointmentDetail.getTypeDisplay());
    appointment.setAppointmentType(codableConcept);
    // Look into this
    // appointment.getType().setText(appointmentDetail.getTypeText());
    String reasonCode = appointmentDetail.getReasonCode();
    String reasonDisplay = appointmentDetail.getReasonDisplay();
    String reasonSystem = SystemURL.DEFAULTREASONURL;
    if (reasonCode != null && reasonDisplay != null && reasonSystem != null) {
        Coding codingReason = new Coding().setSystem(reasonSystem).setCode(String.valueOf(reasonCode)).setDisplay(reasonDisplay);
        CodeableConcept codableConceptReason = new CodeableConcept().addCoding(codingReason);
        codableConceptReason.setText(reasonDisplay);
        appointment.addReason(codableConceptReason);
    }
    appointment.setStart(appointmentDetail.getStartDateTime());
    appointment.setEnd(appointmentDetail.getEndDateTime());
    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()) {
        // DateTimeDt created = new
        // DateTimeDt(appointmentDetail.getCreated());
        // Extension createdExt = new
        // Extension(SystemURL.SD_CC_APPOINTMENT_CREATED, created);
        appointment.setCreated(appointmentDetail.getCreated());
    }
    if (null != appointmentDetail.getBookingOrganization()) {
        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());
        bookingOrg.getTelecomFirstRep().setValue(bookingOrgDetail.getTelephone()).setUse(ContactPointUse.TEMP).setSystem(ContactPointSystem.PHONE);
        bookingOrg.getMeta().addProfile(SystemURL.SD_GPC_ORGANIZATION);
        if (null != bookingOrgDetail.getOrgCode()) {
            bookingOrg.getIdentifierFirstRep().setSystem(SystemURL.ID_ODS_ORGANIZATION_CODE).setValue(bookingOrgDetail.getOrgCode());
        }
        appointment.getContained().add(bookingOrg);
    }
    return appointment;
}
Also used : Appointment(org.hl7.fhir.dstu3.model.Appointment) Organization(org.hl7.fhir.dstu3.model.Organization) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) IdType(org.hl7.fhir.dstu3.model.IdType) Extension(org.hl7.fhir.dstu3.model.Extension) Identifier(org.hl7.fhir.dstu3.model.Identifier) BookingOrgDetail(uk.gov.hscic.model.appointment.BookingOrgDetail) Coding(org.hl7.fhir.dstu3.model.Coding) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 2 with Practitioner

use of org.hl7.fhir.dstu3.model.Practitioner in project gpconnect-demonstrator by nhsconnect.

the class AppointmentResourceProvider method appointmentResourceConverterToAppointmentDetail.

private AppointmentDetail appointmentResourceConverterToAppointmentDetail(Appointment appointment) {
    appointmentValidation.validateAppointmentExtensions(appointment.getExtension());
    if (appointmentValidation.appointmentDescriptionTooLong(appointment)) {
        throw new UnprocessableEntityException("Appointment description cannot be greater then 600 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) {
            throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("Cancellation reason missing."), SystemCode.BAD_REQUEST, IssueType.INVALID);
        }
        appointmentDetail.setCancellationReason(value.toString());
    }
    appointmentDetail.setStatus(appointment.getStatus().toString().toLowerCase(Locale.UK));
    appointmentDetail.setTypeDisplay(appointment.getAppointmentType().getTextElement().toString());
    appointmentDetail.setMinutesDuration(appointment.getMinutesDuration());
    appointmentDetail.setPriority(appointment.getPriority());
    appointmentDetail.setTypeText(appointment.getServiceType().toString());
    Coding codingFirstRep = appointment.getReasonFirstRep().getCodingFirstRep();
    if (!codingFirstRep.isEmpty()) {
        String reasonSystem = codingFirstRep.getSystem();
        if (reasonSystem == null) {
            String message = "Problem with reason property of the appointment. If the reason is provided then the system property must be set.";
            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(message), SystemCode.INVALID_RESOURCE, IssueType.INCOMPLETE);
        } else {
            appointmentDetail.setReasonURL(reasonSystem);
        }
        String reasonCode = codingFirstRep.getCode();
        if (reasonCode == null) {
            String message = "Problem with reason property of the appointment. If the reason is provided then the code property must be set.";
            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(message), SystemCode.INVALID_RESOURCE, IssueType.INCOMPLETE);
        } else {
            appointmentDetail.setReasonCode(reasonCode);
        }
        String reasonDisplay = codingFirstRep.getDisplay();
        if (reasonDisplay == null) {
            String message = "Problem with reason property of the appointment. If the reason is provided then the display property must be set.";
            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(message), SystemCode.INVALID_RESOURCE, IssueType.INCOMPLETE);
        } else {
            appointmentDetail.setReasonDisplay(reasonDisplay);
        }
    }
    appointmentDetail.setStartDateTime(appointment.getStart());
    appointmentDetail.setEndDateTime(appointment.getEnd());
    List<Long> slotIds = new ArrayList<>();
    for (Reference slotReference : appointment.getSlot()) {
        try {
            String here = slotReference.getReference().substring(5).toString();
            Long slotId = new Long(here);
            slotIds.add(slotId);
        } catch (NumberFormatException ex) {
            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(String.format("The slot reference value data type for %s is not valid.", slotReference.getReference())), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
        }
    }
    appointmentDetail.setSlotIds(slotIds);
    appointmentDetail.setComment(appointment.getComment());
    appointmentDetail.setDescription(appointment.getDescription());
    for (AppointmentParticipantComponent participant : appointment.getParticipant()) {
        if (participant.getActor() != null) {
            String participantReference = participant.getActor().getReference().toString();
            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 {
            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(String.format("Participant Actor cannot be null")), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
        }
    }
    if (appointment.getCreated() != null) {
        Date created = appointment.getCreated();
        appointmentDetail.setCreated(created);
    }
    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());
        bookingOrgDetail.setTelephone(bookingOrgRes.getTelecomFirstRep().getValue());
        if (!bookingOrgRes.getIdentifier().isEmpty()) {
            bookingOrgDetail.setOrgCode(bookingOrgRes.getIdentifierFirstRep().getValue());
        }
        bookingOrgDetail.setAppointmentDetail(appointmentDetail);
        appointmentDetail.setBookingOrganization(bookingOrgDetail);
    }
    List<Extension> bktExtension = appointment.getExtensionsByUrl(SystemURL.SD_CC_APPOINTMENT_BOOKINGORG);
    if (bktExtension != null && !bktExtension.isEmpty()) {
        IBaseDatatype bookingOrg = bktExtension.get(0).getValue();
        if (null != bookingOrg && bookingOrg.getClass().getSimpleName().equals("Reference")) {
            for (Resource resource : appointment.getContained()) {
                if (resource.getResourceType().toString().equals("Organization")) {
                // Organization bookingOrgRes = (Organization) resource;
                // Reference bookingOrgRef = (Reference) bookingOrg;
                // if
                // (bookingOrgRes.getId().equals(bookingOrgRef.getReference()))
                // {
                // BookingOrgDetail bookingOrgDetail = new
                // BookingOrgDetail();
                // bookingOrgDetail.setName(bookingOrgRes.getName());
                // bookingOrgDetail.setTelephone(bookingOrgRes.getTelecomFirstRep().getValue());
                // if (!bookingOrgRes.getIdentifier().isEmpty()) {
                // bookingOrgDetail.setOrgCode(bookingOrgRes.getIdentifierFirstRep().getValue());
                // }
                // bookingOrgDetail.setAppointmentDetail(appointmentDetail);
                // appointmentDetail.setBookingOrganization(bookingOrgDetail);
                // }
                }
            }
        }
    }
    return appointmentDetail;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) AppointmentParticipantComponent(org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent) Organization(org.hl7.fhir.dstu3.model.Organization) IBaseDatatype(org.hl7.fhir.instance.model.api.IBaseDatatype) Reference(org.hl7.fhir.dstu3.model.Reference) AppointmentDetail(uk.gov.hscic.model.appointment.AppointmentDetail) ArrayList(java.util.ArrayList) Resource(org.hl7.fhir.dstu3.model.Resource) Date(java.util.Date) Extension(org.hl7.fhir.dstu3.model.Extension) BookingOrgDetail(uk.gov.hscic.model.appointment.BookingOrgDetail) Coding(org.hl7.fhir.dstu3.model.Coding) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)

Example 3 with Practitioner

use of org.hl7.fhir.dstu3.model.Practitioner in project gpconnect-demonstrator by nhsconnect.

the class AppointmentValidation method validateParticipantActor.

public void validateParticipantActor(Reference participantActor) {
    Reference actorRef = participantActor;
    String resourcePart = actorRef.getReference().toString();
    String idPart = actorRef.getId();
    Boolean participantFailedSearch = false;
    switch(resourcePart) {
        case "Patient":
            PatientDetails patient = patientSearch.findPatientByInternalID(idPart);
            participantFailedSearch = (patient == null);
            break;
        case "Practitioner":
            PractitionerDetails practitioner = practitionerSearch.findPractitionerDetails(idPart);
            participantFailedSearch = (practitioner == null);
            break;
        case "Location":
            LocationDetails location = locationSearch.findLocationById(idPart);
            participantFailedSearch = (location == null);
            break;
    }
    if (participantFailedSearch) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(String.format("%s resource reference is not a valid resource", resourcePart)), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
    }
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) PractitionerDetails(uk.gov.hscic.model.practitioner.PractitionerDetails) LocationDetails(uk.gov.hscic.model.location.LocationDetails) Reference(org.hl7.fhir.dstu3.model.Reference) PatientDetails(uk.gov.hscic.model.patient.PatientDetails)

Example 4 with Practitioner

use of org.hl7.fhir.dstu3.model.Practitioner 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);
    }
    if (scheduleDetail.getDeliveryChannelCode() != null) {
        Coding roleCoding = new Coding(SystemURL.VS_GPC_DELIVERY_CHANNEL, scheduleDetail.getDeliveryChannelCode(), scheduleDetail.getDeliveryChannelDisplay());
        Extension deliveryChannelExtension = new Extension(SystemURL.SD_EXTENSION_GPC_DELIVERY_CHANNEL, new CodeableConcept().addCoding(roleCoding));
        schedule.addExtension(deliveryChannelExtension);
    }
    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.setServiceType(Collections.singletonList(codableConcept));
    schedule.addActor(new Reference("Location/" + scheduleDetail.getLocationId()));
    // schedule.setActor((List<Reference>) new Reference("Location/" + scheduleDetail.getLocationId()));
    Period period = new Period();
    period.setStart(scheduleDetail.getStartDateTime());
    period.setEnd(scheduleDetail.getEndDateTime());
    schedule.setPlanningHorizon(period);
    schedule.setComment(scheduleDetail.getComment());
    return schedule;
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Identifier(org.hl7.fhir.dstu3.model.Identifier) 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 5 with Practitioner

use of org.hl7.fhir.dstu3.model.Practitioner in project gpconnect-demonstrator by nhsconnect.

the class MedicationAdministrationResourceProvider method getMedicationAdministrationsForPatientId.

@Search
public List<MedicationAdministration> getMedicationAdministrationsForPatientId(@RequiredParam(name = "patient") String patientId) {
    ArrayList<MedicationAdministration> medicationAdministrations = new ArrayList<>();
    List<MedicationAdministrationDetail> medicationAdministrationDetailList = medicationAdministrationSearch.findMedicationAdministrationForPatient(Long.parseLong(patientId));
    if (medicationAdministrationDetailList != null && !medicationAdministrationDetailList.isEmpty()) {
        for (MedicationAdministrationDetail medicationAdministrationDetail : medicationAdministrationDetailList) {
            MedicationAdministration medicationAdministration = new MedicationAdministration();
            String resourceId = String.valueOf(medicationAdministrationDetail.getId());
            String versionId = String.valueOf(medicationAdministrationDetail.getLastUpdated().getTime());
            String resourceType = medicationAdministration.getResourceType().toString();
            IdType id = new IdType(resourceType, resourceId, versionId);
            medicationAdministration.setId(id);
            medicationAdministration.getMeta().setVersionId(versionId);
            medicationAdministration.getMeta().setLastUpdated(medicationAdministrationDetail.getLastUpdated());
            medicationAdministration.addDefinition(new Reference("Patient/" + medicationAdministrationDetail.getPatientId()));
            medicationAdministration.addDefinition(new Reference("Practitioner/" + medicationAdministrationDetail.getPractitionerId()));
            medicationAdministration.setPrescription(new Reference("MedicationOrder/" + medicationAdministrationDetail.getPrescriptionId()));
            medicationAdministration.setEffective(new DateType(medicationAdministrationDetail.getAdministrationDate()));
            medicationAdministration.setMedication(new Reference("Medication/" + medicationAdministrationDetail.getMedicationId()));
            medicationAdministrations.add(medicationAdministration);
        }
    }
    return medicationAdministrations;
}
Also used : MedicationAdministrationDetail(uk.gov.hscic.model.medication.MedicationAdministrationDetail) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) MedicationAdministration(org.hl7.fhir.dstu3.model.MedicationAdministration) DateType(org.hl7.fhir.dstu3.model.DateType) IdType(org.hl7.fhir.dstu3.model.IdType) Search(ca.uhn.fhir.rest.annotation.Search) MedicationAdministrationSearch(uk.gov.hscic.medication.administration.MedicationAdministrationSearch)

Aggregations

Reference (org.hl7.fhir.dstu3.model.Reference)7 Coding (org.hl7.fhir.dstu3.model.Coding)5 IdType (org.hl7.fhir.dstu3.model.IdType)5 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)4 Extension (org.hl7.fhir.dstu3.model.Extension)4 ArrayList (java.util.ArrayList)3 Identifier (org.hl7.fhir.dstu3.model.Identifier)3 Search (ca.uhn.fhir.rest.annotation.Search)2 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)2 HumanName (org.hl7.fhir.dstu3.model.HumanName)2 Location (org.hl7.fhir.dstu3.model.Location)2 Organization (org.hl7.fhir.dstu3.model.Organization)2 Practitioner (org.hl7.fhir.dstu3.model.Practitioner)2 BookingOrgDetail (uk.gov.hscic.model.appointment.BookingOrgDetail)2 PractitionerDetails (uk.gov.hscic.model.practitioner.PractitionerDetails)2 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)1 StringDt (ca.uhn.fhir.model.primitive.StringDt)1 Count (ca.uhn.fhir.rest.annotation.Count)1 IdParam (ca.uhn.fhir.rest.annotation.IdParam)1