File tree Expand file tree Collapse file tree 3 files changed +72
-1
lines changed
main/java/uk/nhs/adaptors/gp2gp/ehr/mapper
java/uk/nhs/adaptors/gp2gp/ehr/mapper
resources/ehr/mapper/medication_request Expand file tree Collapse file tree 3 files changed +72
-1
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ public class MedicationStatementMapper {
7171 private static final List <String > REPEAT_PRESCRIPTION_TYPE_CODES =
7272 Arrays .asList ("delayed-prescribing" , "repeat" , "repeat-dispensing" );
7373 private static final String ACUTE_REPEAT_VALUE = "0" ;
74+ private static final String INVALID_PRESCRIPTION_TYPE_MESSAGE = "Could not resolve Prescription Type of `%s` in %s" ;
7475
7576 private final MessageContext messageContext ;
7677 private final CodeableConceptCdMapper codeableConceptCdMapper ;
@@ -254,7 +255,7 @@ private String buildRepeatNumber(MedicationRequest medicationRequest) {
254255 } else if (prescriptionTypeCode .isBlank () && prescriptionTypeTextIsNoInfoAvailable (medicationRequest )) {
255256 return extractRepeatValue (medicationRequest );
256257 }
257- throw new EhrMapperException ("Could not resolve Prescription Type for Repeat value" );
258+ throw new EhrMapperException (INVALID_PRESCRIPTION_TYPE_MESSAGE . formatted ( prescriptionTypeCode , medicationRequest . getId ()) );
258259 }
259260 return StringUtils .EMPTY ;
260261 }
Original file line number Diff line number Diff line change @@ -373,6 +373,19 @@ public void When_ConfidentialityServiceReturnsEmptyOptional_Expect_MessageDoesNo
373373 .doesNotContain (CONFIDENTIALITY_CODE );
374374 }
375375
376+ @ Test
377+ void When_MedicationRequestPlanHasInvalidPrescriptionType_Expect_EhrMapperExceptionThrown () {
378+ final var jsonInput = ResourceTestFileUtils .getFileContent (TEST_FILE_DIRECTORY + "mr-plan-with-invalid-prescription-type.json" );
379+ final var parsedMedicationRequest = new FhirParseService ()
380+ .parseResource (jsonInput , MedicationRequest .class );
381+
382+ var exception = assertThrows (
383+ EhrMapperException .class ,
384+ () -> medicationStatementMapper .mapMedicationRequestToMedicationStatement (parsedMedicationRequest ));
385+
386+ assertThat (exception .getMessage ()).isEqualTo ("Could not resolve Prescription Type of `invalid-type` in MedicationRequest/789" );
387+ }
388+
376389 private void assertXmlIsEqual (String outputString , String expected ) {
377390
378391 Diff diff = DiffBuilder .compare (outputString ).withTest (expected )
Original file line number Diff line number Diff line change 1+ {
2+ "resourceType" : " MedicationRequest" ,
3+ "id" : " 789" ,
4+ "meta" : {
5+ "profile" : [
6+ " https://fhir.nhs.uk/STU3/StructureDefinition/CareConnect-GPC-MedicationRequest-1"
7+ ]
8+ },
9+ "extension" : [
10+ {
11+ "url" : " https://fhir.nhs.uk/STU3/StructureDefinition/Extension-CareConnect-GPC-PrescriptionType-1" ,
12+ "valueCodeableConcept" : {
13+ "coding" : [
14+ {
15+ "system" : " https://fhir.nhs.uk/STU3/CodeSystem/CareConnect-PrescriptionType-1" ,
16+ "code" : " invalid-type" ,
17+ "display" : " Invalid Type"
18+ }
19+ ]
20+ }
21+ }
22+ ],
23+ "status" : " completed" ,
24+ "intent" : " plan" ,
25+ "medicationReference" : {
26+ "reference" : " Medication/20"
27+ },
28+ "authoredOn" : " 2022-10-04" ,
29+ "recorder" : {
30+ "reference" : " Practitioner/1332aa9c-28d6-11eb-adc1-0242ac120002"
31+ },
32+ "requester" : {
33+ "agent" : {
34+ "reference" : " Organization/F85003"
35+ }
36+ },
37+ "dosageInstruction" : [
38+ {
39+ "text" : " One puff as needed. Max 10 doses per day"
40+ }
41+ ],
42+ "dispenseRequest" : {
43+ "validityPeriod" : {
44+ "start" : " 2022-10-04" ,
45+ "end" : " 2022-11-01"
46+ },
47+ "quantity" : {
48+ "value" : 1 ,
49+ "unit" : " dose"
50+ },
51+ "expectedSupplyDuration" : {
52+ "value" : 28 ,
53+ "system" : " http://unitsofmeasure.org" ,
54+ "code" : " d"
55+ }
56+ }
57+ }
You can’t perform that action at this time.
0 commit comments