Skip to content

Commit

Permalink
Update original MedicationStatement lastIssueDate for multiple acute …
Browse files Browse the repository at this point in the history
…med (#871)

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.
  • Loading branch information
adrianclay authored Oct 14, 2024
1 parent 4c9c6b4 commit 53457ac
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 53457ac

Please sign in to comment.