From d8342853483b79504ab6062f98beff1eed938b7c Mon Sep 17 00:00:00 2001 From: Adrian Clay Date: Fri, 11 Oct 2024 14:50:19 +0100 Subject: [PATCH] Update original MedicationStatement lastIssueDate for multiple acute med When an accute med has multiple issues, we generate individual plan/statement for each order. This updates the original statements lastIssueDate to correspond to the date on its corresponding MedicationRequest[order]. Previously the lastIssueDate was the most recent date of all the orders. --- .../e2e-mapping/output-json/PWTP2-output.json | 2 +- .../e2e-mapping/output-json/PWTP4-output.json | 4 ++-- .../mapper/medication/MedicationRequestMapper.java | 5 +++++ .../medication/MedicationRequestMapperTest.java | 13 +++++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/gp2gp-translator/src/integrationTest/resources/e2e-mapping/output-json/PWTP2-output.json b/gp2gp-translator/src/integrationTest/resources/e2e-mapping/output-json/PWTP2-output.json index 401d18441..0918c701e 100644 --- a/gp2gp-translator/src/integrationTest/resources/e2e-mapping/output-json/PWTP2-output.json +++ b/gp2gp-translator/src/integrationTest/resources/e2e-mapping/output-json/PWTP2-output.json @@ -2414,7 +2414,7 @@ } }, { "url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-CareConnect-GPC-MedicationStatementLastIssueDate-1", - "valueDateTime": "2010-02-26" + "valueDateTime": "2010-01-13" } ], "identifier": [ { "system": "https://PSSAdaptor/B83002", diff --git a/gp2gp-translator/src/integrationTest/resources/e2e-mapping/output-json/PWTP4-output.json b/gp2gp-translator/src/integrationTest/resources/e2e-mapping/output-json/PWTP4-output.json index 077ba78bd..7692a8033 100644 --- a/gp2gp-translator/src/integrationTest/resources/e2e-mapping/output-json/PWTP4-output.json +++ b/gp2gp-translator/src/integrationTest/resources/e2e-mapping/output-json/PWTP4-output.json @@ -3434,7 +3434,7 @@ } }, { "url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-CareConnect-GPC-MedicationStatementLastIssueDate-1", - "valueDateTime": "2013-01-03" + "valueDateTime": "2010-01-14" } ], "identifier": [ { "system": "https://PSSAdaptor/B83002", @@ -5953,7 +5953,7 @@ } }, { "url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-CareConnect-GPC-MedicationStatementLastIssueDate-1", - "valueDateTime": "2010-05-21" + "valueDateTime": "2010-01-18" } ], "identifier": [ { "system": "https://PSSAdaptor/B83002", diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/medication/MedicationRequestMapper.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/medication/MedicationRequestMapper.java index 003fbed8b..2bebdbda0 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/medication/MedicationRequestMapper.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/medication/MedicationRequestMapper.java @@ -105,6 +105,11 @@ private void generateResourcesForMultipleOrdersLinkedToASingleAcutePlan(ArrayLis resources.add(duplicatedPlan); resources.add(duplicatedMedicationStatement); } + + final var originalMedicationStatement = getMedicationStatementByPlanId(medicationStatements, plan.getId()); + originalMedicationStatement.getExtensionByUrl(MEDICATION_STATEMENT_LAST_ISSUE_DATE_URL).setValue( + orders.get(0).getDispenseRequest().getValidityPeriod().getStartElement() + ); } }); } diff --git a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/mapper/medication/MedicationRequestMapperTest.java b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/mapper/medication/MedicationRequestMapperTest.java index 6a7e046b5..06dedddb9 100644 --- a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/mapper/medication/MedicationRequestMapperTest.java +++ b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/mapper/medication/MedicationRequestMapperTest.java @@ -666,6 +666,19 @@ void expectGeneratedMedicationStatementLastIssueDateExtensionSetToValidityPeriod .isEqualTo(latestOrder.getDispenseRequest().getValidityPeriod().getStartElement()); } + @Test + void expectOriginalMedicationStatementLastIssueDateExtensionSetToValidityPeriodStart() { + var resources = medicationRequestMapper + .mapResources(ehrExtract, (Patient) new Patient().setId(PATIENT_ID), List.of(), PRACTISE_CODE + ); + + var earliestOrder = getMedicationRequestById(resources, EARLIEST_ORDER_ID); + var originalMedicationStatement = getMedicationStatementById(resources, INITIAL_MEDICATION_STATEMENT_ID); + + assertThat(originalMedicationStatement.getExtensionByUrl(MEDICATION_STATEMENT_LAST_ISSUE_DATE_URL).getValue()) + .isEqualTo(earliestOrder.getDispenseRequest().getValidityPeriod().getStartElement()); + } + @Test void expectOriginalMedicationStatementUnchangedPropertiesAreCopiedToGeneratedMedicationStatement() { var resources = medicationRequestMapper