Search in sources :

Example 21 with Reference

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

the class StructuredAllergyIntoleranceBuilder method listResourceBuilder.

private void listResourceBuilder(ListResource buildingListResource, AllergyIntolerance allergyIntolerance, boolean isResolved) {
    ListEntryComponent comp = new ListEntryComponent();
    if (isResolved) {
        buildingListResource.addContained(allergyIntolerance);
        Reference allergyReference = new Reference("#" + allergyIntolerance.getId());
        comp.setItem(allergyReference);
    } else {
        Reference allergyReference = new Reference("AllergyIntolerance/" + allergyIntolerance.getId());
        comp.setItem(allergyReference);
    }
    buildingListResource.addEntry(comp);
}
Also used : ListEntryComponent(org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent)

Example 22 with Reference

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

the class StructuredAllergyIntoleranceBuilder method buildStructuredAllergyIntolerence.

public Bundle buildStructuredAllergyIntolerence(String NHS, Set<String> practitionerIds, Bundle bundle, Boolean includedResolved) {
    List<StructuredAllergyIntoleranceEntity> allergyData = structuredAllergySearch.getAllergyIntollerence(NHS);
    ListResource activeList = initiateListResource(NHS, ACTIVE_ALLERGIES_DISPLAY, allergyData);
    ListResource resolvedList = initiateListResource(NHS, RESOLVED_ALLERGIES_DISPLAY, allergyData);
    // This is patient 5 example 2 only
    if (allergyData.size() == 1 && allergyData.get(0).getClinicalStatus().equals(SystemConstants.NO_KNOWN)) {
        StructuredAllergyIntoleranceEntity noKnownAllergy = allergyData.get(0);
        // #214 had incorrect code and value for no known allergies
        CodeableConcept noKnownAllergies = createCoding(SystemURL.VS_LIST_EMPTY_REASON_CODE, NO_CONTENT_RECORDED, NO_CONTENT_RECORDED_DISPLAY);
        noKnownAllergies.setText("No Known Allergies");
        // activeList.setEmptyReason(noKnownAllergies);
        // see spec example 2 no known allergies positively asserted
        Reference patient = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyData.get(0).getPatientRef());
        String noKnownAllergyId = noKnownAllergy.getGuid();
        Reference allergyIntolerance = new Reference("AllergyIntolerance/" + noKnownAllergyId);
        Resource noKnownAllergyResource = createNoKnownAllergy(noKnownAllergy);
        activeList.setSubject(patient);
        // reference to AllergyIntolerance item
        activeList.addEntry().setItem(allergyIntolerance);
        activeList.setOrderedBy(createCoding(SystemURL.CS_LIST_ORDER, "event-date", "Sorted by Event Date"));
        bundle.addEntry().setResource(activeList);
        bundle.addEntry().setResource(noKnownAllergyResource);
        if (includedResolved) {
            resolvedList.setSubject(patient);
            resolvedList.setEmptyReason(noKnownAllergies);
            bundle.addEntry().setResource(resolvedList);
        }
        return bundle;
    }
    for (StructuredAllergyIntoleranceEntity allergyIntoleranceEntity : allergyData) {
        AllergyIntolerance allergyIntolerance = new AllergyIntolerance();
        allergyIntolerance.setOnset(new DateTimeType(allergyIntoleranceEntity.getOnSetDateTime()));
        allergyIntolerance.setMeta(createMeta(SystemURL.SD_CC_ALLERGY_INTOLERANCE));
        allergyIntolerance.setId(allergyIntoleranceEntity.getId().toString());
        List<Identifier> identifiers = new ArrayList<>();
        Identifier identifier1 = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(allergyIntoleranceEntity.getGuid());
        identifiers.add(identifier1);
        allergyIntolerance.setIdentifier(identifiers);
        if (allergyIntoleranceEntity.getClinicalStatus().equals(SystemConstants.ACTIVE)) {
            allergyIntolerance.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
        } else {
            allergyIntolerance.setClinicalStatus(AllergyIntoleranceClinicalStatus.RESOLVED);
        }
        if (allergyIntoleranceEntity.getCategory().equals(SystemConstants.MEDICATION)) {
            allergyIntolerance.addCategory(AllergyIntoleranceCategory.MEDICATION);
        } else {
            allergyIntolerance.addCategory(AllergyIntoleranceCategory.ENVIRONMENT);
        }
        allergyIntolerance.setVerificationStatus(AllergyIntoleranceVerificationStatus.UNCONFIRMED);
        // CODE
        codeableConceptBuilder.addConceptCode(SystemConstants.SNOMED_URL, allergyIntoleranceEntity.getConceptCode(), allergyIntoleranceEntity.getConceptDisplay()).addDescription(allergyIntoleranceEntity.getDescCode(), allergyIntoleranceEntity.getDescDisplay()).addTranslation(allergyIntoleranceEntity.getCodeTranslationRef());
        allergyIntolerance.setCode(codeableConceptBuilder.build());
        codeableConceptBuilder.clear();
        allergyIntolerance.setAssertedDate(allergyIntoleranceEntity.getAssertedDate());
        Reference patient = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyIntoleranceEntity.getPatientRef());
        allergyIntolerance.setPatient(patient);
        Annotation noteAnnotation = new Annotation(new StringType(allergyIntoleranceEntity.getNote()));
        allergyIntolerance.setNote(Collections.singletonList(noteAnnotation));
        AllergyIntoleranceReactionComponent reaction = new AllergyIntoleranceReactionComponent();
        // MANIFESTATION
        List<CodeableConcept> theManifestation = new ArrayList<>();
        codeableConceptBuilder.addConceptCode(SystemConstants.SNOMED_URL, allergyIntoleranceEntity.getManifestationCoding(), allergyIntoleranceEntity.getManifestationDisplay()).addDescription(allergyIntoleranceEntity.getManifestationDescCoding(), allergyIntoleranceEntity.getManifestationDescDisplay()).addTranslation(allergyIntoleranceEntity.getManTranslationRef());
        theManifestation.add(codeableConceptBuilder.build());
        codeableConceptBuilder.clear();
        reaction.setManifestation(theManifestation);
        reaction.setDescription(allergyIntoleranceEntity.getNote());
        // SEVERITY
        try {
            reaction.setSeverity(AllergyIntoleranceSeverity.fromCode(allergyIntoleranceEntity.getSeverity()));
        } catch (FHIRException e) {
            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Unknown severity: " + allergyIntoleranceEntity.getSeverity()), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
        }
        // EXPOSURE
        CodeableConcept exposureRoute = new CodeableConcept();
        reaction.setExposureRoute(exposureRoute);
        allergyIntolerance.addReaction(reaction);
        // RECORDER
        final Reference refValue = new Reference();
        final Identifier identifier = new Identifier();
        final String recorder = allergyIntoleranceEntity.getRecorder();
        // This is just an example to demonstrate using Reference element instead of Identifier element
        if (recorder.equals(patient2NhsNo.trim())) {
            Reference rec = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyIntoleranceEntity.getPatientRef());
            allergyIntolerance.setRecorder(rec);
        } else if (patientRepository.findByNhsNumber(recorder) != null) {
            identifier.setSystem(SystemURL.ID_NHS_NUMBER);
            identifier.setValue(recorder);
            refValue.setIdentifier(identifier);
            allergyIntolerance.setRecorder(refValue);
        } else if (practitionerSearch.findPractitionerByUserId(recorder) != null) {
            refValue.setReference("Practitioner/" + recorder);
            allergyIntolerance.setRecorder(refValue);
            practitionerIds.add(recorder);
        }
        // CLINICAL STATUS
        List<Extension> extensions = new ArrayList<>();
        if (allergyIntolerance.getClinicalStatus().getDisplay().contains("Active")) {
            listResourceBuilder(activeList, allergyIntolerance, false);
            bundle.addEntry().setResource(allergyIntolerance);
        } else if (allergyIntolerance.getClinicalStatus().getDisplay().equals("Resolved") && includedResolved.equals(true)) {
            listResourceBuilder(resolvedList, allergyIntolerance, true);
            allergyIntolerance.setLastOccurrence(allergyIntoleranceEntity.getEndDate());
            final Extension allergyEndExtension = createAllergyEndExtension(allergyIntoleranceEntity);
            extensions.add(allergyEndExtension);
        }
        if (!extensions.isEmpty()) {
            allergyIntolerance.setExtension(extensions);
        }
        // ASSERTER
        Reference asserter = allergyIntolerance.getAsserter();
        if (asserter != null && asserter.getReference() != null && asserter.getReference().startsWith("Practitioner")) {
            String[] split = asserter.getReference().split("/");
            practitionerIds.add(split[1]);
        }
    }
    if (!activeList.hasEntry()) {
        addEmptyListNote(activeList);
        addEmptyReasonCode(activeList);
    }
    bundle.addEntry().setResource(activeList);
    if (includedResolved && !resolvedList.hasEntry()) {
        addEmptyListNote(resolvedList);
        addEmptyReasonCode(resolvedList);
    }
    if (includedResolved) {
        bundle.addEntry().setResource(resolvedList);
    }
    return bundle;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) StructuredAllergyIntoleranceEntity(uk.gov.hscic.patient.structuredAllergyIntolerance.StructuredAllergyIntoleranceEntity) FHIRException(org.hl7.fhir.exceptions.FHIRException) AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance)

Example 23 with Reference

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

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

the class MedicationRequestResourceProvider method getRequesterComponent.

// TODO - spec needs to clarify whether this should be populated or not
private MedicationRequestRequesterComponent getRequesterComponent(MedicationRequestDetail requestDetail) {
    MedicationRequestRequesterComponent requesterComponent = new MedicationRequestRequesterComponent();
    switch(requestDetail.getRequesterUrl()) {
        case (SystemURL.SD_GPC_PATIENT):
            requesterComponent.setAgent(new Reference(new IdType("Patient", requestDetail.getRequesterId())));
            break;
        case (SystemURL.SD_GPC_PRACTITIONER):
            requesterComponent.setAgent(new Reference(new IdType("Practitioner", requestDetail.getRequesterId())));
            break;
        case (SystemURL.SD_GPC_ORGANIZATION):
            requesterComponent.setAgent(new Reference(new IdType("Organization", requestDetail.getRequesterId())));
            break;
        default:
            break;
    }
    requesterComponent.setOnBehalfOf(new Reference(new IdType("Organization", requestDetail.getDispenseRequestOrganizationId())));
    return requesterComponent;
}
Also used : MedicationRequestRequesterComponent(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestRequesterComponent)

Example 25 with Reference

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

the class PopulateMedicationBundle method createListEntry.

private ListResource createListEntry(List<MedicationStatementDetail> medicationStatements, String nhsNumber) {
    ListResource medicationStatementsList = new ListResource();
    // #179 dont populate List.id
    // medicationStatementsList.setId(new IdType(1));
    medicationStatementsList.setMeta(new Meta().addProfile(SystemURL.SD_GPC_LIST));
    medicationStatementsList.setStatus(ListStatus.CURRENT);
    // #179 dont populate List.id
    // medicationStatementsList.setId(new IdDt(1));
    medicationStatementsList.setMode(ListMode.SNAPSHOT);
    medicationStatementsList.setTitle(SystemConstants.MEDICATION_LIST);
    medicationStatementsList.setCode(new CodeableConcept().addCoding(new Coding(SystemURL.VS_SNOMED, "933361000000108", MEDICATION_LIST)));
    medicationStatementsList.setSubject(new Reference(new IdType("Patient", 1L)).setIdentifier(new Identifier().setValue(nhsNumber).setSystem(SystemURL.ID_NHS_NUMBER)));
    medicationStatementsList.setDate(new Date());
    medicationStatementsList.setOrderedBy(new CodeableConcept().addCoding(new Coding(SystemURL.CS_LIST_ORDER, "event-date", "Sorted by Event Date")));
    medicationStatementsList.addExtension(setClinicalSetting());
    if (medicationStatements.isEmpty()) {
        medicationStatementsList.setEmptyReason(new CodeableConcept().setText(SystemConstants.NO_CONTENT));
        medicationStatementsList.setNote(Arrays.asList(new Annotation(new StringType(SystemConstants.INFORMATION_NOT_AVAILABLE))));
    }
    Set<String> warningCodes = new HashSet<>();
    medicationStatements.forEach(statement -> {
        Reference statementRef = new Reference(new IdType("MedicationStatement", statement.getId()));
        ListEntryComponent listEntryComponent = new ListEntryComponent(statementRef);
        medicationStatementsList.addEntry(listEntryComponent);
        if (statement.getWarningCode() != null) {
            warningCodes.add(statement.getWarningCode());
        }
    });
    WarningCodeExtHelper.addWarningCodeExtensions(warningCodes, medicationStatementsList, patientRepository, medicationStatementRepository, structuredAllergySearch);
    return medicationStatementsList;
}
Also used : IIdType(org.hl7.fhir.instance.model.api.IIdType) ListEntryComponent(org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent)

Aggregations

Reference (org.hl7.fhir.dstu3.model.Reference)10 ArrayList (java.util.ArrayList)7 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)6 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)5 IdType (org.hl7.fhir.dstu3.model.IdType)5 SlotDetail (uk.gov.hscic.model.appointment.SlotDetail)5 Date (java.util.Date)4 Coding (org.hl7.fhir.dstu3.model.Coding)4 Extension (org.hl7.fhir.dstu3.model.Extension)4 AppointmentDetail (uk.gov.hscic.model.appointment.AppointmentDetail)4 IdDt (ca.uhn.fhir.model.primitive.IdDt)3 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)3 AppointmentParticipantComponent (org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent)3 ScheduleDetail (uk.gov.hscic.model.appointment.ScheduleDetail)3 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)2 Search (ca.uhn.fhir.rest.annotation.Search)2 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 ListEntryComponent (org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent)2 Location (org.hl7.fhir.dstu3.model.Location)2