Skip to content

Commit e5214ef

Browse files
committed
Run validator for JSON-LD
1 parent 074286f commit e5214ef

4 files changed

Lines changed: 162 additions & 0 deletions

File tree

.github/workflows/validate_schema.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ jobs:
1515
uses: actions/setup-node@v4
1616
with:
1717
node-version: 20.x
18+
- run: pip install uv
1819
- run: npm install -g ajv-cli ajv-formats
1920
- run: ajv compile --spec draft2020 -c ajv-formats -s schemas/**/schema.json
21+
- run: uv run --no-project bin/validator.py
2022

2123
update-latest-schema:
2224
runs-on: ubuntu-latest

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ To run your changed schema against a JSON definition:
2929
ajv validate --spec draft2020 -c ajv-formats -s schemas/v1/schema.json -d brazil_dengue.json
3030
```
3131

32+
To run JSON-LD validation, you will need [uv](https://docs.astral.sh/uv/) installed. Then run:
33+
34+
```bash
35+
uv run --no-project bin/validator.py
36+
```
37+
3238
If you propose any changes, update the [CHANGELOG](CHANGELOG.md) accordingly.
3339

3440
## Citing & Authors
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"id": "https://opensyndrome.org/definitions/extremetemperaturesheat_argentina_1.0.0",
3+
"@type": "osd:CaseDefinition",
4+
"title": "Heat Exposure",
5+
"description": "Case definition for suspected heat exposure in individuals with history of extreme heat exposure during Early Temperature Extreme Alert by National Meteorological Service, and clinical symptoms attributable to high body temperature (39°C or higher) and 2 or more of the following: sweating, nausea/vomiting, hypotension, tachycardia, tachypnea, altered consciousness, seizures, fainting. In infants: excessive sweating, irritated skin due to sweating.",
6+
"scope": "specific",
7+
"category": "suspected",
8+
"version": "1.0.0",
9+
"open_syndrome_version": "1.0.0",
10+
"location": "Argentina",
11+
"language": "English",
12+
"organization": "Ministerio de Salud",
13+
"inclusion_criteria": [
14+
{
15+
"type": "criterion",
16+
"logical_operator": "AND",
17+
"values": [
18+
{
19+
"type": "symptom",
20+
"name": "High body temperature",
21+
"attribute": "body_temperature",
22+
"operator": ">=",
23+
"value": 39,
24+
"description": "Temperature measured in celsius",
25+
"ontology_id": "hpo:0002045"
26+
},
27+
{
28+
"type": "criterion",
29+
"logical_operator": "AT_LEAST",
30+
"logical_operator_arguments": [
31+
2
32+
],
33+
"values": [
34+
{
35+
"type": "symptom",
36+
"name": "Warm skin",
37+
"ontology_id": "hpo:0032506"
38+
},
39+
{
40+
"type": "symptom",
41+
"name": "Sweating",
42+
"ontology_id": "hpo:0000975"
43+
},
44+
{
45+
"type": "symptom",
46+
"name": "Nausea/vomiting",
47+
"ontology_id": "hpo:0002017"
48+
},
49+
{
50+
"type": "symptom",
51+
"name": "Hypotension",
52+
"ontology_id": "hpo:0002615"
53+
},
54+
{
55+
"type": "symptom",
56+
"name": "Tachycardia",
57+
"ontology_id": "hpo:0001649"
58+
},
59+
{
60+
"type": "symptom",
61+
"name": "Tachypnea",
62+
"ontology_id": "hpo:0002789"
63+
},
64+
{
65+
"type": "symptom",
66+
"name": "Altered consciousness",
67+
"ontology_id": "hpo:0004372"
68+
},
69+
{
70+
"type": "symptom",
71+
"name": "Seizures",
72+
"ontology_id": "hpo:0001250"
73+
},
74+
{
75+
"type": "symptom",
76+
"name": "Fainting",
77+
"ontology_id": "hpo:0001279"
78+
},
79+
{
80+
"type": "symptom",
81+
"name": "Excessive sweating (infants)",
82+
"description": "Irritated skin due to sweating (infants)",
83+
"ontology_id": "hpo:0000975"
84+
}
85+
]
86+
}
87+
]
88+
}
89+
],
90+
"published_in": "https://opensyndrome.org",
91+
"published_at": "2025-02-08T12:20:55Z",
92+
"published_by": [
93+
"Open Syndrome Initiative"
94+
],
95+
"notes": [
96+
"ICD-10 code HEAT: X30 (Exposure to excessive natural heat), T67 (Effects of heat and light)"
97+
],
98+
"references": [
99+
{
100+
"url": "https://www.argentina.gob.ar/sites/default/files/2019/10/msal-manual_de_normas_y_procedimientos_de_vigilancia_y_control_de_eno_2022.pdf"
101+
}
102+
],
103+
"status": "draft",
104+
"human_readable_definition": "Toda persona con antecedentes de\nexposición a calor extremo en circunstancia de Alerta Temprana por Temperatura\nExtrema (calor) del Servicio Meteorológico Nacional, y sintomatología clínica\natribuible - Temperatura corporal mayor o igual a 39 ºC y 2 o más de los siguientes\nsíntomas, a saber:\nSignos y síntomas atribuibles: piel caliente, sudoración abundante en un primer\nmomento o escasa, náuseas y/o vómitos, hipotensión, taquicardia y taquipnea,\nalteración del estado de conciencia, convulsiones, desmayo. En bebés: sudoración\nabundante, piel irritada por sudor.",
105+
"target_public_health_threats": [
106+
"Heat",
107+
"mondo:0020674"
108+
],
109+
"keywords": [
110+
"Heat",
111+
"South America",
112+
"Climate-related"
113+
],
114+
"definition_type": "case_definition",
115+
"@context": "https://opensyndrome.org/schema/v1/context.jsonld"
116+
}

bin/validator.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = [
4+
# "jsonschema>=4.26.0",
5+
# "pyld>=2.0.4",
6+
# ]
7+
# ///
8+
import json
9+
from jsonschema import validate, exceptions
10+
from pyld import jsonld
11+
12+
13+
# TODO download from definitions in the future
14+
with open('bin/extremetemperaturesheat_argentina_jsonld.json') as f:
15+
doc_json = json.load(f)
16+
17+
with open('schemas/v1/schema.json') as f:
18+
schema = json.load(f)
19+
20+
print("--- JSON schema validation ---")
21+
try:
22+
validate(instance=doc_json, schema=schema)
23+
print("JSON Schema OK")
24+
except exceptions.ValidationError as err:
25+
print(f"Validation failed: {err.message} - {err.json_path}")
26+
27+
print("\n--- JSON-LD validation ---")
28+
try:
29+
# check if something was not mapped
30+
expanded = jsonld.expand(doc_json)
31+
print("JSON-LD expansion works")
32+
33+
nquads = jsonld.normalize(doc_json, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
34+
print(f"RFD graph {len(nquads.splitlines())} triplas.")
35+
print(nquads)
36+
37+
except Exception as e:
38+
print(f"❌ Erro ao processar JSON-LD: {e}")

0 commit comments

Comments
 (0)