Search in sources :

Example 1 with Period

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

the class PatientResourceProvider method setStaticPatientData.

private Patient setStaticPatientData(Patient patient) {
    patient.setLanguage(("en-GB"));
    patient.addExtension(createCodingExtension("CG", "Greek Cypriot", SystemURL.CS_CC_ETHNIC_CATEGORY, SystemURL.SD_CC_EXT_ETHNIC_CATEGORY));
    patient.addExtension(createCodingExtension("SomeSnomedCode", "Some Snomed Code", SystemURL.CS_CC_RELIGIOUS_AFFILI, SystemURL.SD_CC_EXT_RELIGIOUS_AFFILI));
    patient.addExtension(new Extension(SystemURL.SD_PATIENT_CADAVERIC_DON, new BooleanType(false)));
    patient.addExtension(createCodingExtension("H", "UK Resident", SystemURL.CS_CC_RESIDENTIAL_STATUS, SystemURL.SD_CC_EXT_RESIDENTIAL_STATUS));
    patient.addExtension(createCodingExtension("3", "To pay hotel fees only", SystemURL.CS_CC_TREATMENT_CAT, SystemURL.SD_CC_EXT_TREATMENT_CAT));
    Extension nhsCommExtension = new Extension();
    nhsCommExtension.setUrl(SystemURL.SD_CC_EXT_NHS_COMMUNICATION);
    nhsCommExtension.addExtension(createCodingExtension("en", "English", SystemURL.CS_CC_HUMAN_LANG, SystemURL.SD_CC_EXT_COMM_LANGUAGE));
    nhsCommExtension.addExtension(new Extension(SystemURL.SD_CC_COMM_PREFERRED, new BooleanType(false)));
    nhsCommExtension.addExtension(createCodingExtension("RWR", "Received written", SystemURL.CS_CC_LANG_ABILITY_MODE, SystemURL.SD_CC_MODE_OF_COMM));
    nhsCommExtension.addExtension(createCodingExtension("E", "Excellent", SystemURL.CS_CC_LANG_ABILITY_PROFI, SystemURL.SD_CC_COMM_PROFICIENCY));
    nhsCommExtension.addExtension(new Extension(SystemURL.SD_CC_INTERPRETER_REQUIRED, new BooleanType(false)));
    patient.addExtension(nhsCommExtension);
    Identifier localIdentifier = new Identifier();
    localIdentifier.setUse(IdentifierUse.USUAL);
    localIdentifier.setSystem(SystemURL.ID_LOCAL_PATIENT_IDENTIFIER);
    localIdentifier.setValue("123456");
    CodeableConcept liType = new CodeableConcept();
    Coding liTypeCoding = new Coding();
    liTypeCoding.setCode("EN");
    liTypeCoding.setDisplay("Employer number");
    liTypeCoding.setSystem(SystemURL.VS_IDENTIFIER_TYPE);
    liType.addCoding(liTypeCoding);
    localIdentifier.setType(liType);
    localIdentifier.setAssigner(new Reference("Organization/1"));
    patient.addIdentifier(localIdentifier);
    Calendar calendar = Calendar.getInstance();
    calendar.set(2017, 1, 1);
    DateTimeDt endDate = new DateTimeDt(calendar.getTime());
    calendar.set(2016, 1, 1);
    DateTimeDt startDate = new DateTimeDt(calendar.getTime());
    Period pastPeriod = new Period().setStart(calendar.getTime()).setEnd(calendar.getTime());
    patient.addName().setFamily("AnotherOfficialFamilyName").addGiven("AnotherOfficialGivenName").setUse(NameUse.OFFICIAL).setPeriod(pastPeriod);
    patient.addName().setFamily("AdditionalFamily").addGiven("AdditionalGiven").setUse(NameUse.TEMP);
    patient.addTelecom(staticElHelper.getValidTelecom());
    patient.addAddress(staticElHelper.getValidAddress());
    return patient;
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Identifier(org.hl7.fhir.dstu3.model.Identifier) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) Coding(org.hl7.fhir.dstu3.model.Coding) Reference(org.hl7.fhir.dstu3.model.Reference) Calendar(java.util.Calendar) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) Period(org.hl7.fhir.dstu3.model.Period) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 2 with Period

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

the class PatientResourceProvider method StructuredRecordOperation.

@Operation(name = GET_STRUCTURED_RECORD_OPERATION_NAME)
public Bundle StructuredRecordOperation(@ResourceParam Parameters params) throws FHIRException {
    Bundle structuredBundle = new Bundle();
    Boolean getAllergies = false;
    Boolean includeResolved = false;
    Boolean getMedications = false;
    Boolean includePrescriptionIssues = false;
    Period medicationPeriod = null;
    String NHS = getNhsNumber(params);
    PatientDetails patientDetails = patientSearch.findPatient(NHS);
    // see https://nhsconnect.github.io/gpconnect/accessrecord_structured_development_retrieve_patient_record.html#error-handling
    if (patientDetails == null || patientDetails.isSensitive() || patientDetails.isDeceased() || !patientDetails.isActive()) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new ResourceNotFoundException("No patient details found for patient ID: " + NHS), SystemCode.PATIENT_NOT_FOUND, IssueType.NOTFOUND);
    }
    if (NHS.equals(patientNoconsent)) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new ForbiddenOperationException("No patient consent to share for patient ID: " + NHS), SystemCode.NO_PATIENT_CONSENT, IssueType.FORBIDDEN);
    }
    operationOutcome = null;
    for (ParametersParameterComponent param : params.getParameter()) {
        if (validateParametersName(param.getName())) {
            if (param.getName().equals(SystemConstants.INCLUDE_ALLERGIES)) {
                getAllergies = true;
                if (param.getPart().isEmpty()) {
                    // addWarningIssue(param, IssueType.REQUIRED, "Miss parameter part : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES);
                    throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Miss parameter : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES), SystemCode.INVALID_PARAMETER, IssueType.REQUIRED);
                }
                boolean includeResolvedParameterPartPresent = false;
                for (ParametersParameterComponent paramPart : param.getPart()) {
                    if (paramPart.getName().equals(SystemConstants.INCLUDE_RESOLVED_ALLERGIES)) {
                        if (paramPart.getValue() instanceof BooleanType) {
                            includeResolved = Boolean.valueOf(paramPart.getValue().primitiveValue());
                            includeResolvedParameterPartPresent = true;
                        } else {
                            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Miss parameter : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES), SystemCode.INVALID_PARAMETER, IssueType.REQUIRED);
                        }
                    } else {
                        addWarningIssue(param, paramPart, IssueType.NOTSUPPORTED);
                    // throw OperationOutcomeFactory.buildOperationOutcomeException(
                    // new UnprocessableEntityException("Incorrect parameter passed : " + paramPart.getName()),
                    // SystemCode.INVALID_PARAMETER, IssueType.INVALID);
                    }
                }
                if (!includeResolvedParameterPartPresent) {
                    throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Miss parameter : " + SystemConstants.INCLUDE_RESOLVED_ALLERGIES), SystemCode.INVALID_PARAMETER, IssueType.REQUIRED);
                }
            }
            if (param.getName().equals(SystemConstants.INCLUDE_MEDICATION)) {
                getMedications = true;
                boolean isIncludedPrescriptionIssuesExist = false;
                for (ParametersParameterComponent paramPart : param.getPart()) {
                    if (paramPart.getName().equals(SystemConstants.INCLUDE_PRESCRIPTION_ISSUES)) {
                        if (paramPart.getValue() instanceof BooleanType) {
                            includePrescriptionIssues = Boolean.valueOf(paramPart.getValue().primitiveValue());
                            isIncludedPrescriptionIssuesExist = true;
                        }
                    } else if (paramPart.getName().equals(SystemConstants.MEDICATION_SEARCH_FROM_DATE) && paramPart.getValue() instanceof DateType) {
                        DateType startDateDt = (DateType) paramPart.getValue();
                        medicationPeriod = new Period();
                        medicationPeriod.setStart(startDateDt.getValue());
                        medicationPeriod.setEnd(null);
                        String startDate = startDateDt.asStringValue();
                        if (!validateStartDateParamAndEndDateParam(startDate, null)) {
                        // addWarningIssue(param, paramPart, IssueType.INVALID, "Invalid date used");
                        }
                    } else {
                        addWarningIssue(param, paramPart, IssueType.NOTSUPPORTED);
                    // throw OperationOutcomeFactory.buildOperationOutcomeException(
                    // new UnprocessableEntityException("Incorrect parameter passed : " + paramPart.getName()),
                    // SystemCode.INVALID_PARAMETER, IssueType.INVALID);
                    }
                }
                if (!isIncludedPrescriptionIssuesExist) {
                    // # 1.2.6 now defaults to true if not provided
                    includePrescriptionIssues = true;
                }
            }
        } else {
            // invalid parameter
            addWarningIssue(param, IssueType.NOTSUPPORTED);
        }
    }
    // for parameter
    // Add Patient
    Patient patient = patientDetailsToPatientResourceConverter(patientDetails);
    if (patient.getIdentifierFirstRep().getValue().equals(NHS)) {
        structuredBundle.addEntry().setResource(patient);
    }
    // Organization from patient
    Set<String> orgIds = new HashSet<>();
    orgIds.add(patientDetails.getManagingOrganization());
    // Practitioner from patient
    Set<String> practitionerIds = new HashSet<>();
    List<Reference> practitionerReferenceList = patient.getGeneralPractitioner();
    practitionerReferenceList.forEach(practitionerReference -> {
        String[] pracRef = practitionerReference.getReference().split("/");
        if (pracRef.length > 1) {
            practitionerIds.add(pracRef[1]);
        }
    });
    if (getAllergies) {
        structuredBundle = structuredAllergyIntoleranceBuilder.buildStructuredAllergyIntolerence(NHS, practitionerIds, structuredBundle, includeResolved);
    }
    if (getMedications) {
        structuredBundle = populateMedicationBundle.addMedicationBundleEntries(structuredBundle, patientDetails, includePrescriptionIssues, medicationPeriod, practitionerIds, orgIds);
    }
    // Add all practitioners and practitioner roles
    for (String practitionerId : practitionerIds) {
        Practitioner pracResource = practitionerResourceProvider.getPractitionerById(new IdType(practitionerId));
        structuredBundle.addEntry().setResource(pracResource);
        List<PractitionerRole> practitionerRoleList = practitionerRoleResourceProvider.getPractitionerRoleByPracticionerId(new IdType(practitionerId));
        for (PractitionerRole role : practitionerRoleList) {
            String[] split = role.getOrganization().getReference().split("/");
            orgIds.add(split[1]);
            structuredBundle.addEntry().setResource(role);
        }
    }
    // Add all organizations
    for (String orgId : orgIds) {
        OrganizationDetails organizationDetails = organizationSearch.findOrganizationDetails(new Long(orgId));
        Organization organization = organizationResourceProvider.convertOrganizationDetailsToOrganization(organizationDetails);
        structuredBundle.addEntry().setResource(organization);
    }
    structuredBundle.setType(BundleType.COLLECTION);
    structuredBundle.getMeta().addProfile(SystemURL.SD_GPC_STRUCTURED_BUNDLE);
    if (operationOutcome != null) {
        structuredBundle.addEntry().setResource(operationOutcome);
    } else {
        removeDuplicateResources(structuredBundle);
    }
    return structuredBundle;
}
Also used : OrganizationDetails(uk.gov.hscic.model.organization.OrganizationDetails) ForbiddenOperationException(ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) PopulateMedicationBundle(uk.gov.hscic.medications.PopulateMedicationBundle) PatientDetails(uk.gov.hscic.model.patient.PatientDetails) ParametersParameterComponent(org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent)

Example 3 with Period

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

the class PopulateMedicationBundle method addMedicationBundleEntries.

public Bundle addMedicationBundleEntries(Bundle structuredBundle, PatientDetails patientDetails, Boolean includePrescriptionIssues, Period medicationPeriod, Set<String> practitionerIds, Set<String> orgIds) {
    BundleEntryComponent listEntry = new BundleEntryComponent();
    List<MedicationStatementDetail> medicationStatements = findMedicationStatements(Long.valueOf(patientDetails.getId()), medicationPeriod);
    structuredBundle.addEntry(listEntry.setResource(createListEntry(medicationStatements, patientDetails.getNhsNumber())));
    medicationStatements.forEach(medicationStatement -> {
        createBundleEntries(medicationStatement, includePrescriptionIssues, patientDetails, practitionerIds, orgIds).forEach(bundleEntry -> structuredBundle.addEntry(bundleEntry));
    });
    return structuredBundle;
}
Also used : BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) MedicationStatementDetail(uk.gov.hscic.model.medication.MedicationStatementDetail)

Example 4 with Period

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

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

Aggregations

Period (org.hl7.fhir.dstu3.model.Period)4 Date (java.util.Date)3 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)3 Coding (org.hl7.fhir.dstu3.model.Coding)3 Extension (org.hl7.fhir.dstu3.model.Extension)3 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)2 IdType (org.hl7.fhir.dstu3.model.IdType)2 Identifier (org.hl7.fhir.dstu3.model.Identifier)2 Reference (org.hl7.fhir.dstu3.model.Reference)2 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)1 ForbiddenOperationException (ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException)1 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 BooleanType (org.hl7.fhir.dstu3.model.BooleanType)1 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)1 DateTimeType (org.hl7.fhir.dstu3.model.DateTimeType)1 MedicationRequestDispenseRequestComponent (org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent)1 ParametersParameterComponent (org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent)1 Patient (org.hl7.fhir.dstu3.model.Patient)1