Skip to content

Commit e8c0606

Browse files
WIP - working on test still
1 parent a9515f8 commit e8c0606

File tree

1 file changed

+102
-26
lines changed

1 file changed

+102
-26
lines changed

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

Lines changed: 102 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -129,39 +129,17 @@ class ConditionLinkSetMapperTest {
129129
private InputBundle inputBundle;
130130

131131
private ConditionLinkSetMapper conditionLinkSetMapperSpy;
132-
private ConditionLinkSetMapper conditionLinkSetMapper;
133132

134133
@BeforeEach
135134
void setUp() {
136135
var bundleInput = ResourceTestFileUtils.getFileContent(TEST_FILES_DIRECTORY + INPUT_JSON_BUNDLE);
137136
final Bundle bundle = new FhirParseService().parseResource(bundleInput, Bundle.class);
138137
inputBundle = new InputBundle(bundle);
139-
140-
lenient().when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
141-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
142-
lenient().when(codeableConceptCdMapper.mapCodeableConceptToCdForTransformedActualProblemHeader(any(CodeableConcept.class)))
143-
.thenReturn(CodeableConceptMapperMockUtil.ACTUAL_PROBLEM_CODE);
144-
lenient().when(messageContext.getIdMapper()).thenReturn(idMapper);
145-
lenient().when(messageContext.getAgentDirectory()).thenReturn(agentDirectory);
146-
lenient().when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
147-
148-
IdType conditionId = buildIdType(ResourceType.Condition, CONDITION_ID);
149-
IdType allergyId = buildIdType(ResourceType.AllergyIntolerance, ALLERGY_ID);
150-
IdType immunizationId = buildIdType(ResourceType.Immunization, IMMUNIZATION_ID);
151-
lenient().when(idMapper.getOrNew(ResourceType.Condition, conditionId)).thenReturn(CONDITION_ID);
152-
lenient().when(idMapper.getOrNew(ResourceType.Observation, allergyId)).thenReturn(ALLERGY_ID);
153-
lenient().when(idMapper.getOrNew(ResourceType.Observation, immunizationId)).thenReturn(IMMUNIZATION_ID);
154-
lenient().when(idMapper.getOrNew(any(Reference.class))).thenAnswer(answerWithObjectId(ResourceType.Condition));
155-
lenient().when(agentDirectory.getAgentId(any(Reference.class))).thenAnswer(answerWithObjectId());
156-
lenient().when(randomIdGeneratorService.createNewId()).thenReturn(GENERATED_ID);
157-
158-
159-
conditionLinkSetMapper = new ConditionLinkSetMapper(messageContext, randomIdGeneratorService, codeableConceptCdMapper,
160-
new ParticipantMapper(), confidentialityService);
138+
ConditionLinkSetMapper conditionLinkSetMapper = new ConditionLinkSetMapper(messageContext, randomIdGeneratorService, codeableConceptCdMapper,
139+
new ParticipantMapper(), confidentialityService);
161140

162141
conditionLinkSetMapperSpy = spy(conditionLinkSetMapper);
163142

164-
lenient().doNothing().when(conditionLinkSetMapperSpy).testForValidReferences(any());
165143
}
166144

167145
@AfterEach
@@ -173,9 +151,18 @@ void afterEach() {
173151
void When_MappingParsedConditionWithoutMappedAgent_Expect_EhrMapperException() {
174152
final EhrMapperException propagatedException = new EhrMapperException("expected exception");
175153
final Condition condition = getConditionResourceFromJson(INPUT_JSON_STATUS_ACTIVE);
154+
IdType conditionId = buildIdType(ResourceType.Condition, CONDITION_ID);
176155

156+
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
157+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
158+
when(messageContext.getIdMapper()).thenReturn(idMapper);
159+
when(messageContext.getAgentDirectory()).thenReturn(agentDirectory);
160+
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
161+
when(idMapper.getOrNew(ResourceType.Condition, conditionId)).thenReturn(CONDITION_ID);
162+
when(idMapper.getOrNew(any(Reference.class))).thenAnswer(answerWithObjectId(ResourceType.Condition));
177163
when(agentDirectory.getAgentId(any(Reference.class)))
178164
.thenThrow(propagatedException);
165+
lenient().doNothing().when(conditionLinkSetMapperSpy).testForValidReferences(any());
179166

180167
assertThatThrownBy(() -> conditionLinkSetMapperSpy.mapConditionToLinkSet(condition, false))
181168
.isSameAs(propagatedException);
@@ -185,6 +172,18 @@ void When_MappingParsedConditionWithoutMappedAgent_Expect_EhrMapperException() {
185172
void When_MappingParsedConditionWithAsserterNotPractitioner_Expect_EhrMapperException() {
186173
final Condition condition = getConditionResourceFromJson(INPUT_JSON_ASSERTER_NOT_PRACTITIONER);
187174

175+
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
176+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
177+
when(messageContext.getIdMapper()).thenReturn(idMapper);
178+
when(messageContext.getAgentDirectory()).thenReturn(agentDirectory);
179+
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
180+
181+
IdType conditionId = buildIdType(ResourceType.Condition, CONDITION_ID);
182+
when(idMapper.getOrNew(ResourceType.Condition, conditionId)).thenReturn(CONDITION_ID);
183+
when(idMapper.getOrNew(any(Reference.class))).thenAnswer(answerWithObjectId(ResourceType.Condition));
184+
when(agentDirectory.getAgentId(any(Reference.class))).thenAnswer(answerWithObjectId());
185+
lenient().doNothing().when(conditionLinkSetMapperSpy).testForValidReferences(any());
186+
188187
assertThatThrownBy(() -> conditionLinkSetMapperSpy.mapConditionToLinkSet(condition, false))
189188
.isExactlyInstanceOf(EhrMapperException.class)
190189
.hasMessage("Condition.asserter must be a Practitioner");
@@ -195,6 +194,17 @@ void When_MappingParsedConditionWithAsserterNotPractitioner_Expect_EhrMapperExce
195194
void When_MappingParsedCondition_With_RealProblem_Expect_LinkSetXml(String conditionJson, String outputXml, boolean isNested) {
196195
final Condition condition = getConditionResourceFromJson(conditionJson);
197196
final String expectedXml = getXmlStringFromFile(outputXml);
197+
IdType conditionId = buildIdType(ResourceType.Condition, CONDITION_ID);
198+
199+
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
200+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
201+
when(messageContext.getIdMapper()).thenReturn(idMapper);
202+
when(messageContext.getAgentDirectory()).thenReturn(agentDirectory);
203+
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
204+
when(idMapper.getOrNew(ResourceType.Condition, conditionId)).thenReturn(CONDITION_ID);
205+
when(idMapper.getOrNew(any(Reference.class))).thenAnswer(answerWithObjectId(ResourceType.Condition));
206+
when(agentDirectory.getAgentId(any(Reference.class))).thenAnswer(answerWithObjectId());
207+
lenient().doNothing().when(conditionLinkSetMapperSpy).testForValidReferences(any());
198208

199209
final String actualXml = conditionLinkSetMapperSpy.mapConditionToLinkSet(condition, isNested);
200210

@@ -208,6 +218,19 @@ void When_MappingParsedCondition_With_ActualProblemContentAndIsObservation_Expec
208218
final Condition condition = getConditionResourceFromJson(conditionJson);
209219
final String expectedXml = getXmlStringFromFile(outputXml);
210220

221+
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
222+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
223+
when(messageContext.getIdMapper()).thenReturn(idMapper);
224+
when(messageContext.getAgentDirectory()).thenReturn(agentDirectory);
225+
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
226+
227+
IdType conditionId = buildIdType(ResourceType.Condition, CONDITION_ID);
228+
when(idMapper.getOrNew(ResourceType.Condition, conditionId)).thenReturn(CONDITION_ID);
229+
when(idMapper.getOrNew(any(Reference.class))).thenAnswer(answerWithObjectId(ResourceType.Condition));
230+
when(agentDirectory.getAgentId(any(Reference.class))).thenAnswer(answerWithObjectId());
231+
when(randomIdGeneratorService.createNewId()).thenReturn(GENERATED_ID);
232+
lenient().doNothing().when(conditionLinkSetMapperSpy).testForValidReferences(any());
233+
211234
final String actualXml = conditionLinkSetMapperSpy.mapConditionToLinkSet(condition, isNested);
212235

213236
assertThat(actualXml).isEqualTo(expectedXml);
@@ -217,6 +240,17 @@ void When_MappingParsedCondition_With_ActualProblemContentAndIsObservation_Expec
217240
void When_MappingParsedCondition_With_NoRelatedClinicalContent_Expect_LinkSetXml() {
218241
final Condition condition = getConditionResourceFromJson(INPUT_JSON_NO_RELATED_CLINICAL_CONTENT);
219242
final String expectedXml = getXmlStringFromFile(OUTPUT_XML_WITH_NO_RELATED_CLINICAL_CONTENT);
243+
IdType conditionId = buildIdType(ResourceType.Condition, CONDITION_ID);
244+
245+
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
246+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
247+
when(messageContext.getIdMapper()).thenReturn(idMapper);
248+
when(messageContext.getAgentDirectory()).thenReturn(agentDirectory);
249+
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
250+
when(idMapper.getOrNew(ResourceType.Condition, conditionId)).thenReturn(CONDITION_ID);
251+
when(idMapper.getOrNew(any(Reference.class))).thenAnswer(answerWithObjectId(ResourceType.Condition));
252+
when(agentDirectory.getAgentId(any(Reference.class))).thenAnswer(answerWithObjectId());
253+
lenient().doNothing().when(conditionLinkSetMapperSpy).testForValidReferences(any());
220254

221255
final String actualXml = conditionLinkSetMapperSpy.mapConditionToLinkSet(condition, false);
222256

@@ -239,6 +273,13 @@ void When_MappingParsedCondition_With_NonExistentReferenceInRelatedClinicalConte
239273
void When_MappingParsedConditionCodeIsMissing_Expect_MapperException() {
240274
final Condition condition = getConditionResourceFromJson(INPUT_JSON_MISSING_CONDITION_CODE);
241275

276+
when(messageContext.getIdMapper()).thenReturn(idMapper);
277+
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
278+
IdType conditionId = buildIdType(ResourceType.Condition, CONDITION_ID);
279+
when(idMapper.getOrNew(ResourceType.Condition, conditionId)).thenReturn(CONDITION_ID);
280+
when(idMapper.getOrNew(any(Reference.class))).thenAnswer(answerWithObjectId(ResourceType.Condition));
281+
lenient().doNothing().when(conditionLinkSetMapperSpy).testForValidReferences(any());
282+
242283
assertThatThrownBy(() -> conditionLinkSetMapperSpy.mapConditionToLinkSet(condition, false))
243284
.isExactlyInstanceOf(EhrMapperException.class)
244285
.hasMessage("Condition code not present");
@@ -249,6 +290,18 @@ void When_MappingCondition_With_SuppressedMedReqAsRelatedClinicalContent_Expect_
249290
final Condition condition = getConditionResourceFromJson(INPUT_JSON_SUPPRESSED_RELATED_MEDICATION_REQUEST);
250291
final String expectedXml = getXmlStringFromFile(OUTPUT_XML_SUPPRESSED_RELATED_MEDICATION_REQUEST);
251292

293+
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
294+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
295+
when(messageContext.getIdMapper()).thenReturn(idMapper);
296+
when(messageContext.getAgentDirectory()).thenReturn(agentDirectory);
297+
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
298+
299+
IdType conditionId = buildIdType(ResourceType.Condition, CONDITION_ID);
300+
when(idMapper.getOrNew(ResourceType.Condition, conditionId)).thenReturn(CONDITION_ID);
301+
when(idMapper.getOrNew(any(Reference.class))).thenAnswer(answerWithObjectId(ResourceType.Condition));
302+
when(agentDirectory.getAgentId(any(Reference.class))).thenAnswer(answerWithObjectId());
303+
lenient().doNothing().when(conditionLinkSetMapperSpy).testForValidReferences(any());
304+
252305
final String actualXml = conditionLinkSetMapperSpy.mapConditionToLinkSet(condition, false);
253306

254307
XMLAssert.assertXMLEqual(expectedXml, actualXml);
@@ -262,6 +315,18 @@ void When_MappingCondition_With_NopatMetaSecurity_Expect_ConfidentialityCodeInBo
262315
.getNopatConfidentialityCodeXpathSegment();
263316

264317
ConfidentialityCodeUtility.appendNopatSecurityToMetaForResource(condition);
318+
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
319+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
320+
when(messageContext.getIdMapper()).thenReturn(idMapper);
321+
when(messageContext.getAgentDirectory()).thenReturn(agentDirectory);
322+
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
323+
324+
IdType conditionId = buildIdType(ResourceType.Condition, CONDITION_ID);
325+
when(idMapper.getOrNew(ResourceType.Condition, conditionId)).thenReturn(CONDITION_ID);
326+
when(idMapper.getOrNew(any(Reference.class))).thenAnswer(answerWithObjectId(ResourceType.Condition));
327+
when(agentDirectory.getAgentId(any(Reference.class))).thenAnswer(answerWithObjectId());
328+
lenient().doNothing().when(conditionLinkSetMapperSpy).testForValidReferences(any());
329+
265330
when(confidentialityService.generateConfidentialityCode(conditionArgumentCaptor.capture()))
266331
.thenReturn(Optional.of(NOPAT_HL7_CONFIDENTIALITY_CODE));
267332

@@ -280,10 +345,21 @@ void When_MappingCondition_With_NopatMetaSecurity_Expect_ConfidentialityCodeInBo
280345
@Test
281346
void When_MappingCondition_With_NoscrubMetaSecurity_Expect_ConfidentialityCodeNotPresent() {
282347
final Condition condition = getConditionResourceFromJson(INPUT_JSON_SUPPRESSED_RELATED_MEDICATION_REQUEST);
283-
284348
ConfidentialityCodeUtility.appendNoscrubSecurityToMetaForResource(condition);
349+
350+
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
351+
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
352+
when(messageContext.getIdMapper()).thenReturn(idMapper);
353+
when(messageContext.getAgentDirectory()).thenReturn(agentDirectory);
354+
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
355+
IdType conditionId = buildIdType(ResourceType.Condition, CONDITION_ID);
356+
when(idMapper.getOrNew(ResourceType.Condition, conditionId)).thenReturn(CONDITION_ID);
357+
when(idMapper.getOrNew(any(Reference.class))).thenAnswer(answerWithObjectId(ResourceType.Condition));
358+
when(agentDirectory.getAgentId(any(Reference.class))).thenAnswer(answerWithObjectId());
285359
when(confidentialityService.generateConfidentialityCode(conditionArgumentCaptor.capture()))
286-
.thenReturn(Optional.empty());
360+
.thenReturn(Optional.empty());
361+
362+
lenient().doNothing().when(conditionLinkSetMapperSpy).testForValidReferences(any());
287363

288364
final String actualXml = conditionLinkSetMapperSpy.mapConditionToLinkSet(condition, false);
289365
final String conditionSecurityCode = ConfidentialityCodeUtility

0 commit comments

Comments
 (0)