Search in sources :

Example 16 with IdType

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

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

the class PatientResourceProvider method patientDetailsToMinimalPatient.

private Patient patientDetailsToMinimalPatient(PatientDetails patientDetails) throws FHIRException {
    Patient patient = new Patient();
    Date lastUpdated = patientDetails.getLastUpdated() == null ? new Date() : patientDetails.getLastUpdated();
    String resourceId = String.valueOf(patientDetails.getId());
    String versionId = String.valueOf(lastUpdated.getTime());
    String resourceType = patient.getResourceType().toString();
    IdType id = new IdType(resourceType, resourceId, versionId);
    patient.setId(id);
    patient.getMeta().setVersionId(versionId);
    patient.getMeta().setLastUpdated(lastUpdated);
    patient.getMeta().addProfile(SystemURL.SD_GPC_PATIENT);
    Identifier patientNhsNumber = new Identifier().setSystem(SystemURL.ID_NHS_NUMBER).setValue(patientDetails.getNhsNumber());
    Extension extension = createCodingExtension("01", "Number present and verified", SystemURL.CS_CC_NHS_NUMBER_VERIF, SystemURL.SD_CC_EXT_NHS_NUMBER_VERIF);
    patientNhsNumber.addExtension(extension);
    patient.addIdentifier(patientNhsNumber);
    patient.setBirthDate(patientDetails.getDateOfBirth());
    String gender = patientDetails.getGender();
    if (gender != null) {
        patient.setGender(AdministrativeGender.fromCode(gender.toLowerCase(Locale.UK)));
    }
    Date registrationEndDateTime = patientDetails.getRegistrationEndDateTime();
    Date registrationStartDateTime = patientDetails.getRegistrationStartDateTime();
    Extension regDetailsExtension = new Extension(SystemURL.SD_EXTENSION_CC_REG_DETAILS);
    Period registrationPeriod = new Period().setStart(registrationStartDateTime).setEnd(registrationEndDateTime);
    Extension regPeriodExt = new Extension(SystemURL.SD_CC_EXT_REGISTRATION_PERIOD, registrationPeriod);
    regDetailsExtension.addExtension(regPeriodExt);
    String registrationStatusValue = patientDetails.getRegistrationStatus();
    patient.setActive(ACTIVE_REGISTRATION_STATUS.equals(registrationStatusValue) || null == registrationStatusValue);
    String registrationTypeValue = patientDetails.getRegistrationType();
    if (registrationTypeValue != null) {
        Coding regTypeCode = new Coding();
        regTypeCode.setCode(registrationTypeValue);
        // Should always be Temporary
        regTypeCode.setDisplay("Temporary");
        regTypeCode.setSystem(SystemURL.CS_REGISTRATION_TYPE);
        CodeableConcept regTypeConcept = new CodeableConcept();
        regTypeConcept.addCoding(regTypeCode);
        Extension regTypeExt = new Extension(SystemURL.SD_CC_EXT_REGISTRATION_TYPE, regTypeConcept);
        regDetailsExtension.addExtension(regTypeExt);
    }
    patient.addExtension(regDetailsExtension);
    String maritalStatus = patientDetails.getMaritalStatus();
    if (maritalStatus != null) {
        CodeableConcept marital = new CodeableConcept();
        Coding maritalCoding = new Coding();
        maritalCoding.setSystem(SystemURL.VS_CC_MARITAL_STATUS);
        maritalCoding.setCode(patientDetails.getMaritalStatus());
        maritalCoding.setDisplay("Married");
        marital.addCoding(maritalCoding);
        patient.setMaritalStatus(marital);
    }
    patient.setMultipleBirth(patientDetails.isMultipleBirth());
    if (patientDetails.isDeceased()) {
        DateTimeType decesed = new DateTimeType(patientDetails.getDeceased());
        patient.setDeceased(decesed);
    }
    return patient;
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) Patient(org.hl7.fhir.dstu3.model.Patient) Period(org.hl7.fhir.dstu3.model.Period) Date(java.util.Date) IdType(org.hl7.fhir.dstu3.model.IdType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 18 with IdType

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

IdType (org.hl7.fhir.dstu3.model.IdType)10 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)7 Coding (org.hl7.fhir.dstu3.model.Coding)7 Identifier (org.hl7.fhir.dstu3.model.Identifier)7 Reference (org.hl7.fhir.dstu3.model.Reference)7 Read (ca.uhn.fhir.rest.annotation.Read)6 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Extension (org.hl7.fhir.dstu3.model.Extension)4 Search (ca.uhn.fhir.rest.annotation.Search)3 Appointment (org.hl7.fhir.dstu3.model.Appointment)3 Location (org.hl7.fhir.dstu3.model.Location)3 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)3 InternalErrorException (ca.uhn.fhir.rest.server.exceptions.InternalErrorException)2 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)2 Organization (org.hl7.fhir.dstu3.model.Organization)2 Patient (org.hl7.fhir.dstu3.model.Patient)2 Practitioner (org.hl7.fhir.dstu3.model.Practitioner)2 AppointmentDetail (uk.gov.hscic.model.appointment.AppointmentDetail)2