{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://vitalscan4pacvs.com/biomarkers.schema.json",
  "title": "BiomarkerAtlas",
  "description": "Schema for VitalScan4PACVS peer-reviewed biomarker atlas data files",
  "type": "object",
  "required": ["slug", "id", "condition", "page", "categories", "filters", "markers"],
  "properties": {
    "slug": { "type": "string", "pattern": "^[a-z0-9-]+$" },
    "id": { "type": "string" },
    "condition": {
      "type": "object",
      "required": ["name", "shortName", "alternateNames"],
      "properties": {
        "name": { "type": "string" },
        "shortName": { "type": "string" },
        "alternateNames": { "type": "array", "items": { "type": "string" } }
      }
    },
    "page": {
      "type": "object",
      "required": ["title", "description", "canonical", "hero", "dateModified"],
      "properties": {
        "title": { "type": "string" },
        "breadcrumbName": { "type": "string" },
        "description": { "type": "string" },
        "keywords": { "type": "array", "items": { "type": "string" } },
        "canonical": { "type": "string", "format": "uri" },
        "hero": { "type": "string" },
        "dateModified": { "type": "string", "format": "date" }
      }
    },
    "faq": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["question", "answer"],
        "properties": {
          "question": { "type": "string" },
          "answer": { "type": "string" }
        }
      }
    },
    "categories": {
      "type": "object",
      "additionalProperties": { "type": "string" }
    },
    "filters": {
      "type": "array",
      "items": { "type": "string" }
    },
    "markers": {
      "type": "array",
      "items": { "$ref": "#/$defs/marker" }
    }
  },
  "$defs": {
    "marker": {
      "type": "object",
      "required": ["name", "direction", "category", "comparison", "reference"],
      "properties": {
        "name": { "type": "string" },
        "alternateName": { "type": "string" },
        "direction": { "type": "string", "enum": ["up", "down", "mixed"] },
        "category": { "type": "string" },
        "comparison": { "type": "string" },
        "symptoms": { "type": "string" },
        "testType": {
          "type": "string",
          "enum": ["BloodTest", "PathologyTest", "MedicalTest"]
        },
        "loinc": {
          "type": "string",
          "pattern": "^[0-9]+-[0-9]$",
          "description": "LOINC code from https://loinc.org"
        },
        "consumableProduct": {
          "type": "object",
          "description": "Tag when the biomarker is also available as an oral supplement or nutrient (generated by build-consumable-product-links.js)",
          "properties": {
            "consumable": { "type": "boolean", "const": true },
            "productName": { "type": "string" },
            "productType": { "type": "string" },
            "note": { "type": "string" }
          }
        },
        "commercialTest": {
          "type": "object",
          "description": "Commercial lab ordering links (generated by build-commercial-test-links.js)",
          "properties": {
            "availability": { "type": "string", "enum": ["commercial", "specialty", "reference"] },
            "testName": { "type": "string" },
            "vendors": {
              "type": "array",
              "items": {
                "type": "object",
                "required": ["vendor", "url"],
                "properties": {
                  "vendor": { "type": "string" },
                  "url": { "type": "string", "format": "uri" }
                }
              }
            },
            "note": { "type": "string" }
          }
        },
        "trialLinks": {
          "type": "array",
          "description": "Clinical trials using this biomarker as a primary or secondary outcome (generated by build-biomarker-trial-links.js)",
          "items": {
            "type": "object",
            "required": ["nct_id", "outcomeType", "outcomeMeasure", "link"],
            "properties": {
              "nct_id": { "type": "string" },
              "title": { "type": "string" },
              "status": { "type": "string" },
              "outcomeType": { "type": "string", "enum": ["primary", "secondary"] },
              "outcomeMeasure": { "type": "string" },
              "outcomeDescription": { "type": "string" },
              "link": { "type": "string", "format": "uri" },
              "matchScore": { "type": "number" }
            }
          }
        },
        "reference": {
          "type": "object",
          "required": ["citation", "doi"],
          "properties": {
            "citation": { "type": "string" },
            "doi": { "type": "string" }
          }
        }
      }
    }
  }
}