{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://doseweek-legal.wonyoungchoi.dev/import/draft-v1.schema.json",
  "title": "DoseWeek record extraction draft v1",
  "description": "Unreviewed transcription draft for DoseWeek Import records from another app. Not an encrypted backup. Passing this schema does not mean a row can be saved; every row is reviewed in the app before the selected rows are added.",
  "$comment": "Application resource limits: at most 10000 records, input JSON at most 10 MiB (10485760 bytes), nesting depth at most 32, and each decoded JSON string at most 16 KiB (16384 UTF-8 bytes). JSON Schema maxLength counts Unicode code points, not UTF-8 bytes; the importer must enforce the byte and nesting limits separately.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "format",
    "version",
    "reviewed_by_user",
    "records",
    "unreadable_sections"
  ],
  "properties": {
    "format": {
      "const": "doseweek.record_extraction_draft"
    },
    "version": {
      "const": 1
    },
    "reviewed_by_user": {
      "const": false
    },
    "records": {
      "type": "array",
      "maxItems": 10000,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "row_id",
          "record_type",
          "source_app",
          "source_record_id",
          "source_references",
          "date_text",
          "date_iso",
          "time_text",
          "time_24h",
          "time_zone",
          "utc_offset",
          "medication_name",
          "dose_value_text",
          "dose_unit",
          "site_text",
          "measurement_type",
          "measurement_value_text",
          "measurement_unit",
          "symptom_text",
          "severity_text",
          "note",
          "needs_review"
        ],
        "properties": {
          "source_app": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "source_record_id": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "date_text": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "date_iso": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
          },
          "time_text": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "time_24h": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9](\\.[0-9]+)?)?$"
          },
          "time_zone": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "utc_offset": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[+-]((0[0-9]|1[0-3]):[0-5][0-9]|14:00)$"
          },
          "medication_name": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "dose_value_text": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "dose_unit": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "site_text": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "measurement_type": {
            "enum": [
              "weight",
              "height",
              "waist",
              "body_fat",
              "lean_body_mass",
              null
            ]
          },
          "measurement_value_text": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "measurement_unit": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "symptom_text": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "severity_text": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "note": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "row_id": {
            "type": "string",
            "pattern": "^row-[0-9]{4,}$"
          },
          "record_type": {
            "enum": [
              "administration",
              "body_measurement",
              "symptom",
              "unclassified"
            ]
          },
          "source_references": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "document",
                "page",
                "row",
                "visible_text"
              ],
              "properties": {
                "document": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "minLength": 1
                },
                "page": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 1
                },
                "row": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "minLength": 1
                },
                "visible_text": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "minLength": 1
                }
              }
            }
          },
          "needs_review": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      }
    },
    "unreadable_sections": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      }
    }
  }
}
