Search in sources :

Example 1 with Schedule

use of com.google.api.services.storagetransfer.v1.model.Schedule 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 2 with Schedule

use of com.google.api.services.storagetransfer.v1.model.Schedule in project java-docs-samples by GoogleCloudPlatform.

the class AwsRequester method createAwsTransferJob.

/**
 * Creates and executes a request for a TransferJob from Amazon S3 to Cloud Storage.
 *
 * <p>The {@code startDate} and {@code startTime} parameters should be set according to the UTC
 * Time Zone. See:
 * https://developers.google.com/resources/api-libraries/documentation/storagetransfer/v1/java/latest/com/google/api/services/storagetransfer/v1/model/Schedule.html#getStartTimeOfDay()
 *
 * @return the response TransferJob if the request is successful
 * @throws InstantiationException
 *           if instantiation fails when building the TransferJob
 * @throws IllegalAccessException
 *           if an illegal access occurs when building the TransferJob
 * @throws IOException
 *           if the client failed to complete the request
 */
public static TransferJob createAwsTransferJob(String projectId, String jobDescription, String awsSourceBucket, String gcsSinkBucket, String startDate, String startTime, String awsAccessKeyId, String awsSecretAccessKey) throws InstantiationException, IllegalAccessException, IOException {
    Date date = TransferJobUtils.createDate(startDate);
    TimeOfDay time = TransferJobUtils.createTimeOfDay(startTime);
    TransferJob transferJob = new TransferJob().setDescription(jobDescription).setProjectId(projectId).setTransferSpec(new TransferSpec().setAwsS3DataSource(new AwsS3Data().setBucketName(awsSourceBucket).setAwsAccessKey(new AwsAccessKey().setAccessKeyId(awsAccessKeyId).setSecretAccessKey(awsSecretAccessKey))).setGcsDataSink(new GcsData().setBucketName(gcsSinkBucket))).setSchedule(new Schedule().setScheduleStartDate(date).setScheduleEndDate(date).setStartTimeOfDay(time)).setStatus("ENABLED");
    Storagetransfer client = TransferClientCreator.createStorageTransferClient();
    return client.transferJobs().create(transferJob).execute();
}
Also used : TimeOfDay(com.google.api.services.storagetransfer.v1.model.TimeOfDay) TransferSpec(com.google.api.services.storagetransfer.v1.model.TransferSpec) AwsAccessKey(com.google.api.services.storagetransfer.v1.model.AwsAccessKey) Schedule(com.google.api.services.storagetransfer.v1.model.Schedule) Storagetransfer(com.google.api.services.storagetransfer.v1.Storagetransfer) Date(com.google.api.services.storagetransfer.v1.model.Date) AwsS3Data(com.google.api.services.storagetransfer.v1.model.AwsS3Data) GcsData(com.google.api.services.storagetransfer.v1.model.GcsData) TransferJob(com.google.api.services.storagetransfer.v1.model.TransferJob)

Example 3 with Schedule

use of com.google.api.services.storagetransfer.v1.model.Schedule in project java-docs-samples by GoogleCloudPlatform.

the class NearlineRequester method createNearlineTransferJob.

/**
 * Creates and executes a request for a TransferJob to Cloud Storage Nearline.
 *
 * <p>The {@code startDate} and {@code startTime} parameters should be set according to the UTC
 * Time Zone. See:
 * https://developers.google.com/resources/api-libraries/documentation/storagetransfer/v1/java/latest/com/google/api/services/storagetransfer/v1/model/Schedule.html#getStartTimeOfDay()
 *
 * @return the response TransferJob if the request is successful
 * @throws InstantiationException
 *           if instantiation fails when building the TransferJob
 * @throws IllegalAccessException
 *           if an illegal access occurs when building the TransferJob
 * @throws IOException
 *           if the client failed to complete the request
 */
public static TransferJob createNearlineTransferJob(String projectId, String jobDescription, String gcsSourceBucket, String gcsNearlineSinkBucket, String startDate, String startTime) throws InstantiationException, IllegalAccessException, IOException {
    Date date = TransferJobUtils.createDate(startDate);
    TimeOfDay time = TransferJobUtils.createTimeOfDay(startTime);
    TransferJob transferJob = new TransferJob().setDescription(jobDescription).setProjectId(projectId).setTransferSpec(new TransferSpec().setGcsDataSource(new GcsData().setBucketName(gcsSourceBucket)).setGcsDataSink(new GcsData().setBucketName(gcsNearlineSinkBucket)).setObjectConditions(new ObjectConditions().setMinTimeElapsedSinceLastModification("2592000s")).setTransferOptions(new TransferOptions().setDeleteObjectsFromSourceAfterTransfer(true))).setSchedule(new Schedule().setScheduleStartDate(date).setStartTimeOfDay(time)).setStatus("ENABLED");
    Storagetransfer client = TransferClientCreator.createStorageTransferClient();
    return client.transferJobs().create(transferJob).execute();
}
Also used : TimeOfDay(com.google.api.services.storagetransfer.v1.model.TimeOfDay) TransferSpec(com.google.api.services.storagetransfer.v1.model.TransferSpec) TransferOptions(com.google.api.services.storagetransfer.v1.model.TransferOptions) ObjectConditions(com.google.api.services.storagetransfer.v1.model.ObjectConditions) Schedule(com.google.api.services.storagetransfer.v1.model.Schedule) Storagetransfer(com.google.api.services.storagetransfer.v1.Storagetransfer) Date(com.google.api.services.storagetransfer.v1.model.Date) GcsData(com.google.api.services.storagetransfer.v1.model.GcsData) TransferJob(com.google.api.services.storagetransfer.v1.model.TransferJob)

Example 4 with Schedule

use of com.google.api.services.storagetransfer.v1.model.Schedule in project gpconnect-demonstrator by nhsconnect.

the class PopulateSlotBundle method populateBundle.

/**
 * @param bundle Bundle resource to populate
 * @param operationOutcome
 * @param planningHorizonStart Date
 * @param planningHorizonEnd Date
 * @param actorPractitioner boolean
 * @param actorLocation boolean
 * @param managingOrganisation boolean
 * @param bookingOdsCode String
 * @param bookingOrgType String eg "urgent-care"
 */
public void populateBundle(Bundle bundle, OperationOutcome operationOutcome, Date planningHorizonStart, Date planningHorizonEnd, boolean actorPractitioner, boolean actorLocation, boolean managingOrganisation, String bookingOdsCode, String bookingOrgType) {
    bundle.getMeta().addProfile(SystemURL.SD_GPC_SRCHSET_BUNDLE);
    // TODO remove hard coding pick up from providerRouting.json ?
    final String OUR_ODS_CODE = "A20047";
    // find all locations for this ODS practice code and construct Resources for them
    // #144 generalise to handle 1..n locations for a practice
    HashMap<String, BundleEntryComponent> locationEntries = new HashMap<>();
    for (LocationDetails aLocationDetail : locationSearch.findAllLocations()) {
        if (aLocationDetail.getOrgOdsCode().equals(OUR_ODS_CODE)) {
            Location aLocationResource = locationResourceProvider.getLocationById(new IdType(aLocationDetail.getId()));
            BundleEntryComponent locationEntry = new BundleEntryComponent();
            locationEntry.setResource(aLocationResource);
            // #202 use full urls
            // #215 full url removed completely
            // locationEntry.setFullUrl(serverBaseUrl + "Location/" + aLocationResource.getIdElement().getIdPart());
            locationEntries.put(aLocationResource.getIdElement().getIdPart(), locationEntry);
        }
    }
    // find the provider organization from the ods code
    List<OrganizationDetails> ourOrganizationsDetails = organizationSearch.findOrganizationDetailsByOrgODSCode(OUR_ODS_CODE);
    OrganizationDetails ourOrganizationDetails = null;
    if (!ourOrganizationsDetails.isEmpty()) {
        // at 1.2.2 these are added regardless of the status of the relevant parameter
        // Just picks the first organization. There should only be one.
        ourOrganizationDetails = ourOrganizationsDetails.get(0);
    } else {
    // do something here .. should never happen
    }
    // find the bookng organization from the ods code
    List<OrganizationDetails> bookingOrganizationsDetails = organizationSearch.findOrganizationDetailsByOrgODSCode(bookingOdsCode);
    OrganizationDetails bookingOrganizationDetails = null;
    if (!bookingOrganizationsDetails.isEmpty()) {
        // at 1.2.2 these are added regardless of the status of the relevant parameter
        // Just picks the first organization. There should only be one.
        bookingOrganizationDetails = bookingOrganizationsDetails.get(0);
    }
    HashSet<BundleEntryComponent> addedSchedule = new HashSet<>();
    HashSet<BundleEntryComponent> addedLocation = new HashSet<>();
    HashSet<String> addedPractitioner = new HashSet<>();
    HashSet<String> addedOrganization = new HashSet<>();
    // issue #165 don't add duplicate slots, hashSet contains slot id as String
    HashSet<String> addedSlot = new HashSet<>();
    // #144 process all locations
    for (String locationId : locationEntries.keySet()) {
        // process the schedules
        for (Schedule schedule : scheduleResourceProvider.getSchedulesForLocationId(locationId, planningHorizonStart, planningHorizonEnd)) {
            boolean slotsAdded = false;
            schedule.getMeta().addProfile(SystemURL.SD_GPC_SCHEDULE);
            BundleEntryComponent scheduleEntry = new BundleEntryComponent();
            scheduleEntry.setResource(schedule);
            // #202 use full urls
            // #215 full url removed completely
            // scheduleEntry.setFullUrl(serverBaseUrl + "Schedule/" + schedule.getIdElement().getIdPart());
            // This Set does not work as expected because Slot does not implement hashCode
            // so the second set call to getSlots returns different objects with the same slot id
            Set<Slot> slots = new HashSet<>();
            // 
            if (bookingOrgType.isEmpty() && bookingOdsCode.isEmpty()) {
                // OPTION 1 get slots Specfying  neither org type nor org code
                slots.addAll(slotResourceProvider.getSlotsForScheduleIdNoOrganizationTypeOrODS(schedule.getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd));
            } else if (!bookingOrgType.isEmpty() && bookingOdsCode.isEmpty()) {
                // OPTION 2 organisation type only
                for (Slot slot : slotResourceProvider.getSlotsForScheduleId(schedule.getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd)) {
                    SlotDetail slotDetail = slotSearch.findSlotByID(Long.parseLong(slot.getId()));
                    if (slotDetail.getOrganizationIds().isEmpty() && (slotDetail.getOrganizationTypes().isEmpty() || slotDetail.getOrganizationTypes().contains(bookingOrgType))) {
                        slots.add(slot);
                    }
                }
            } else if (!bookingOdsCode.isEmpty() && bookingOrgType.isEmpty()) {
                // OPTION 3 org code only
                for (Slot slot : slotResourceProvider.getSlotsForScheduleId(schedule.getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd)) {
                    SlotDetail slotDetail = slotSearch.findSlotByID(Long.parseLong(slot.getId()));
                    if (slotDetail.getOrganizationTypes().isEmpty() && (slotDetail.getOrganizationIds().isEmpty() || bookingOrganizationDetails != null && slotDetail.getOrganizationIds().contains(bookingOrganizationDetails.getId()))) {
                        slots.add(slot);
                    }
                }
            } else if (!bookingOrgType.isEmpty() && !bookingOdsCode.isEmpty()) {
                // OPTION 4 both org code and org type
                for (Slot slot : slotResourceProvider.getSlotsForScheduleId(schedule.getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd)) {
                    SlotDetail slotDetail = slotSearch.findSlotByID(Long.parseLong(slot.getId()));
                    if (((slotDetail.getOrganizationTypes().isEmpty() || slotDetail.getOrganizationTypes().contains(bookingOrgType))) && (slotDetail.getOrganizationIds().isEmpty() || bookingOrganizationDetails != null && slotDetail.getOrganizationIds().contains(bookingOrganizationDetails.getId()))) {
                        slots.add(slot);
                    }
                }
            }
            // added at 1.2.2 add the organisation but only if there are some slots available
            if (slots.size() > 0 && ourOrganizationDetails != null && !addedOrganization.contains(ourOrganizationDetails.getOrgCode())) {
                addOrganisation(ourOrganizationDetails, bundle);
                addedOrganization.add(ourOrganizationDetails.getOrgCode());
            }
            String freeBusyType = "FREE";
            // process all the slots to be returned
            for (Slot slot : slots) {
                if (freeBusyType.equalsIgnoreCase(slot.getStatus().toString())) {
                    String slotId = slot.getIdElement().getIdPart();
                    if (!addedSlot.contains(slotId)) {
                        BundleEntryComponent slotEntry = new BundleEntryComponent();
                        slotEntry.setResource(slot);
                        // #202 use full urls
                        // #215 full url removed completely
                        // slotEntry.setFullUrl(serverBaseUrl + "Slot/" + slotId);
                        bundle.addEntry(slotEntry);
                        addedSlot.add(slotId);
                        slotsAdded = true;
                    }
                    if (!addedSchedule.contains(scheduleEntry)) {
                        // only add a schedule if there's a reference to it and only add it once
                        bundle.addEntry(scheduleEntry);
                        addedSchedule.add(scheduleEntry);
                    }
                    if (actorLocation == true) {
                        // only add a unique location once
                        if (!addedLocation.contains(locationEntries.get(locationId))) {
                            bundle.addEntry(locationEntries.get(locationId));
                            addedLocation.add(locationEntries.get(locationId));
                        }
                    }
                }
            // if free/busy status matches
            }
            // # 193 for each schedule only add a practitioner if there have been some slots added.
            if (slotsAdded) {
                // practitioners for this schedule
                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) {
                            if (!addedPractitioner.contains(practitioner.getIdElement().getIdPart())) {
                                addPractitioner(practitioner, bundle);
                                addedPractitioner.add(practitioner.getIdElement().getIdPart());
                            }
                        }
                    }
                // for practitioner
                }
            // if non empty practitioner list
            }
        // if slots added
        }
    // for schedules
    }
// for location
}
Also used : HashMap(java.util.HashMap) LocationDetails(uk.gov.hscic.model.location.LocationDetails) Reference(org.hl7.fhir.dstu3.model.Reference) OrganizationDetails(uk.gov.hscic.model.organization.OrganizationDetails) IdType(org.hl7.fhir.dstu3.model.IdType) 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) SlotDetail(uk.gov.hscic.model.appointment.SlotDetail) Location(org.hl7.fhir.dstu3.model.Location) HashSet(java.util.HashSet) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 5 with Schedule

use of com.google.api.services.storagetransfer.v1.model.Schedule in project gpconnect-demonstrator by nhsconnect.

the class ScheduleResourceProvider method getSchedulesForLocationId.

public List<Schedule> getSchedulesForLocationId(String locationId, Date startDateTime, Date endDateTime) {
    ArrayList<Schedule> schedules = new ArrayList<>();
    List<ScheduleDetail> scheduleDetails = scheduleSearch.findScheduleForLocationId(Long.valueOf(locationId), startDateTime, endDateTime);
    if (scheduleDetails != null && !scheduleDetails.isEmpty()) {
        for (ScheduleDetail scheduleDetail : scheduleDetails) {
            schedules.add(scheduleDetailToScheduleResourceConverter(scheduleDetail));
        }
    }
    return schedules;
}
Also used : Schedule(org.hl7.fhir.dstu3.model.Schedule) ArrayList(java.util.ArrayList) ScheduleDetail(uk.gov.hscic.model.appointment.ScheduleDetail)

Aggregations

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 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)2 Coding (org.hl7.fhir.dstu3.model.Coding)2 IdType (org.hl7.fhir.dstu3.model.IdType)2 Reference (org.hl7.fhir.dstu3.model.Reference)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 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1