feat: add date-based OHIP data reporting alongside XML

This commit is contained in:
Wyndham ARR committed 2026-09-18 15:29:27 +08:00
1 parent 5ecd571e3b
commit ad2c59256f
259 files changed
+37326 -126

No files matched your search

+23 -7
View File
@@ -322,9 +322,25 @@ class PostgresIngestionRepository(IngestionRepository):
)
return int(cursor.fetchone()[0])
def assert_data_source_schema(self) -> None:
"""Fail before exposing the button if direct-source migration is absent."""
def check(cursor):
cursor.execute("""SELECT conname, pg_get_constraintdef(oid)
FROM pg_constraint WHERE (conrelid = 'ingestion.artifacts'::regclass
AND conname = 'artifacts_artifact_kind_check')
OR (conrelid = 'ingestion.processing_runs'::regclass
AND conname IN ('processing_runs_terminal_shape', 'processing_runs_uploaded_filename_check'))""")
definitions = dict(cursor.fetchall())
expected = {"artifacts_artifact_kind_check": "ohip_json",
"processing_runs_terminal_shape": "5.0",
"processing_runs_uploaded_filename_check": "ARR.json"}
if any(value not in definitions.get(key, "") for key, value in expected.items()):
raise IngestionError("DATABASE_MIGRATION_MISSING", "direct data entry requires migration 019")
self._run_transaction(check, "direct data schema could not be checked")
def register_job(self, registration: JobRegistration) -> None:
if (
registration.source.role != "source_xml"
registration.source.role not in {"source_xml", "source_data"}
or registration.attempt_no < 1
or not SHA256_RE.fullmatch(registration.idempotency_key)
):
@@ -957,7 +973,7 @@ class PostgresIngestionRepository(IngestionRepository):
source_row = cursor.fetchone()
if (
source_row is None
or str(source_row[0]) != "opera_xml"
or str(source_row[0]) not in {"opera_xml", "ohip_json"}
or not isinstance(source_row[1], str)
or not isinstance(source_row[2], str)
or not isinstance(source_row[3], str)
@@ -966,8 +982,8 @@ class PostgresIngestionRepository(IngestionRepository):
):
raise IngestionError("DATABASE_STATE_INVALID", "复核源XML制品无效")
source_ref = ArtifactRef(
role="source_xml",
file_kind="opera_xml",
role="source_data" if str(source_row[0]) == "ohip_json" else "source_xml",
file_kind=str(source_row[0]),
object_key=source_row[1],
original_filename=source_row[2],
sha256=source_row[3],
@@ -1389,7 +1405,7 @@ class PostgresIngestionRepository(IngestionRepository):
"delivery does not match its job",
)
source_ref = envelope.artifacts["source_xml"]
source_ref = envelope.source
result_ref = envelope.artifacts["result_json"]
structured_ref = envelope.artifacts["structured_result_json"]
if source_ref is None or result_ref is None or structured_ref is None:
@@ -1611,7 +1627,7 @@ class PostgresIngestionRepository(IngestionRepository):
business_date = envelope.business_date
if business_date is None:
raise IngestionError("RESULT_CONTRACT_INVALID", "review delivery has no business date")
source_ref = envelope.artifacts["source_xml"]
source_ref = envelope.source
issues = payload.get("review_issues")
if source_ref is None or not isinstance(issues, list) or not issues:
raise IngestionError("RESULT_CONTRACT_INVALID", "review delivery is incomplete")
@@ -1953,7 +1969,7 @@ class PostgresIngestionRepository(IngestionRepository):
if (
str(case[2]) != "processing"
or int(case[11]) != processing_run_id
or str(case[7]) != envelope.artifacts["source_xml"].sha256
or str(case[7]) != envelope.source.sha256
or str(case[5]) != envelope.processor_version
or str(case[6]) != envelope.rule_set_sha256
or str(case[9]) != manual_override_sha256