Skip to content

feat: Add materialized helper table in SQLite which unfolds the recursive Segment Group structure + Pydantic/SQLModel and can easily be queried #111

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

Merged
merged 30 commits into from
Apr 10, 2025

Conversation

hf-kklein
Copy link
Contributor

@hf-kklein hf-kklein commented Apr 9, 2025

Tldr: query ahbs like you'd query PDFs but get tree structure Information for free.

this will be a mid-term replacement for Hochfrequenz/machine-readable_anwendungshandbuecher#336 because it saves us from scraping the .docx files, now that we pay for the XMLs.

@hf-kklein hf-kklein changed the title feat: Add helper view to DB which unrolls recursive structure feat: Add helper view to DB which unrolls the recursive Segment Group structure Apr 9, 2025
@hf-kklein hf-kklein changed the title feat: Add helper view to DB which unrolls the recursive Segment Group structure feat: Add helper view to DB which unfolds the recursive Segment Group structure Apr 9, 2025
@hf-kklein hf-kklein changed the title feat: Add helper view to DB which unfolds the recursive Segment Group structure feat: Add materialized helper view + Pydantic Model which unfolds the recursive Segment Group structure Apr 9, 2025
@hf-kklein hf-kklein changed the title feat: Add materialized helper view + Pydantic Model which unfolds the recursive Segment Group structure feat: Add materialized helper view which unfolds the recursive Segment Group structure + Pydantic/SQLModel Apr 9, 2025
@hf-kklein hf-kklein requested a review from Copilot April 9, 2025 15:47
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 8 changed files in this pull request and generated 1 comment.

Files not reviewed (3)
  • domain-specific-terms.txt: Language not supported
  • src/fundamend/sqlmodels/materialize_ahb_view.sql: Language not supported
  • tox.ini: Language not supported
Comments suppressed due to low confidence (1)

unittests/test_sqlmodels_anwendungshandbuch.py:83

  • [nitpick] The variable name 'ahb_is_not_suited_for_equality_comparison' is quite verbose; consider renaming it to something shorter and clearer, for example 'skip_equality_test'.
ahb_is_not_suited_for_equality_comparison = any(x for x in ahb.anwendungsfaelle if x.is_outdated)

@hf-kklein hf-kklein marked this pull request as ready for review April 9, 2025 15:48
@hf-kklein hf-kklein changed the title feat: Add materialized helper view which unfolds the recursive Segment Group structure + Pydantic/SQLModel feat: Add materialized helper view (a plain table in SQLite) which unfolds the recursive Segment Group structure + Pydantic/SQLModel Apr 9, 2025
@hf-kklein hf-kklein changed the title feat: Add materialized helper view (a plain table in SQLite) which unfolds the recursive Segment Group structure + Pydantic/SQLModel feat: Add materialized helper view (a plain table in SQLite) which unfolds the recursive Segment Group structure + Pydantic/SQLModel and can easily be queried Apr 9, 2025
@hf-kklein hf-kklein changed the title feat: Add materialized helper view (a plain table in SQLite) which unfolds the recursive Segment Group structure + Pydantic/SQLModel and can easily be queried feat: Add materialized helper table in SQLite which unfolds the recursive Segment Group structure + Pydantic/SQLModel and can easily be queried Apr 9, 2025
@@ -507,3 +507,65 @@ def to_model(self) -> PydanticAnwendungshandbuch:
pakete=tuple(x.to_model() for x in sorted(self.pakete, key=lambda y: y.position or 0)),
anwendungsfaelle=tuple(x.to_model() for x in sorted(self.anwendungsfaelle, key=lambda y: y.position or 0)),
)


Copy link
Contributor Author

Choose a reason for hiding this comment

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

Diese Struktur lässt sich mit wenig Aufwand direkt auf ein flatahb ausm kohlrahbi Mappen.

Copy link
Contributor

Choose a reason for hiding this comment

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

hier bietet es sich schon mal an diese Datei aufzuteilen in mehrere Modules.

|- sqlmodels
  |- anwendungshandbuch
    |- code.py
    |- dataelement.py

Aber das ist hier out of scope :)

# Segment Group
segmentgroup_id: Optional[str] = Field(default=None, index=True)
segmentgroup_name: Optional[str] = Field(default=None, index=True)
segmentgroup_ahb_status: Optional[str] = Field(default=None)
Copy link
Contributor

Choose a reason for hiding this comment

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

ich finde Status beschreibt nicht so gut was dahinter steckt.
Sind hier die Muss [10] bspw. drin oder? Bei AHB Tabellen nennen wir es Pflichtfeld-Kennzeichen.
Auf Englisch vll sowas wie mandatory field indicator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ich würde hier auch die "out of scope"-karte ziehen. Der Spaltenname bildet nur das ab, was genau unter diesem Namen "AHB_Status" aus ursprünglichen einzelnen Tabelle und den XML-dateien kommt:

<S_RFF Name="Referenz auf einen Rechenschritt" Number="00018" AHB_Status="Muss [5]">
<C_C506 Name="Referenz">
<D_1153 Name="Referenz, Qualifier">
<Code Name="Rechenschritt" Description="" AHB_Status="X">Z23</Code>
</D_1153>
<D_1154 Name="Rechenschrittidentifikator" AHB_Status="X [913] [8] ∧ [9]"/>
</C_C506>
</S_RFF>

dort heißt das Ding immer "AHB_Status" und damit man in der gejointen Tabelle sieht, von welcher ebene der jeweilige AHB_Status kam, kommt ein Präfix vorne dran. Mein vorschlag wäre: Wir bauen noch eine weitere Sicht auf die tabelle und ändern da das Naming. Kann ich auch in diesem PR machen, ich würde aber den namen in dieser Tabelle gleich lassen.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay wenn sie das in den xml auch so nennen passt das für mich :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

weitere sicht ist vertagt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

=> #115

Renames the variable storing the path to the SQL command file to `sql_command_path` for improved clarity and readability.
#111 (comment)
SELECT
h.anwendungsfall_pk,
child.primary_key, h.root_id, link.parent_id, h.depth + 1, child.position,
h.path || ' > ' || child.name, h.path, h.root_order, 'segment_group',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hf-krechan statt oder zusätzlich zu den Namen der SG und Segmente könnt man auch ihre keys (SG4 statt Vorgang, DTM statt Datum) nehmen um den Path zu bauen. Dann kann man das "Klapp" Feature bauen

Copy link
Contributor

Choose a reason for hiding this comment

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

yes please ^^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sieht z.b. so aus jetzt:

id_path': 'SG2>SG5>STS>C_C555>D_4405>Berechnungsformel besitzt keine Rechenoperation>',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hf-kklein hf-kklein enabled auto-merge (squash) April 10, 2025 14:31
@hf-kklein hf-kklein merged commit 4854086 into main Apr 10, 2025
18 checks passed
@hf-kklein hf-kklein deleted the crate-db branch April 10, 2025 14:32
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

Successfully merging this pull request may close these issues.

2 participants