Skip to content

Commit

Permalink
Merge pull request #114 from c3g/fixing_validation
Browse files Browse the repository at this point in the history
Fixing validation
  • Loading branch information
zxenia committed Apr 28, 2020
2 parents afde5e9 + 7d85a7e commit efe98b7
Show file tree
Hide file tree
Showing 13 changed files with 369 additions and 294 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.2.10 on 2020-04-01 18:45

import chord_metadata_service.restapi.validators
import django.contrib.postgres.fields.jsonb
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('experiments', '0003_auto_20200331_1841'),
]

operations = [
migrations.AlterField(
model_name='experiment',
name='experiment_ontology',
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, help_text='(Ontology: OBI) links to experiment ontology information.', null=True, validators=[chord_metadata_service.restapi.validators.JsonSchemaValidator({'$id': 'ONTOLOGY_CLASS_LIST', '$schema': 'http://json-schema.org/draft-07/schema#', 'description': 'Ontology class list', 'items': {'$id': 'chord_metadata_service:ontology_class_schema', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'todo', 'properties': {'id': {'description': 'CURIE style identifier.', 'type': 'string'}, 'label': {'description': 'Human-readable class name.', 'type': 'string'}}, 'required': ['id', 'label'], 'title': 'Ontology class schema', 'type': 'object'}, 'title': 'Ontology class list', 'type': 'array'})]),
),
migrations.AlterField(
model_name='experiment',
name='molecule_ontology',
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, help_text='(Ontology: SO) links to molecule ontology information.', null=True, validators=[chord_metadata_service.restapi.validators.JsonSchemaValidator({'$id': 'ONTOLOGY_CLASS_LIST', '$schema': 'http://json-schema.org/draft-07/schema#', 'description': 'Ontology class list', 'items': {'$id': 'chord_metadata_service:ontology_class_schema', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'todo', 'properties': {'id': {'description': 'CURIE style identifier.', 'type': 'string'}, 'label': {'description': 'Human-readable class name.', 'type': 'string'}}, 'required': ['id', 'label'], 'title': 'Ontology class schema', 'type': 'object'}, 'title': 'Ontology class list', 'type': 'array'})]),
),
]
9 changes: 4 additions & 5 deletions chord_metadata_service/experiments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from django.contrib.postgres.fields import JSONField, ArrayField
from chord_metadata_service.restapi.models import IndexableMixin
from chord_metadata_service.restapi.description_utils import rec_help
from chord_metadata_service.restapi.validators import ontologyListValidator, keyValueValidator
from chord_metadata_service.restapi.schemas import ONTOLOGY_CLASS_LIST, KEY_VALUE_OBJECT
from chord_metadata_service.restapi.validators import ontology_list_validator, key_value_validator
from chord_metadata_service.patients.models import Individual
from chord_metadata_service.phenopackets.models import Biosample
import chord_metadata_service.experiments.descriptions as d
Expand Down Expand Up @@ -42,12 +41,12 @@ class Experiment(models.Model, IndexableMixin):
reference_registry_id = CharField(max_length=30, blank=True, null=True, help_text=rec_help(d.EXPERIMENT, 'reference_registry_id'))
qc_flags = ArrayField(CharField(max_length=100, help_text=rec_help(d.EXPERIMENT, 'qc_flags')), null=True, blank=True, default=list)
experiment_type = CharField(max_length=30, help_text=rec_help(d.EXPERIMENT, 'experiment_type'))
experiment_ontology = JSONField(blank=True, null=True, validators=[ontologyListValidator], help_text=rec_help(d.EXPERIMENT, 'experiment_ontology'))
molecule_ontology = JSONField(blank=True, null=True, validators=[ontologyListValidator], help_text=rec_help(d.EXPERIMENT, 'molecule_ontology'))
experiment_ontology = JSONField(blank=True, null=True, validators=[ontology_list_validator], help_text=rec_help(d.EXPERIMENT, 'experiment_ontology'))
molecule_ontology = JSONField(blank=True, null=True, validators=[ontology_list_validator], help_text=rec_help(d.EXPERIMENT, 'molecule_ontology'))
molecule = CharField(choices=MOLECULE, max_length=20, blank=True, null=True, help_text=rec_help(d.EXPERIMENT, 'molecule'))
library_strategy = CharField(choices=LIBRARY_STRATEGY, max_length=25, help_text=rec_help(d.EXPERIMENT, 'library_strategy'))

other_fields = JSONField(blank=True, null=True, validators=[keyValueValidator], help_text=rec_help(d.EXPERIMENT, 'other_fields'))
other_fields = JSONField(blank=True, null=True, validators=[key_value_validator], help_text=rec_help(d.EXPERIMENT, 'other_fields'))

biosample = models.ForeignKey(Biosample, on_delete=models.SET_NULL, blank=True, null=True, help_text=rec_help(d.EXPERIMENT, 'biosample'))
individual = models.ForeignKey(Individual, on_delete=models.SET_NULL, blank=True, null=True, help_text=rec_help(d.EXPERIMENT, 'individual'))
Expand Down
3 changes: 0 additions & 3 deletions chord_metadata_service/experiments/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from rest_framework import serializers
from chord_metadata_service.restapi.schemas import ONTOLOGY_CLASS, AGE_OR_AGE_RANGE
from chord_metadata_service.restapi.validators import JsonSchemaValidator, ontologyListValidator, keyValueValidator
from chord_metadata_service.restapi.serializers import GenericSerializer
from .models import Experiment

Expand Down
40 changes: 20 additions & 20 deletions chord_metadata_service/mcode/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from chord_metadata_service.restapi.description_utils import rec_help
import chord_metadata_service.mcode.descriptions as d
from chord_metadata_service.restapi.validators import (
ontologyValidator, quantity_validator, tumor_marker_test_validator,
complex_ontology_validator, time_or_period_validator, ontologyListValidator
ontology_validator, quantity_validator, tumor_marker_test_validator,
complex_ontology_validator, time_or_period_validator, ontology_list_validator
)


Expand All @@ -23,16 +23,16 @@ class GeneticVariantTested(models.Model, IndexableMixin):
# make writable if it doesn't exist
gene_studied = models.ForeignKey(Gene, blank=True, null=True, on_delete=models.SET_NULL,
help_text=rec_help(d.GENETIC_VARIANT_TESTED, "gene_studied"))
method = JSONField(blank=True, null=True, validators=[ontologyValidator],
method = JSONField(blank=True, null=True, validators=[ontology_validator],
help_text=rec_help(d.GENETIC_VARIANT_TESTED, "method"))
variant_tested_identifier = JSONField(blank=True, null=True, validators=[ontologyValidator],
variant_tested_identifier = JSONField(blank=True, null=True, validators=[ontology_validator],
help_text=rec_help(d.GENETIC_VARIANT_TESTED, "variant_tested_identifier"))
variant_tested_hgvs_name = ArrayField(models.CharField(max_length=200), blank=True, null=True,
help_text=rec_help(d.GENETIC_VARIANT_TESTED, "variant_tested_hgvs_name"))
variant_tested_description = models.CharField(max_length=200, blank=True,
help_text=rec_help(d.GENETIC_VARIANT_TESTED,
"variant_tested_description"))
data_value = JSONField(blank=True, null=True, validators=[ontologyValidator],
data_value = JSONField(blank=True, null=True, validators=[ontology_validator],
help_text=rec_help(d.GENETIC_VARIANT_TESTED, "data_value"))
extra_properties = JSONField(blank=True, null=True,
help_text=rec_help(d.GENETIC_VARIANT_TESTED, "extra_properties"))
Expand Down Expand Up @@ -60,16 +60,16 @@ class GeneticVariantFound(models.Model, IndexableMixin):
# TODO Discuss: Connection to Gene from Phenopackets
id = models.CharField(primary_key=True, max_length=200,
help_text=rec_help(d.GENETIC_VARIANT_FOUND, "id"))
method = JSONField(blank=True, null=True, validators=[ontologyValidator],
method = JSONField(blank=True, null=True, validators=[ontology_validator],
help_text=rec_help(d.GENETIC_VARIANT_FOUND, "method"))
variant_found_identifier = JSONField(blank=True, null=True, validators=[ontologyValidator],
variant_found_identifier = JSONField(blank=True, null=True, validators=[ontology_validator],
help_text=rec_help(d.GENETIC_VARIANT_FOUND, "variant_found_identifier"))
variant_found_hgvs_name = ArrayField(models.CharField(max_length=200), blank=True, null=True,
help_text=rec_help(d.GENETIC_VARIANT_FOUND, "variant_found_hgvs_name"))
variant_found_description = models.CharField(max_length=200, blank=True,
help_text=rec_help(d.GENETIC_VARIANT_FOUND, "variant_found_description"))
# loinc value set https://loinc.org/48002-0/
genomic_source_class = JSONField(blank=True, null=True, validators=[ontologyValidator],
genomic_source_class = JSONField(blank=True, null=True, validators=[ontology_validator],
help_text=rec_help(d.GENETIC_VARIANT_FOUND, "genomic_source_class"))
extra_properties = JSONField(blank=True, null=True,
help_text=rec_help(d.GENETIC_VARIANT_FOUND, "extra_properties"))
Expand All @@ -94,10 +94,10 @@ class GenomicsReport(models.Model, IndexableMixin):
"""

id = models.CharField(primary_key=True, max_length=200, help_text=rec_help(d.GENOMICS_REPORT, "id"))
test_name = JSONField(validators=[ontologyValidator], help_text=rec_help(d.GENOMICS_REPORT, "test_name"))
test_name = JSONField(validators=[ontology_validator], help_text=rec_help(d.GENOMICS_REPORT, "test_name"))
performing_organization_name = models.CharField(max_length=200, blank=True,
help_text=rec_help(d.GENOMICS_REPORT, "performing_organization_name"))
specimen_type = JSONField(blank=True, null=True, validators=[ontologyValidator],
specimen_type = JSONField(blank=True, null=True, validators=[ontology_validator],
help_text=rec_help(d.GENOMICS_REPORT, "specimen_type"))
genetic_variant_tested = models.ManyToManyField(GeneticVariantTested, blank=True,
help_text=rec_help(d.GENOMICS_REPORT, "genetic_variant_tested"))
Expand Down Expand Up @@ -172,15 +172,15 @@ class CancerCondition(models.Model, IndexableMixin):
condition_type = models.CharField(choices=CANCER_CONDITION_TYPE, max_length=200,
help_text=rec_help(d.CANCER_CONDITION, "condition_type"))
# TODO add body_location_code validator array of json
body_location_code = JSONField(null=True, validators=[ontologyListValidator],
body_location_code = JSONField(null=True, validators=[ontology_list_validator],
help_text=rec_help(d.CANCER_CONDITION, 'body_location_code'))
clinical_status = JSONField(blank=True, null=True, validators=[ontologyValidator],
clinical_status = JSONField(blank=True, null=True, validators=[ontology_validator],
help_text=rec_help(d.CANCER_CONDITION, "clinical_status"))
condition_code = JSONField(validators=[ontologyValidator],
condition_code = JSONField(validators=[ontology_validator],
help_text=rec_help(d.CANCER_CONDITION, "condition_code"))
date_of_diagnosis = models.DateTimeField(blank=True, null=True,
help_text=rec_help(d.CANCER_CONDITION, "date_of_diagnosis"))
histology_morphology_behavior = JSONField(blank=True, null=True, validators=[ontologyValidator],
histology_morphology_behavior = JSONField(blank=True, null=True, validators=[ontology_validator],
help_text=rec_help(d.CANCER_CONDITION, "histology_morphology_behavior"))
extra_properties = JSONField(blank=True, null=True,
help_text=rec_help(d.CANCER_CONDITION, "extra_properties"))
Expand Down Expand Up @@ -243,12 +243,12 @@ class CancerRelatedProcedure(models.Model, IndexableMixin):
id = models.CharField(primary_key=True, max_length=200, help_text=rec_help(d.CANCER_RELATED_PROCEDURE, "id"))
procedure_type = models.CharField(choices=PROCEDURE_TYPES, max_length=200,
help_text=rec_help(d.CANCER_RELATED_PROCEDURE, "procedure_type"))
code = JSONField(validators=[ontologyValidator], help_text=rec_help(d.CANCER_RELATED_PROCEDURE, "code"))
code = JSONField(validators=[ontology_validator], help_text=rec_help(d.CANCER_RELATED_PROCEDURE, "code"))
occurence_time_or_period = JSONField(validators=[time_or_period_validator],
help_text=rec_help(d.CANCER_RELATED_PROCEDURE, "occurence_time_or_period"))
target_body_site = JSONField(null=True, validators=[ontologyListValidator],
target_body_site = JSONField(null=True, validators=[ontology_list_validator],
help_text=rec_help(d.CANCER_RELATED_PROCEDURE, 'target_body_site'))
treatment_intent = JSONField(blank=True, null=True, validators=[ontologyValidator],
treatment_intent = JSONField(blank=True, null=True, validators=[ontology_validator],
help_text=rec_help(d.CANCER_RELATED_PROCEDURE, "treatment_intent"))
extra_properties = JSONField(blank=True, null=True,
help_text=rec_help(d.CANCER_RELATED_PROCEDURE, "extra_properties"))
Expand All @@ -270,11 +270,11 @@ class MedicationStatement(models.Model, IndexableMixin):

id = models.CharField(primary_key=True, max_length=200, help_text=rec_help(d.MEDICATION_STATEMENT, "id"))
# list http://hl7.org/fhir/us/core/STU3.1/ValueSet-us-core-medication-codes.html
medication_code = JSONField(validators=[ontologyValidator],
medication_code = JSONField(validators=[ontology_validator],
help_text=rec_help(d.MEDICATION_STATEMENT, "medication_code"))
termination_reason = JSONField(null=True, validators=[ontologyListValidator],
termination_reason = JSONField(null=True, validators=[ontology_list_validator],
help_text=rec_help(d.MEDICATION_STATEMENT, 'termination_reason'))
treatment_intent = JSONField(blank=True, null=True, validators=[ontologyValidator],
treatment_intent = JSONField(blank=True, null=True, validators=[ontology_validator],
help_text=rec_help(d.MEDICATION_STATEMENT, "treatment_intent"))
start_date = models.DateTimeField(blank=True, null=True, help_text=rec_help(d.MEDICATION_STATEMENT, "start_date"))
end_date = models.DateTimeField(blank=True, null=True, help_text=rec_help(d.MEDICATION_STATEMENT, "end_date"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 2.2.10 on 2020-04-01 19:04

import chord_metadata_service.restapi.validators
import django.contrib.postgres.fields.jsonb
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('patients', '0005_auto_20200311_1610'),
]

operations = [
migrations.AlterField(
model_name='individual',
name='age',
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, help_text='The age or age range of the individual.', null=True, validators=[chord_metadata_service.restapi.validators.JsonSchemaValidator({'$id': 'chord_metadata_service:age_or_age_range_schema', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'An age object describing the age of the individual at the time of collection of biospecimens or phenotypic observations.', 'properties': {'age': {'anyOf': [{'description': 'An ISO8601 string represent age.', 'type': 'string'}, {'$id': 'chord_metadata_service:age_range_schema', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'An age range of a subject.', 'properties': {'end': {'properties': {'age': {'description': 'An ISO8601 string represent age.', 'type': 'string'}}, 'type': 'object'}, 'start': {'properties': {'age': {'description': 'An ISO8601 string represent age.', 'type': 'string'}}, 'type': 'object'}}, 'required': ['start', 'end'], 'title': 'Age schema', 'type': 'object'}]}}, 'title': 'Age schema', 'type': 'object'})]),
),
migrations.AlterField(
model_name='individual',
name='comorbid_condition',
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, help_text='One or more conditions that occur with primary condition.', null=True, validators=[chord_metadata_service.restapi.validators.JsonSchemaValidator({'$id': 'chord_metadata_service:comorbid_condition_schema', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'Comorbid condition schema.', 'properties': {'clinical_status': {'$id': 'chord_metadata_service:ontology_class_schema', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'todo', 'properties': {'id': {'description': 'CURIE style identifier.', 'type': 'string'}, 'label': {'description': 'Human-readable class name.', 'type': 'string'}}, 'required': ['id', 'label'], 'title': 'Ontology class schema', 'type': 'object'}, 'code': {'$id': 'chord_metadata_service:ontology_class_schema', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'todo', 'properties': {'id': {'description': 'CURIE style identifier.', 'type': 'string'}, 'label': {'description': 'Human-readable class name.', 'type': 'string'}}, 'required': ['id', 'label'], 'title': 'Ontology class schema', 'type': 'object'}}, 'required': [], 'title': 'Comorbid Condition schema', 'type': 'object'})]),
),
migrations.AlterField(
model_name='individual',
name='ecog_performance_status',
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, help_text='Value representing the Eastern Cooperative Oncology Group performance status.', null=True, validators=[chord_metadata_service.restapi.validators.JsonSchemaValidator({'$id': 'chord_metadata_service:ontology_class_schema', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'todo', 'properties': {'id': {'description': 'CURIE style identifier.', 'type': 'string'}, 'label': {'description': 'Human-readable class name.', 'type': 'string'}}, 'required': ['id', 'label'], 'title': 'Ontology class schema', 'type': 'object'})]),
),
migrations.AlterField(
model_name='individual',
name='karnofsky',
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, help_text='Value representing the Karnofsky Performance status.', null=True, validators=[chord_metadata_service.restapi.validators.JsonSchemaValidator({'$id': 'chord_metadata_service:ontology_class_schema', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'todo', 'properties': {'id': {'description': 'CURIE style identifier.', 'type': 'string'}, 'label': {'description': 'Human-readable class name.', 'type': 'string'}}, 'required': ['id', 'label'], 'title': 'Ontology class schema', 'type': 'object'})]),
),
migrations.AlterField(
model_name='individual',
name='taxonomy',
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, help_text='Ontology resource representing the species (e.g., NCBITaxon:9615).', null=True, validators=[chord_metadata_service.restapi.validators.JsonSchemaValidator({'$id': 'chord_metadata_service:ontology_class_schema', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'todo', 'properties': {'id': {'description': 'CURIE style identifier.', 'type': 'string'}, 'label': {'description': 'Human-readable class name.', 'type': 'string'}}, 'required': ['id', 'label'], 'title': 'Ontology class schema', 'type': 'object'})]),
),
]

0 comments on commit efe98b7

Please sign in to comment.