Search in sources :

Example 16 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project eCRNow by drajer-health.

the class CdaProblemGenerator method generateProblemSection.

public static String generateProblemSection(R4FhirData data, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    List<Condition> conds = data.getConditions();
    if (conds != null && !conds.isEmpty()) {
        // Generate the component and section end tags
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMP_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.SECTION_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_SEC_TEMPLATE_ID));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_SEC_TEMPLATE_ID, CdaGeneratorConstants.PROB_SEC_TEMPLATE_ID_EXT));
        sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.PROB_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.PROB_SEC_NAME));
        // Add Title
        sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.PROB_SEC_TITLE));
        // Add Narrative Text
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Create Table Header.
        List<String> list = new ArrayList<>();
        list.add(CdaGeneratorConstants.PROB_TABLE_COL_1_TITLE);
        list.add(CdaGeneratorConstants.PROB_TABLE_COL_2_TITLE);
        sb.append(CdaGeneratorUtils.getXmlForTableHeader(list, CdaGeneratorConstants.TABLE_BORDER, CdaGeneratorConstants.TABLE_WIDTH));
        // Add Table Body
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        // Add Body Rows
        int rowNum = 1;
        for (Condition prob : conds) {
            String probDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (prob.getCode() != null && prob.getCode().getCodingFirstRep() != null && !StringUtils.isEmpty(prob.getCode().getCodingFirstRep().getDisplay())) {
                probDisplayName = prob.getCode().getCodingFirstRep().getDisplay();
            }
            Map<String, String> bodyvals = new LinkedHashMap<>();
            bodyvals.put(CdaGeneratorConstants.PROB_TABLE_COL_1_BODY_CONTENT, probDisplayName);
            if (prob.getClinicalStatus() != null && prob.getClinicalStatus().getCodingFirstRep() != null && !StringUtils.isEmpty(prob.getClinicalStatus().getCodingFirstRep().getCode()) && (prob.getClinicalStatus().getCodingFirstRep().getCode().contentEquals(ConditionClinical.ACTIVE.toCode()) || prob.getClinicalStatus().getCodingFirstRep().getCode().contentEquals(ConditionClinical.RELAPSE.toCode()))) {
                bodyvals.put(CdaGeneratorConstants.PROB_TABLE_COL_2_BODY_CONTENT, CdaGeneratorConstants.TABLE_ACTIVE_STATUS);
            } else {
                bodyvals.put(CdaGeneratorConstants.PROB_TABLE_COL_2_BODY_CONTENT, CdaGeneratorConstants.TABLE_RESOLVED_STATUS);
            }
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
            // TODO: ++rowNum or rowNum++
            ++rowNum;
        }
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        // End Table.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TEXT_EL_NAME));
        for (Condition pr : conds) {
            // Add the Entries.
            sb.append(CdaGeneratorUtils.getXmlForActEntry(CdaGeneratorConstants.TYPE_CODE_DEF));
            // Add the problem Concern Act
            sb.append(CdaGeneratorUtils.getXmlForAct(CdaGeneratorConstants.ACT_EL_NAME, CdaGeneratorConstants.ACT_CLASS_CODE, CdaGeneratorConstants.MOOD_CODE_DEF));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_CONCERN_TEMPLATE_ID));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_CONCERN_TEMPLATE_ID, CdaGeneratorConstants.PROB_CONCERN_TEMPLATE_ID_EXT));
            sb.append(CdaGeneratorUtils.getXmlForIIUsingGuid());
            sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.PROB_CONC_ACT_CODE, CdaGeneratorConstants.HL7_ACT_CLASS_OID, CdaGeneratorConstants.HL7_ACT_CLASS_NAME, CdaGeneratorConstants.PROB_CONC_ACT_NAME));
            if (pr.getClinicalStatus() != null && pr.getClinicalStatus().getCodingFirstRep() != null && !StringUtils.isEmpty(pr.getClinicalStatus().getCodingFirstRep().getCode()) && (pr.getClinicalStatus().getCodingFirstRep().getCode().contentEquals(ConditionClinical.ACTIVE.toCode()) || pr.getClinicalStatus().getCodingFirstRep().getCode().contentEquals(ConditionClinical.RELAPSE.toCode()))) {
                sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.ACTIVE_STATUS));
            } else {
                sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.COMPLETED_STATUS));
            }
            Pair<Date, TimeZone> onset = CdaFhirUtilities.getActualDate(pr.getOnset());
            Pair<Date, TimeZone> abatement = CdaFhirUtilities.getActualDate(pr.getAbatement());
            Pair<Date, TimeZone> recordedDate = null;
            if (pr.getRecordedDateElement() != null) {
                recordedDate = new Pair<>(pr.getRecordedDate(), pr.getRecordedDateElement().getTimeZone());
            }
            sb.append(CdaGeneratorUtils.getXmlForIVLWithTS(CdaGeneratorConstants.EFF_TIME_EL_NAME, recordedDate, abatement, true));
            // Add the Problem Observation
            sb.append(CdaGeneratorUtils.getXmlForEntryRelationship(CdaGeneratorConstants.ENTRY_REL_SUBJ_CODE));
            sb.append(CdaGeneratorUtils.getXmlForAct(CdaGeneratorConstants.OBS_ACT_EL_NAME, CdaGeneratorConstants.OBS_CLASS_CODE, CdaGeneratorConstants.MOOD_CODE_DEF));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_OBS_TEMPLATE_ID));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_OBS_TEMPLATE_ID, CdaGeneratorConstants.PROB_OBS_TEMPALTE_ID_EXT));
            sb.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), pr.getId()));
            sb.append(CdaGeneratorUtils.getXmlForCDWithoutEndTag(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.DIAGNOSIS_SNOMED, CdaGeneratorConstants.SNOMED_CODESYSTEM_OID, CdaGeneratorConstants.SNOMED_CODESYSTEM_NAME, CdaGeneratorConstants.DIAGNOSIS_DISPLAY_NAME));
            sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.TRANSLATION_EL_NAME, CdaGeneratorConstants.DIAGNOSIS_LOINC, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.DIAGNOSIS_DISPLAY_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.CODE_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.COMPLETED_STATUS));
            sb.append(CdaGeneratorUtils.getXmlForIVLWithTS(CdaGeneratorConstants.EFF_TIME_EL_NAME, onset, abatement, true));
            List<CodeableConcept> cds = new ArrayList<>();
            cds.add(pr.getCode());
            String codeXml = CdaFhirUtilities.getCodeableConceptXmlForCodeSystem(cds, CdaGeneratorConstants.VAL_EL_NAME, true, CdaGeneratorConstants.FHIR_SNOMED_URL, false);
            if (!codeXml.isEmpty()) {
                sb.append(codeXml);
            } else {
                sb.append(CdaFhirUtilities.getCodeableConceptXml(cds, CdaGeneratorConstants.VAL_EL_NAME, true));
            }
            // End Tag for Entry Relationship
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.OBS_ACT_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ENTRY_REL_EL_NAME));
            logger.debug("Add Trigger Codes to Problem Observation if applicable {}", pr.getId());
            sb.append(addTriggerCodes(details, pr, onset, abatement));
            logger.debug("Completed adding Trigger Codes ");
            // End Tags for Entries
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ACT_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ENTRY_EL_NAME));
        }
        // Complete the section end tags.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SECTION_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMP_EL_NAME));
    } else {
        sb.append(generateEmptyProblemSection());
    }
    return sb.toString();
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) ArrayList(java.util.ArrayList) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) TimeZone(java.util.TimeZone) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 17 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project eCRNow by drajer-health.

the class PlanDefinitionProcessor method readErsdBundleFromFile.

private Bundle readErsdBundleFromFile() {
    logger.debug("About to read ERSD File {}", ersdFileLocation);
    Bundle bundle = null;
    try (InputStream in = new FileInputStream(new File(ersdFileLocation))) {
        logger.debug("Reading ERSD File ");
        bundle = jsonParser.parseResource(Bundle.class, in);
        logger.debug("Completed Reading ERSD File");
    } catch (Exception e) {
        logger.error("Exception Reading ERSD File", e);
    }
    return bundle;
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 18 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project nia-patient-switching-standard-adaptor by NHSDigital.

the class TemplateMapper method createQuestionnaireResponse.

private QuestionnaireResponse createQuestionnaireResponse(RCMRMT030101UK04CompoundStatement compoundStatement, String practiseCode, Patient patient, Optional<Reference> encounter, Observation parentObservation, RCMRMT030101UK04EhrComposition ehrComposition, RCMRMT030101UK04EhrExtract ehrExtract) {
    var questionnaireResponse = new QuestionnaireResponse();
    var id = compoundStatement.getId().get(0).getRoot();
    questionnaireResponse.addItem(createdLinkedId(compoundStatement)).setAuthoredElement(getAuthored(ehrComposition, ehrExtract)).setSubject(new Reference(patient)).setStatus(COMPLETED).setParent(List.of(new Reference(parentObservation))).setIdentifier(buildIdentifier(id, practiseCode)).setMeta(generateMeta(QUESTIONNAIRE_META_PROFILE)).setId(QUESTIONNAIRE_REFERENCE.formatted(id));
    encounter.ifPresent(questionnaireResponse::setContext);
    return questionnaireResponse;
}
Also used : ParticipantReferenceUtil.getParticipantReference(uk.nhs.adaptors.pss.translator.util.ParticipantReferenceUtil.getParticipantReference) Reference(org.hl7.fhir.dstu3.model.Reference) QuestionnaireResponse(org.hl7.fhir.dstu3.model.QuestionnaireResponse)

Example 19 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project nia-patient-switching-standard-adaptor by NHSDigital.

the class MedicationRequestOrderMapper method mapToOrderMedicationRequest.

public MedicationRequest mapToOrderMedicationRequest(RCMRMT030101UK04EhrExtract ehrExtract, RCMRMT030101UK04MedicationStatement medicationStatement, RCMRMT030101UK04Prescribe supplyPrescribe, String practiseCode) {
    var ehrSupplyPrescribeIdExtract = extractEhrSupplyPrescribeId(supplyPrescribe);
    var inFulfillmentOfId = extractInFulfillmentOfId(supplyPrescribe);
    if (ehrSupplyPrescribeIdExtract.isPresent()) {
        var ehrSupplyPrescribeId = ehrSupplyPrescribeIdExtract.get();
        MedicationRequest medicationRequest = createMedicationRequestSkeleton(ehrSupplyPrescribeId);
        medicationRequest.addIdentifier(buildIdentifier(ehrSupplyPrescribeId, practiseCode));
        medicationRequest.setStatus(COMPLETED);
        medicationRequest.setIntent(ORDER);
        medicationRequest.addDosageInstruction(buildDosage(medicationStatement.getPertinentInformation()));
        medicationRequest.setDispenseRequest(buildDispenseRequestForPrescribe(supplyPrescribe));
        buildNotesForPrescribe(supplyPrescribe).forEach(medicationRequest::addNote);
        medicationMapper.extractMedicationReference(medicationStatement).ifPresent(medicationRequest::setMedication);
        inFulfillmentOfId.ifPresent(inFulfillmentId -> {
            var supplyAuthorise = extractSupplyAuthorise(ehrExtract, inFulfillmentId);
            buildPrescriptionTypeExtension(supplyAuthorise).ifPresent(medicationRequest::addExtension);
            medicationRequest.addBasedOn(buildMedicationRequestReference(inFulfillmentId));
        });
        return medicationRequest;
    }
    return null;
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest)

Example 20 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED 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)

Aggregations

Immunization (org.hl7.fhir.r4.model.Immunization)13 Date (java.util.Date)9 ArrayList (java.util.ArrayList)8 InputStream (java.io.InputStream)7 Reference (org.hl7.fhir.dstu3.model.Reference)7 Test (org.junit.jupiter.api.Test)7 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)6 Collectors (java.util.stream.Collectors)5 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)5 Reference (org.hl7.fhir.r4.model.Reference)5 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)5 FhirContext (ca.uhn.fhir.context.FhirContext)4 Search (ca.uhn.fhir.rest.annotation.Search)4 Trace (com.newrelic.api.agent.Trace)4 File (java.io.File)4 List (java.util.List)4 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)4 Coding (org.hl7.fhir.dstu3.model.Coding)4 Bundle (org.hl7.fhir.r4.model.Bundle)4 CodeType (org.hl7.fhir.r4.model.CodeType)4