{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://solvinghealth.com/schemas/person-file-v1.json",
  "title": "The person's file, v1",
  "description": "The record a person keeps on their own device: the FHIR R4 Bundle exported from https://comfortcard.org/family (format comfortcard-family-file, version 1). It is the person's, not ours: no server in the network stores it, and a tool built on it reads the copy the person opens and never uploads it. Read it with https://solvinghealth.com/sdk/kit.mjs (readFamilyFile), add a result to it with addToFileLink, and see a sample at https://solvinghealth.com/sdk/sample-family-file.json (invented person, invented results).",
  "x-rules": [
    "The file stays with the person. Never send it, a result from it or any part of either to a server, an analytics tool or a model you do not run on the device.",
    "A result in it (an Observation tagged carried-in) is a self-check the person brought from a named site. Show it as a self-check, never as a diagnosis or a finding.",
    "A signature comes only from a licensed physician who signed that case, through https://clinicalswipe.com/build. Nothing else in the file is signed, approved or attested.",
    "Attached papers keep their bytes in the file. A tool that does not need them does not open them."
  ],
  "x-reference-implementation": "https://comfortcard.org/family-core.js (buildBundle, restoreFromBundle)",
  "x-results-contract": "https://solvinghealth.com/schemas/pollen-kinds-v1.json",
  "type": "object",
  "required": ["resourceType", "type", "entry"],
  "properties": {
    "resourceType": { "const": "Bundle" },
    "type": { "const": "collection" },
    "timestamp": { "type": "string", "description": "When the person exported it (ISO 8601)." },
    "meta": { "type": "object", "description": "Tagged https://comfortcard.org/fhir/tag | comfortcard-family-file." },
    "identifier": { "type": "object", "description": "A random id for this export (system https://comfortcard.org/family-file). Not the person's identifier." },
    "entry": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["resource"],
        "properties": {
          "fullUrl": { "type": "string" },
          "resource": {
            "type": "object",
            "required": ["resourceType"],
            "properties": { "resourceType": { "enum": ["Patient", "Observation", "CarePlan", "DocumentReference", "Coverage", "Binary"] } }
          }
        }
      }
    }
  },
  "x-entries": {
    "Patient": "One. name[0].text is whatever the family typed for the person being cared for (often a first name or a role). No other identifier.",
    "Observation (meta.tag carried-in)": "One per result carried in from a sibling site. code.coding[system https://comfortcard.org/fhir/CodeSystem/carried-in].code is the result kind from pollen-kinds-v1; method.text names the site; note says it is a self-check and not a diagnosis.",
    "Observation (meta.tag family-hours)": "Hours of care a family member gave, as the family recorded it.",
    "CarePlan": "The caregiver plan from the ClinicalSwipe navigator, when the family kept one.",
    "DocumentReference": "A paper the family keeps (a receipt, a letter, care wishes, a family decision). Attachments may carry the file bytes.",
    "Coverage": "An HSA, FSA or HRA the family noted.",
    "Binary (meta.tag comfortcard-family-file)": "The exact state of the file as base64 JSON, so it restores itself: { format, version, exported, carried[{kind, from, made, fields}], hours[], documents[], decisions[], plan }. kit.readFamilyFile reads results from here first."
  }
}
