From 23192facb5a3c42a1ac8043e8013e0b243cc8bb0 Mon Sep 17 00:00:00 2001 From: chgl Date: Tue, 7 May 2024 11:39:18 +0200 Subject: [PATCH] fix: create output xml folder if not exists and update snapshots (#176) * fix: create output folder for XMLs if not exists * test: update snapshot tests (not yet ran in pipeline) --- .../__snapshots__/decompose_xmls_test.ambr | 396 +++++++++++++++++- src/decompose_xmls/decompose_xmls.py | 7 + 2 files changed, 399 insertions(+), 4 deletions(-) diff --git a/src/decompose_xmls/__snapshots__/decompose_xmls_test.ambr b/src/decompose_xmls/__snapshots__/decompose_xmls_test.ambr index e6238f57..772bffb4 100644 --- a/src/decompose_xmls/__snapshots__/decompose_xmls_test.ambr +++ b/src/decompose_xmls/__snapshots__/decompose_xmls_test.ambr @@ -1,9 +1,397 @@ # serializer version: 1 # name: test_decompose_sammelmeldung[input-obds-reports/test-2patients.xml] list([ - {"xml": "\n\n UKKK\n \n xxxxxxxxxxxxxxxxxxxx\n \n \n \n F00000000\n 9999999\n Hafnero\n B\n E\n W\n 14.01.1900\n \n \n DE\n 91058\n Erlangen\n \n \n \n \n \n 10.03.1900\n I\n behandlungsende\n \n D07.3\n 10 2022 GM\n 08.08.1900\n L\n \n \n \n K\n 01.09.2022\n \n 5-543.42\n 5-683.00\n \n 2022\n \n 01.09.1900\n 12226123\n 8460/2\n 33\n B\n \n \n 01.09.2022\n 8\n p\n 1c3\n c\n 0\n c\n 0\n L0\n V0\n Pn0\n \n \n R0\n R0\n \n \n N\n \n \n jjjjj\n xxxxx\n \n Makroskopischer Tumorrest: R0\n \n \n \n \n \n ", "patient_id": "1004444444", "meldung_id": "FK0037275"}, - {"xml": "\n\n UKKK\n \n xxxxxxxxxxxxxxxxxxxx\n \n \n \n F00000000\n 9999999\n Hafnero\n B\n E\n W\n 14.01.1900\n \n \n DE\n 91058\n Erlangen\n \n \n \n \n \n 10.03.1900\n I\n behandlungsende\n \n D07.3\n 10 2022 GM\n 08.08.1900\n L\n \n \n \n K\n 01.09.2022\n \n 5-543.42\n 5-683.00\n \n 2022\n \n 01.09.1900\n 12226123\n 8460/2\n 33\n B\n \n \n 01.09.2022\n 8\n p\n 1c3\n c\n 0\n c\n 0\n L0\n V0\n Pn0\n \n \n R0\n R0\n \n \n N\n \n \n jjjjj\n xxxxx\n \n Makroskopischer Tumorrest: R0\n \n \n \n \n \n ", "patient_id": "1004444444", "meldung_id": "FK0037276"}, - {"xml": "\n\n UKKK\n \n xxxxxxxxxxxxxxxxxxxx\n \n \n \n 277777777\n 9777777777\n Riedelo\n \n \n M\n \n M\n 28.10.1900\n \n \n xxxxxxxxx\n \n DE\n 90\n xxxxxxx\n \n \n \n \n \n 10.03.1900\n I\n behandlungsbeginn\n \n C61\n 10 2022 GM\n 29.07.1900\n T\n \n \n \n K\n O\n \n \n 5.4.+\n U\n 13.10.1900\n PRCN\n \n 1.8\n Gy\n \n \n \n 5.4.-\n U\n 28.11.1900\n S\n \n \n 5.12.\n L\n 24.11.1900\n S\n \n \n Boost 1: Brachy-Boost in HDR-Technik ED 9,5 Gy GD 19 Gy Boost 2: SEQ ED 1,8\n Gy GD 21,6 Gy\n \n \n \n \n \n ", "patient_id": "101777777777", "meldung_id": "UR0045297"}, - {"xml": "\n\n UKKK\n \n xxxxxxxxxxxxxxxxxxxx\n \n \n \n 277777777\n 9777777777\n Riedelo\n \n \n M\n \n M\n 28.10.1900\n \n \n xxxxxxxxx\n \n DE\n 90\n xxxxxxx\n \n \n \n \n \n 10.03.1900\n I\n behandlungsbeginn\n \n C61\n 10 2022 GM\n 29.07.1900\n T\n \n \n \n K\n O\n \n \n 5.4.+\n U\n 13.10.1900\n PRCN\n \n 1.8\n Gy\n \n \n \n 5.4.-\n U\n 28.11.1900\n S\n \n \n 5.12.\n L\n 24.11.1900\n S\n \n \n Boost 1: Brachy-Boost in HDR-Technik ED 9,5 Gy GD 19 Gy Boost 2: SEQ ED 1,8\n Gy GD 21,6 Gy\n \n \n \n \n \n ", "patient_id": "101777777777", "meldung_id": "ST0047290"}, + dict({ + 'payload': dict({ + 'LKR_MELDUNG': 'FK0037275', + 'REFERENZ_NUMMER': '1004444444', + 'VERSIONSNUMMER': 1, + 'XML_DATEN': ''' + + + + UKKK + + xxxxxxxxxxxxxxxxxxxx + + + + + F00000000 + 9999999 + Hafnero + B + E + W + 14.01.1900 + + + DE + 91058 + Erlangen + + + + + + 10.03.1900 + I + diagnose + + D07.3 + 10 2022 GM + 08.08.1900 + L + + + D07.3 + 10 2022 GM + C56.9 + 32 + 08.08.1900 + 7 + L + + + 08.08.1900 + 12223678 + 8460/2 + 33 + B + + + 01.09.1900 + 12226123 + 8460/2 + 33 + B + + + + 08.08.2022 + 8 + c + is + c + 0 + c + 0 + + + 01.09.2022 + 8 + p + 1c3 + L0 + V0 + Pn0 + + + + 1900-09-12 + + + N + + + + + + + + + ''', + }), + }), + dict({ + 'payload': dict({ + 'LKR_MELDUNG': 'FK0037276', + 'REFERENZ_NUMMER': '1004444444', + 'VERSIONSNUMMER': 1, + 'XML_DATEN': ''' + + + + UKKK + + xxxxxxxxxxxxxxxxxxxx + + + + + F00000000 + 9999999 + Hafnero + B + E + W + 14.01.1900 + + + DE + 91058 + Erlangen + + + + + + 10.03.1900 + I + behandlungsende + + D07.3 + 10 2022 GM + 08.08.1900 + L + + + + K + 01.09.2022 + + 5-543.42 + 5-683.00 + + 2022 + + 01.09.1900 + 12226123 + 8460/2 + 33 + B + + + 01.09.2022 + 8 + p + 1c3 + c + 0 + c + 0 + L0 + V0 + Pn0 + + + R0 + R0 + + + N + + + jjjjj + xxxxx + + Makroskopischer Tumorrest: R0 + + + + + + + + ''', + }), + }), + dict({ + 'payload': dict({ + 'LKR_MELDUNG': 'UR0045297', + 'REFERENZ_NUMMER': '101777777777', + 'VERSIONSNUMMER': 1, + 'XML_DATEN': ''' + + + + UKKK + + xxxxxxxxxxxxxxxxxxxx + + + + + 277777777 + 9777777777 + Riedelo + + + M + + M + 28.10.1900 + + + xxxxxxxxx + + DE + 90 + xxxxxxx + + + + + + 10.03.1900 + I + diagnose + + C61 + 10 2022 GM + 29.07.1900 + T + + + C61 + 10 2022 GM + C61.9 + 32 + 29.07.1900 + 7 + T + + + 29.07.1900 + 12222763 + 8140/3 + 33 + T + + + + 29.07.1900 + 8 + c + 3b + c + 1 + c + 0 + + + + 29.07.1900 + UICC + IV + + + + + 4 + 4 + 8 + + S + 1900-07-29+02:00 + 12 + 9 + + 80 + + 22.200 + 1900-07-29+02:00 + + + + N + + + 1 + + + + + + + ''', + }), + }), + dict({ + 'payload': dict({ + 'LKR_MELDUNG': 'ST0047290', + 'REFERENZ_NUMMER': '101777777777', + 'VERSIONSNUMMER': 1, + 'XML_DATEN': ''' + + + + UKKK + + xxxxxxxxxxxxxxxxxxxx + + + + + 277777777 + 9777777777 + Riedelo + + + M + + M + 28.10.1900 + + + xxxxxxxxx + + DE + 90 + xxxxxxx + + + + + + 10.03.1900 + I + behandlungsbeginn + + C61 + 10 2022 GM + 29.07.1900 + T + + + + K + O + + + 5.4.+ + U + 13.10.1900 + PRCN + + 1.8 + Gy + + + + 5.4.- + U + 28.11.1900 + S + + + 5.12. + L + 24.11.1900 + S + + + Boost 1: Brachy-Boost in HDR-Technik ED 9,5 Gy GD 19 Gy Boost 2: SEQ ED 1,8 + Gy GD 21,6 Gy + + + + + + + + ''', + }), + }), ]) # --- diff --git a/src/decompose_xmls/decompose_xmls.py b/src/decompose_xmls/decompose_xmls.py index 765097f5..d2c771ae 100644 --- a/src/decompose_xmls/decompose_xmls.py +++ b/src/decompose_xmls/decompose_xmls.py @@ -29,6 +29,8 @@ def save_xml_files(meldung_root, patient_id, meldung_id): tree = ET.ElementTree(meldung_root) ET.indent(tree, " ") # ET.ElementTree(meldung_root) + + conditional_folder_create(settings.output_folder_xml) tree.write( f"{settings.output_folder_xml}/patient_{patient_id}" f"_meldung_{meldung_id}.xml", @@ -45,6 +47,7 @@ def kafka_delivery_report(err, msg): def decompose_sammelmeldung(root: ET.Element, filename: str): + results = [] settings = Settings() kafka_producer: Producer = None if settings.kafka_enabled: @@ -119,6 +122,8 @@ def decompose_sammelmeldung(root: ET.Element, filename: str): } } + results.append(result_data) + if settings.save_as_files_enabled: with open( f"{settings.output_folder}/" @@ -152,6 +157,8 @@ def decompose_sammelmeldung(root: ET.Element, filename: str): if kafka_producer is not None: kafka_producer.flush() + return results + def decompose_folder(input_folder: str): settings = Settings()