Skip to content

feat: Add Segment.is_on_uebertragungsdatei_level to AHB(esser) View (the aggregated instead of only the bare data model) #134

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 13 commits into from
Apr 24, 2025
Merged
1 change: 1 addition & 0 deletions src/fundamend/sqlmodels/ahbtabellen_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class AhbTabellenLine(SQLModel, table=True):
segment_code: str | None = Field()
data_element: str | None = Field()
qualifier: str | None = Field()
is_on_uebertragungsdatei_level: bool | None = Field() #: !=null as soon as at least one segment is part of the path
line_ahb_status: str | None = Field()
line_name: str | None = Field()
line_type: str | None = Field() # 'code' or 'dataelement' or 'segment' or 'segmentgroup' or 'dataelementgroup'
Expand Down
1 change: 1 addition & 0 deletions src/fundamend/sqlmodels/ahbview.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class AhbHierarchyMaterialized(SQLModel, table=True):
segment_number: Optional[str] = Field(default=None, index=True)
segment_ahb_status: Optional[str] = Field(default=None)
segment_position: Optional[int] = Field(default=None, index=True)
is_on_uebertragungsdatei_level: Optional[bool] = Field(default=None, index=False) #: null for SG only (no segment)

# Data Element Group
dataelementgroup_id: Optional[str] = Field(default=None, index=True)
Expand Down
6 changes: 4 additions & 2 deletions src/fundamend/sqlmodels/create_ahbtabellen_view.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ WITH consolidated_ahm AS (SELECT id,
beschreibung,
segmentgroup_id,
segment_id,
is_on_uebertragungsdatei_level,
dataelement_id,
code_value,
sort_path,
Expand All @@ -39,12 +40,13 @@ SELECT c.id as id,
c.segmentgroup_id as segmentgroup_key, -- eg 'SG6'
c.segment_id as segment_code, -- e.g 'NAD'
c.dataelement_id as data_element, -- e.g 'D_3035'
c.is_on_uebertragungsdatei_level as is_on_uebertragungsdatei_level, -- true for UNA/UNB+UNZ, not for UNH
--CASE
-- WHEN dataelement_id IS NOT NULL THEN SUBSTR(dataelement_id, 3)
-- END AS dataelement_without_leading_d_, -- e.g '3035'
c.code_value as qualifier,
c.line_ahb_status as line_ahb_status, -- e.g. 'Muss [28] ∧ [64]'
c.line_name as line_name, -- e.g. 'Datums- oder Uhrzeit- oder Zeitspannen-Format, Code' or 'Produkt-Daten für Lieferant relevant'
c.line_ahb_status as line_ahb_status, -- e.g. 'Muss [28] ∧ [64]'
c.line_name as line_name, -- e.g. 'Datums- oder Uhrzeit- oder Zeitspannen-Format, Code' or 'Produkt-Daten für Lieferant relevant'
c.line_type as line_type,
c.sort_path as sort_path,
NULLIF(ahe.node_texts, '') as bedingung,
Expand Down
23 changes: 13 additions & 10 deletions src/fundamend/sqlmodels/materialize_ahb_view.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ WITH RECURSIVE
af.beschreibung,
af.kommunikation_von,
ah.edifact_format_version,
af.anwendungshandbuch_primary_key
af.anwendungshandbuch_primary_key,
null as is_on_uebertragungsdatei_level
FROM segmentgroup sg
JOIN anwendungsfall af ON sg.anwendungsfall_primary_key = af.primary_key
JOIN anwendungshandbuch ah ON af.anwendungshandbuch_primary_key = ah.primary_key
Expand All @@ -34,8 +35,8 @@ WITH RECURSIVE

SELECT s.primary_key,
s.position,
'segment' AS type,
s.id AS root_id_text,
'segment' AS type,
s.id AS root_id_text,
s.name,
s.ahb_status,
s.anwendungsfall_primary_key,
Expand All @@ -48,7 +49,8 @@ WITH RECURSIVE
af.beschreibung,
af.kommunikation_von,
ah.edifact_format_version,
af.anwendungshandbuch_primary_key
af.anwendungshandbuch_primary_key,
s.is_on_uebertragungsdatei_level as is_on_uebertragungsdatei_level
FROM segment s
JOIN anwendungsfall af ON s.anwendungsfall_primary_key = af.primary_key
JOIN anwendungshandbuch ah ON af.anwendungshandbuch_primary_key = ah.primary_key
Expand Down Expand Up @@ -83,7 +85,7 @@ WITH RECURSIVE
o.kommunikation_von,
o.edifact_format_version,
o.anwendungshandbuch_primary_key,

o.is_on_uebertragungsdatei_level,
CASE WHEN o.type = 'segment_group' THEN o.root_id_text ELSE NULL END AS segmentgroup_id,
CASE WHEN o.type = 'segment_group' THEN o.name ELSE NULL END AS segmentgroup_name,
CASE WHEN o.type = 'segment_group' THEN o.ahb_status ELSE NULL END AS segmentgroup_ahb_status,
Expand Down Expand Up @@ -142,6 +144,7 @@ WITH RECURSIVE
h.kommunikation_von,
h.edifact_format_version,
h.anwendungshandbuch_primary_key,
h.is_on_uebertragungsdatei_level,

'SG' || child.id,
child.name,
Expand Down Expand Up @@ -199,7 +202,7 @@ WITH RECURSIVE
h.kommunikation_von,
h.edifact_format_version,
h.anwendungshandbuch_primary_key,

s.is_on_uebertragungsdatei_level,
h.segmentgroup_id,
h.segmentgroup_name,
h.segmentgroup_ahb_status,
Expand Down Expand Up @@ -255,7 +258,7 @@ WITH RECURSIVE
h.kommunikation_von,
h.edifact_format_version,
h.anwendungshandbuch_primary_key,

h.is_on_uebertragungsdatei_level,
h.segmentgroup_id,
h.segmentgroup_name,
h.segmentgroup_ahb_status,
Expand Down Expand Up @@ -311,7 +314,7 @@ WITH RECURSIVE
h.kommunikation_von,
h.edifact_format_version,
h.anwendungshandbuch_primary_key,

h.is_on_uebertragungsdatei_level,
h.segmentgroup_id,
h.segmentgroup_name,
h.segmentgroup_ahb_status,
Expand Down Expand Up @@ -368,7 +371,7 @@ WITH RECURSIVE
h.kommunikation_von,
h.edifact_format_version,
h.anwendungshandbuch_primary_key,

h.is_on_uebertragungsdatei_level,
h.segmentgroup_id,
h.segmentgroup_name,
h.segmentgroup_ahb_status,
Expand Down Expand Up @@ -424,7 +427,7 @@ WITH RECURSIVE
h.kommunikation_von,
h.edifact_format_version,
h.anwendungshandbuch_primary_key,

h.is_on_uebertragungsdatei_level,
h.segmentgroup_id,
h.segmentgroup_name,
h.segmentgroup_ahb_status,
Expand Down
Loading