Skip to content

Commit 7529d68

Browse files
committed
adding test coverage
1 parent 78c1d35 commit 7529d68

File tree

5 files changed

+2410
-6
lines changed

5 files changed

+2410
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,15 @@ private String mapTopicListToComponent(ListResource topicList) {
120120
+ "Topic (EHR)", topicList.getId()));
121121
}
122122

123+
var confidentialityCode = confidentialityService.generateConfidentialityCode(topicList);
124+
123125
return buildCompoundStatement(
124126
topicList,
125127
TOPIC.getCode(),
126128
prepareCdForTopic(topicList),
127129
false,
128-
mapTopicListComponents(topicList)
130+
mapTopicListComponents(topicList),
131+
confidentialityCode
129132
);
130133
}
131134

@@ -164,7 +167,8 @@ private String mapCategoryListToComponent(ListResource categoryList) {
164167
CATEGORY.getCode(),
165168
prepareCdForCategory(categoryList),
166169
true,
167-
mapListResourceToComponents(categoryList)
170+
mapListResourceToComponents(categoryList),
171+
Optional.empty()
168172
);
169173
}
170174

@@ -196,7 +200,8 @@ private String mapUncategorizedResources(ListResource topicList) {
196200
CATEGORY.getCode(),
197201
codeableConceptCdMapper.getCdForCategory(),
198202
true,
199-
components
203+
components,
204+
Optional.empty()
200205
);
201206
}
202207

@@ -409,9 +414,8 @@ private String buildCompoundStatement(
409414
String classCode,
410415
String compoundStatementCode,
411416
boolean nested,
412-
String components) {
413-
414-
var confidentialityCode = confidentialityService.generateConfidentialityCode(topicList);
417+
String components,
418+
Optional<String> confidentialityCode) {
415419

416420
if (StringUtils.isEmpty(components)) {
417421
return StringUtils.EMPTY;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
{{{effectiveTime}}}
88
</effectiveTime>
99
{{{availabilityTime}}}
10+
{{#confidentialityCode}}
11+
{{{confidentialityCode}}}
12+
{{/confidentialityCode}}
1013
{{{components}}}
1114
</CompoundStatement>
1215
</component>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.hl7.fhir.dstu3.model.CodeableConcept;
66
import org.hl7.fhir.dstu3.model.Encounter;
77
import org.hl7.fhir.dstu3.model.IdType;
8+
import org.hl7.fhir.dstu3.model.ListResource;
89
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
910
import org.hl7.fhir.dstu3.model.Reference;
1011
import org.hl7.fhir.dstu3.model.Resource;
@@ -54,6 +55,7 @@ public class EncounterComponentsMapperTest {
5455
private static final String TEST_DIRECTORY = "/ehr/mapper/encountercomponents/";
5556
private static final String INPUT_BUNDLE_WITH_ALL_MAPPERS_USED = TEST_DIRECTORY + "input-bundle-1.json";
5657
private static final String EXPECTED_COMPONENTS_MAPPED_WITH_ALL_MAPPERS_USED = TEST_DIRECTORY + "expected-components-1.xml";
58+
private static final String EXPECTED_COMPONENTS_MAPPED_WITH_NOPAT = TEST_DIRECTORY + "expected-components-with-nopat.xml";
5759
private static final String INPUT_BUNDLE_WITH_EMPTY_CONSULTATION_LIST = TEST_DIRECTORY + "input-bundle-2.json";
5860
private static final String INPUT_BUNDLE_WITH_EMPTY_TOPIC_LIST = TEST_DIRECTORY + "input-bundle-3.json";
5961
private static final String INPUT_BUNDLE_WITH_EMPTY_CATEGORY_LIST = TEST_DIRECTORY + "input-bundle-4.json";
@@ -63,6 +65,7 @@ public class EncounterComponentsMapperTest {
6365
private static final String INPUT_BUNDLE_WITH_NON_TOPIC_CONSULTATION_LIST_ENTRY = TEST_DIRECTORY + "input-bundle-8.json";
6466
private static final String INPUT_BUNDLE_WITH_UNSUPPORTED_RESOURCES = TEST_DIRECTORY + "input-bundle-9-unsupported-resource.json";
6567
private static final String INPUT_BUNDLE_WITH_IGNORED_RESOURCE = TEST_DIRECTORY + "input-bundle-10-ignored-resource.json";
68+
private static final String INPUT_BUNDLE_WITH_META_SECURITY = TEST_DIRECTORY + "input-bundle-10-with-meta.json";
6669
private static final String INPUT_BUNDLE_WITH_NON_CATEGORY_TOPIC_LIST_ENTRY = TEST_DIRECTORY
6770
+ "input-bundle-11-invalid-category-list.json";
6871
private static final String INPUT_BUNDLE_WITH_RELATED_PROBLEM_IN_TOPIC = TEST_DIRECTORY + "input-bundle-12-related-problem.json";
@@ -270,6 +273,18 @@ public void When_MappingEncounterComponents_Expect_IgnoredResourceNotMapped() {
270273
assertThat(mappedXml).isEqualToIgnoringWhitespace(expectedXml);
271274
}
272275

276+
@Test
277+
public void When_EncounterComponentsIncludeListWithMetaSecurity_Expect_CompoundStatementWithNOPAT() {
278+
String expectedXml = ResourceTestFileUtils.getFileContent(EXPECTED_COMPONENTS_MAPPED_WITH_NOPAT);
279+
280+
var bundle = initializeMessageContext(INPUT_BUNDLE_WITH_META_SECURITY);
281+
var encounter = extractEncounter(bundle);
282+
when(confidentialityService.generateConfidentialityCode(any(ListResource.class))).thenReturn(Optional.of(CONFIDENTIALITY_CODE));
283+
284+
String mappedXml = encounterComponentsMapper.mapComponents(encounter);
285+
assertThat(mappedXml).isEqualToIgnoringWhitespace(expectedXml);
286+
}
287+
273288
@ParameterizedTest
274289
@MethodSource("emptyResult")
275290
public void When_MappingEncounterComponents_Expect_NoResourceMapped(String inputJsonPath) {

0 commit comments

Comments
 (0)