@@ -36,145 +36,112 @@ class AllergyStructureExtractorTest {
3636 private static final String EXPECTED_ONSET_DATE = "19781231" ;
3737 private static final String REACTION_START = "Reaction 1 " ;
3838 private static final String FULL_REACTION = REACTION_START + "Description: description Exposure Route: exposure route "
39- + "Severity: MODERATE Manifestation(s): manifestation 1, manifestation 2" ;
39+ + "Severity: MODERATE Manifestation(s): manifestation 1, manifestation 2" ;
4040
4141 private Extension extension ;
4242 private List <Extension > extensionList ;
43- private Extension nestedExtension ;
4443
4544 private static Stream <Arguments > reasonEndTextParams () {
4645 return Stream .of (
47- Arguments .of (REASON_END_URL , REASON_END_TEXT , EXPECTED_REASON_END_TEXT ),
48- Arguments .of (REASON_END_URL , REASON_END_NO_INFO , StringUtils .EMPTY ),
49- Arguments .of (INVALID_URL , REASON_END_TEXT , StringUtils .EMPTY )
46+ Arguments .of (REASON_END_URL , REASON_END_TEXT , EXPECTED_REASON_END_TEXT ),
47+ Arguments .of (REASON_END_URL , REASON_END_NO_INFO , StringUtils .EMPTY ),
48+ Arguments .of (INVALID_URL , REASON_END_TEXT , StringUtils .EMPTY )
5049 );
5150 }
5251
5352 private static Stream <Arguments > reasonEndDateHL7Params () {
5453 return Stream .of (
55- Arguments .of (ALLERGY_END_DATE_URL , REASON_END_DATE , EXPECTED_REASON_END_DATE_HL7 ),
56- Arguments .of (INVALID_URL , REASON_END_DATE , StringUtils .EMPTY )
54+ Arguments .of (ALLERGY_END_DATE_URL , REASON_END_DATE , EXPECTED_REASON_END_DATE_HL7 ),
55+ Arguments .of (INVALID_URL , REASON_END_DATE , StringUtils .EMPTY )
5756 );
5857 }
5958
6059 private static Stream <Arguments > reasonEndDateHumanReadableParams () {
6160 return Stream .of (
62- Arguments .of (ALLERGY_END_DATE_URL , REASON_END_DATE , EXPECTED_REASON_END_DATE_HUMAN_READABLE ),
63- Arguments .of (INVALID_URL , REASON_END_DATE , StringUtils .EMPTY )
61+ Arguments .of (ALLERGY_END_DATE_URL , REASON_END_DATE , EXPECTED_REASON_END_DATE_HUMAN_READABLE ),
62+ Arguments .of (INVALID_URL , REASON_END_DATE , StringUtils .EMPTY )
6463 );
6564 }
6665
6766 private static Stream <Arguments > onsetDateParams () {
6867 return Stream .of (
69- Arguments .of (ONSET_DATE , EXPECTED_ONSET_DATE ),
70- Arguments .of (null , StringUtils .EMPTY )
68+ Arguments .of (ONSET_DATE , EXPECTED_ONSET_DATE ),
69+ Arguments .of (null , StringUtils .EMPTY )
7170 );
7271 }
7372
7473 @ BeforeEach
75- public void setUp () {
74+ void setUp () {
7675 extension = new Extension ();
7776 extensionList = new ArrayList <>();
78- nestedExtension = new Extension ();
77+ }
78+
79+ private void setupNestedExtension (String url , org .hl7 .fhir .dstu3 .model .Type value ) {
80+ var nested = new Extension (url , value );
81+ extensionList .clear ();
82+ extensionList .add (nested );
83+ extension .setExtension (extensionList );
7984 }
8085
8186 @ ParameterizedTest
8287 @ MethodSource ("reasonEndTextParams" )
8388 void When_ExtractingReasonEnd_Expect_ReasonOutput (String reasonEndUrl , String reasonEndText , String expectedReasonEnd ) {
84- nestedExtension .setUrl (reasonEndUrl );
85- nestedExtension .setValue (new StringType (reasonEndText ));
86- extensionList .add (nestedExtension );
87- extension .setExtension (extensionList );
88-
89- String outputReasonEnd = AllergyStructureExtractor .extractReasonEnd (extension );
90-
91- assertEquals (expectedReasonEnd , outputReasonEnd );
89+ setupNestedExtension (reasonEndUrl , new StringType (reasonEndText ));
90+ assertEquals (expectedReasonEnd , AllergyStructureExtractor .extractReasonEnd (extension ));
9291 }
9392
9493 @ ParameterizedTest
9594 @ MethodSource ("reasonEndDateHL7Params" )
9695 void When_ExtractingReasonEndDate_Expect_EndDateOutput (String reasonEndDateUrl , String reasonEndDate , String expectedEndDate ) {
97- nestedExtension .setUrl (reasonEndDateUrl );
98- nestedExtension .setValue (new DateTimeType (reasonEndDate ));
99- extensionList .add (nestedExtension );
100- extension .setExtension (extensionList );
101-
102- String outputEndDate = AllergyStructureExtractor .extractEndDate (extension , DateFormatUtil ::toHl7Format );
103-
104- assertEquals (expectedEndDate , outputEndDate );
96+ setupNestedExtension (reasonEndDateUrl , new DateTimeType (reasonEndDate ));
97+ assertEquals (expectedEndDate , AllergyStructureExtractor .extractEndDate (extension , DateFormatUtil ::toHl7Format ));
10598 }
10699
107100 @ ParameterizedTest
108101 @ MethodSource ("reasonEndDateHumanReadableParams" )
109102 void When_ExtractingReasonEndDateHumanReadable_Expect_EndDateOutput (String reasonEndDateUrl , String reasonEndDate ,
110- String expectedEndDate ) {
111- nestedExtension .setUrl (reasonEndDateUrl );
112- nestedExtension .setValue (new DateTimeType (reasonEndDate ));
113- extensionList .add (nestedExtension );
114- extension .setExtension (extensionList );
115-
116- String outputEndDate = AllergyStructureExtractor .extractEndDate (extension , DateFormatUtil ::toTextFormat );
117-
118- assertEquals (expectedEndDate , outputEndDate );
103+ String expectedEndDate ) {
104+ setupNestedExtension (reasonEndDateUrl , new DateTimeType (reasonEndDate ));
105+ assertEquals (expectedEndDate , AllergyStructureExtractor .extractEndDate (extension , DateFormatUtil ::toTextFormat ));
119106 }
120107
121108 @ ParameterizedTest
122109 @ MethodSource ("onsetDateParams" )
123110 void When_ExtractingOnsetDate_Expect_OnsetDateOutput (String onsetDate , String expectedOnsetDate ) {
124111 AllergyIntolerance allergyIntolerance = new AllergyIntolerance ();
125112 allergyIntolerance .setOnset (new DateTimeType (onsetDate ));
126-
127- String outputReasonEnd = AllergyStructureExtractor .extractOnsetDate (allergyIntolerance );
128-
129- assertEquals (expectedOnsetDate , outputReasonEnd );
113+ assertEquals (expectedOnsetDate , AllergyStructureExtractor .extractOnsetDate (allergyIntolerance ));
130114 }
131115
132116 @ Test
133117 void When_ExtractingNoOnsetDate_Expect_EmptyOutput () {
134118 AllergyIntolerance allergyIntolerance = new AllergyIntolerance ();
135-
136- String outputOnsetDate = AllergyStructureExtractor .extractOnsetDate (allergyIntolerance );
137-
138- assertEquals (StringUtils .EMPTY , outputOnsetDate );
119+ assertEquals (StringUtils .EMPTY , AllergyStructureExtractor .extractOnsetDate (allergyIntolerance ));
139120 }
140121
141122 @ Test
142123 void When_ExtractingFullReaction_Expect_Output () {
143124 AtomicInteger atomicInteger = new AtomicInteger (1 );
144- AllergyIntolerance .AllergyIntoleranceReactionComponent reactionComponent
145- = new AllergyIntolerance .AllergyIntoleranceReactionComponent ();
146-
125+ AllergyIntolerance .AllergyIntoleranceReactionComponent reactionComponent = new AllergyIntolerance .AllergyIntoleranceReactionComponent ();
147126 reactionComponent .setDescription ("description" );
148127
149128 CodeableConcept exposureRoute = new CodeableConcept ();
150129 exposureRoute .setText ("exposure route" );
151-
152130 reactionComponent .setExposureRoute (exposureRoute );
153-
154131 reactionComponent .setSeverity (MODERATE );
155132
156133 List <CodeableConcept > manifestations = new ArrayList <>();
157- CodeableConcept manifestation1 = new CodeableConcept ();
158- CodeableConcept manifestation2 = new CodeableConcept ();
159- manifestation1 .setText ("manifestation 1" );
160- manifestation2 .setText ("manifestation 2" );
161- manifestations .add (manifestation1 );
162- manifestations .add (manifestation2 );
134+ manifestations .add (new CodeableConcept ().setText ("manifestation 1" ));
135+ manifestations .add (new CodeableConcept ().setText ("manifestation 2" ));
163136 reactionComponent .setManifestation (manifestations );
164137
165- String outputOnsetDate = AllergyStructureExtractor .extractReaction (reactionComponent , atomicInteger );
166-
167- assertEquals (FULL_REACTION , outputOnsetDate );
138+ assertEquals (FULL_REACTION , AllergyStructureExtractor .extractReaction (reactionComponent , atomicInteger ));
168139 }
169140
170141 @ Test
171142 void When_ExtractingEmptyReaction_Expect_Output () {
172143 AtomicInteger atomicInteger = new AtomicInteger (1 );
173- AllergyIntolerance .AllergyIntoleranceReactionComponent reactionComponent =
174- new AllergyIntolerance .AllergyIntoleranceReactionComponent ();
175-
176- String outputOnsetDate = AllergyStructureExtractor .extractReaction (reactionComponent , atomicInteger );
177-
178- assertEquals (REACTION_START , outputOnsetDate );
144+ AllergyIntolerance .AllergyIntoleranceReactionComponent reactionComponent = new AllergyIntolerance .AllergyIntoleranceReactionComponent ();
145+ assertEquals (REACTION_START , AllergyStructureExtractor .extractReaction (reactionComponent , atomicInteger ));
179146 }
180147}
0 commit comments