Search in sources :

Example 6 with Practitioner

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

the class MedicationOrderResourceProvider method medicationOrderDetailsToMedicationOrderResourceConverter.

private MedicationRequest medicationOrderDetailsToMedicationOrderResourceConverter(MedicationOrderDetails medicationOrderDetails) {
    MedicationRequest medicationOrder = new MedicationRequest();
    String resourceId = String.valueOf(medicationOrderDetails.getId());
    String versionId = String.valueOf(medicationOrderDetails.getLastUpdated().getTime());
    String resourceType = medicationOrder.getResourceType().toString();
    IdType id = new IdType(resourceType, resourceId, versionId);
    medicationOrder.setId(id);
    medicationOrder.getMeta().setVersionId(versionId);
    medicationOrder.getMeta().setLastUpdated(medicationOrderDetails.getLastUpdated());
    switch(medicationOrderDetails.getOrderStatus().toLowerCase(Locale.UK)) {
        case "active":
            medicationOrder.setStatus(MedicationRequestStatus.ACTIVE);
            break;
        case "completed":
            medicationOrder.setStatus(MedicationRequestStatus.COMPLETED);
            break;
        case "draft":
            medicationOrder.setStatus(MedicationRequestStatus.DRAFT);
            break;
        case "entered_in_error":
            medicationOrder.setStatus(MedicationRequestStatus.ENTEREDINERROR);
            break;
        case "on_hold":
            medicationOrder.setStatus(MedicationRequestStatus.ONHOLD);
            break;
        case "stopped":
            medicationOrder.setStatus(MedicationRequestStatus.STOPPED);
            break;
    }
    if (medicationOrderDetails.getPatientId() != null) {
        medicationOrder.setSubject(new Reference("Patient/" + medicationOrderDetails.getPatientId()));
    } else {
        medicationOrder.setSubject(new Reference());
    }
    medicationOrder.setRecorder(new Reference("Practitioner/" + medicationOrderDetails.getAutherId()));
    medicationOrder.setMedication(new Reference("Medication/" + medicationOrderDetails.getMedicationId()));
    medicationOrder.addDosageInstruction().setText(medicationOrderDetails.getDosageText());
    MedicationRequestDispenseRequestComponent dispenseRequest = new MedicationRequestDispenseRequestComponent();
    dispenseRequest.addExtension(new Extension(SystemURL.SD_EXTENSION_MEDICATION_QUANTITY_TEXT, new StringDt(medicationOrderDetails.getDispenseQuantityText())));
    dispenseRequest.addExtension(new Extension(SystemURL.SD_EXTENSION_PERSCRIPTION_REPEAT_REVIEW_DATE, new DateTimeDt(medicationOrderDetails.getDispenseReviewDate())));
    dispenseRequest.setId("Medication/" + medicationOrderDetails.getDispenseMedicationId());
    dispenseRequest.setNumberOfRepeatsAllowed(medicationOrderDetails.getDispenseRepeatsAllowed());
    medicationOrder.setDispenseRequest(dispenseRequest);
    return medicationOrder;
}
Also used : DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) MedicationRequestDispenseRequestComponent(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent) StringDt(ca.uhn.fhir.model.primitive.StringDt)

Example 7 with Practitioner

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

the class PractitionerResourceProvider method practitionerDetailsToPractitionerResourceConverter.

private Practitioner practitionerDetailsToPractitionerResourceConverter(PractitionerDetails practitionerDetails) {
    Identifier identifier = new Identifier().setSystem(SystemURL.ID_SDS_USER_ID).setValue(practitionerDetails.getUserId());
    Practitioner practitioner = new Practitioner().addIdentifier(identifier);
    practitionerDetails.getRoleIds().stream().distinct().map(roleId -> new Identifier().setSystem(SystemURL.ID_SDS_ROLE_PROFILE_ID).setValue(roleId)).forEach(practitioner::addIdentifier);
    String resourceId = String.valueOf(practitionerDetails.getId());
    String versionId = String.valueOf(practitionerDetails.getLastUpdated().getTime());
    String resourceType = practitioner.getResourceType().toString();
    IdType id = new IdType(resourceType, resourceId, versionId);
    practitioner.setId(id);
    practitioner.getMeta().setVersionId(versionId);
    practitioner.getMeta().setLastUpdated(practitionerDetails.getLastUpdated());
    practitioner.getMeta().addProfile(SystemURL.SD_GPC_PRACTITIONER);
    HumanName name = new HumanName().setFamily(practitionerDetails.getNameFamily()).addGiven(practitionerDetails.getNameGiven()).addPrefix(practitionerDetails.getNamePrefix()).setUse(NameUse.USUAL);
    practitioner.addName(name);
    switch(practitionerDetails.getGender().toLowerCase(Locale.UK)) {
        case "male":
            practitioner.setGender(AdministrativeGender.MALE);
            break;
        case "female":
            practitioner.setGender(AdministrativeGender.FEMALE);
            break;
        case "other":
            practitioner.setGender(AdministrativeGender.OTHER);
            break;
        default:
            practitioner.setGender(AdministrativeGender.UNKNOWN);
            break;
    }
    Coding roleCoding = new Coding(SystemURL.VS_SDS_JOB_ROLE_NAME, practitionerDetails.getRoleCode(), practitionerDetails.getRoleDisplay());
    for (int i = 0; i < practitionerDetails.getComCode().size(); i++) {
        Coding comCoding = new Coding(SystemURL.VS_HUMAN_LANGUAGE, practitionerDetails.getComCode().get(i), null).setDisplay(practitionerDetails.getComDisplay().get(i));
        practitioner.addCommunication().addCoding(comCoding);
    }
    return practitioner;
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) IdParam(ca.uhn.fhir.rest.annotation.IdParam) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) IdType(org.hl7.fhir.dstu3.model.IdType) Autowired(org.springframework.beans.factory.annotation.Autowired) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) Extension(org.hl7.fhir.dstu3.model.Extension) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) Locale(java.util.Locale) Search(ca.uhn.fhir.rest.annotation.Search) IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Location(org.hl7.fhir.dstu3.model.Location) Read(ca.uhn.fhir.rest.annotation.Read) Practitioner(org.hl7.fhir.dstu3.model.Practitioner) Sort(ca.uhn.fhir.rest.annotation.Sort) Count(ca.uhn.fhir.rest.annotation.Count) Collectors(java.util.stream.Collectors) SystemURL(uk.gov.hscic.SystemURL) IssueType(org.hl7.fhir.dstu3.model.OperationOutcome.IssueType) TokenParam(ca.uhn.fhir.rest.param.TokenParam) PractitionerDetails(uk.gov.hscic.model.practitioner.PractitionerDetails) AdministrativeGender(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender) OperationOutcomeFactory(uk.gov.hscic.OperationOutcomeFactory) List(java.util.List) Component(org.springframework.stereotype.Component) SortSpec(ca.uhn.fhir.rest.api.SortSpec) IdentifierValidator(uk.gov.hscic.common.validators.IdentifierValidator) SystemCode(uk.gov.hscic.SystemCode) Collections(java.util.Collections) HumanName(org.hl7.fhir.dstu3.model.HumanName) NameUse(org.hl7.fhir.dstu3.model.HumanName.NameUse) HumanName(org.hl7.fhir.dstu3.model.HumanName) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 8 with Practitioner

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

the class PatientResourceProvider method patientDetailsToPatientResourceConverter.

private Patient patientDetailsToPatientResourceConverter(PatientDetails patientDetails) throws FHIRException {
    Patient patient = patientDetailsToMinimalPatient(patientDetails);
    HumanName name = getPatientNameFromPatientDetails(patientDetails);
    patient.addName(name);
    String addressLines = patientDetails.getAddress();
    if (addressLines != null) {
        patient.addAddress().setUse(AddressUse.HOME).setType(AddressType.PHYSICAL).setText(addressLines);
    }
    Long gpId = patientDetails.getGpId();
    if (gpId != null) {
        Practitioner prac = practitionerResourceProvider.getPractitionerById(new IdType(gpId));
        HumanName practitionerName = prac.getNameFirstRep();
        Reference practitionerReference = new Reference("Practitioner/" + gpId).setDisplay(practitionerName.getPrefix() + " " + practitionerName.getGivenAsSingleString() + " " + practitionerName.getFamily());
    // patient.getCareProvider().add(practitionerReference);
    }
    String telephoneNumber = patientDetails.getTelephone();
    if (telephoneNumber != null) {
        ContactPoint telephone = new ContactPoint().setSystem(ContactPointSystem.PHONE).setValue(telephoneNumber).setUse(ContactPointUse.HOME);
        patient.setTelecom(Collections.singletonList(telephone));
    }
    String managingOrganization = patientDetails.getManagingOrganization();
    if (managingOrganization != null) {
        patient.setManagingOrganization(new Reference("Organization/" + managingOrganization));
    }
    return patient;
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) HumanName(org.hl7.fhir.dstu3.model.HumanName) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) Reference(org.hl7.fhir.dstu3.model.Reference) Patient(org.hl7.fhir.dstu3.model.Patient) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 9 with Practitioner

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

the class PopulateSlotBundle method populateBundle.

public void populateBundle(Bundle bundle, OperationOutcome operationOutcome, Date planningHorizonStart, Date planningHorizonEnd, boolean actorPractitioner, boolean actorLocation, String bookingOdsCode, String bookingOrgType) {
    bundle.getMeta().addProfile(SystemURL.SD_GPC_SRCHSET_BUNDLE);
    List<Location> locations = locationResourceProvider.getAllLocationDetails();
    BundleEntryComponent locationEntry = new BundleEntryComponent();
    locationEntry.setResource(locations.get(0));
    locationEntry.setFullUrl("Location/" + locations.get(0).getIdElement().getIdPart());
    // find the organization from the ods code
    List<OrganizationDetails> organizations = organizationSearch.findOrganizationDetailsByOrgODSCode(bookingOdsCode);
    // schedules
    List<Schedule> schedules = scheduleResourceProvider.getSchedulesForLocationId(locations.get(0).getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd);
    if (!schedules.isEmpty()) {
        for (Schedule schedule : schedules) {
            schedule.getMeta().addProfile(SystemURL.SD_GPC_SCHEDULE);
            BundleEntryComponent scheduleEntry = new BundleEntryComponent();
            scheduleEntry.setResource(schedule);
            scheduleEntry.setFullUrl("Schedule/" + schedule.getIdElement().getIdPart());
            // practitioners
            List<Reference> practitionerActors = scheduleResourceProvider.getPractitionerReferences(schedule);
            if (!practitionerActors.isEmpty()) {
                for (Reference practitionerActor : practitionerActors) {
                    Practitioner practitioner = practitionerResourceProvider.getPractitionerById((IdType) practitionerActor.getReferenceElement());
                    if (practitioner == null) {
                        Coding errorCoding = new Coding().setSystem(SystemURL.VS_GPC_ERROR_WARNING_CODE).setCode(SystemCode.REFERENCE_NOT_FOUND);
                        CodeableConcept errorCodableConcept = new CodeableConcept().addCoding(errorCoding);
                        errorCodableConcept.setText("Invalid Reference");
                        operationOutcome.addIssue().setSeverity(IssueSeverity.ERROR).setCode(IssueType.NOTFOUND).setDetails(errorCodableConcept);
                        throw new ResourceNotFoundException("Practitioner Reference returning null");
                    }
                    if (actorPractitioner == true) {
                        BundleEntryComponent practionerEntry = new BundleEntryComponent();
                        practionerEntry.setResource(practitioner);
                        practionerEntry.setFullUrl("Practitioner/" + practitioner.getIdElement().getIdPart());
                        bundle.addEntry(practionerEntry);
                    }
                }
            }
            Set<Slot> slots = new HashSet<Slot>();
            if (!organizations.isEmpty()) {
                slots.addAll(slotResourceProvider.getSlotsForScheduleIdAndOrganizationId(schedule.getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd, organizations.get(0).getId()));
            }
            slots.addAll(slotResourceProvider.getSlotsForScheduleIdAndOrganizationType(schedule.getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd, bookingOrgType));
            String freeBusyType = "FREE";
            if (!slots.isEmpty()) {
                for (Slot slot : slots) {
                    if (freeBusyType.equalsIgnoreCase(slot.getStatus().toString())) {
                        BundleEntryComponent slotEntry = new BundleEntryComponent();
                        slotEntry.setResource(slot);
                        slotEntry.setFullUrl("Slot/" + slot.getIdElement().getIdPart());
                        bundle.addEntry(slotEntry);
                        bundle.addEntry(scheduleEntry);
                        if (actorLocation == true) {
                            bundle.addEntry(locationEntry);
                        }
                    }
                }
            }
        }
    }
}
Also used : Reference(org.hl7.fhir.dstu3.model.Reference) OrganizationDetails(uk.gov.hscic.model.organization.OrganizationDetails) Practitioner(org.hl7.fhir.dstu3.model.Practitioner) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.dstu3.model.Coding) Schedule(org.hl7.fhir.dstu3.model.Schedule) Slot(org.hl7.fhir.dstu3.model.Slot) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Location(org.hl7.fhir.dstu3.model.Location) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) HashSet(java.util.HashSet)

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