Search in sources :

Example 6 with Period

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

the class MedicationRequestResourceProvider method getDispenseRequestComponent.

private MedicationRequestDispenseRequestComponent getDispenseRequestComponent(MedicationRequestDetail requestDetail) {
    MedicationRequestDispenseRequestComponent dispenseRequest = new MedicationRequestDispenseRequestComponent();
    Period period = new Period().setStart(requestDetail.getDispenseRequestStartDate());
    if (requestDetail.getDispenseRequestEndDate() != null) {
        period.setEnd(requestDetail.getDispenseRequestEndDate());
    }
    dispenseRequest.setValidityPeriod(period);
    setDispenseQuantity(dispenseRequest, requestDetail);
    Duration duration = new Duration();
    duration.setSystem(SystemURL.CS_UNITS_OF_MEASURE);
    duration.setCode("d");
    duration.setValue(requestDetail.getExpectedSupplyDuration());
    duration.setUnit("day");
    // TODO - spec needs to clarify whether this should be populated or not
    dispenseRequest.setExpectedSupplyDuration(duration);
    dispenseRequest.setPerformer(new Reference(new IdType("Organization", requestDetail.getDispenseRequestOrganizationId())));
    return dispenseRequest;
}
Also used : MedicationRequestDispenseRequestComponent(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent)

Example 7 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)

Example 8 with Period

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

the class PatientResourceProvider method IsActiveName.

private Boolean IsActiveName(HumanName name) {
    Period period = name.getPeriod();
    if (null == period) {
        return true;
    }
    Date start = period.getStart();
    Date end = period.getEnd();
    if ((null == end || end.after(new Date())) && (null == start || start.equals(new Date()) || start.before(new Date()))) {
        return true;
    }
    return false;
}
Also used : Period(org.hl7.fhir.dstu3.model.Period) Date(java.util.Date)

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