Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MIG Elements between <Uebertragsgungsdatei> and <M_FORMAT> (UNA, UNB) #57

Open
hf-kklein opened this issue Dec 5, 2024 · 4 comments
Assignees

Comments

@hf-kklein
Copy link
Contributor

hf-kklein commented Dec 5, 2024

Typically S_UNA and S_UNB...
zum reinkommen erstmal mit #68 starten :)

@hf-kklein

This comment was marked as resolved.

@hf-kklein
Copy link
Contributor Author

hf-kklein commented Dec 9, 2024

Ansatzpunkte:

if _is_uebertragungsdatei(root):
for elem in root.iter():
if elem.tag.startswith("M_"):
root = elem
break

  • Analog zu den vorhandenen Funktionen
    def _to_code(element: ET.Element) -> Code:
    assert _is_code(element)
    return Code(name=element.attrib["Name"], description=element.attrib["Description"] or None, value=element.text)
    def _to_data_element(element: ET.Element) -> DataElement:
    assert _is_data_element(element)
    codes = []
    for child in element:
    if _is_code(child):
    codes.append(_to_code(child))
    else:
    raise ValueError(f"unexpected element: {child.tag}")
    return DataElement(
    id=element.tag,
    name=element.attrib["Name"],
    description=element.attrib["Description"] or None,
    status_std=MigStatus(element.attrib["Status_Std"]),
    status_specification=MigStatus(element.attrib["Status_Specification"]),
    format_std=element.attrib["Format_Std"],
    format_specification=element.attrib["Format_Specification"],
    codes=codes,
    )
    def _to_data_element_group(element: ET.Element) -> DataElementGroup:
    assert _is_data_element_group(element)
    data_elements = []
    for child in element:
    if _is_data_element(child):
    data_elements.append(_to_data_element(child))
    else:
    raise ValueError(f"unexpected element: {child.tag}")
    return DataElementGroup(
    id=element.tag,
    name=element.attrib["Name"],
    description=element.attrib["Description"] or None,
    status_std=MigStatus(element.attrib["Status_Std"]),
    status_specification=MigStatus(element.attrib["Status_Specification"]),
    data_elements=data_elements,
    )
    def _to_segment(element: ET.Element) -> Segment:
    assert _is_segment(element)
    data_elements: list[DataElement | DataElementGroup] = []
    for child in element:
    if _is_data_element_group(child):
    data_elements.append(_to_data_element_group(child))
    elif _is_data_element(child):
    data_elements.append(_to_data_element(child))
    else:
    raise ValueError(f"unexpected element: {child.tag}")
    return Segment(
    id=element.tag.lstrip("S_"),
    name=element.attrib["Name"],
    description=element.attrib["Description"] or None,
    counter=element.attrib["Counter"],
    level=int(element.attrib["Level"]),
    max_rep_std=int(element.attrib["MaxRep_Std"]),
    max_rep_specification=int(element.attrib["MaxRep_Specification"]),
    status_std=MigStatus(element.attrib["Status_Std"]),
    status_specification=MigStatus(element.attrib["Status_Specification"]),
    example=element.attrib["Example"] or None,
    number=element.attrib["Number"],
    data_elements=data_elements,
    )
    def _to_segment_group(element: ET.Element) -> SegmentGroup:
    assert _is_segment_group(element)
    segments_and_groups: list[SegmentGroup | Segment] = []
    for child in element:
    if _is_segment_group(child):
    segments_and_groups.append(_to_segment_group(child))
    elif _is_segment(child):
    segments_and_groups.append(_to_segment(child))
    else:
    raise ValueError(f"unexpected element: {child.tag}")
    return SegmentGroup(
    id=element.tag.lstrip("G_SG"),
    name=element.attrib["Name"],
    status_std=MigStatus(element.attrib["Status_Std"]),
    status_specification=MigStatus(element.attrib["Status_Specification"]),
    counter=element.attrib["Counter"],
    level=int(element.attrib["Level"]),
    max_rep_std=int(element.attrib["MaxRep_Std"]),
    max_rep_specification=int(element.attrib["MaxRep_Specification"]),
    segments=[s for s in segments_and_groups if isinstance(s, Segment)],
    segment_groups=[sg for sg in segments_and_groups if isinstance(sg, SegmentGroup)],
    )

eine Funktion bauen, die ein etree.Element in eine repräsentation der Übertragungsdatei in Python-Objekten transformiert.

@hf-kklein

This comment has been minimized.

@hf-kklein
Copy link
Contributor Author

@DeltaDaniel @lord-haffi es gibt schon einen draft-pr: #72, vllt könnt ihr darauf aufsetzen, oder ihr löst es anders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants