Skip to content

Commit

Permalink
Add condition field to AHBLine (#410)
Browse files Browse the repository at this point in the history
* add conditions field to AHBLine

* update schema too

* updated tests
  • Loading branch information
DeltaDaniel authored Jul 10, 2024
1 parent b8ef0cf commit 7b91f58
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile requirements.in
Expand All @@ -8,6 +8,8 @@ attrs==23.2.0
# via -r requirements.in
click==8.1.7
# via -r requirements.in
colorama==0.4.6
# via click
lark==1.1.9
# via -r requirements.in
lxml==5.2.2
Expand Down
9 changes: 8 additions & 1 deletion src/maus/models/anwendungshandbuch.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ class AhbLine:
)
"""a requirement indicator + an optional condition ("ahb expression"), e.g. 'Muss [123] O [456]' """
# note: to parse expressions from AHBs consider using AHBicht: https://github.com/Hochfrequenz/ahbicht/

conditions: Optional[str] = attrs.field(
validator=attrs.validators.optional(validator=attrs.validators.instance_of(str)), default=None
)
"""
The condition text describes the text to the optional condition of the ahb expression.
E.g. '[492] This is a condition text. [999] And this is another one.'
"""
section_name: Optional[str] = attrs.field(
validator=attrs.validators.optional(validator=attrs.validators.instance_of(str)), default=None
)
Expand Down Expand Up @@ -141,6 +147,7 @@ class AhbLineSchema(Schema):
value_pool_entry = fields.String(required=False, load_default=None)
name = fields.String(required=False, load_default=None)
ahb_expression = fields.String(required=False, load_default=None)
conditions = fields.String(required=False, load_default=None)
section_name = fields.String(required=False, load_default=None)
index = fields.Int(required=False, load_default=None, dump_default=None)

Expand Down
12 changes: 12 additions & 0 deletions tests/unit_tests/test_ahb.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

line_x = AhbLine(
ahb_expression="Muss [1] O [2]",
conditions="[1] Test\n[2] Test",
segment_group_key="SG2",
segment_code="NAD",
data_element="3039",
Expand All @@ -37,6 +38,7 @@
)
line_y = AhbLine(
ahb_expression="Muss [3] O [4]",
conditions="[3] Test\n[4] Test",
segment_group_key="SG2",
segment_code="NAD",
data_element="3039",
Expand Down Expand Up @@ -86,6 +88,7 @@ def test_ahb_meta_information_equality(self, ahb_x: AhbMetaInformation, ahb_y: A
pytest.param(
AhbLine(
ahb_expression="Muss [1] O [2]",
conditions="[1] Test\n[2] Test",
segment_group_key="SG2",
segment_code="NAD",
segment_id="01234",
Expand All @@ -105,12 +108,14 @@ def test_ahb_meta_information_equality(self, ahb_x: AhbMetaInformation, ahb_y: A
"name": "MP-ID",
"guid": "12b1a98a-edf5-4177-89e5-a6d8a92c5fdc",
"section_name": "Foo",
"conditions": "[1] Test\n[2] Test",
"index": None,
},
),
pytest.param(
AhbLine(
ahb_expression="Muss [1] O [2]",
conditions="[1] Test\n[2] Test",
segment_group_key="SG2",
segment_code="NAD",
segment_id=None,
Expand All @@ -131,6 +136,7 @@ def test_ahb_meta_information_equality(self, ahb_x: AhbMetaInformation, ahb_y: A
"name": "MP-ID",
"guid": "12b1a98a-edf5-4177-89e5-a6d8a92c5fdc",
"section_name": "Foo",
"conditions": "[1] Test\n[2] Test",
"index": 42,
},
),
Expand All @@ -156,6 +162,7 @@ def test_ahb_line_equality(self, line_x: AhbLine, line_y: AhbLine, are_equal: bo
pytest.param(
AhbLine(
ahb_expression="Muss [1] O [2]",
conditions="[1] Test\n[2] Test",
segment_group_key="SG2",
segment_code="NAD",
data_element="3039",
Expand Down Expand Up @@ -201,6 +208,7 @@ def test_ahbline_holds_any_information(self, ahb_line: AhbLine, expected_holds_a
pytest.param(
AhbLine(
ahb_expression="Muss [1] O [2]",
conditions="[1] Test\n[2] Test",
segment_group_key="SG2",
segment_code="NAD",
data_element="3039",
Expand All @@ -214,6 +222,7 @@ def test_ahbline_holds_any_information(self, ahb_line: AhbLine, expected_holds_a
pytest.param(
AhbLine(
ahb_expression="Muss [1] O [2]",
conditions="[1] Test\n[2] Test",
segment_group_key="SG2",
segment_code="NAD",
data_element="3039",
Expand All @@ -227,6 +236,7 @@ def test_ahbline_holds_any_information(self, ahb_line: AhbLine, expected_holds_a
pytest.param(
AhbLine(
ahb_expression="Muss [1] O [2]",
conditions="[1] Test\n[2] Test",
segment_group_key=None,
segment_code="UNH",
data_element="0062",
Expand All @@ -252,6 +262,7 @@ def test_ahbline_get_discriminator(self, ahb_line: AhbLine, include_name: bool,
lines=[
AhbLine(
ahb_expression="Muss [1] O [2]",
conditions="[1] Test\n[2] Test",
segment_group_key="SG2",
segment_code="NAD",
data_element="3039",
Expand Down Expand Up @@ -280,6 +291,7 @@ def test_ahbline_get_discriminator(self, ahb_line: AhbLine, include_name: bool,
"name": "MP-ID",
"guid": "12b1a98a-edf5-4177-89e5-a6d8a92c5fdc",
"section_name": "MP-ID Absender",
"conditions": "[1] Test\n[2] Test",
"index": None,
}
],
Expand Down

0 comments on commit 7b91f58

Please sign in to comment.