Skip to content

Commit d9ea87e

Browse files
Augmentation Updates for V3 Spec Modifications (#380)
## Description Updated the Augmenter to satisfy the changes for V3 of the Augmentation spec given to us by APHL. - Remove FunctionCode from Header Author section - Add additional information and comment for the softwareName element - Correct typo in the system oid - Added additional values to the applicationcode enum and methods to get those values back - Updated and added tests See examples below of the changes requested: <img width="789" height="646" alt="image" src="https://github.com/user-attachments/assets/6e18eb74-ac70-44f6-8488-853cd00ac246" /> Example of Author Header (provided by APHL): <img width="695" height="665" alt="image" src="https://github.com/user-attachments/assets/87b1937a-6818-4f36-b119-9d4084ef5815" /> Example of entry level with changes requested for Author (Provided by APHL): <img width="772" height="452" alt="image" src="https://github.com/user-attachments/assets/5976dc64-87dd-4aa3-bbe4-dcc8ec508c5a" /> ## Related Issues Closes #363 ## Additional Notes ## 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 9f67c66 commit d9ea87e

File tree

7 files changed

+45
-33
lines changed

7 files changed

+45
-33
lines changed

packages/augmentation/src/augmentation/models/application.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
from enum import StrEnum
1+
from enum import Enum
22

33
from pydantic import BaseModel
44
from pydantic import ConfigDict
55

66
from shared_models import NonstandardCodeInstance
77

88

9-
class ApplicationCode(StrEnum):
9+
class ApplicationCode(Enum):
1010
"""The list of applications that will leveraging Augmentation functionality."""
1111

12-
TEXT_TO_CODE = "text-to-code"
12+
code: str
13+
display: str
14+
TEXT_TO_CODE = ("text-to-code", "Text-to-Code")
15+
16+
def __new__(cls, value: str, display: str) -> "ApplicationCode":
17+
"""Initialize ApplicationCode enum."""
18+
obj = object.__new__(cls)
19+
obj._value_ = value
20+
obj.display = display
21+
obj.code = value
22+
return obj
1323

1424

1525
class NonstandardCodeInstanceMetadata(NonstandardCodeInstance):

packages/augmentation/src/augmentation/models/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TTCAugmenterConfig(AugmenterConfig):
5151
}
5252
# 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.
5353
author_function_code: str = "code-text-to-code"
54-
author_function_code_system: str = "2.16.840.1.113663.10.20.15.2.7.1"
54+
author_function_code_system: str = "2.16.840.1.113883.10.20.15.2.7.1"
5555
author_function_code_system_name: str = "eCRDataAugmentation"
5656

5757
@model_validator(mode="after")

packages/augmentation/src/augmentation/services/augmenter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ def document_payload_not_none(cls, v: str) -> Element:
4848
return clean_xml_tree(v)
4949

5050
def _get_application_code_value(self) -> str:
51-
return self.application_code.value
51+
return self.application_code.code
52+
53+
def _get_application_code_display(self) -> str:
54+
return self.application_code.display
5255

5356
@abstractmethod
5457
def augment(self) -> Metadata:

packages/augmentation/src/augmentation/services/eicr_augmenter.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -229,24 +229,15 @@ def _get_old_xrfm_related_document(self) -> Element | None:
229229
def _generate_author(self, level: str = "header") -> Element:
230230
null_flavor_comment = " set to nullFlavor 'NA' "
231231
author = etree.Element("author")
232-
function_code = etree.SubElement(author, "functionCode")
233-
function_code.set("code", value=self.config.author_function_code)
234-
function_code.set("codeSystem", value=self.config.author_function_code_system)
235-
function_code.set("codeSystemName", value=self.config.author_function_code_system_name)
236-
# TODO: Eventually we wwill not only separate by header vs. data_element
232+
# TODO: Eventually we will not only separate by header vs. data_element
237233
# but will also separate out the various comments by the various data element
238-
# type being modified. This can easily be stored in the model for the data elemnts
234+
# type being modified. This can easily be stored in the model for the data element.
239235
# For now we are hard coding for code-text-to-code and observation in the comment
240-
if level == "header":
241-
self._add_previous_element_comment(
242-
(
243-
"functionCode specifies type of change "
244-
"'text-to-code' which signifies this document has been transformed using the "
245-
"text-to-code data augmentation tool "
246-
),
247-
function_code,
248-
)
249-
else:
236+
if level != "header":
237+
function_code = etree.SubElement(author, "functionCode")
238+
function_code.set("code", value=self.config.author_function_code)
239+
function_code.set("codeSystem", value=self.config.author_function_code_system)
240+
function_code.set("codeSystemName", value=self.config.author_function_code_system_name)
250241
self._add_previous_element_comment(
251242
(
252243
"functionCode specifies type of change "
@@ -283,7 +274,14 @@ def _generate_author(self, level: str = "header") -> Element:
283274
" set to 'Data Augmentation Tool' ", assigned_authoring_device
284275
)
285276
software_name = etree.SubElement(assigned_authoring_device, "softwareName")
286-
software_name.set("displayName", "Data Augmentation Tool")
277+
software_name.set("code", value=self._get_application_code_value())
278+
software_name.set("codeSystem", value=self.config.author_function_code_system)
279+
software_name.set("codeSystemName", value=self.config.author_function_code_system_name)
280+
software_name.set("displayName", self._get_application_code_display())
281+
self._add_previous_element_comment(
282+
" assignedAuthoringDevice/softwareName specifies that this document has been transformed using the Text-to-Code data augmentation tool",
283+
software_name,
284+
)
287285

288286
return author
289287

packages/augmentation/tests/unit/snapshots/test_eicr_augmenter/test_basic_eicr/basic_eicr_augmented.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</code>
2929
<author>
3030
<!--DATA AUGMENTATION: functionCode specifies type of change 'code-text-to-code' which signifies that the code in this observation has been augmented with a code derived from the text in the code element -->
31-
<functionCode code="code-text-to-code" codeSystem="2.16.840.1.113663.10.20.15.2.7.1" codeSystemName="eCRDataAugmentation"/>
31+
<functionCode code="code-text-to-code" codeSystem="2.16.840.1.113883.10.20.15.2.7.1" codeSystemName="eCRDataAugmentation"/>
3232
<!--DATA AUGMENTATION: time of data augmentation operation -->
3333
<effectiveTime value="20260213152757"/>
3434
<assignedAuthor>
@@ -40,7 +40,8 @@
4040
<telecom nullFlavor="NA"/>
4141
<!--DATA AUGMENTATION: set to 'Data Augmentation Tool' -->
4242
<assignedAuthoringDevice>
43-
<softwareName displayName="Data Augmentation Tool"/>
43+
<!--DATA AUGMENTATION: assignedAuthoringDevice/softwareName specifies that this document has been transformed using the Text-to-Code data augmentation tool -->
44+
<softwareName code="text-to-code" codeSystem="2.16.840.1.113883.10.20.15.2.7.1" codeSystemName="eCRDataAugmentation" displayName="Text-to-Code"/>
4445
</assignedAuthoringDevice>
4546
</assignedAuthor>
4647
</author>
@@ -64,8 +65,6 @@
6465
</parentDocument>
6566
</relatedDocument>
6667
<author>
67-
<!--DATA AUGMENTATION: functionCode specifies type of change 'text-to-code' which signifies this document has been transformed using the text-to-code data augmentation tool -->
68-
<functionCode code="code-text-to-code" codeSystem="2.16.840.1.113663.10.20.15.2.7.1" codeSystemName="eCRDataAugmentation"/>
6968
<!--DATA AUGMENTATION: time of data augmentation operation -->
7069
<effectiveTime value="20260213152757"/>
7170
<assignedAuthor>
@@ -77,7 +76,8 @@
7776
<telecom nullFlavor="NA"/>
7877
<!--DATA AUGMENTATION: set to 'Data Augmentation Tool' -->
7978
<assignedAuthoringDevice>
80-
<softwareName displayName="Data Augmentation Tool"/>
79+
<!--DATA AUGMENTATION: assignedAuthoringDevice/softwareName specifies that this document has been transformed using the Text-to-Code data augmentation tool -->
80+
<softwareName code="text-to-code" codeSystem="2.16.840.1.113883.10.20.15.2.7.1" codeSystemName="eCRDataAugmentation" displayName="Text-to-Code"/>
8181
</assignedAuthoringDevice>
8282
</assignedAuthor>
8383
</author>

packages/augmentation/tests/unit/snapshots/test_eicr_augmenter/test_eicr_related_doc/basic_eicr_related_doc_augmented.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</code>
3636
<author>
3737
<!--DATA AUGMENTATION: functionCode specifies type of change 'code-text-to-code' which signifies that the code in this observation has been augmented with a code derived from the text in the code element -->
38-
<functionCode code="code-text-to-code" codeSystem="2.16.840.1.113663.10.20.15.2.7.1" codeSystemName="eCRDataAugmentation"/>
38+
<functionCode code="code-text-to-code" codeSystem="2.16.840.1.113883.10.20.15.2.7.1" codeSystemName="eCRDataAugmentation"/>
3939
<!--DATA AUGMENTATION: time of data augmentation operation -->
4040
<effectiveTime value="20260213152757"/>
4141
<assignedAuthor>
@@ -47,7 +47,8 @@
4747
<telecom nullFlavor="NA"/>
4848
<!--DATA AUGMENTATION: set to 'Data Augmentation Tool' -->
4949
<assignedAuthoringDevice>
50-
<softwareName displayName="Data Augmentation Tool"/>
50+
<!--DATA AUGMENTATION: assignedAuthoringDevice/softwareName specifies that this document has been transformed using the Text-to-Code data augmentation tool -->
51+
<softwareName code="text-to-code" codeSystem="2.16.840.1.113883.10.20.15.2.7.1" codeSystemName="eCRDataAugmentation" displayName="Text-to-Code"/>
5152
</assignedAuthoringDevice>
5253
</assignedAuthor>
5354
</author>
@@ -71,8 +72,6 @@
7172
</parentDocument>
7273
</relatedDocument>
7374
<author>
74-
<!--DATA AUGMENTATION: functionCode specifies type of change 'text-to-code' which signifies this document has been transformed using the text-to-code data augmentation tool -->
75-
<functionCode code="code-text-to-code" codeSystem="2.16.840.1.113663.10.20.15.2.7.1" codeSystemName="eCRDataAugmentation"/>
7675
<!--DATA AUGMENTATION: time of data augmentation operation -->
7776
<effectiveTime value="20260213152757"/>
7877
<assignedAuthor>
@@ -84,7 +83,8 @@
8483
<telecom nullFlavor="NA"/>
8584
<!--DATA AUGMENTATION: set to 'Data Augmentation Tool' -->
8685
<assignedAuthoringDevice>
87-
<softwareName displayName="Data Augmentation Tool"/>
86+
<!--DATA AUGMENTATION: assignedAuthoringDevice/softwareName specifies that this document has been transformed using the Text-to-Code data augmentation tool -->
87+
<softwareName code="text-to-code" codeSystem="2.16.840.1.113883.10.20.15.2.7.1" codeSystemName="eCRDataAugmentation" displayName="Text-to-Code"/>
8888
</assignedAuthoringDevice>
8989
</assignedAuthor>
9090
</author>

packages/augmentation/tests/unit/test_model_application.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ class TestApplicationModel:
55
def test_application_code(self):
66
"""Basic unit test for ApplicationCode enum."""
77
app_enum = ApplicationCode
8-
assert app_enum.TEXT_TO_CODE.value == "text-to-code"
8+
assert app_enum.TEXT_TO_CODE.code == "text-to-code"
9+
assert app_enum.TEXT_TO_CODE.display == "Text-to-Code"

0 commit comments

Comments
 (0)