FHIR: every URL the API emits hangs from one base, set by FHIR_BASE_URL
The code systems, value sets and the extensions (cut-offs, report id, interval, quartiles) each wrote the domain by hand. They now derive from webapi.fhir_base, a leaf module so metrics and durations can use it without a cycle. The default is unchanged; the WebApp still reads the same URLs by exact match, so changing the domain goes to both. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+3
-2
@@ -20,6 +20,7 @@ from pathlib import Path
|
||||
|
||||
from sqlalchemy import Integer, Select, String, and_, case, cast, column, func, literal, not_, null, select, table, true
|
||||
|
||||
from webapi.fhir_base import STRUCTURE
|
||||
from webapi.metrics import (
|
||||
AGGREGATION_VERSION,
|
||||
EVENT_CUTOFF,
|
||||
@@ -278,9 +279,9 @@ def duration_report(definition: DurationDefinition, question: Question, result:
|
||||
]}
|
||||
if result.median is not None:
|
||||
group["measureScore"] = {"value": result.median, "unit": "d",
|
||||
"extension": [{"url": "https://isssteleon.org/fhir/StructureDefinition/q1",
|
||||
"extension": [{"url": f"{STRUCTURE}/q1",
|
||||
"valueDecimal": result.q1},
|
||||
{"url": "https://isssteleon.org/fhir/StructureDefinition/q3",
|
||||
{"url": f"{STRUCTURE}/q3",
|
||||
"valueDecimal": result.q3}]}
|
||||
extensions = [{"url": HISTORY_ENTRY, "valueInteger": result.report_id},
|
||||
{"url": EVENT_CUTOFF, "valueDate": (result.event_cutoff or question.event_cutoff).isoformat()}]
|
||||
|
||||
@@ -9,12 +9,14 @@ from urllib.parse import urlencode
|
||||
|
||||
from flask import Response, request
|
||||
|
||||
from webapi.fhir_base import BASE as _BASE, STRUCTURE as _STRUCTURE
|
||||
|
||||
FHIR_VERSION = "4.0.1"
|
||||
MEDIA_TYPE = "application/fhir+json"
|
||||
BASE = "https://isssteleon.org/fhir"
|
||||
BASE = _BASE
|
||||
CODE_SYSTEM = f"{BASE}/CodeSystem"
|
||||
VALUE_SET = f"{BASE}/ValueSet"
|
||||
STRUCTURE = f"{BASE}/StructureDefinition"
|
||||
STRUCTURE = _STRUCTURE
|
||||
SIMULATED = {"system": f"{CODE_SYSTEM}/etiqueta", "code": "simulado", "display": "Datos simulados"}
|
||||
MAX_COUNT = 200
|
||||
DEFAULT_COUNT = 50
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
"""The base of every FHIR URL this API emits: code systems, value sets and extensions.
|
||||
|
||||
It is a name we mint, not an address that has to resolve. `FHIR_BASE_URL` sets it. The WebApp reads these URLs by
|
||||
exact match (`fhir.ts` CODE_SYSTEM and `paciente-riesgo.validation.ts` INTERVAL), so a change of domain goes to both.
|
||||
|
||||
A module of its own, with no imports from the package, so `metrics` and `durations` can use it without a cycle.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
BASE = os.environ.get("FHIR_BASE_URL", "https://isssteleon.org/fhir").rstrip("/")
|
||||
STRUCTURE = f"{BASE}/StructureDefinition"
|
||||
+6
-5
@@ -42,6 +42,7 @@ from sqlalchemy import (
|
||||
)
|
||||
|
||||
from webapi.cama_analysis.stats import wilson
|
||||
from webapi.fhir_base import STRUCTURE
|
||||
|
||||
AGGREGATION_VERSION = "md19.1" # the unit-row contract the publication views read
|
||||
TOTAL = "total"
|
||||
@@ -665,11 +666,11 @@ def _from_counts(definition: MeasureDefinition, report_id: int, counts: dict, by
|
||||
# --- the contract --------------------------------------------------------------------------------------------------
|
||||
|
||||
POPULATION_SYSTEM = "http://terminology.hl7.org/CodeSystem/measure-population"
|
||||
EVENT_CUTOFF = "https://isssteleon.org/fhir/StructureDefinition/corte-evento"
|
||||
KNOWLEDGE_CUTOFF = "https://isssteleon.org/fhir/StructureDefinition/corte-conocimiento"
|
||||
HISTORY_ENTRY = "https://isssteleon.org/fhir/StructureDefinition/reporte-id"
|
||||
INTERVAL_LOW = "https://isssteleon.org/fhir/StructureDefinition/ic-bajo"
|
||||
INTERVAL_HIGH = "https://isssteleon.org/fhir/StructureDefinition/ic-alto"
|
||||
EVENT_CUTOFF = f"{STRUCTURE}/corte-evento"
|
||||
KNOWLEDGE_CUTOFF = f"{STRUCTURE}/corte-conocimiento"
|
||||
HISTORY_ENTRY = f"{STRUCTURE}/reporte-id"
|
||||
INTERVAL_LOW = f"{STRUCTURE}/ic-bajo"
|
||||
INTERVAL_HIGH = f"{STRUCTURE}/ic-alto"
|
||||
|
||||
|
||||
def _populations(definition: MeasureDefinition, counts: Counts) -> list[dict]:
|
||||
|
||||
Reference in New Issue
Block a user