Skip to content

Commit 0d0d781

Browse files
authored
Restructured availability time value mappings (#602)
* Restructured availability time value mappings * Changed source value for availabilityTime from onsetDate to assertedDate * Corrected test data. * Removed Line Break
1 parent 1a2a723 commit 0d0d781

File tree

39 files changed

+152
-92
lines changed

39 files changed

+152
-92
lines changed

service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AllergyStructureExtractor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ public static String extractOnsetDate(AllergyIntolerance allergyIntolerance) {
5959
return StringUtils.EMPTY;
6060
}
6161

62+
public static String extractAssertedDate(AllergyIntolerance allergyIntolerance) {
63+
if (allergyIntolerance.hasAssertedDateElement() && allergyIntolerance.getAssertedDateElement().hasValue()) {
64+
return toHl7Format(allergyIntolerance.getAssertedDateElement());
65+
}
66+
return StringUtils.EMPTY;
67+
}
68+
6269
public static String extractReaction(AllergyIntolerance.AllergyIntoleranceReactionComponent reactionComponent,
6370
AtomicInteger reactionCount) {
6471
String reaction = String.format(REACTION, reactionCount.getAndIncrement());

service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AllergyStructureMapper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static uk.nhs.adaptors.gp2gp.ehr.mapper.AllergyStructureExtractor.extractOnsetDate;
44
import static uk.nhs.adaptors.gp2gp.ehr.mapper.AllergyStructureExtractor.extractReaction;
5+
import static uk.nhs.adaptors.gp2gp.ehr.mapper.AllergyStructureExtractor.extractAssertedDate;
56
import static uk.nhs.adaptors.gp2gp.ehr.utils.DateFormatUtil.toTextFormat;
67
import static uk.nhs.adaptors.gp2gp.ehr.utils.ExtensionMappingUtils.filterExtensionByUrl;
78

@@ -124,11 +125,10 @@ private String buildCode(AllergyIntolerance allergyIntolerance) {
124125
}
125126

126127
private String buildAvailabilityTime(AllergyIntolerance allergyIntolerance) {
127-
return Optional.of(allergyIntolerance)
128-
.filter(AllergyIntolerance::hasOnsetDateTimeType)
129-
.map(AllergyIntolerance::getOnsetDateTimeType)
130-
.map(DateFormatUtil::toHl7Format)
131-
.orElse(StringUtils.EMPTY);
128+
129+
var availabilityTime = extractAssertedDate(allergyIntolerance);
130+
131+
return StatementTimeMappingUtils.prepareAvailabilityTimeForAllergyIntolerance(availabilityTime);
132132
}
133133

134134
private String buildEffectiveTime(AllergyIntolerance allergyIntolerance) {

service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/utils/StatementTimeMappingUtils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ public static String prepareEffectiveTimeForAllergyIntolerance(String onsetDate)
117117
}
118118
}
119119

120+
public static String prepareAvailabilityTimeForAllergyIntolerance(String date) {
121+
if (!date.isEmpty()) {
122+
return String.format(AVAILABILITY_TIME_VALUE_TEMPLATE, date);
123+
}
124+
125+
return DEFAULT_AVAILABILITY_TIME_VALUE;
126+
}
127+
120128
public static String prepareEffectiveTimeForMedicationRequest(MedicationRequest medicationRequest) {
121129
final var dispenseRequest = medicationRequest.getDispenseRequest();
122130
if (dispenseRequest.hasValidityPeriod() && dispenseRequest.getValidityPeriod().hasStart()) {

service/src/main/resources/templates/ehr_allergy_structure_template.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<effectiveTime>
77
{{{effectiveTime}}}
88
</effectiveTime>
9-
<availabilityTime {{#availabilityTime}}value="{{availabilityTime}}"{{/availabilityTime}}{{^availabilityTime}}nullFlavor="UNK"{{/availabilityTime}} />
9+
{{{availabilityTime}}}
1010
<component typeCode="COMP" contextConductionInd="true">
1111
<ObservationStatement classCode="OBS" moodCode="ENV">
1212
<id root="{{observationId}}"/>
@@ -15,7 +15,7 @@
1515
<effectiveTime>
1616
{{{effectiveTime}}}
1717
</effectiveTime>
18-
<availabilityTime {{#availabilityTime}}value="{{availabilityTime}}"{{/availabilityTime}}{{^availabilityTime}}nullFlavor="UNK"{{/availabilityTime}} />
18+
{{{availabilityTime}}}
1919
<pertinentInformation typeCode="PERT">
2020
<sequenceNumber value="+1"/>
2121
<pertinentAnnotation classCode="OBS" moodCode="EVN">

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AllergyStructureMapperTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public class AllergyStructureMapperTest {
7070
+ "example-allergy-intolerance-resource-20.json";
7171
private static final String INPUT_JSON_WITHOUT_END_DATE = TEST_FILE_DIRECTORY
7272
+ "example-allergy-intolerance-resource-without-endDate.json";
73+
private static final String INPUT_JSON_WITHOUT_ASSERTED_DATE = TEST_FILE_DIRECTORY
74+
+ "example-allergy-intolerance-resource-without-assertedDate.json";
7375
private static final String INPUT_JSON_WITH_VALID_RECORDER_NO_ASSERTER = TEST_FILE_DIRECTORY
7476
+ "example-allergy-intolerance-resource-21.json";
7577
private static final String INPUT_JSON_WITH_INVALID_RECORDER_NO_ASSERTER = TEST_FILE_DIRECTORY
@@ -108,6 +110,8 @@ public class AllergyStructureMapperTest {
108110
private static final String OUTPUT_XML_USES_END_DATE = TEST_FILE_DIRECTORY + "expected-output-allergy-structure-17.xml";
109111
private static final String OUTPUT_XML_USES_NO_END_DATE = TEST_FILE_DIRECTORY
110112
+ "expected-output-allergy-structure-without-endDate.xml";
113+
private static final String OUTPUT_XML_USES_NO_ASSERTED_DATE = TEST_FILE_DIRECTORY
114+
+ "expected-output-allergy-structure-without-assertedDate.xml";
111115
private static final String OUTPUT_XML_USES_RECORDER_AS_PERFORMER = TEST_FILE_DIRECTORY
112116
+ "expected-output-allergy-structure-17.xml";
113117
private static final String OUTPUT_XML_USES_NO_AUTHOR_OR_PERFORMER = TEST_FILE_DIRECTORY
@@ -151,6 +155,7 @@ private static Stream<Arguments> resourceFileParams() {
151155
Arguments.of(INPUT_JSON_WITH_RELATED_PERSON_ASSERTER_NAME_TEXT, OUTPUT_XML_USES_RELATED_PERSON_ASSERTER),
152156
Arguments.of(INPUT_JSON_WITH_RELATED_PERSON_ASSERTER_NO_NAME, OUTPUT_XML_USES_RELATED_PERSON_ASSERTER_NO_NAME),
153157
Arguments.of(INPUT_JSON_WITHOUT_END_DATE, OUTPUT_XML_USES_NO_END_DATE),
158+
Arguments.of(INPUT_JSON_WITHOUT_ASSERTED_DATE, OUTPUT_XML_USES_NO_ASSERTED_DATE),
154159
Arguments.of(INPUT_JSON_WITH_VALID_RECORDER_NO_ASSERTER, OUTPUT_XML_USES_RECORDER_AS_FALLBACK_ASSERTER),
155160
Arguments.of(INPUT_JSON_WITH_INVALID_RECORDER_NO_ASSERTER, OUTPUT_XML_USES_NO_AUTHOR_OR_PERFORMER),
156161
Arguments.of(INPUT_JSON_WITH_VALID_RECORDER_RELATED_PERSON_ASSERTER,

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EhrExtractMapperComponentTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public void When_MappingJsonBody_Expect_OnlyOneConsultationResource() throws IOE
245245
getGpcStructuredTaskDefinition,
246246
bundle);
247247
String output = ehrExtractMapper.mapEhrExtractToXml(ehrExtractTemplateParameters);
248-
assertThat(output).isEqualTo(expectedJsonToXmlContent);
248+
assertThat(output).isEqualToIgnoringWhitespace(expectedJsonToXmlContent);
249249
}
250250

251251
@Test
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"resourceType": "AllergyIntolerance",
3+
"id": "230D3D37-99E3-450A-AE88-B5AB802B7137",
4+
"onsetDateTime": "1978-12-31",
5+
"clinicalStatus": "resolved",
6+
"category": [
7+
"medication"
8+
],
9+
"code": {
10+
"text": "test"
11+
}
12+
}

service/src/test/resources/ehr/mapper/allergy/expected-output-allergy-structure-1.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<effectiveTime>
77
<center value="19781231"/>
88
</effectiveTime>
9-
<availabilityTime value="19781231" />
9+
<availabilityTime value="20100114095757"/>
1010
<component typeCode="COMP" contextConductionInd="true">
1111
<ObservationStatement classCode="OBS" moodCode="ENV">
1212
<id root="394559384658936"/>
@@ -15,7 +15,7 @@
1515
<effectiveTime>
1616
<center value="19781231"/>
1717
</effectiveTime>
18-
<availabilityTime value="19781231" />
18+
<availabilityTime value="20100114095757"/>
1919
<pertinentInformation typeCode="PERT">
2020
<sequenceNumber value="+1"/>
2121
<pertinentAnnotation classCode="OBS" moodCode="EVN">

service/src/test/resources/ehr/mapper/allergy/expected-output-allergy-structure-10.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<effectiveTime>
77
<center value="20200724"/>
88
</effectiveTime>
9-
<availabilityTime value="20200724" />
9+
<availabilityTime value="20200724133829"/>
1010
<component typeCode="COMP" contextConductionInd="true">
1111
<ObservationStatement classCode="OBS" moodCode="ENV">
1212
<id root="394559384658936"/>
@@ -15,7 +15,7 @@
1515
<effectiveTime>
1616
<center value="20200724"/>
1717
</effectiveTime>
18-
<availabilityTime value="20200724" />
18+
<availabilityTime value="20200724133829"/>
1919
<pertinentInformation typeCode="PERT">
2020
<sequenceNumber value="+1"/>
2121
<pertinentAnnotation classCode="OBS" moodCode="EVN">

service/src/test/resources/ehr/mapper/allergy/expected-output-allergy-structure-11.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<effectiveTime>
77
<center value="20100114"/>
88
</effectiveTime>
9-
<availabilityTime value="20100114" />
9+
<availabilityTime value="20100114095728"/>
1010
<component typeCode="COMP" contextConductionInd="true">
1111
<ObservationStatement classCode="OBS" moodCode="ENV">
1212
<id root="394559384658936"/>
@@ -15,7 +15,7 @@
1515
<effectiveTime>
1616
<center value="20100114"/>
1717
</effectiveTime>
18-
<availabilityTime value="20100114" />
18+
<availabilityTime value="20100114095728"/>
1919
<pertinentInformation typeCode="PERT">
2020
<sequenceNumber value="+1"/>
2121
<pertinentAnnotation classCode="OBS" moodCode="EVN">

0 commit comments

Comments
 (0)