diff --git a/packages/augmentation/src/augmentation/models/application.py b/packages/augmentation/src/augmentation/models/application.py index c008ce0..29fd6a1 100644 --- a/packages/augmentation/src/augmentation/models/application.py +++ b/packages/augmentation/src/augmentation/models/application.py @@ -1,4 +1,4 @@ -from enum import StrEnum +from enum import Enum from pydantic import BaseModel from pydantic import ConfigDict @@ -6,10 +6,20 @@ from shared_models import NonstandardCodeInstance -class ApplicationCode(StrEnum): +class ApplicationCode(Enum): """The list of applications that will leveraging Augmentation functionality.""" - TEXT_TO_CODE = "text-to-code" + code: str + display: str + TEXT_TO_CODE = ("text-to-code", "Text-to-Code") + + def __new__(cls, value: str, display: str) -> "ApplicationCode": + """Initialize ApplicationCode enum.""" + obj = object.__new__(cls) + obj._value_ = value + obj.display = display + obj.code = value + return obj class NonstandardCodeInstanceMetadata(NonstandardCodeInstance): diff --git a/packages/augmentation/src/augmentation/models/config.py b/packages/augmentation/src/augmentation/models/config.py index 4cf11af..d93147a 100644 --- a/packages/augmentation/src/augmentation/models/config.py +++ b/packages/augmentation/src/augmentation/models/config.py @@ -51,7 +51,7 @@ class TTCAugmenterConfig(AugmenterConfig): } # TODO: The function code is currently a constant (used for both lab orders and results), but will need to be dynamic when additional fields with different function codes are introduced. author_function_code: str = "code-text-to-code" - author_function_code_system: str = "2.16.840.1.113663.10.20.15.2.7.1" + author_function_code_system: str = "2.16.840.1.113883.10.20.15.2.7.1" author_function_code_system_name: str = "eCRDataAugmentation" @model_validator(mode="after") diff --git a/packages/augmentation/src/augmentation/services/augmenter.py b/packages/augmentation/src/augmentation/services/augmenter.py index 37f2133..6184ca3 100644 --- a/packages/augmentation/src/augmentation/services/augmenter.py +++ b/packages/augmentation/src/augmentation/services/augmenter.py @@ -48,7 +48,10 @@ def document_payload_not_none(cls, v: str) -> Element: return clean_xml_tree(v) def _get_application_code_value(self) -> str: - return self.application_code.value + return self.application_code.code + + def _get_application_code_display(self) -> str: + return self.application_code.display @abstractmethod def augment(self) -> Metadata: diff --git a/packages/augmentation/src/augmentation/services/eicr_augmenter.py b/packages/augmentation/src/augmentation/services/eicr_augmenter.py index 33a0c13..1550065 100644 --- a/packages/augmentation/src/augmentation/services/eicr_augmenter.py +++ b/packages/augmentation/src/augmentation/services/eicr_augmenter.py @@ -229,24 +229,15 @@ def _get_old_xrfm_related_document(self) -> Element | None: def _generate_author(self, level: str = "header") -> Element: null_flavor_comment = " set to nullFlavor 'NA' " author = etree.Element("author") - function_code = etree.SubElement(author, "functionCode") - function_code.set("code", value=self.config.author_function_code) - function_code.set("codeSystem", value=self.config.author_function_code_system) - function_code.set("codeSystemName", value=self.config.author_function_code_system_name) - # TODO: Eventually we wwill not only separate by header vs. data_element + # TODO: Eventually we will not only separate by header vs. data_element # but will also separate out the various comments by the various data element - # type being modified. This can easily be stored in the model for the data elemnts + # type being modified. This can easily be stored in the model for the data element. # For now we are hard coding for code-text-to-code and observation in the comment - if level == "header": - self._add_previous_element_comment( - ( - "functionCode specifies type of change " - "'text-to-code' which signifies this document has been transformed using the " - "text-to-code data augmentation tool " - ), - function_code, - ) - else: + if level != "header": + function_code = etree.SubElement(author, "functionCode") + function_code.set("code", value=self.config.author_function_code) + function_code.set("codeSystem", value=self.config.author_function_code_system) + function_code.set("codeSystemName", value=self.config.author_function_code_system_name) self._add_previous_element_comment( ( "functionCode specifies type of change " @@ -283,7 +274,14 @@ def _generate_author(self, level: str = "header") -> Element: " set to 'Data Augmentation Tool' ", assigned_authoring_device ) software_name = etree.SubElement(assigned_authoring_device, "softwareName") - software_name.set("displayName", "Data Augmentation Tool") + software_name.set("code", value=self._get_application_code_value()) + software_name.set("codeSystem", value=self.config.author_function_code_system) + software_name.set("codeSystemName", value=self.config.author_function_code_system_name) + software_name.set("displayName", self._get_application_code_display()) + self._add_previous_element_comment( + " assignedAuthoringDevice/softwareName specifies that this document has been transformed using the Text-to-Code data augmentation tool", + software_name, + ) return author diff --git a/packages/augmentation/tests/unit/snapshots/test_eicr_augmenter/test_basic_eicr/basic_eicr_augmented.xml b/packages/augmentation/tests/unit/snapshots/test_eicr_augmenter/test_basic_eicr/basic_eicr_augmented.xml index b69a847..81e359f 100644 --- a/packages/augmentation/tests/unit/snapshots/test_eicr_augmenter/test_basic_eicr/basic_eicr_augmented.xml +++ b/packages/augmentation/tests/unit/snapshots/test_eicr_augmenter/test_basic_eicr/basic_eicr_augmented.xml @@ -28,7 +28,7 @@ - + @@ -40,7 +40,8 @@ - + + @@ -64,8 +65,6 @@ - - @@ -77,7 +76,8 @@ - + + diff --git a/packages/augmentation/tests/unit/snapshots/test_eicr_augmenter/test_eicr_related_doc/basic_eicr_related_doc_augmented.xml b/packages/augmentation/tests/unit/snapshots/test_eicr_augmenter/test_eicr_related_doc/basic_eicr_related_doc_augmented.xml index d0d9011..b71930d 100644 --- a/packages/augmentation/tests/unit/snapshots/test_eicr_augmenter/test_eicr_related_doc/basic_eicr_related_doc_augmented.xml +++ b/packages/augmentation/tests/unit/snapshots/test_eicr_augmenter/test_eicr_related_doc/basic_eicr_related_doc_augmented.xml @@ -35,7 +35,7 @@ - + @@ -47,7 +47,8 @@ - + + @@ -71,8 +72,6 @@ - - @@ -84,7 +83,8 @@ - + + diff --git a/packages/augmentation/tests/unit/test_model_application.py b/packages/augmentation/tests/unit/test_model_application.py index 57d04af..018f2b1 100644 --- a/packages/augmentation/tests/unit/test_model_application.py +++ b/packages/augmentation/tests/unit/test_model_application.py @@ -5,4 +5,5 @@ class TestApplicationModel: def test_application_code(self): """Basic unit test for ApplicationCode enum.""" app_enum = ApplicationCode - assert app_enum.TEXT_TO_CODE.value == "text-to-code" + assert app_enum.TEXT_TO_CODE.code == "text-to-code" + assert app_enum.TEXT_TO_CODE.display == "Text-to-Code"