{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "contract": {
      "type": "string",
      "const": "PREPAIRE-TYPED-EVIDENCE@1.0.0"
    },
    "records": {
      "minItems": 1,
      "maxItems": 100,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "l0": {
            "type": "object",
            "properties": {
              "schema_version": {
                "type": "string",
                "enum": [
                  "PREPAIRE-KG-SCHEMA@1.0.0",
                  "PREPAIRE-KG-SCHEMA@1.1.0",
                  "PREPAIRE-KG-SCHEMA@1.2.0",
                  "PREPAIRE-KG-SCHEMA@1.4.0",
                  "PREPAIRE-KG-SCHEMA@1.7.0"
                ]
              },
              "identity": {
                "type": "object",
                "properties": {
                  "encounter_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "subject_token": {
                    "type": "string",
                    "minLength": 1
                  },
                  "specimen_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "run_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "instrument_serial": {
                    "type": "string",
                    "minLength": 1
                  },
                  "product": {
                    "type": "string",
                    "enum": [
                      "passport",
                      "check",
                      "axiom"
                    ]
                  },
                  "aliquot_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "operator_token": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "encounter_id",
                  "subject_token",
                  "specimen_id",
                  "run_id",
                  "instrument_serial",
                  "product"
                ],
                "additionalProperties": false
              },
              "method": {
                "type": "object",
                "properties": {
                  "assay_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "assay_version": {
                    "type": "string",
                    "minLength": 1
                  },
                  "adapter_digest": {
                    "type": "string",
                    "pattern": "^sha256:[a-f0-9]{64}$"
                  },
                  "firmware": {
                    "type": "string",
                    "minLength": 1
                  },
                  "workstation_software": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "assay_id",
                  "assay_version",
                  "adapter_digest"
                ],
                "additionalProperties": false
              },
              "software": {
                "type": "object",
                "properties": {
                  "canonical": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "minLength": 1
                      },
                      "version": {
                        "type": "string",
                        "minLength": 1
                      },
                      "digest": {
                        "type": "string",
                        "pattern": "^sha256:[a-f0-9]{64}$"
                      },
                      "role": {
                        "type": "string",
                        "enum": [
                          "canonical",
                          "comparator"
                        ]
                      },
                      "arm64": {
                        "type": "boolean"
                      }
                    },
                    "required": [
                      "name",
                      "version",
                      "digest",
                      "role"
                    ],
                    "additionalProperties": false
                  },
                  "comparator": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "minLength": 1
                      },
                      "version": {
                        "type": "string",
                        "minLength": 1
                      },
                      "digest": {
                        "type": "string",
                        "pattern": "^sha256:[a-f0-9]{64}$"
                      },
                      "role": {
                        "type": "string",
                        "enum": [
                          "canonical",
                          "comparator"
                        ]
                      },
                      "arm64": {
                        "type": "boolean"
                      }
                    },
                    "required": [
                      "name",
                      "version",
                      "digest",
                      "role"
                    ],
                    "additionalProperties": false
                  },
                  "reference_releases": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "minLength": 1
                        },
                        "version": {
                          "type": "string",
                          "minLength": 1
                        },
                        "hash": {
                          "type": "string",
                          "pattern": "^sha256:[a-f0-9]{64}$"
                        }
                      },
                      "required": [
                        "name",
                        "version",
                        "hash"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "parameter_set_hash": {
                    "type": "string",
                    "pattern": "^sha256:[a-f0-9]{64}$"
                  }
                },
                "required": [
                  "canonical",
                  "reference_releases",
                  "parameter_set_hash"
                ],
                "additionalProperties": false
              },
              "quality": {
                "type": "object",
                "properties": {
                  "qc_state": {
                    "type": "string",
                    "enum": [
                      "pass",
                      "warn",
                      "fail",
                      "quarantine"
                    ]
                  },
                  "caller_agreement": {
                    "type": "string",
                    "enum": [
                      "agree",
                      "disagree",
                      "single",
                      "not_applicable"
                    ]
                  },
                  "control_results": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {}
                  },
                  "coverage": {
                    "type": "number",
                    "minimum": 0
                  },
                  "completeness": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "interference_flags": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1
                    }
                  },
                  "confidence": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  }
                },
                "required": [
                  "qc_state",
                  "caller_agreement"
                ],
                "additionalProperties": false
              },
              "provenance": {
                "type": "object",
                "properties": {
                  "input_sha256": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "pattern": "^[a-f0-9]{64}$"
                    }
                  },
                  "output_sha256": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "pattern": "^[a-f0-9]{64}$"
                    }
                  },
                  "native_bundle_uri": {
                    "type": "string",
                    "minLength": 1
                  },
                  "started_at": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                  },
                  "ended_at": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                  },
                  "vendor_comparator": {
                    "type": "object",
                    "properties": {
                      "present": {
                        "type": "boolean"
                      },
                      "digest": {
                        "type": "string",
                        "minLength": 1
                      },
                      "delta": {
                        "type": "object",
                        "propertyNames": {
                          "type": "string"
                        },
                        "additionalProperties": {}
                      }
                    },
                    "required": [
                      "present"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "input_sha256",
                  "output_sha256",
                  "native_bundle_uri",
                  "started_at",
                  "ended_at"
                ],
                "additionalProperties": false
              },
              "semantics": {
                "type": "object",
                "properties": {
                  "binds_to": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "namespace": {
                          "type": "string",
                          "minLength": 1
                        },
                        "id": {
                          "type": "string",
                          "minLength": 1
                        },
                        "node_label": {
                          "type": "string",
                          "minLength": 1
                        },
                        "unit_ucum": {
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "required": [
                        "namespace",
                        "id",
                        "node_label"
                      ],
                      "additionalProperties": false
                    }
                  }
                },
                "required": [
                  "binds_to"
                ],
                "additionalProperties": false
              },
              "release": {
                "type": "object",
                "properties": {
                  "decision": {
                    "type": "string",
                    "enum": [
                      "hold",
                      "quarantine",
                      "release",
                      "blocked_critical"
                    ]
                  },
                  "gates": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "minLength": 1
                        },
                        "passed": {
                          "type": "boolean"
                        },
                        "detail": {
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "required": [
                        "name",
                        "passed"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "reviewer_token": {
                    "type": "string",
                    "minLength": 1
                  },
                  "signed_at": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                  }
                },
                "required": [
                  "decision",
                  "gates"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "schema_version",
              "identity",
              "method",
              "software",
              "quality",
              "provenance",
              "semantics",
              "release"
            ],
            "additionalProperties": false
          },
          "facts": {
            "minItems": 1,
            "maxItems": 500000,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "schema_version": {
                  "type": "string",
                  "enum": [
                    "PREPAIRE-KG-SCHEMA@1.0.0",
                    "PREPAIRE-KG-SCHEMA@1.1.0",
                    "PREPAIRE-KG-SCHEMA@1.2.0",
                    "PREPAIRE-KG-SCHEMA@1.4.0",
                    "PREPAIRE-KG-SCHEMA@1.7.0"
                  ]
                },
                "fact_id": {
                  "type": "string",
                  "minLength": 1
                },
                "l0_run_id": {
                  "type": "string",
                  "minLength": 1
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "observation",
                    "genomic_call",
                    "diplotype_call",
                    "taxon_abundance",
                    "function_abundance",
                    "clock_age",
                    "polygenic_score",
                    "index_value"
                  ]
                },
                "subject_token": {
                  "type": "string",
                  "minLength": 1
                },
                "encounter_id": {
                  "type": "string",
                  "minLength": 1
                },
                "specimen_id": {
                  "type": "string",
                  "minLength": 1
                },
                "product": {
                  "type": "string",
                  "enum": [
                    "passport",
                    "check",
                    "axiom"
                  ]
                },
                "binds_to": {
                  "type": "object",
                  "properties": {
                    "namespace": {
                      "type": "string",
                      "minLength": 1
                    },
                    "id": {
                      "type": "string",
                      "minLength": 1
                    },
                    "node_label": {
                      "type": "string",
                      "minLength": 1
                    }
                  },
                  "required": [
                    "namespace",
                    "id",
                    "node_label"
                  ],
                  "additionalProperties": false
                },
                "value": {
                  "type": [
                    "number",
                    "string",
                    "null"
                  ]
                },
                "unit_ucum": {
                  "anyOf": [
                    {
                      "type": "string",
                      "minLength": 1
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "payload": {
                  "type": "object",
                  "propertyNames": {
                    "type": "string"
                  },
                  "additionalProperties": {}
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "active",
                    "provisional",
                    "quarantine",
                    "blocked_critical",
                    "withheld"
                  ]
                },
                "confidence": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                }
              },
              "required": [
                "schema_version",
                "fact_id",
                "l0_run_id",
                "kind",
                "subject_token",
                "encounter_id",
                "specimen_id",
                "product",
                "binds_to",
                "value",
                "unit_ucum",
                "payload",
                "status"
              ],
              "additionalProperties": false
            }
          },
          "context": {
            "type": "object",
            "properties": {
              "contract": {
                "type": "string",
                "const": "PREPAIRE-BIOLOGICAL-CONTEXT@1.0.0"
              },
              "nodeId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500
              },
              "jurisdiction": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500
              },
              "collectedAt": {
                "type": "string",
                "format": "date-time",
                "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
              },
              "specimenType": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500
              },
              "modality": {
                "type": "string",
                "enum": [
                  "genomics",
                  "epigenomics",
                  "proteomics",
                  "metabolomics",
                  "microbiomics",
                  "clinical_chemistry",
                  "hematology",
                  "urinalysis",
                  "imaging",
                  "wearable",
                  "clinical_history",
                  "experimental_biology"
                ]
              },
              "source": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "instrument_export",
                      "historical_report",
                      "clinical_record",
                      "wearable_export",
                      "experimental_result",
                      "self_report"
                    ]
                  },
                  "artifactSha256": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "anchor": {
                    "type": "object",
                    "properties": {
                      "page": {
                        "type": "integer",
                        "exclusiveMinimum": 0,
                        "maximum": 9007199254740991
                      },
                      "recordId": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 500
                      }
                    },
                    "additionalProperties": false
                  }
                },
                "required": [
                  "type",
                  "artifactSha256",
                  "anchor"
                ],
                "additionalProperties": false
              },
              "evidenceClass": {
                "type": "string",
                "enum": [
                  "measured",
                  "derived_measurement",
                  "model_inference",
                  "self_report"
                ]
              },
              "method": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  },
                  "version": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  },
                  "platform": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  }
                },
                "required": [
                  "id",
                  "version",
                  "platform"
                ],
                "additionalProperties": false
              },
              "preanalytics": {
                "type": "object",
                "properties": {
                  "fasting": {
                    "type": "string",
                    "enum": [
                      "fasted",
                      "not_fasted",
                      "not_applicable",
                      "unknown"
                    ]
                  },
                  "medicationContext": {
                    "type": "string",
                    "enum": [
                      "recorded",
                      "not_applicable",
                      "unknown"
                    ]
                  },
                  "contextRecordSha256": {
                    "anyOf": [
                      {
                        "type": "string",
                        "pattern": "^[a-f0-9]{64}$"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "reagentLot": {
                    "anyOf": [
                      {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 500
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "calibratorLot": {
                    "anyOf": [
                      {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 500
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "confounders": {
                    "maxItems": 100,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 500
                    }
                  }
                },
                "required": [
                  "fasting",
                  "medicationContext",
                  "contextRecordSha256",
                  "reagentLot",
                  "calibratorLot",
                  "confounders"
                ],
                "additionalProperties": false
              },
              "permittedUses": {
                "minItems": 1,
                "maxItems": 5,
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "history",
                    "trend",
                    "current_state",
                    "personal_baseline",
                    "research"
                  ]
                }
              },
              "currentStateUntil": {
                "anyOf": [
                  {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "policy": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  },
                  "version": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  },
                  "sha256": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  }
                },
                "required": [
                  "id",
                  "version",
                  "sha256"
                ],
                "additionalProperties": false
              },
              "inference": {
                "type": "object",
                "properties": {
                  "modelDigest": {
                    "type": "string",
                    "pattern": "^sha256:[a-f0-9]{64}$"
                  },
                  "weightsSha256": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "validationEvidenceSha256": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "inputFactIds": {
                    "minItems": 1,
                    "maxItems": 10000,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 500
                    }
                  },
                  "uncertainty": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  },
                  "limitations": {
                    "minItems": 1,
                    "maxItems": 100,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 500
                    }
                  }
                },
                "required": [
                  "modelDigest",
                  "weightsSha256",
                  "validationEvidenceSha256",
                  "inputFactIds",
                  "uncertainty",
                  "limitations"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "contract",
              "nodeId",
              "jurisdiction",
              "collectedAt",
              "specimenType",
              "modality",
              "source",
              "evidenceClass",
              "method",
              "preanalytics",
              "permittedUses",
              "currentStateUntil",
              "policy"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "l0",
          "facts"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "contract",
    "records"
  ],
  "additionalProperties": false,
  "x-runtimeValidation": "Structural schema only. Cross-record identity, provenance, semantic binding and release-policy checks also run in the VERA service."
}
