Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from aws_lambda_typing import context as lambda_context
from aws_lambda_typing import events as lambda_events
from botocore.client import BaseClient
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure why this ruffed now?


import lambda_handler
from augmentation.models import TTCAugmenterConfig
from botocore.client import BaseClient
from augmentation.models.application import TTCAugmenterOutput
from augmentation.services.eicr_augmenter import EICRAugmenter
from shared_models import TTCAugmenterInput
Expand Down
13 changes: 13 additions & 0 deletions packages/text-to-code/tests/unit/models/test_labs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ def test_base_lab_element_requires_xpaths(self):
schematron_errors=[],
)

def test_base_lab_element_accepts_valid_xpaths(self):
"""Tests returning xpaths when valid xpaths are provided."""
xpaths = [next(iter(LabXPaths))]

lab_field = BaseLabField(
data_field="Lab Test Name Resulted",
min_word_count=2,
xpaths=xpaths,
schematron_errors=[],
)

assert lab_field.xpaths == xpaths

def test_lab_test_name_resulted_defaults(self):
"""Tests default values for LabTestNameResulted schema."""
lab_test = LabTestNameResulted(
Expand Down
169 changes: 169 additions & 0 deletions packages/text-to-code/tests/unit/test_eicr_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"/ClinicalDocument/component/structuredBody/component/section/entry/component/observation"
)

NO_MATCH_FOUND_ERROR_MESSAGE = "No ID element found in eICR XML."


class TestEmptyEicrProcessor:
def test_init(self):
Expand Down Expand Up @@ -52,6 +54,40 @@ def test_get_text_candidates_logs_when_xpath_lookup_fails(self):
},
)

def test_resolve_reference_returns_none_for_empty_reference_value(self):
processor = EicrProcessor("<ClinicalDocument />")

assert processor.resolve_reference(None) is None
assert processor.resolve_reference("") is None
assert processor.resolve_reference(" ") is None

def test_resolve_reference_returns_none_when_reference_is_missing(self):
processor = EicrProcessor(
"<ClinicalDocument><section><text>ID exists</text></section></ClinicalDocument>"
)

assert processor.resolve_reference("#missing-id") is None

def test_extract_text_candidates_from_element_includes_child_tail_text(self):
processor = EicrProcessor(
"""
<ClinicalDocument>
<section>
<text>
<target>first<inner>second</inner>third</target>
</text>
</section>
</ClinicalDocument>
"""
)

element = processor._xml_root.find(".//target")
assert element is not None

result = processor._extract_text_candidates_from_element(element)

assert result == ["first second third third"]


class TestBadEicr:
def test_bad_eicr(self):
Expand Down Expand Up @@ -100,6 +136,139 @@ def test_metadata(self, eicr_metadata: Metadata):
eicr_vendor="Test eCR Vendor Name",
)

def test_metadata_raises_when_id_is_missing(self):
processor = EicrProcessor(
"""
<ClinicalDocument>
<author>
<assignedAuthor>
<assignedAuthoringDevice>
<softwareName>Test eCR Vendor Name</softwareName>
</assignedAuthoringDevice>
</assignedAuthor>
</author>
</ClinicalDocument>
"""
)

with pytest.raises(ValueError, match=NO_MATCH_FOUND_ERROR_MESSAGE):
_ = processor.eicr_metadata

def test_metadata_raises_when_id_has_null_flavor(self):
processor = EicrProcessor(
"""
<ClinicalDocument>
<id nullFlavor="UNK" />
<author>
<assignedAuthor>
<assignedAuthoringDevice>
<softwareName>Test eCR Vendor Name</softwareName>
</assignedAuthoringDevice>
</assignedAuthor>
</author>
</ClinicalDocument>
"""
)

with pytest.raises(ValueError, match=NO_MATCH_FOUND_ERROR_MESSAGE):
_ = processor.eicr_metadata

def test_metadata_parses_false_displayable(self):
processor = EicrProcessor(
"""
<ClinicalDocument>
<id
root="test-root"
extension="test-extension"
assigningAuthorityName="test-authority"
displayable="false"
/>
<author>
<assignedAuthor>
<assignedAuthoringDevice>
<softwareName>Test eCR Vendor Name</softwareName>
</assignedAuthoringDevice>
</assignedAuthor>
</author>
</ClinicalDocument>
"""
)

assert processor.eicr_metadata == Metadata(
eicr_id=CdaInstanceIdentifier(
root="test-root",
extension="test-extension",
assigning_authority_name="test-authority",
displayable=False,
null_flavor=None,
),
eicr_vendor="Test eCR Vendor Name",
)

def test_metadata_parses_unknown_displayable_as_none(self):
processor = EicrProcessor(
"""
<ClinicalDocument>
<id
root="test-root"
extension="test-extension"
assigningAuthorityName="test-authority"
displayable="not-a-bool"
/>
<author>
<assignedAuthor>
<assignedAuthoringDevice>
<softwareName>Test eCR Vendor Name</softwareName>
</assignedAuthoringDevice>
</assignedAuthor>
</author>
</ClinicalDocument>
"""
)

assert processor.eicr_metadata == Metadata(
eicr_id=CdaInstanceIdentifier(
root="test-root",
extension="test-extension",
assigning_authority_name="test-authority",
displayable=None,
null_flavor=None,
),
eicr_vendor="Test eCR Vendor Name",
)

def test_metadata_parses_true_displayable(self):
processor = EicrProcessor(
"""
<ClinicalDocument>
<id
root="test-root"
extension="test-extension"
assigningAuthorityName="test-authority"
displayable="true"
/>
<author>
<assignedAuthor>
<assignedAuthoringDevice>
<softwareName>Test eCR Vendor Name</softwareName>
</assignedAuthoringDevice>
</assignedAuthor>
</author>
</ClinicalDocument>
"""
)

assert processor.eicr_metadata == Metadata(
eicr_id=CdaInstanceIdentifier(
root="test-root",
extension="test-extension",
assigning_authority_name="test-authority",
displayable=True,
null_flavor=None,
),
eicr_vendor="Test eCR Vendor Name",
)


class TestReferences:
@pytest.fixture(scope="class")
Expand Down
Loading
Loading