Search in sources :

Example 61 with ResourceType

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

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

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

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

the class OrganizationResourceProvider method convertOrganizatonDetailsListToOrganizationList.

private List<Organization> convertOrganizatonDetailsListToOrganizationList(List<OrganizationDetails> organizationDetails) {
    Map<Long, Organization> map = new HashMap<>();
    for (OrganizationDetails organizationDetail : organizationDetails) {
        // Changed key to be logical id rather than ods code since can have > 1 org per ods code
        // for 1.2.2
        Long mapKey = organizationDetail.getId();
        if (map.containsKey(mapKey)) {
            continue;
        }
        Identifier identifier = new Identifier().setSystem(SystemURL.ID_ODS_ORGANIZATION_CODE).setValue(organizationDetail.getOrgCode());
        Organization organization = new Organization().setName(organizationDetail.getOrgName()).addIdentifier(identifier);
        String resourceId = String.valueOf(organizationDetail.getId());
        String versionId = String.valueOf(organizationDetail.getLastUpdated().getTime());
        String resourceType = organization.getResourceType().toString();
        IdType id = new IdType(resourceType, resourceId, versionId);
        organization.setId(id);
        organization.getMeta().setVersionId(versionId);
        organization.getMeta().setLastUpdated(organizationDetail.getLastUpdated());
        organization.getMeta().addProfile(SystemURL.SD_GPC_ORGANIZATION);
        organization = addAdditionalProperties(organization);
        map.put(mapKey, organization);
    }
    return new ArrayList<>(map.values());
}
Also used : Organization(org.hl7.fhir.dstu3.model.Organization) Identifier(org.hl7.fhir.dstu3.model.Identifier) HashMap(java.util.HashMap) OrganizationDetails(uk.gov.hscic.model.organization.OrganizationDetails) ArrayList(java.util.ArrayList) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 65 with ResourceType

use of org.hl7.fhir.dstu3.model.ResourceType in project dpc-app by CMSgov.

the class DataServiceTest method whenGetJobBatchesReturnsCompletedJobWithResourceType.

@Test
public void whenGetJobBatchesReturnsCompletedJobWithResourceType() {
    DPCResourceType resourceType = DPCResourceType.ExplanationOfBenefit;
    workJob(false, resourceType);
    Resource resource = dataService.retrieveData(orgID, orgNPI, providerNPI, List.of(patientID.toString()), resourceType);
    Assertions.assertTrue(resource instanceof Bundle);
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) Resource(org.hl7.fhir.dstu3.model.Resource) DPCResourceType(gov.cms.dpc.fhir.DPCResourceType) Test(org.junit.jupiter.api.Test)

Aggregations

JsonElement (com.google.gson.JsonElement)33 HashSet (java.util.HashSet)26 Bundle (org.hl7.fhir.r4.model.Bundle)24 ResourceType (org.hl7.fhir.r4.model.Enumerations.ResourceType)21 Test (org.junit.Test)20 Nonnull (javax.annotation.Nonnull)18 ArrayList (java.util.ArrayList)15 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)10 FhirContext (ca.uhn.fhir.context.FhirContext)9 File (java.io.File)9 Row (org.apache.spark.sql.Row)9 IdType (org.hl7.fhir.dstu3.model.IdType)9 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)9 JsonObject (com.google.gson.JsonObject)8 Test (org.junit.jupiter.api.Test)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 IOException (java.io.IOException)7 List (java.util.List)7 Bundle (org.hl7.fhir.dstu3.model.Bundle)7 Resource (org.hl7.fhir.r4.model.Resource)7