Search in sources :

Example 6 with Extension

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

the class SlotResourceProvider method slotDetailToSlotResourceConverter.

private Slot slotDetailToSlotResourceConverter(SlotDetail slotDetail) {
    Slot slot = new Slot();
    Date lastUpdated = slotDetail.getLastUpdated() == null ? new Date() : slotDetail.getLastUpdated();
    String resourceId = String.valueOf(slotDetail.getId());
    String versionId = String.valueOf(lastUpdated.getTime());
    IdType id = new IdType(resourceId);
    slot.setId(id);
    slot.getMeta().setVersionId(versionId);
    slot.getMeta().addProfile(SystemURL.SD_GPC_SLOT);
    slot.setSchedule(new Reference("Schedule/" + slotDetail.getScheduleReference()));
    slot.setStart(slotDetail.getStartDateTime());
    slot.setEnd(slotDetail.getEndDateTime());
    // #218 Date time formats
    slot.getStartElement().setPrecision(TemporalPrecisionEnum.SECOND);
    slot.getEndElement().setPrecision(TemporalPrecisionEnum.SECOND);
    switch(slotDetail.getFreeBusyType().toLowerCase(Locale.UK)) {
        case "free":
            slot.setStatus(SlotStatus.FREE);
            break;
        default:
            slot.setStatus(SlotStatus.BUSY);
            break;
    }
    String deliveryChannelCode = slotDetail.getDeliveryChannelCode();
    ArrayList<Extension> al = new ArrayList<>();
    if (deliveryChannelCode != null && !deliveryChannelCode.trim().isEmpty()) {
        Extension deliveryChannelExtension = new Extension(SystemURL.SD_EXTENSION_GPC_DELIVERY_CHANNEL, new CodeType(deliveryChannelCode));
        al.add(deliveryChannelExtension);
    }
    slot.setExtension(al);
    // 1.2.7 add slot type description as service type
    slot.addServiceType(new CodeableConcept().setText(slotDetail.getTypeDisply()));
    return slot;
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) Slot(org.hl7.fhir.dstu3.model.Slot) CodeType(org.hl7.fhir.dstu3.model.CodeType) Date(java.util.Date) IdType(org.hl7.fhir.dstu3.model.IdType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 7 with Extension

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

the class WarningCodeExtHelper method addWarningCodeExtensions.

/**
 * confidential items are per record but the other two are global values per
 * patient
 *
 * @param warningCodes
 * @param list
 * @param patientRepository
 * @param medicationStatementRepository
 * @param structuredAllergySearch
 */
public static void addWarningCodeExtensions(Set<String> warningCodes, ListResource list, PatientRepository patientRepository, MedicationStatementRepository medicationStatementRepository, StructuredAllergySearch structuredAllergySearch) {
    String NHS = list.getSubject().getIdentifier().getValue();
    PatientEntity patientEntity = patientRepository.findByNhsNumber(NHS);
    List<MedicationStatementEntity> medicationStatements = medicationStatementRepository.findByPatientId(patientEntity.getId());
    for (MedicationStatementEntity medicationStatement : medicationStatements) {
        setFlags(medicationStatement.getWarningCode());
    }
    List<StructuredAllergyIntoleranceEntity> allergies = structuredAllergySearch.getAllergyIntollerence(NHS);
    for (StructuredAllergyIntoleranceEntity allergy : allergies) {
        setFlags(allergy.getWarningCode());
    }
    // check medication_statements for either of the global flags
    if (dataInTransit) {
        warningCodes.add(DATA_IN_TRANSIT);
    }
    if (dataAwaitingFiling) {
        warningCodes.add(DATA_AWAITING_FILING);
    }
    StringBuilder sb = new StringBuilder();
    warningCodes.forEach(warningCode -> {
        if (warningCode != null) {
            String warningCodeDisplay = "";
            Annotation annotation = new Annotation();
            switch(warningCode) {
                case CONFIDENTIAL_ITEMS:
                    warningCodeDisplay = "Confidential Items";
                    // #266
                    annotation.setText(CONFIDENTIAL_ITEMS_NOTE);
                    // list.addNote(annotation);
                    sb.append("\r\n").append(annotation.getText());
                    break;
                case DATA_IN_TRANSIT:
                    warningCodeDisplay = "Data in Transit";
                    Calendar cal = new GregorianCalendar();
                    Date now = new Date();
                    cal.setTime(now);
                    // a week before now
                    cal.add(Calendar.DAY_OF_YEAR, -7);
                    // #266
                    annotation.setText(String.format(DATA_IN_TRANSIT_NOTE, DATE_FORMAT.format(cal.getTime())));
                    // list.addNote(annotation);
                    sb.append("\r\n").append(annotation.getText());
                    break;
                case DATA_AWAITING_FILING:
                    warningCodeDisplay = "Data Awaiting Filing";
                    // #266
                    annotation.setText(DATA_AWAITING_FILING_NOTE);
                    // list.addNote(annotation);
                    sb.append("\r\n").append(annotation.getText());
                    break;
                default:
                    break;
            }
            // #182
            Extension warningExt = new Extension(SystemURL.WARNING_CODE, new CodeType(warningCode));
            list.addExtension(warningExt);
        }
    });
    // cardinality of note 0..1 #266
    if (sb.length() > 0) {
        Annotation annotation = null;
        if (list.getNote().size() > 0) {
            annotation = list.getNote().get(0);
            annotation.setText(annotation.getText());
            annotation.setText(annotation.getText() + sb.toString());
        } else {
            annotation = new Annotation();
            list.addNote(annotation);
            annotation.setText(sb.toString().replaceFirst("^\r\n", ""));
        }
    }
}
Also used : StructuredAllergyIntoleranceEntity(uk.gov.hscic.patient.structuredAllergyIntolerance.StructuredAllergyIntoleranceEntity) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Annotation(org.hl7.fhir.dstu3.model.Annotation) Date(java.util.Date) PatientEntity(uk.gov.hscic.patient.details.PatientEntity) MedicationStatementEntity(uk.gov.hscic.medication.statement.MedicationStatementEntity) Extension(org.hl7.fhir.dstu3.model.Extension) CodeType(org.hl7.fhir.dstu3.model.CodeType)

Example 8 with Extension

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

the class MedicationStatementResourceProvider method getMedicationStatementResource.

public MedicationStatement getMedicationStatementResource(MedicationStatementDetail statementDetail) {
    MedicationStatement medicationStatement = new MedicationStatement();
    medicationStatement.setId(statementDetail.getId().toString());
    List<Identifier> identifiers = new ArrayList<>();
    Identifier identifier = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(statementDetail.getGuid());
    identifiers.add(identifier);
    medicationStatement.setIdentifier(identifiers);
    medicationStatement.setMeta(new Meta().addProfile(SystemURL.SD_GPC_MEDICATION_STATEMENT));
    medicationStatement.addExtension(new Extension(SystemURL.SD_CC_EXT_MEDICATION_STATEMENT_LAST_ISSUE, new DateTimeType(statementDetail.getLastIssueDate(), TemporalPrecisionEnum.DAY)));
    if (statementDetail.getMedicationRequestPlanId() != null) {
        medicationStatement.addBasedOn(new Reference(new IdType("MedicationRequest", statementDetail.getMedicationRequestPlanId())));
    }
    try {
        medicationStatement.setStatus(MedicationStatementStatus.fromCode(statementDetail.getStatusCode()));
    } catch (FHIRException e) {
        throw new UnprocessableEntityException(e.getMessage());
    }
    if (statementDetail.getMedicationId() != null) {
        medicationStatement.setMedication(new Reference(new IdType("Medication", statementDetail.getMedicationId())));
    }
    medicationStatement.setEffective(new Period().setStart(statementDetail.getStartDate()).setEnd(statementDetail.getEndDate()));
    medicationStatement.setDateAsserted(statementDetail.getDateAsserted());
    if (statementDetail.getPatientId() != null)
        medicationStatement.setSubject(new Reference(new IdType("Patient", statementDetail.getPatientId())));
    try {
        medicationStatement.setTaken(statementDetail.getTakenCode() != null ? MedicationStatementTaken.fromCode(statementDetail.getTakenCode()) : MedicationStatementTaken.UNK);
    } catch (FHIRException e) {
        throw new UnprocessableEntityException(e.getMessage());
    }
    setReasonCodes(medicationStatement, statementDetail);
    setNotes(medicationStatement, statementDetail);
    String dosageText = statementDetail.getDosageText();
    medicationStatement.addDosage(new Dosage().setText(dosageText == null || dosageText.trim().isEmpty() ? NO_INFORMATION_AVAILABLE : dosageText).setPatientInstruction(statementDetail.getDosagePatientInstruction()));
    String prescribingAgency = statementDetail.getPrescribingAgency();
    if (prescribingAgency != null && !prescribingAgency.trim().isEmpty()) {
        String prescribingAgencyDisplay = "";
        if (prescribingAgency.equalsIgnoreCase("prescribed-at-gp-practice")) {
            prescribingAgencyDisplay = "Prescribed at GP practice";
        } else if (prescribingAgency.equalsIgnoreCase("prescribed-by-another-organisation")) {
            prescribingAgencyDisplay = "Prescribed by another organisation";
        }
        Coding coding = new Coding(SystemURL.CS_CC_PRESCRIBING_AGENCY_STU3, prescribingAgency, prescribingAgencyDisplay);
        CodeableConcept codeableConcept = new CodeableConcept().addCoding(coding);
        medicationStatement.addExtension(new Extension(SystemURL.SD_EXTENSION_CC_PRESCRIBING_AGENCY, codeableConcept));
    }
    // #281 1.2.5 add dosageLastChanged
    Date dosageLastChanged = statementDetail.getDosageLastChanged();
    if (dosageLastChanged != null) {
        medicationStatement.addExtension(new Extension(SystemURL.SD_EXTENSION_CC_DOSAGE_LAST_CHANGED, new DateTimeType(dosageLastChanged)));
    }
    return medicationStatement;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException) Date(java.util.Date)

Example 9 with Extension

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

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

the class StructuredAllergyIntoleranceBuilder method createNoKnownAllergy.

/**
 * This relates to the positively asserted this patient has no know
 * allergies as opposed to the the negatively asserted no allergies recorded
 * patient 5 example 2 from the spec
 *
 * @param allergyIntoleranceEntity object from the db
 * @return the allergy intolerance resource
 */
private AllergyIntolerance createNoKnownAllergy(StructuredAllergyIntoleranceEntity allergyIntoleranceEntity) {
    AllergyIntolerance allergyIntolerance = new AllergyIntolerance();
    allergyIntolerance.setId(allergyIntoleranceEntity.getGuid());
    allergyIntolerance.setAssertedDate(allergyIntoleranceEntity.getAssertedDate());
    // db has clinical status of "no known" which is not a valid value
    allergyIntolerance.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
    allergyIntolerance.setVerificationStatus(AllergyIntoleranceVerificationStatus.valueOf(allergyIntoleranceEntity.getVerificationStatus().toUpperCase()));
    allergyIntolerance.setType(AllergyIntoleranceType.ALLERGY);
    CodeableConcept codeableConcept = new CodeableConcept();
    Coding coding = new Coding();
    coding.setDisplay(allergyIntoleranceEntity.getConceptDisplay());
    // That's as in db under concept code 716186003
    coding.setCode(allergyIntoleranceEntity.getConceptCode());
    coding.setSystem(SystemConstants.SNOMED_URL);
    Extension extension = new Extension(SystemURL.SD_EXT_SCT_DESC_ID);
    // 3305010017
    extension.addExtension("descriptionId", new StringType(allergyIntoleranceEntity.getDescCode()));
    // NKA - No known allergy
    extension.addExtension("descriptionDisplay", new StringType(allergyIntoleranceEntity.getDescDisplay()));
    coding.addExtension(extension);
    codeableConcept.addCoding(coding);
    allergyIntolerance.setCode(codeableConcept);
    return allergyIntolerance;
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance)

Aggregations

Extension (org.hl7.fhir.dstu3.model.Extension)8 Date (java.util.Date)4 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)4 Reference (org.hl7.fhir.dstu3.model.Reference)4 ArrayList (java.util.ArrayList)3 Coding (org.hl7.fhir.dstu3.model.Coding)3 IdType (org.hl7.fhir.dstu3.model.IdType)3 Period (org.hl7.fhir.dstu3.model.Period)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)2 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)2 Calendar (java.util.Calendar)2 AllergyIntolerance (org.hl7.fhir.dstu3.model.AllergyIntolerance)2 AppointmentParticipantComponent (org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent)2 CodeType (org.hl7.fhir.dstu3.model.CodeType)2 Identifier (org.hl7.fhir.dstu3.model.Identifier)2 IBaseDatatype (org.hl7.fhir.instance.model.api.IBaseDatatype)2 AppointmentDetail (uk.gov.hscic.model.appointment.AppointmentDetail)2 BookingOrgDetail (uk.gov.hscic.model.appointment.BookingOrgDetail)2 ScheduleDetail (uk.gov.hscic.model.appointment.ScheduleDetail)2