Search in sources :

Example 16 with RCMRMT030101UK04EhrExtract

use of org.hl7.v3.RCMRMT030101UK04EhrExtract in project nia-patient-switching-standard-adaptor by NHSDigital.

the class MedicationStatementMapperTest method When_MappingPrescribeResourceWithNoLastIssueDate_Expect_AllFieldsToBeMappedCorrectly.

@Test
public void When_MappingPrescribeResourceWithNoLastIssueDate_Expect_AllFieldsToBeMappedCorrectly() {
    var medicationStatement = unmarshallMedicationStatement("medicationStatementAuthoriseNoOptionals_MedicationStatement.xml");
    var authorise = medicationStatement.getComponent().stream().filter(RCMRMT030101UK04Component2::hasEhrSupplyAuthorise).map(RCMRMT030101UK04Component2::getEhrSupplyAuthorise).findFirst();
    when(medicationMapper.extractMedicationReference(any())).thenReturn(Optional.of(new Reference(new IdType(ResourceType.Medication.name(), MEDICATION_ID))));
    assertThat(authorise.isPresent()).isTrue();
    var medicationStatement1 = medicationStatementMapper.mapToMedicationStatement(new RCMRMT030101UK04EhrExtract(), medicationStatement, authorise.get(), PRACTISE_CODE, new DateTimeType());
    var lastIssuedDate = medicationStatement1.getExtensionsByUrl("https://fhir.nhs.uk/STU3/StructureDefinition/Extension-CareConnect-GPC-MedicationStatementLastIssueDate-1");
    assertThat(lastIssuedDate.size()).isEqualTo(0);
    var prescribingAgency = medicationStatement1.getExtensionsByUrl("https://fhir.nhs.uk/STU3/StructureDefinition/Extension-CareConnect-GPC-PrescribingAgency-1");
    assertThat(prescribingAgency.size()).isEqualTo(1);
    assertThat(medicationStatement1.getBasedOnFirstRep().getReferenceElement().getIdPart()).isEqualTo(TEST_ID);
    assertThat(medicationStatement1.getStatus()).isEqualTo(ACTIVE);
    assertThat(medicationStatement1.getMedicationReference().getReferenceElement().getIdPart()).isEqualTo(MEDICATION_ID);
    assertThat(medicationStatement1.getTaken()).isEqualTo(UNK);
    assertThat(medicationStatement1.getDosageFirstRep().getText()).isEqualTo(TAKE_ONE_DAILY);
}
Also used : DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) RCMRMT030101UK04EhrExtract(org.hl7.v3.RCMRMT030101UK04EhrExtract) Reference(org.hl7.fhir.dstu3.model.Reference) RCMRMT030101UK04Component2(org.hl7.v3.RCMRMT030101UK04Component2) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.jupiter.api.Test)

Example 17 with RCMRMT030101UK04EhrExtract

use of org.hl7.v3.RCMRMT030101UK04EhrExtract in project nia-patient-switching-standard-adaptor by NHSDigital.

the class MedicationRequestPlanMapper method mapToPlanMedicationRequest.

public MedicationRequest mapToPlanMedicationRequest(RCMRMT030101UK04EhrExtract ehrExtract, RCMRMT030101UK04MedicationStatement medicationStatement, RCMRMT030101UK04Authorise supplyAuthorise, String practiseCode) {
    var ehrSupplyAuthoriseIdExtract = extractEhrSupplyAuthoriseId(supplyAuthorise);
    if (ehrSupplyAuthoriseIdExtract.isPresent()) {
        var ehrSupplyAuthoriseId = ehrSupplyAuthoriseIdExtract.get();
        var discontinue = extractMatchingDiscontinue(ehrSupplyAuthoriseId, ehrExtract);
        MedicationRequest medicationRequest = createMedicationRequestSkeleton(ehrSupplyAuthoriseId);
        medicationRequest.addIdentifier(buildIdentifier(ehrSupplyAuthoriseId, practiseCode));
        medicationRequest.setStatus(buildMedicationRequestStatus(supplyAuthorise));
        medicationRequest.setIntent(PLAN);
        medicationRequest.addDosageInstruction(buildDosage(medicationStatement.getPertinentInformation()));
        medicationRequest.setDispenseRequest(buildDispenseRequestForAuthorise(supplyAuthorise, medicationStatement));
        List<Extension> repeatInformationExtensions = new ArrayList<>();
        extractSupplyAuthoriseRepeatInformation(supplyAuthorise).ifPresent(repeatInformationExtensions::add);
        extractRepeatInformationIssued(ehrExtract, supplyAuthorise, ehrSupplyAuthoriseId).ifPresent(repeatInformationExtensions::add);
        extractAuthorisationExpiryDate(supplyAuthorise).ifPresent(repeatInformationExtensions::add);
        buildCondensedExtensions(REPEAT_INFORMATION_URL, repeatInformationExtensions).ifPresent(medicationRequest::addExtension);
        List<Extension> statusChangeExtensions = new ArrayList<>();
        discontinue.map(this::buildStatusChangeDateExtension).ifPresent(statusChangeExtensions::add);
        discontinue.map(this::extractTermText).map(this::buildStatusReasonCodeableConceptExtension).ifPresent(statusChangeExtensions::add);
        buildCondensedExtensions(STATUS_CHANGE_URL, statusChangeExtensions).ifPresent(medicationRequest::addExtension);
        buildPrescriptionTypeExtension(supplyAuthorise).ifPresent(medicationRequest::addExtension);
        buildNotesForAuthorise(supplyAuthorise).forEach(medicationRequest::addNote);
        extractPriorPrescription(supplyAuthorise).ifPresent(medicationRequest::setPriorPrescription);
        medicationMapper.extractMedicationReference(medicationStatement).ifPresent(medicationRequest::setMedication);
        return medicationRequest;
    }
    return null;
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) MedicationMapperUtils.buildPrescriptionTypeExtension(uk.nhs.adaptors.pss.translator.mapper.medication.MedicationMapperUtils.buildPrescriptionTypeExtension) MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) ArrayList(java.util.ArrayList)

Example 18 with RCMRMT030101UK04EhrExtract

use of org.hl7.v3.RCMRMT030101UK04EhrExtract in project nia-patient-switching-standard-adaptor by NHSDigital.

the class MedicationStatementMapper method mapToMedicationStatement.

public MedicationStatement mapToMedicationStatement(RCMRMT030101UK04EhrExtract ehrExtract, RCMRMT030101UK04MedicationStatement medicationStatement, RCMRMT030101UK04Authorise supplyAuthorise, String practiseCode, DateTimeType authoredOn) {
    var ehrSupplyAuthoriseIdExtract = extractEhrSupplyAuthoriseId(supplyAuthorise);
    if (ehrSupplyAuthoriseIdExtract.isPresent()) {
        String ehrSupplyAuthoriseId = ehrSupplyAuthoriseIdExtract.get();
        MedicationStatement medicationStatement1 = new MedicationStatement();
        medicationStatement1.setId(ehrSupplyAuthoriseId + MS_SUFFIX);
        medicationStatement1.setMeta(generateMeta(MEDICATION_STATEMENT_URL));
        medicationStatement1.addIdentifier(buildIdentifier(ehrSupplyAuthoriseId + MS_SUFFIX, practiseCode));
        medicationStatement1.setTaken(UNK);
        medicationStatement1.addBasedOn(new Reference(new IdType(ResourceType.MedicationRequest.name(), ehrSupplyAuthoriseId)));
        medicationStatement1.addExtension(generatePrescribingAgencyExtension());
        medicationStatement1.setStatus(buildMedicationStatementStatus(supplyAuthorise));
        medicationStatement1.addDosage(buildDosage(medicationStatement.getPertinentInformation()));
        extractHighestSupplyPrescribeTime(ehrExtract, ehrSupplyAuthoriseId).map(dateTime -> new Extension(MS_LAST_ISSUE_DATE, dateTime)).ifPresent(medicationStatement1::addExtension);
        medicationMapper.extractMedicationReference(medicationStatement).ifPresent(medicationStatement1::setMedication);
        MedicationMapperUtils.extractDispenseRequestPeriodStart(supplyAuthorise).ifPresentOrElse(dateTimeType -> {
            medicationStatement1.setEffective(buildDispenseRequestPeriodEnd(supplyAuthorise, medicationStatement).setStartElement(dateTimeType));
        }, () -> {
            medicationStatement1.setEffective(buildDispenseRequestPeriodEnd(supplyAuthorise, medicationStatement).setStartElement(authoredOn));
        });
        return medicationStatement1;
    }
    return null;
}
Also used : RCMRMT030101UK04Component3(org.hl7.v3.RCMRMT030101UK04Component3) RCMRMT030101UK04EhrFolder(org.hl7.v3.RCMRMT030101UK04EhrFolder) RCMRMT030101UK04Component2(org.hl7.v3.RCMRMT030101UK04Component2) RCMRMT030101UK04Prescribe(org.hl7.v3.RCMRMT030101UK04Prescribe) DateFormatUtil(uk.nhs.adaptors.pss.translator.util.DateFormatUtil) Coding(org.hl7.fhir.dstu3.model.Coding) IdType(org.hl7.fhir.dstu3.model.IdType) UNK(org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementTaken.UNK) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) Extension(org.hl7.fhir.dstu3.model.Extension) MedicationMapperUtils.extractEhrSupplyAuthoriseId(uk.nhs.adaptors.pss.translator.mapper.medication.MedicationMapperUtils.extractEhrSupplyAuthoriseId) ResourceType(org.hl7.fhir.dstu3.model.ResourceType) Service(org.springframework.stereotype.Service) RCMRMT030101UK04EhrExtract(org.hl7.v3.RCMRMT030101UK04EhrExtract) MedicationStatement(org.hl7.fhir.dstu3.model.MedicationStatement) COMPLETED(org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementStatus.COMPLETED) MedicationMapperUtils.buildDispenseRequestPeriodEnd(uk.nhs.adaptors.pss.translator.mapper.medication.MedicationMapperUtils.buildDispenseRequestPeriodEnd) ACTIVE(org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementStatus.ACTIVE) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Reference(org.hl7.fhir.dstu3.model.Reference) MedicationMapperUtils.buildDosage(uk.nhs.adaptors.pss.translator.mapper.medication.MedicationMapperUtils.buildDosage) RCMRMT030101UK04EhrComposition(org.hl7.v3.RCMRMT030101UK04EhrComposition) RCMRMT030101UK04MedicationStatement(org.hl7.v3.RCMRMT030101UK04MedicationStatement) RCMRMT030101UK04Authorise(org.hl7.v3.RCMRMT030101UK04Authorise) Objects(java.util.Objects) TS(org.hl7.v3.TS) List(java.util.List) RCMRMT030101UK04Component(org.hl7.v3.RCMRMT030101UK04Component) Optional(java.util.Optional) ResourceUtil.generateMeta(uk.nhs.adaptors.pss.translator.util.ResourceUtil.generateMeta) Comparator(java.util.Comparator) AllArgsConstructor(lombok.AllArgsConstructor) ResourceUtil.buildIdentifier(uk.nhs.adaptors.pss.translator.util.ResourceUtil.buildIdentifier) Extension(org.hl7.fhir.dstu3.model.Extension) Reference(org.hl7.fhir.dstu3.model.Reference) MedicationStatement(org.hl7.fhir.dstu3.model.MedicationStatement) RCMRMT030101UK04MedicationStatement(org.hl7.v3.RCMRMT030101UK04MedicationStatement) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 19 with RCMRMT030101UK04EhrExtract

use of org.hl7.v3.RCMRMT030101UK04EhrExtract in project nia-patient-switching-standard-adaptor by NHSDigital.

the class DiagnosticReportMapper method mapResources.

@Override
public List<DiagnosticReport> mapResources(RCMRMT030101UK04EhrExtract ehrExtract, Patient patient, List<Encounter> encounters, String practiseCode) {
    return mapEhrExtractToFhirResource(ehrExtract, (extract, composition, component) -> extractAllCompoundStatements(component).filter(Objects::nonNull).filter(ResourceFilterUtil::isDiagnosticReport).map(compoundStatement -> {
        DiagnosticReport diagnosticReport = createDiagnosticReport(compoundStatement, patient, composition, encounters, practiseCode);
        getIssued(ehrExtract, compoundStatement, composition).ifPresent(diagnosticReport::setIssuedElement);
        return diagnosticReport;
    })).toList();
}
Also used : RCMRMT030101UK04Author(org.hl7.v3.RCMRMT030101UK04Author) Identifier(org.hl7.fhir.dstu3.model.Identifier) IdType(org.hl7.fhir.dstu3.model.IdType) TextUtil.getLastLine(uk.nhs.adaptors.pss.translator.util.TextUtil.getLastLine) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) RCMRMT030101UK04Component02(org.hl7.v3.RCMRMT030101UK04Component02) ArrayList(java.util.ArrayList) DiagnosticReportStatus(org.hl7.fhir.dstu3.model.DiagnosticReport.DiagnosticReportStatus) Collectors.toCollection(java.util.stream.Collectors.toCollection) DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) ResourceType(org.hl7.fhir.dstu3.model.ResourceType) II(org.hl7.v3.II) Service(org.springframework.stereotype.Service) RCMRMT030101UK04EhrExtract(org.hl7.v3.RCMRMT030101UK04EhrExtract) CompoundStatementResourceExtractors.extractAllCompoundStatements(uk.nhs.adaptors.pss.translator.util.CompoundStatementResourceExtractors.extractAllCompoundStatements) RCMRMT030101UK04CompoundStatement(org.hl7.v3.RCMRMT030101UK04CompoundStatement) AbstractMapper(uk.nhs.adaptors.pss.translator.mapper.AbstractMapper) DateFormatUtil.parseToInstantType(uk.nhs.adaptors.pss.translator.util.DateFormatUtil.parseToInstantType) ResourceFilterUtil(uk.nhs.adaptors.pss.translator.util.ResourceFilterUtil) CompoundStatementResourceExtractors(uk.nhs.adaptors.pss.translator.util.CompoundStatementResourceExtractors) Reference(org.hl7.fhir.dstu3.model.Reference) InstantType(org.hl7.fhir.dstu3.model.InstantType) RCMRMT030101UK04EhrComposition(org.hl7.v3.RCMRMT030101UK04EhrComposition) Observation(org.hl7.fhir.dstu3.model.Observation) Objects(java.util.Objects) Encounter(org.hl7.fhir.dstu3.model.Encounter) TS(org.hl7.v3.TS) List(java.util.List) Patient(org.hl7.fhir.dstu3.model.Patient) Optional(java.util.Optional) ResourceUtil.generateMeta(uk.nhs.adaptors.pss.translator.util.ResourceUtil.generateMeta) ResourceUtil.buildIdentifier(uk.nhs.adaptors.pss.translator.util.ResourceUtil.buildIdentifier) Objects(java.util.Objects) DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport)

Example 20 with RCMRMT030101UK04EhrExtract

use of org.hl7.v3.RCMRMT030101UK04EhrExtract in project nia-patient-switching-standard-adaptor by NHSDigital.

the class ConditionMapper method getCondition.

private Condition getCondition(RCMRMT030101UK04EhrExtract ehrExtract, Patient patient, List<Encounter> encounters, RCMRMT030101UK04EhrComposition composition, RCMRMT030101UK04LinkSet linkSet, String practiseCode) {
    String id = linkSet.getId().getRoot();
    Condition condition = (Condition) new Condition().addIdentifier(buildIdentifier(id, practiseCode)).addCategory(generateCategory()).setId(id).setMeta(generateMeta(META_PROFILE));
    buildClinicalStatus(linkSet.getCode()).ifPresentOrElse(condition::setClinicalStatus, () -> {
        condition.setClinicalStatus(ACTIVE);
        condition.addNote(new Annotation(new StringType(DEFAULT_CLINICAL_STATUS)));
    });
    condition.setSubject(new Reference(patient));
    condition.addExtension(buildProblemSignificance(linkSet.getCode()));
    generateAnnotationToMinor(linkSet.getCode()).ifPresent(condition::addNote);
    buildContext(composition, encounters).ifPresent(condition::setContext);
    buildOnsetDateTimeType(linkSet).ifPresent(condition::setOnset);
    buildAbatementDateTimeType(linkSet.getEffectiveTime()).ifPresent(condition::setAbatement);
    buildAssertedDateTimeType(composition).ifPresentOrElse(condition::setAssertedDateElement, () -> condition.setAssertedDateElement(parseToDateTimeType(ehrExtract.getAvailabilityTime().getValue())));
    composition.getParticipant2().stream().findFirst().ifPresent(participant2 -> condition.setAsserter(new Reference(new IdType(ResourceType.Practitioner.name(), participant2.getAgentRef().getId().getRoot()))));
    return condition;
}
Also used : Condition(org.hl7.fhir.dstu3.model.Condition) StringType(org.hl7.fhir.dstu3.model.StringType) Reference(org.hl7.fhir.dstu3.model.Reference) Annotation(org.hl7.fhir.dstu3.model.Annotation) RCMRMT030101UK04Annotation(org.hl7.v3.RCMRMT030101UK04Annotation) IdType(org.hl7.fhir.dstu3.model.IdType)

Aggregations

RCMRMT030101UK04EhrExtract (org.hl7.v3.RCMRMT030101UK04EhrExtract)19 Reference (org.hl7.fhir.dstu3.model.Reference)13 Test (org.junit.jupiter.api.Test)13 Condition (org.hl7.fhir.dstu3.model.Condition)7 IdType (org.hl7.fhir.dstu3.model.IdType)7 List (java.util.List)5 Encounter (org.hl7.fhir.dstu3.model.Encounter)5 Observation (org.hl7.fhir.dstu3.model.Observation)5 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)4 RCMRMT030101UK04Component2 (org.hl7.v3.RCMRMT030101UK04Component2)4 ArrayList (java.util.ArrayList)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Specimen (org.hl7.fhir.dstu3.model.Specimen)3 RCMRMT030101UK04EhrComposition (org.hl7.v3.RCMRMT030101UK04EhrComposition)3 Service (org.springframework.stereotype.Service)3 ParticipantReferenceUtil.getParticipantReference (uk.nhs.adaptors.pss.translator.util.ParticipantReferenceUtil.getParticipantReference)3 Coding (org.hl7.fhir.dstu3.model.Coding)2 DateTimeType (org.hl7.fhir.dstu3.model.DateTimeType)2 DiagnosticReport (org.hl7.fhir.dstu3.model.DiagnosticReport)2