Search in sources :

Example 1 with Patient

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

the class MedicationAdministrationResourceProvider method getMedicationAdministrationsForPatientId.

@Search
public List<MedicationAdministration> getMedicationAdministrationsForPatientId(@RequiredParam(name = "patient") String patientId) {
    ArrayList<MedicationAdministration> medicationAdministrations = new ArrayList<>();
    List<MedicationAdministrationDetail> medicationAdministrationDetailList = medicationAdministrationSearch.findMedicationAdministrationForPatient(Long.parseLong(patientId));
    if (medicationAdministrationDetailList != null && !medicationAdministrationDetailList.isEmpty()) {
        for (MedicationAdministrationDetail medicationAdministrationDetail : medicationAdministrationDetailList) {
            MedicationAdministration medicationAdministration = new MedicationAdministration();
            String resourceId = String.valueOf(medicationAdministrationDetail.getId());
            String versionId = String.valueOf(medicationAdministrationDetail.getLastUpdated().getTime());
            String resourceType = medicationAdministration.getResourceType().toString();
            IdType id = new IdType(resourceType, resourceId, versionId);
            medicationAdministration.setId(id);
            medicationAdministration.getMeta().setVersionId(versionId);
            medicationAdministration.getMeta().setLastUpdated(medicationAdministrationDetail.getLastUpdated());
            medicationAdministration.addDefinition(new Reference("Patient/" + medicationAdministrationDetail.getPatientId()));
            medicationAdministration.addDefinition(new Reference("Practitioner/" + medicationAdministrationDetail.getPractitionerId()));
            medicationAdministration.setPrescription(new Reference("MedicationOrder/" + medicationAdministrationDetail.getPrescriptionId()));
            medicationAdministration.setEffective(new DateType(medicationAdministrationDetail.getAdministrationDate()));
            medicationAdministration.setMedication(new Reference("Medication/" + medicationAdministrationDetail.getMedicationId()));
            medicationAdministrations.add(medicationAdministration);
        }
    }
    return medicationAdministrations;
}
Also used : MedicationAdministrationDetail(uk.gov.hscic.model.medication.MedicationAdministrationDetail) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) MedicationAdministration(org.hl7.fhir.dstu3.model.MedicationAdministration) DateType(org.hl7.fhir.dstu3.model.DateType) IdType(org.hl7.fhir.dstu3.model.IdType) Search(ca.uhn.fhir.rest.annotation.Search) MedicationAdministrationSearch(uk.gov.hscic.medication.administration.MedicationAdministrationSearch)

Example 2 with Patient

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

the class MedicationOrderResourceProvider method medicationOrderDetailsToMedicationOrderResourceConverter.

private MedicationRequest medicationOrderDetailsToMedicationOrderResourceConverter(MedicationOrderDetails medicationOrderDetails) {
    MedicationRequest medicationOrder = new MedicationRequest();
    String resourceId = String.valueOf(medicationOrderDetails.getId());
    String versionId = String.valueOf(medicationOrderDetails.getLastUpdated().getTime());
    String resourceType = medicationOrder.getResourceType().toString();
    IdType id = new IdType(resourceType, resourceId, versionId);
    medicationOrder.setId(id);
    medicationOrder.getMeta().setVersionId(versionId);
    medicationOrder.getMeta().setLastUpdated(medicationOrderDetails.getLastUpdated());
    switch(medicationOrderDetails.getOrderStatus().toLowerCase(Locale.UK)) {
        case "active":
            medicationOrder.setStatus(MedicationRequestStatus.ACTIVE);
            break;
        case "completed":
            medicationOrder.setStatus(MedicationRequestStatus.COMPLETED);
            break;
        case "draft":
            medicationOrder.setStatus(MedicationRequestStatus.DRAFT);
            break;
        case "entered_in_error":
            medicationOrder.setStatus(MedicationRequestStatus.ENTEREDINERROR);
            break;
        case "on_hold":
            medicationOrder.setStatus(MedicationRequestStatus.ONHOLD);
            break;
        case "stopped":
            medicationOrder.setStatus(MedicationRequestStatus.STOPPED);
            break;
    }
    if (medicationOrderDetails.getPatientId() != null) {
        medicationOrder.setSubject(new Reference("Patient/" + medicationOrderDetails.getPatientId()));
    } else {
        medicationOrder.setSubject(new Reference());
    }
    medicationOrder.setRecorder(new Reference("Practitioner/" + medicationOrderDetails.getAutherId()));
    medicationOrder.setMedication(new Reference("Medication/" + medicationOrderDetails.getMedicationId()));
    medicationOrder.addDosageInstruction().setText(medicationOrderDetails.getDosageText());
    MedicationRequestDispenseRequestComponent dispenseRequest = new MedicationRequestDispenseRequestComponent();
    dispenseRequest.addExtension(new Extension(SystemURL.SD_EXTENSION_MEDICATION_QUANTITY_TEXT, new StringDt(medicationOrderDetails.getDispenseQuantityText())));
    dispenseRequest.addExtension(new Extension(SystemURL.SD_EXTENSION_PERSCRIPTION_REPEAT_REVIEW_DATE, new DateTimeDt(medicationOrderDetails.getDispenseReviewDate())));
    dispenseRequest.setId("Medication/" + medicationOrderDetails.getDispenseMedicationId());
    dispenseRequest.setNumberOfRepeatsAllowed(medicationOrderDetails.getDispenseRepeatsAllowed());
    medicationOrder.setDispenseRequest(dispenseRequest);
    return medicationOrder;
}
Also used : DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) MedicationRequestDispenseRequestComponent(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent) StringDt(ca.uhn.fhir.model.primitive.StringDt)

Example 3 with Patient

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

the class PatientResourceProvider method validateNames.

private void validateNames(Patient patient) {
    List<HumanName> names = patient.getName();
    if (names.size() < 1) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("The patient must have at least one Name."), SystemCode.BAD_REQUEST, IssueType.INVALID);
    }
    List<HumanName> activeOfficialNames = names.stream().filter(nm -> IsActiveName(nm)).filter(nm -> NameUse.OFFICIAL.equals(nm.getUse())).collect(Collectors.toList());
    if (activeOfficialNames.size() != 1) {
        InvalidRequestException exception = new InvalidRequestException("The patient must have one Active Name with a Use of OFFICIAL");
        throw OperationOutcomeFactory.buildOperationOutcomeException(exception, SystemCode.BAD_REQUEST, IssueType.INVALID);
    }
    List<String> officialFamilyNames = new ArrayList<>();
    for (HumanName humanName : activeOfficialNames) {
        if (humanName.getFamily() != null) {
            officialFamilyNames.add(humanName.getFamily());
        }
    }
    validateNameCount(officialFamilyNames, "family");
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) ParametersParameterComponent(org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent) Type(org.hl7.fhir.dstu3.model.Type) Bundle(org.hl7.fhir.dstu3.model.Bundle) ContactDetail(org.hl7.fhir.dstu3.model.ContactDetail) AppointmentResourceProvider(uk.gov.hscic.appointments.AppointmentResourceProvider) MedicationAdministration(org.hl7.fhir.dstu3.model.MedicationAdministration) Date(java.util.Date) 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) Operation(ca.uhn.fhir.rest.annotation.Operation) Extension(org.hl7.fhir.dstu3.model.Extension) IdentifierUse(org.hl7.fhir.dstu3.model.Identifier.IdentifierUse) NhsCodeValidator(uk.gov.hscic.util.NhsCodeValidator) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Locale(java.util.Locale) IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) Map(java.util.Map) EnumSet(java.util.EnumSet) IdDt(ca.uhn.fhir.model.primitive.IdDt) Reference(org.hl7.fhir.dstu3.model.Reference) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Set(java.util.Set) Count(ca.uhn.fhir.rest.annotation.Count) Collectors(java.util.stream.Collectors) Appointment(org.hl7.fhir.dstu3.model.Appointment) IssueType(org.hl7.fhir.dstu3.model.OperationOutcome.IssueType) AdministrativeGender(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender) List(java.util.List) SortSpec(ca.uhn.fhir.rest.api.SortSpec) IdentifierValidator(uk.gov.hscic.common.validators.IdentifierValidator) PostConstruct(javax.annotation.PostConstruct) ContactPointSystem(org.hl7.fhir.dstu3.model.ContactPoint.ContactPointSystem) SystemCode(uk.gov.hscic.SystemCode) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) NameUse(org.hl7.fhir.dstu3.model.HumanName.NameUse) PatientSearch(uk.gov.hscic.patient.details.PatientSearch) AddressType(org.hl7.fhir.dstu3.model.Address.AddressType) MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) PatientStore(uk.gov.hscic.patient.details.PatientStore) HashMap(java.util.HashMap) PractitionerResourceProvider(uk.gov.hscic.practitioner.PractitionerResourceProvider) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) Calendar(java.util.Calendar) UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) MedicationOrderResourceProvider(uk.gov.hscic.medications.MedicationOrderResourceProvider) AddressUse(org.hl7.fhir.dstu3.model.Address.AddressUse) Search(ca.uhn.fhir.rest.annotation.Search) Period(org.hl7.fhir.dstu3.model.Period) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Read(ca.uhn.fhir.rest.annotation.Read) Practitioner(org.hl7.fhir.dstu3.model.Practitioner) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Sort(ca.uhn.fhir.rest.annotation.Sort) PatientDetails(uk.gov.hscic.model.patient.PatientDetails) BundleType(org.hl7.fhir.dstu3.model.Bundle.BundleType) SystemURL(uk.gov.hscic.SystemURL) TokenParam(ca.uhn.fhir.rest.param.TokenParam) MedicationAdministrationResourceProvider(uk.gov.hscic.medications.MedicationAdministrationResourceProvider) OperationOutcomeFactory(uk.gov.hscic.OperationOutcomeFactory) Component(org.springframework.stereotype.Component) ResourceParam(ca.uhn.fhir.rest.annotation.ResourceParam) StaticElementsHelper(uk.gov.hscic.common.helpers.StaticElementsHelper) MedicationDispenseResourceProvider(uk.gov.hscic.medications.MedicationDispenseResourceProvider) Patient(org.hl7.fhir.dstu3.model.Patient) DateAndListParam(ca.uhn.fhir.rest.param.DateAndListParam) ContactPointUse(org.hl7.fhir.dstu3.model.ContactPoint.ContactPointUse) Parameters(org.hl7.fhir.dstu3.model.Parameters) OrganizationResourceProvider(uk.gov.hscic.organization.OrganizationResourceProvider) MedicationDispense(org.hl7.fhir.dstu3.model.MedicationDispense) FHIRException(org.hl7.fhir.exceptions.FHIRException) Collections(java.util.Collections) HumanName(org.hl7.fhir.dstu3.model.HumanName) HumanName(org.hl7.fhir.dstu3.model.HumanName) ArrayList(java.util.ArrayList) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)

Example 4 with Patient

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

the class PatientResourceProvider method valiateGender.

private void valiateGender(Patient patient) {
    AdministrativeGender gender = patient.getGender();
    if (gender != null) {
        EnumSet<AdministrativeGender> genderList = EnumSet.allOf(AdministrativeGender.class);
        Boolean valid = false;
        for (AdministrativeGender genderItem : genderList) {
            if (genderItem.toCode().equalsIgnoreCase(gender.toString())) {
                valid = true;
                break;
            }
        }
        if (!valid) {
            throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException(String.format("The supplied Patient gender %s is an unrecognised type.", gender)), SystemCode.BAD_REQUEST, IssueType.INVALID);
        }
    }
}
Also used : InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) AdministrativeGender(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender)

Example 5 with Patient

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

Aggregations

ArrayList (java.util.ArrayList)8 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)7 Patient (org.hl7.fhir.dstu3.model.Patient)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)7 Reference (org.hl7.fhir.dstu3.model.Reference)6 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)5 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)5 Extension (org.hl7.fhir.dstu3.model.Extension)5 IdDt (ca.uhn.fhir.model.primitive.IdDt)4 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)4 Date (java.util.Date)4 Coding (org.hl7.fhir.dstu3.model.Coding)4 AdministrativeGender (org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender)4 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)3 Search (ca.uhn.fhir.rest.annotation.Search)3 Calendar (java.util.Calendar)3 Collectors (java.util.stream.Collectors)3 IdType (org.hl7.fhir.dstu3.model.IdType)3 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)3 PatientDetails (uk.gov.hscic.model.patient.PatientDetails)3