Search in sources :

Example 6 with Location

use of org.hl7.fhir.dstu3.model.Location in project metacat by Netflix.

the class S3ConnectorInfoConverter method toAuditInfo.

/**
 * Creates audit info from s3 table info.
 * @param table table info
 * @return audit info
 */
public AuditInfo toAuditInfo(final Table table) {
    final AuditInfo result = AuditInfo.builder().createdDate(table.getCreatedDate()).lastModifiedDate(table.getLastUpdatedDate()).build();
    final Location location = table.getLocation();
    if (location != null) {
        final Info info = location.getInfo();
        if (info != null) {
            result.setCreatedBy(info.getOwner());
            result.setLastModifiedBy(info.getOwner());
        }
    }
    return result;
}
Also used : AuditInfo(com.netflix.metacat.common.server.connectors.model.AuditInfo) AuditInfo(com.netflix.metacat.common.server.connectors.model.AuditInfo) DatabaseInfo(com.netflix.metacat.common.server.connectors.model.DatabaseInfo) FieldInfo(com.netflix.metacat.common.server.connectors.model.FieldInfo) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo) StorageInfo(com.netflix.metacat.common.server.connectors.model.StorageInfo) Info(com.netflix.metacat.connector.s3.model.Info) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) Location(com.netflix.metacat.connector.s3.model.Location)

Example 7 with Location

use of org.hl7.fhir.dstu3.model.Location in project metacat by Netflix.

the class S3ConnectorInfoConverter method toLocation.

/**
 * Creates location.
 * @param tableInfo table info
 * @return location
 */
public Location toLocation(final TableInfo tableInfo) {
    final Location location = fromStorageInfo(tableInfo.getSerde());
    final Schema schema = new Schema();
    schema.setLocation(location);
    schema.setFields(toFields(tableInfo, schema));
    location.setSchema(schema);
    return location;
}
Also used : Schema(com.netflix.metacat.connector.s3.model.Schema) Location(com.netflix.metacat.connector.s3.model.Location)

Example 8 with Location

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

the class AppointmentResourceProvider method appointmentResourceConverterToAppointmentDetail.

/**
 * fhir resource Appointment to AppointmentDetail
 *
 * @param appointment Resource
 * @return populated AppointmentDetail
 */
private AppointmentDetail appointmentResourceConverterToAppointmentDetail(Appointment appointment) {
    appointmentValidation.validateAppointmentExtensions(appointment.getExtension());
    if (appointmentValidation.appointmentDescriptionTooLong(appointment)) {
        throwUnprocessableEntity422_InvalidResourceException("Appointment description cannot be greater then " + APPOINTMENT_DESCRIPTION_LENGTH + " 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) {
            throwInvalidRequest400_BadRequestException("Cancellation reason missing.");
        }
        appointmentDetail.setCancellationReason(value.toString());
    }
    appointmentDetail.setStatus(appointment.getStatus().toString().toLowerCase(Locale.UK));
    appointmentDetail.setMinutesDuration(appointment.getMinutesDuration());
    appointmentDetail.setPriority(appointment.getPriority());
    appointmentDetail.setStartDateTime(appointment.getStart());
    appointmentDetail.setEndDateTime(appointment.getEnd());
    List<Long> slotIds = new ArrayList<>();
    for (Reference slotReference : appointment.getSlot()) {
        // #200 check slots for absolute references
        checkReferenceIsRelative(slotReference.getReference());
        try {
            String here = slotReference.getReference().substring("Slot/".length());
            Long slotId = new Long(here);
            slotIds.add(slotId);
        } catch (NumberFormatException ex) {
            throwUnprocessableEntity422_InvalidResourceException(String.format("The slot reference value data type for %s is not valid.", slotReference.getReference()));
        }
    }
    appointmentDetail.setSlotIds(slotIds);
    if (appointmentValidation.appointmentCommentTooLong(appointment)) {
        throwUnprocessableEntity422_InvalidResourceException("Appointment comment cannot be greater than " + APPOINTMENT_COMMENT_LENGTH + " characters");
    }
    appointmentDetail.setComment(appointment.getComment());
    appointmentDetail.setDescription(appointment.getDescription());
    for (AppointmentParticipantComponent participant : appointment.getParticipant()) {
        if (participant.getActor() != null) {
            String participantReference = participant.getActor().getReference();
            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 {
            throwUnprocessableEntity422_InvalidResourceException("Participant Actor cannot be null");
        }
    }
    if (appointment.getCreated() != null) {
        Date created = appointment.getCreated();
        appointmentDetail.setCreated(created);
    }
    // #200 check extensions for absolute references
    List<Extension> extensions = appointment.getExtension();
    for (Extension extension : extensions) {
        try {
            Reference reference = (Reference) extension.getValue();
            if (reference != null) {
                checkReferenceIsRelative(reference.getReference());
            }
        } catch (ClassCastException ex) {
        }
    }
    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());
        // #198 add system and optional use type. Pick system phone if > 1 and available otherwise use the one supplied
        Iterator<ContactPoint> iter = bookingOrgRes.getTelecom().iterator();
        ContactPoint telecom = bookingOrgRes.getTelecomFirstRep();
        while (iter.hasNext()) {
            ContactPoint thisTelecom = iter.next();
            if (thisTelecom.getSystem() == ContactPoint.ContactPointSystem.PHONE) {
                telecom = thisTelecom;
                break;
            }
        }
        bookingOrgDetail.setTelephone(telecom.getValue());
        bookingOrgDetail.setSystem(telecom.getSystem().toString());
        if (telecom.getUse() != null && !telecom.getUse().toString().trim().isEmpty()) {
            bookingOrgDetail.setUsetype(telecom.getUse().toString());
        }
        if (!bookingOrgRes.getIdentifier().isEmpty()) {
            bookingOrgDetail.setOrgCode(bookingOrgRes.getIdentifierFirstRep().getValue());
            String system = bookingOrgRes.getIdentifierFirstRep().getSystem();
            // check that organization identifier system is https://fhir.nhs.uk/Id/ods-organization-code
            if (system != null && !system.trim().isEmpty()) {
                if (!system.equals(ID_ODS_ORGANIZATION_CODE)) {
                    throwUnprocessableEntity422_InvalidResourceException("Appointment organisation identifier system must be an ODS code!");
                }
            } else {
                throwUnprocessableEntity422_InvalidResourceException("Appointment organisation identifier system must be populated!");
            }
        }
        bookingOrgDetail.setAppointmentDetail(appointmentDetail);
        appointmentDetail.setBookingOrganization(bookingOrgDetail);
        // 1.2.7
        appointmentDetail.setServiceCategory(appointment.getServiceCategory().getText());
        appointmentDetail.setServiceType(appointment.getServiceTypeFirstRep().getText());
    }
    return appointmentDetail;
}
Also used : AppointmentParticipantComponent(org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent) IBaseDatatype(org.hl7.fhir.instance.model.api.IBaseDatatype) AppointmentDetail(uk.gov.hscic.model.appointment.AppointmentDetail) BookingOrgDetail(uk.gov.hscic.model.appointment.BookingOrgDetail)

Example 9 with Location

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

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

Aggregations

Location (com.netflix.metacat.connector.s3.model.Location)9 Location (com.google.api.services.appengine.v1.model.Location)6 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)6 Info (com.netflix.metacat.connector.s3.model.Info)6 FieldInfo (com.netflix.metacat.common.server.connectors.model.FieldInfo)5 AuditInfo (com.netflix.metacat.common.server.connectors.model.AuditInfo)4 DatabaseInfo (com.netflix.metacat.common.server.connectors.model.DatabaseInfo)4 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)4 StorageInfo (com.netflix.metacat.common.server.connectors.model.StorageInfo)4 Schema (com.netflix.metacat.connector.s3.model.Schema)4 Reference (org.hl7.fhir.dstu3.model.Reference)4 Field (com.netflix.metacat.connector.s3.model.Field)3 Table (com.netflix.metacat.connector.s3.model.Table)3 IdType (org.hl7.fhir.dstu3.model.IdType)3 Location (org.hl7.fhir.dstu3.model.Location)3 SlotDetail (uk.gov.hscic.model.appointment.SlotDetail)3 LocationDetails (uk.gov.hscic.model.location.LocationDetails)3 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 ListLocationsResponse (com.google.api.services.appengine.v1.model.ListLocationsResponse)2 QualifiedName (com.netflix.metacat.common.QualifiedName)2