{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schema.humancellatlas.org/module/biomaterial/7.0.0/medical_history",
  "description": "Information about the medical history of a donor.",
  "additionalProperties": false,
  "title": "Medical history",
  "name": "medical_history",
  "type": "object",
  "properties": {
    "describedBy": {
      "description": "The URL reference to the schema.",
      "type": "string",
      "pattern": "^(http|https)://schema.(.*?)humancellatlas.org/module/biomaterial/(([0-9]{1,}.[0-9]{1,}.[0-9]{1,})|([a-zA-Z]*?))/medical_history"
    },
    "schema_version": {
      "description": "The version number of the schema in major.minor.patch format.",
      "type": "string",
      "pattern": "^[0-9]{1,}.[0-9]{1,}.[0-9]{1,}$",
      "example": "4.6.1"
    },
    "alcohol_history": {
      "description": "Estimated amount of alcohol consumed per day.",
      "type": "string",
      "user_friendly": "Alcohol history",
      "example": "3-6 alcohol units/day; 1 drink per day",
      "guidelines": "Enter the amount consumed per day using units such as alcohol units (10mL or 8g of alcohol) or drinks (14g of alcohol)."
    },
    "medication": {
      "description": "Medication(s) the individual was taking at time of biomaterial collection.",
      "type": "array",
      "items": {
        "$ref": "https://schema.humancellatlas.org/module/ontology/1.0.0/medication_ontology"
      },
      "user_friendly": "Medication"
    },
    "smoking_status": {
      "description": "Whether the individual is actively, was formerly or never consumed smoking tobacco products like cigarettes, cigars, pipe etc.",
      "type": "string",
      "enum": [
        "active",
        "former",
        "never"
      ],
      "user_friendly": "Smoking status",
      "example": "Should be one of: active, former, never."
    },
    "smoking_pack_years": {
      "description": "Estimated number of packs (20 cigarettes) smoked per day multiplied by the number of years the individual was smoking.",
      "type": "number",
      "user_friendly": "Smoking pack years",
      "minimum": 0,
      "example": 4.55
    },
    "years_since_smoking_cessation": {
      "description": "If smoking status is 'former', specify the number of years since smoking cessation.",
      "type": "integer",
      "user_friendly": "Years since smoking cessation",
      "minimum": 0,
      "example": 12
    },
    "nutritional_state": {
      "description": "Nutritional state of individual at time of biomaterial collection.",
      "type": "string",
      "enum": [
        "normal",
        "fasting",
        "feeding tube removed"
      ],
      "user_friendly": "Nutritional state",
      "example": "Should be one of: normal, fasting, or feeding tube removed."
    },
    "test_results": {
      "description": "Results from medical tests performed on the individual.",
      "type": "string",
      "user_friendly": "Test results",
      "example": "lipid panel shows normal level of LDL (124 mg/dL); HIV, HBV, HCV: Negative"
    },
    "treatment": {
      "description": "Treatments the individual has undergone prior to biomaterial collection.",
      "type": "string",
      "user_friendly": "Treatments",
      "example": "Patient treated with antibiotics for a urinary tract infection; Patient treated with chemotherapy (Epirubicin, cisplatin, capecitabine) to treat stomach cancer"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "smoking_status": {
            "const": "active"
          }
        }
      },
      "then": {
        "properties": {
          "years_since_smoking_cessation": {
            "maximum": 0
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "smoking_status": {
            "const": "never"
          }
        }
      },
      "then": {
        "properties": {
          "years_since_smoking_cessation": {
            "type": "null"
          },
          "smoking_pack_years": {
            "maximum": 0
          }
        }
      }
    }
  ]
}
