{
  "$id": "https://github.com/mrueda",
  "additionalProperties": false,
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "description": "JSON Schema for Convert-Pheno mapping file",
  "type": "object",
  "required": [
    "project",
    "id",
    "sex"
  ],
  "properties": {
    "project": {
      "type": "object",
      "required": [
        "id",
        "source",
        "ontology",
        "version",
        "baselineFieldsToPropagate"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/stringField"
        },
        "source": {
          "type": "string",
          "enum": [
            "redcap",
            "cdisc-odm",
            "csv"
          ]
        },
        "ontology": {
          "$ref": "#/$defs/objectField/properties/ontology"
        },
        "version": {
          "$ref": "#/$defs/stringField"
        },
        "description": {
          "$ref": "#/$defs/stringField"
        },
        "baselineFieldsToPropagate": {
          "$ref": "#/$defs/arrayField"
        }
      }
    },
    "diseases": {
      "$ref": "#/$defs/objectField"
    },
    "ethnicity": {
      "$ref": "#/$defs/objectField"
    },
    "exposures": {
      "$ref": "#/$defs/objectField"
    },
    "geographicOrigin": {
      "$ref": "#/$defs/stringField"
    },
    "id": {
      "$ref": "#/$defs/objectField"
    },
    "info": {
      "$ref": "#/$defs/objectField"
    },
    "interventionsOrProcedures": {
      "$ref": "#/$defs/objectField"
    },
    "karyotypicSex": {
      "$ref": "#/$defs/stringField"
    },
    "measures": {
      "$ref": "#/$defs/objectField"
    },
    "pedigrees": {
      "$ref": "#/$defs/objectField"
    },
    "phenotypicFeatures": {
      "$ref": "#/$defs/objectField"
    },
    "sex": {
      "$ref": "#/$defs/objectField"
    },
    "treatments": {
      "$ref": "#/$defs/objectField"
    }
  },
  "$defs": {
    "objectField": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "fields": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "$ref": "#/$defs/arrayField"
            }
          ]
        },
        "dictionary": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "selector": {
          "type": "object",
          "additionalProperties": {
            "type": "object"
          }
        },
        "routeOfAdministration": {
          "type": "object",
          "additionalProperties": {
            "type": "string",
            "enum": [
              "oral",
              "rectal",
              "intravenous",
              "intramuscular",
              "subcutaneous",
              "inhalation",
              "topical",
              "transdermal",
              "sublingual",
              "buccal",
              "intranasal",
              "ocular",
              "otic",
              "vaginal",
              "intrathecal",
              "epidural"
            ]
          }
        },
        "ontology": {
          "type": "string",
          "enum": [
            "ncit",
            "ohdsi",
            "cdisc",
            "omim",
            "hpo"
          ]
        },
        "mapping": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "terminology": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^\\w[^:]+:.+$"
              },
              "label": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "label"
            ],
            "additionalProperties": false
          }
        },
        "assignTermIdFromHeader": {
          "$ref": "#/$defs/arrayField"
        },
        "drugDose": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "duration": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "drugUnit": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "durationUnit": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "bodySite": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "visitId": {
          "type": "string"
        },
        "dateOfProcedure": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "ageOfOnset": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "familyHistory": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "unit": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "label": {
                "type": "string"
              },
              "referenceRange": {
                "type": "object",
                "properties": {
                  "low": {
                    "type": "number"
                  },
                  "high": {
                    "type": "number"
                  }
                },
                "required": [
                  "low",
                  "high"
                ]
              },
              "procedureCodeLabel": {
                "$ref": "#/$defs/stringField"
              }
            },
            "required": [
              "label",
              "referenceRange"
            ]
          }
        }
      },
      "required": [
        "fields"
      ]
    },
    "stringField": {
      "type": "string"
    },
    "arrayField": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  }
}