Skip to content

Commit

Permalink
Merge pull request #247 from bento-platform/develop
Browse files Browse the repository at this point in the history
Version 2.2.1
  • Loading branch information
zxenia authored Jul 28, 2021
2 parents b89a4b8 + be3d7a6 commit 58aac95
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
22 changes: 21 additions & 1 deletion chord_metadata_service/chord/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import shutil
import tempfile
import uuid
import jsonschema

from dateutil.parser import isoparse
from typing import Callable
Expand All @@ -30,6 +31,7 @@
)
from chord_metadata_service.mcode.parse_fhir_mcode import parse_bundle
from chord_metadata_service.mcode.mcode_ingest import ingest_mcodepacket
from chord_metadata_service.phenopackets.schemas import PHENOPACKET_SCHEMA

requests_unixsocket.monkeypatch()

Expand Down Expand Up @@ -344,9 +346,27 @@ def ingest_experiment(experiment_data, table_id) -> em.Experiment:
return new_experiment


def ingest_phenopacket(phenopacket_data, table_id) -> pm.Phenopacket:
def ingest_phenopacket(phenopacket_data, table_id):
"""Ingests a single phenopacket."""

v = jsonschema.Draft7Validator(PHENOPACKET_SCHEMA, format_checker=jsonschema.FormatChecker())
try:
jsonschema.validate(
phenopacket_data,
PHENOPACKET_SCHEMA,
format_checker=jsonschema.FormatChecker(),
)
logger.info("JSON schema validation passed.")

except jsonschema.exceptions.ValidationError:
errors = [e for e in v.iter_errors(phenopacket_data)]
logger.info(f"JSON schema validation failed. Errors: {errors}")
for i, error in enumerate(errors, 1):
logger.error(
f"{i} Validation error in {'.'.join(str(v) for v in error.path)}: {error.message}",
)
return

new_phenopacket_id = phenopacket_data.get("id", str(uuid.uuid4()))

subject = phenopacket_data.get("subject")
Expand Down
6 changes: 2 additions & 4 deletions chord_metadata_service/chord/tests/example_phenopacket.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"label": "Hematuria"
},
"negated": false,
"modifier": [],
"evidence": []
"modifier": []
},
{
"description": "",
Expand All @@ -27,8 +26,7 @@
"id": "HP:0012828",
"label": "Severe"
},
"modifier": [],
"evidence": []
"modifier": []
}
],
"diseases": [
Expand Down
2 changes: 1 addition & 1 deletion chord_metadata_service/package.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[package]
name = katsu
version = 2.2.0
version = 2.2.1
authors = Ksenia Zaytseva, David Lougheed, Simon Chénard, Romain Grégoire
2 changes: 1 addition & 1 deletion chord_metadata_service/phenopackets/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,5 +360,5 @@
"meta_data": PHENOPACKET_META_DATA_SCHEMA,
"extra_properties": EXTRA_PROPERTIES_SCHEMA
},
"required": ["id", "meta_data"],
"required": ["meta_data"],
}, descriptions.PHENOPACKET)

0 comments on commit 58aac95

Please sign in to comment.