fhir_to_pad_converter.py working

This commit is contained in:
Alexander Domene
2025-10-26 13:51:38 +01:00
parent f9d4bc6f11
commit a71284ee64
34 changed files with 279941 additions and 0 deletions

BIN
_archived/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,65 @@
#!/usr/bin/env python3
# validate_padnext_2_12.py
# Validate PADneXt 2.12 ADL and AUF XML files against XSDs using lxml.
# Usage:
# python validate_padnext_2_12.py <XML_FILE> <XSD_FILE> [<XML_FILE> <XSD_FILE> ...]
from lxml import etree
from pathlib import Path
import sys
import textwrap
def load_schema(xsd_path: Path) -> etree.XMLSchema:
parser = etree.XMLParser(remove_blank_text=True)
doc = etree.parse(str(xsd_path), parser)
return etree.XMLSchema(doc)
def validate(xml_path: Path, schema: etree.XMLSchema):
parser = etree.XMLParser(remove_blank_text=True)
doc = etree.parse(str(xml_path), parser)
ok = schema.validate(doc)
return ok, schema.error_log
def main(argv):
if len(argv) < 3 or len(argv[1:]) % 2 != 0:
print("Usage: python validate_padnext_2_12.py <XML_FILE> <XSD_FILE> [<XML_FILE> <XSD_FILE> ...]")
return 2
# Process pairs
for i in range(1, len(argv), 2):
xml_path = Path(argv[i])
xsd_path = Path(argv[i+1])
print(f"— Validate —")
print(f" XML: {xml_path}")
print(f" XSD: {xsd_path}")
try:
schema = load_schema(xsd_path)
except Exception as e:
print(" ❌ Failed to load schema:")
print(textwrap.indent(str(e), " "))
print()
continue
try:
ok, log = validate(xml_path, schema)
except Exception as e:
print(" ❌ Exception during validation:")
print(textwrap.indent(str(e), " "))
print()
continue
if ok:
print(" ✅ VALID\n")
else:
print(" ❌ NOT VALID")
for entry in log:
loc = f"{Path(entry.filename).name if entry.filename else xml_path.name}:{entry.line}:{entry.column}"
print(f" - {loc}: {entry.message}")
print()
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))