Search in sources :

Example 6 with Schedule

use of org.hl7.fhir.dstu3.model.Schedule 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

CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)3 Coding (org.hl7.fhir.dstu3.model.Coding)3 Reference (org.hl7.fhir.dstu3.model.Reference)3 Schedule (org.hl7.fhir.dstu3.model.Schedule)3 Storagetransfer (com.google.api.services.storagetransfer.v1.Storagetransfer)2 Date (com.google.api.services.storagetransfer.v1.model.Date)2 GcsData (com.google.api.services.storagetransfer.v1.model.GcsData)2 Schedule (com.google.api.services.storagetransfer.v1.model.Schedule)2 TimeOfDay (com.google.api.services.storagetransfer.v1.model.TimeOfDay)2 TransferJob (com.google.api.services.storagetransfer.v1.model.TransferJob)2 TransferSpec (com.google.api.services.storagetransfer.v1.model.TransferSpec)2 ArrayList (java.util.ArrayList)2 IdType (org.hl7.fhir.dstu3.model.IdType)2 Identifier (org.hl7.fhir.dstu3.model.Identifier)2 Slot (org.hl7.fhir.dstu3.model.Slot)2 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)1 AwsAccessKey (com.google.api.services.storagetransfer.v1.model.AwsAccessKey)1 AwsS3Data (com.google.api.services.storagetransfer.v1.model.AwsS3Data)1 ObjectConditions (com.google.api.services.storagetransfer.v1.model.ObjectConditions)1 TransferOptions (com.google.api.services.storagetransfer.v1.model.TransferOptions)1