{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "AfricanHealthOS_Patient_FHIR_Profile",
  "description": "HL7 FHIR R4-aligned pan-African interoperable patient identity profile with cryptographic privacy preservation.",
  "type": "object",
  "required": [
    "resourceType",
    "id",
    "sovereigntyDomain",
    "identifier",
    "active",
    "telecomOfflineBackup",
    "consentMatrix"
  ],
  "properties": {
    "resourceType": {
      "type": "string",
      "const": "Patient"
    },
    "id": {
      "type": "string",
      "pattern": "^AFR-PAT-[A-Z]{3}-[0-9A-F]{8}$",
      "description": "Decentralized Sovereign Universal Patient Identifier (e.g., AFR-PAT-TGO-A49F81BC)"
    },
    "sovereigntyDomain": {
      "type": "object",
      "required": ["countryIso3", "regionalEconomicCommunity", "dataProtectionAuthority"],
      "properties": {
        "countryIso3": {
          "type": "string",
          "enum": ["TGO", "GHA", "BEN", "CIV", "SEN", "NGA", "RWA", "KEN", "ZAF", "MAR", "COD"]
        },
        "regionalEconomicCommunity": {
          "type": "string",
          "enum": ["CEDEAO/ECOWAS", "EAC", "SADC", "ECCAS", "UMA"]
        },
        "dataProtectionAuthority": {
          "type": "string"
        }
      }
    },
    "identifier": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["system", "value"],
        "properties": {
          "system": {
            "type": "string",
            "format": "uri"
          },
          "value": {
            "type": "string"
          }
        }
      }
    },
    "active": {
      "type": "boolean"
    },
    "emergencyClinicalFlags": {
      "type": "object",
      "properties": {
        "bloodGroup": {
          "type": "string",
          "enum": ["A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-", "UNKNOWN"]
        },
        "criticalAllergies": {
          "type": "array",
          "items": { "type": "string" }
        },
        "chronicConditions": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    },
    "consentMatrix": {
      "type": "object",
      "required": ["crossBorderEmergencyAccess", "anonymizedResearchUse", "consentTimestampUtc"],
      "properties": {
        "crossBorderEmergencyAccess": { "type": "boolean" },
        "anonymizedResearchUse": { "type": "boolean" },
        "consentTimestampUtc": { "type": "string", "format": "date-time" }
      }
    }
  }
}
