Skip to content

Commit d90ecf6

Browse files
Adding text-to-code coverage (#411)
## Description Updating `models` and `services`: https://app.codecov.io/gh/CDCgov/dibbs-text-to-code/tree/main/packages%2Ftext-to-code%2Fsrc%2Ftext_to_code Should then be at 100% coverage: https://app.codecov.io/gh/CDCgov/dibbs-text-to-code/tree/rob%2F410-code-coverage-increasing-coverage-on-text_to_code/packages%2Ftext-to-code%2Fsrc%2Ftext_to_code ## Related Issues Closes #410 ## Additional Notes [Add any additional context or notes that reviewers should know about.] <--------------------- REMOVE THE LINES BELOW BEFORE MERGING ---------------------> ## Checklist Please review and complete the following checklist before submitting your pull request: - [ ] I have ensured that the pull request is of a manageable size, allowing it to be reviewed within a single session. - [ ] I have reviewed my changes to ensure they are clear, concise, and well-documented. - [ ] I have updated the documentation, if applicable. - [ ] I have added or updated test cases to cover my changes, if applicable. - [ ] I have minimized the number of reviewers to include only those essential for the review. ## Checklist for Reviewers Please review and complete the following checklist during the review process: - [ ] The code follows best practices and conventions. - [ ] The changes implement the desired functionality or fix the reported issue. - [ ] The tests cover the new changes and pass successfully. - [ ] Any potential edge cases or error scenarios have been considered.
1 parent 1a8e8dd commit d90ecf6

File tree

6 files changed

+684
-1
lines changed

6 files changed

+684
-1
lines changed

packages/augmentation-lambda/src/augmentation_lambda/lambda_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
from aws_lambda_typing import context as lambda_context
77
from aws_lambda_typing import events as lambda_events
8+
from botocore.client import BaseClient
89

910
import lambda_handler
1011
from augmentation.models import TTCAugmenterConfig
11-
from botocore.client import BaseClient
1212
from augmentation.models.application import TTCAugmenterOutput
1313
from augmentation.services.eicr_augmenter import EICRAugmenter
1414
from shared_models import TTCAugmenterInput

packages/text-to-code/tests/unit/models/test_labs.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ def test_base_lab_element_requires_xpaths(self):
2121
schematron_errors=[],
2222
)
2323

24+
def test_base_lab_element_accepts_valid_xpaths(self):
25+
"""Tests returning xpaths when valid xpaths are provided."""
26+
xpaths = [next(iter(LabXPaths))]
27+
28+
lab_field = BaseLabField(
29+
data_field="Lab Test Name Resulted",
30+
min_word_count=2,
31+
xpaths=xpaths,
32+
schematron_errors=[],
33+
)
34+
35+
assert lab_field.xpaths == xpaths
36+
2437
def test_lab_test_name_resulted_defaults(self):
2538
"""Tests default values for LabTestNameResulted schema."""
2639
lab_test = LabTestNameResulted(

packages/text-to-code/tests/unit/test_eicr_processor.py

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"/ClinicalDocument/component/structuredBody/component/section/entry/component/observation"
1919
)
2020

21+
NO_MATCH_FOUND_ERROR_MESSAGE = "No ID element found in eICR XML."
22+
2123

2224
class TestEmptyEicrProcessor:
2325
def test_init(self):
@@ -52,6 +54,40 @@ def test_get_text_candidates_logs_when_xpath_lookup_fails(self):
5254
},
5355
)
5456

57+
def test_resolve_reference_returns_none_for_empty_reference_value(self):
58+
processor = EicrProcessor("<ClinicalDocument />")
59+
60+
assert processor.resolve_reference(None) is None
61+
assert processor.resolve_reference("") is None
62+
assert processor.resolve_reference(" ") is None
63+
64+
def test_resolve_reference_returns_none_when_reference_is_missing(self):
65+
processor = EicrProcessor(
66+
"<ClinicalDocument><section><text>ID exists</text></section></ClinicalDocument>"
67+
)
68+
69+
assert processor.resolve_reference("#missing-id") is None
70+
71+
def test_extract_text_candidates_from_element_includes_child_tail_text(self):
72+
processor = EicrProcessor(
73+
"""
74+
<ClinicalDocument>
75+
<section>
76+
<text>
77+
<target>first<inner>second</inner>third</target>
78+
</text>
79+
</section>
80+
</ClinicalDocument>
81+
"""
82+
)
83+
84+
element = processor._xml_root.find(".//target")
85+
assert element is not None
86+
87+
result = processor._extract_text_candidates_from_element(element)
88+
89+
assert result == ["first second third third"]
90+
5591

5692
class TestBadEicr:
5793
def test_bad_eicr(self):
@@ -100,6 +136,139 @@ def test_metadata(self, eicr_metadata: Metadata):
100136
eicr_vendor="Test eCR Vendor Name",
101137
)
102138

139+
def test_metadata_raises_when_id_is_missing(self):
140+
processor = EicrProcessor(
141+
"""
142+
<ClinicalDocument>
143+
<author>
144+
<assignedAuthor>
145+
<assignedAuthoringDevice>
146+
<softwareName>Test eCR Vendor Name</softwareName>
147+
</assignedAuthoringDevice>
148+
</assignedAuthor>
149+
</author>
150+
</ClinicalDocument>
151+
"""
152+
)
153+
154+
with pytest.raises(ValueError, match=NO_MATCH_FOUND_ERROR_MESSAGE):
155+
_ = processor.eicr_metadata
156+
157+
def test_metadata_raises_when_id_has_null_flavor(self):
158+
processor = EicrProcessor(
159+
"""
160+
<ClinicalDocument>
161+
<id nullFlavor="UNK" />
162+
<author>
163+
<assignedAuthor>
164+
<assignedAuthoringDevice>
165+
<softwareName>Test eCR Vendor Name</softwareName>
166+
</assignedAuthoringDevice>
167+
</assignedAuthor>
168+
</author>
169+
</ClinicalDocument>
170+
"""
171+
)
172+
173+
with pytest.raises(ValueError, match=NO_MATCH_FOUND_ERROR_MESSAGE):
174+
_ = processor.eicr_metadata
175+
176+
def test_metadata_parses_false_displayable(self):
177+
processor = EicrProcessor(
178+
"""
179+
<ClinicalDocument>
180+
<id
181+
root="test-root"
182+
extension="test-extension"
183+
assigningAuthorityName="test-authority"
184+
displayable="false"
185+
/>
186+
<author>
187+
<assignedAuthor>
188+
<assignedAuthoringDevice>
189+
<softwareName>Test eCR Vendor Name</softwareName>
190+
</assignedAuthoringDevice>
191+
</assignedAuthor>
192+
</author>
193+
</ClinicalDocument>
194+
"""
195+
)
196+
197+
assert processor.eicr_metadata == Metadata(
198+
eicr_id=CdaInstanceIdentifier(
199+
root="test-root",
200+
extension="test-extension",
201+
assigning_authority_name="test-authority",
202+
displayable=False,
203+
null_flavor=None,
204+
),
205+
eicr_vendor="Test eCR Vendor Name",
206+
)
207+
208+
def test_metadata_parses_unknown_displayable_as_none(self):
209+
processor = EicrProcessor(
210+
"""
211+
<ClinicalDocument>
212+
<id
213+
root="test-root"
214+
extension="test-extension"
215+
assigningAuthorityName="test-authority"
216+
displayable="not-a-bool"
217+
/>
218+
<author>
219+
<assignedAuthor>
220+
<assignedAuthoringDevice>
221+
<softwareName>Test eCR Vendor Name</softwareName>
222+
</assignedAuthoringDevice>
223+
</assignedAuthor>
224+
</author>
225+
</ClinicalDocument>
226+
"""
227+
)
228+
229+
assert processor.eicr_metadata == Metadata(
230+
eicr_id=CdaInstanceIdentifier(
231+
root="test-root",
232+
extension="test-extension",
233+
assigning_authority_name="test-authority",
234+
displayable=None,
235+
null_flavor=None,
236+
),
237+
eicr_vendor="Test eCR Vendor Name",
238+
)
239+
240+
def test_metadata_parses_true_displayable(self):
241+
processor = EicrProcessor(
242+
"""
243+
<ClinicalDocument>
244+
<id
245+
root="test-root"
246+
extension="test-extension"
247+
assigningAuthorityName="test-authority"
248+
displayable="true"
249+
/>
250+
<author>
251+
<assignedAuthor>
252+
<assignedAuthoringDevice>
253+
<softwareName>Test eCR Vendor Name</softwareName>
254+
</assignedAuthoringDevice>
255+
</assignedAuthor>
256+
</author>
257+
</ClinicalDocument>
258+
"""
259+
)
260+
261+
assert processor.eicr_metadata == Metadata(
262+
eicr_id=CdaInstanceIdentifier(
263+
root="test-root",
264+
extension="test-extension",
265+
assigning_authority_name="test-authority",
266+
displayable=True,
267+
null_flavor=None,
268+
),
269+
eicr_vendor="Test eCR Vendor Name",
270+
)
271+
103272

104273
class TestReferences:
105274
@pytest.fixture(scope="class")

0 commit comments

Comments
 (0)