{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://w3id.org/materica/schema/0.1/read_result.json",
  "$comment": "Hand-edited. Each member is typed from the writer schema's $defs and the vocabulary; a case's expected answer takes the same shapes (case.json). A result_ definition named like a writer one is that definition as a result returns it: closed alike, but without the patterns of members a read checks only as strings (an anatomical site's UBERON identifier, a record check's; a derivation input's pinned record, provenance.md section 5), so that a correct result validates. tests/spec_sync/test_schemas.py holds each to the writer's.",
  "title": "ReadResult",
  "description": "read_side_contract.md section 2.",
  "type": "object",
  "required": ["status", "reasons"],
  "properties": {
    "status": {"$ref": "#/$defs/read_status"},
    "reasons": {"type": "array", "items": {"$ref": "#/$defs/reason"}},
    "value": {"$ref": "#/$defs/result_value"},
    "alternative_values": {"type": "array", "items": {"$ref": "#/$defs/alternative_value"}},
    "unit": {"$ref": "record.writer.json#/$defs/unit"},
    "conditions": {"type": "array", "items": {"$ref": "#/$defs/condition_entry"}},
    "specimen": {"$ref": "#/$defs/result_specimen"},
    "statistics": {"$ref": "record.writer.json#/$defs/field_statistics"},
    "provenance": {"$ref": "#/$defs/result_provenance"},
    "labels": {"type": "array", "items": {"$ref": "#/$defs/returned_label"}},
    "assumption": {"$ref": "#/$defs/assumption"},
    "table": {"$ref": "record.writer.json#/$defs/table"}
  },
  "additionalProperties": false,
  "$defs": {
    "read_status": {"enum": ["met", "not_met", "unknown"]},
    "reason": {
      "description": "read_side_contract.md section 2; a reason is identified by its code, condition and alternative, and detail is for people.",
      "type": "object",
      "required": ["code"],
      "properties": {
        "code": {"$ref": "vocabulary/reasons.json#/$defs/reason_code"},
        "condition": {"type": "string"},
        "alternative": {"description": "The index among the stored alternatives of the one the reason was found reading.", "type": "integer", "minimum": 0},
        "detail": {"type": "string"}
      },
      "additionalProperties": false
    },
    "result_value": {
      "description": "What a read gives (read_side_contract.md section 6), or in an alternative_values entry a form's member as stored; a content hash or a listing for the operations content_hash and list_records (README.md, \"Operations\").",
      "anyOf": [
        {"type": "number"},
        {"$ref": "record.writer.json#/$defs/interval"},
        {"$ref": "record.writer.json#/$defs/composition"},
        {"type": "array", "items": {"anyOf": [{"$ref": "#/$defs/result_evidence_entry"}, {"$ref": "#/$defs/result_withheld_evidence_entry"}]}},
        {"$ref": "record.writer.json#/$defs/table"},
        {"$ref": "record.writer.json#/$defs/placeholder"},
        {"$ref": "record.writer.json#/$defs/content_hash"},
        {"type": "array", "items": {"$ref": "#/$defs/listed_record"}}
      ]
    },
    "listed_record": {
      "description": "A record list_records gives, by its id and version (README.md, \"Operations\").",
      "type": "object",
      "required": ["id", "version"],
      "properties": {
        "id": {"$ref": "record.writer.json#/$defs/record_id"},
        "version": {"$ref": "record.writer.json#/$defs/version"}
      },
      "additionalProperties": false
    },
    "alternative_value": {
      "description": "An alternative that stays under no_pick (read_side_contract.md section 2): its index among the stored alternatives of the field read, and its members as a read of it alone gives them, its unit among them.",
      "type": "object",
      "required": ["alternative", "value", "unit", "conditions", "specimen", "provenance", "labels"],
      "properties": {
        "alternative": {"type": "integer", "minimum": 0},
        "value": {"$ref": "#/$defs/result_value"},
        "unit": {"$ref": "record.writer.json#/$defs/unit"},
        "conditions": {"type": "array", "items": {"$ref": "#/$defs/condition_entry"}},
        "specimen": {"$ref": "#/$defs/result_specimen"},
        "statistics": {"$ref": "record.writer.json#/$defs/field_statistics"},
        "provenance": {"$ref": "#/$defs/result_provenance"},
        "labels": {"type": "array", "items": {"$ref": "#/$defs/returned_label"}}
      },
      "additionalProperties": false
    },
    "condition_entry": {
      "description": "One condition checked (read_side_contract.md section 2 item 6): record is the record's entry as read, its status object, or the value an implied condition supplies with basis implied; operating is the request's operating condition.",
      "type": "object",
      "required": ["name", "status"],
      "properties": {
        "name": {"type": "string"},
        "status": {"$ref": "#/$defs/read_status"},
        "record": {"anyOf": [{"$ref": "record.writer.json#/$defs/numeric_condition"}, {"$ref": "record.writer.json#/$defs/condition_density_kind"}, {"$ref": "record.writer.json#/$defs/condition_specimen_shape"}, {"$ref": "record.writer.json#/$defs/condition_measurement_geometry"}, {"$ref": "record.writer.json#/$defs/condition_test_method"}, {"$ref": "record.writer.json#/$defs/status_object"}, {"$ref": "#/$defs/implied_value"}]},
        "operating": {"$ref": "read_request.json#/$defs/operating_condition"}
      },
      "additionalProperties": false
    },
    "implied_value": {
      "description": "The value an implied condition supplies, as the request gives it, with basis implied (read_side_contract.md section 2 item 6; declarations.md section 4.1).",
      "anyOf": [{"$ref": "#/$defs/implied_numeric_value"}, {"$ref": "#/$defs/implied_token_value"}]
    },
    "implied_numeric_value": {
      "description": "A value or a range, with its unit.",
      "type": "object",
      "required": ["unit", "basis"],
      "properties": {
        "value": {"type": "number"},
        "range": {"$ref": "record.writer.json#/$defs/range"},
        "unit": {"type": "string"},
        "basis": {"const": "implied"}
      },
      "if": {"required": ["value"]},
      "then": {"not": {"required": ["range"]}},
      "else": {"required": ["range"]},
      "additionalProperties": false
    },
    "implied_token_value": {
      "description": "A token.",
      "type": "object",
      "required": ["token", "basis"],
      "properties": {
        "token": {"type": "string"},
        "basis": {"const": "implied"}
      },
      "additionalProperties": false
    },
    "result_provenance": {
      "description": "The provenance a read returns (read_side_contract.md section 2): the origin token, the review as provenance.md section 2 item 6 reads it, the source's key, and a derived value's derivation.",
      "type": "object",
      "required": ["origin", "review"],
      "properties": {
        "origin": {"$ref": "vocabulary/provenance.json#/$defs/origin"},
        "review": {"anyOf": [{"$ref": "#/$defs/result_review"}, {"$ref": "record.writer.json#/$defs/status_not_checked"}]},
        "source": {"type": "string"},
        "derivation": {"$ref": "#/$defs/result_derivation"}
      },
      "additionalProperties": false
    },
    "result_evidence_entry": {
      "description": "A test report as a read returns it (record_format.md section 4.3 item 2): the writer's evidence_entry, its provenance as a report returns it.",
      "type": "object",
      "required": ["endpoint", "standard", "contact_category", "contact_duration", "material_form", "processing", "reported_result", "provenance"],
      "properties": {
        "endpoint": {"$ref": "record.writer.json#/$defs/report_text"},
        "standard": {"anyOf": [{"$ref": "record.writer.json#/$defs/standard"}, {"$ref": "record.writer.json#/$defs/status_not_withheld"}]},
        "contact_category": {"$ref": "record.writer.json#/$defs/report_text"},
        "contact_duration": {"$ref": "record.writer.json#/$defs/report_text"},
        "material_form": {"$ref": "record.writer.json#/$defs/report_text"},
        "processing": {"$ref": "record.writer.json#/$defs/report_text"},
        "reported_result": {"$ref": "record.writer.json#/$defs/report_text"},
        "provenance": {"$ref": "#/$defs/result_entry_provenance"}
      },
      "additionalProperties": false
    },
    "result_withheld_evidence_entry": {
      "description": "A withheld test report as a read returns it: the writer's withheld_evidence_entry, its provenance as a report returns it, whose recipe a read does not check (record_format.md section 4.3 item 2).",
      "type": "object",
      "required": ["endpoint", "standard", "contact_category", "contact_duration", "material_form", "processing", "reported_result", "provenance"],
      "properties": {
        "endpoint": {"$ref": "record.writer.json#/$defs/status_withheld"},
        "standard": {"$ref": "record.writer.json#/$defs/status_withheld"},
        "contact_category": {"$ref": "record.writer.json#/$defs/status_withheld"},
        "contact_duration": {"$ref": "record.writer.json#/$defs/status_withheld"},
        "material_form": {"$ref": "record.writer.json#/$defs/status_withheld"},
        "processing": {"$ref": "record.writer.json#/$defs/status_withheld"},
        "reported_result": {"$ref": "record.writer.json#/$defs/status_withheld"},
        "provenance": {"$ref": "#/$defs/result_entry_provenance"}
      },
      "additionalProperties": false
    },
    "result_entry_provenance": {
      "description": "A test report's provenance as a read returns it, whole (record_format.md section 4.3 item 2): checked as a field's, its origin, a source's key and a derived value's derivation; its review as provenance.md section 2 item 6 reads every review; and every member the writer marks x-materica-write-only, which that check leaves unchecked, as found.",
      "type": "object",
      "required": ["origin", "review"],
      "properties": {
        "origin": {"$ref": "vocabulary/provenance.json#/$defs/origin"},
        "source": {"$ref": "#/$defs/result_entry_source"},
        "extraction": {"$ref": "record.writer.json#/$defs/json_value"},
        "evidence": {"$ref": "record.writer.json#/$defs/json_value"},
        "assistance": {"$ref": "record.writer.json#/$defs/json_value"},
        "review": {"anyOf": [{"$ref": "#/$defs/result_review"}, {"$ref": "record.writer.json#/$defs/status_not_checked"}]},
        "derivation": {"$ref": "record.writer.json#/$defs/json_value"},
        "formulation": {"$ref": "record.writer.json#/$defs/json_value"},
        "search": {"$ref": "record.writer.json#/$defs/json_value"},
        "import": {"$ref": "record.writer.json#/$defs/json_value"},
        "per_parameter": {"$ref": "record.writer.json#/$defs/json_value"},
        "recipe": {"$ref": "record.writer.json#/$defs/json_value"}
      },
      "additionalProperties": false,
      "allOf": [
        {"if": {"required": ["origin"], "properties": {"origin": {"const": "measured_by_source"}}}, "then": {"required": ["source"]}},
        {"if": {"required": ["origin"], "properties": {"origin": {"const": "derived"}}}, "then": {"required": ["derivation"], "properties": {"derivation": {"$ref": "#/$defs/result_derivation"}}}}
      ]
    },
    "result_entry_source": {
      "description": "A test report's source as a read returns it: its key, which a read checks, and its document and locator, the record checks', as found (provenance.md section 2 item 6).",
      "type": "object",
      "required": ["key"],
      "properties": {
        "key": {"type": "string"},
        "document": {"$ref": "record.writer.json#/$defs/json_value"},
        "locator": {"$ref": "record.writer.json#/$defs/json_value"}
      },
      "additionalProperties": false
    },
    "result_specimen": {
      "description": "Specimen facts, by name (provenance.md section 6.2); a field's override its section's, fact by fact. Where a fact's row fixes its unit, step 9 compares the unit with it and the writer binds the unit to it: a fact whose unit the source does not give is written as a status object.",
      "type": "object",
      "allOf": [{"$ref": "vocabulary/specimen_facts.json#/$defs/units"}],
      "properties": {
        "species": {"anyOf": [{"$ref": "record.writer.json#/$defs/species"}, {"$ref": "record.writer.json#/$defs/status_object"}]},
        "anatomical_site": {"anyOf": [{"$ref": "#/$defs/result_anatomical_site"}, {"$ref": "record.writer.json#/$defs/status_object"}]},
        "tissue_state": {"anyOf": [{"$ref": "record.writer.json#/$defs/tissue_state"}, {"$ref": "record.writer.json#/$defs/status_object"}]},
        "disease_and_treatment_state": {"anyOf": [{"$ref": "record.writer.json#/$defs/disease_and_treatment_state"}, {"$ref": "record.writer.json#/$defs/status_object"}]},
        "preparation": {"anyOf": [{"$ref": "record.writer.json#/$defs/preparation"}, {"$ref": "record.writer.json#/$defs/status_object"}]},
        "preservation": {"anyOf": [{"$ref": "record.writer.json#/$defs/preservation"}, {"$ref": "record.writer.json#/$defs/status_object"}]},
        "post_mortem_interval": {"anyOf": [{"$ref": "record.writer.json#/$defs/post_mortem_interval"}, {"$ref": "record.writer.json#/$defs/status_object"}]},
        "donor_age": {"anyOf": [{"$ref": "record.writer.json#/$defs/donor_age"}, {"$ref": "record.writer.json#/$defs/status_object"}]},
        "mimics": {"anyOf": [{"$ref": "record.writer.json#/$defs/mimics"}, {"$ref": "record.writer.json#/$defs/status_object"}]},
        "supply_form": {"anyOf": [{"$ref": "record.writer.json#/$defs/supply_form"}, {"$ref": "record.writer.json#/$defs/status_object"}]},
        "lot": {"anyOf": [{"$ref": "record.writer.json#/$defs/lot"}, {"$ref": "record.writer.json#/$defs/status_object"}]}
      },
      "additionalProperties": false
    },
    "result_anatomical_site": {
      "description": "A UBERON identifier.",
      "type": "object",
      "allOf": [{"$ref": "record.writer.json#/$defs/based"}],
      "required": ["uberon", "label"],
      "properties": {
        "uberon": {"type": "string"},
        "label": {"type": "string"}
      },
      "unevaluatedProperties": false
    },
    "result_derivation": {
      "description": "A derived value's method, its inputs as pinned references, its assumptions, the inputs' specimen facts, and whether the inputs' conditions differ (provenance.md section 5).",
      "type": "object",
      "required": ["method", "inputs", "assumptions", "input_specimens"],
      "properties": {
        "method": {"type": "string"},
        "inputs": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/result_derivation_input"}},
        "assumptions": {"type": "array", "items": {"type": "string"}},
        "input_specimens": {"type": "array", "items": {"$ref": "#/$defs/result_input_specimen"}},
        "mixed_conditions": {"type": "boolean"}
      },
      "additionalProperties": false
    },
    "result_derivation_input": {
      "type": "object",
      "required": ["record", "field"],
      "properties": {
        "record": {"$ref": "#/$defs/result_pinned_record"},
        "field": {"type": "string"}
      },
      "additionalProperties": false
    },
    "result_pinned_record": {
      "description": "A record by its id and version, pinned by its content hash.",
      "type": "object",
      "required": ["id", "version", "content_hash"],
      "properties": {
        "id": {"type": "string"},
        "version": {"type": "string"},
        "content_hash": {"type": "string"}
      },
      "additionalProperties": false
    },
    "result_input_specimen": {
      "description": "An input's specimen facts, input being its index in inputs.",
      "type": "object",
      "required": ["input", "specimen"],
      "properties": {
        "input": {"type": "integer", "minimum": 0},
        "specimen": {"$ref": "#/$defs/result_specimen"}
      },
      "additionalProperties": false
    },
    "result_review": {
      "description": "A review as found, its result a token the reader knows: a review never refuses, so the members a review names that the record holds are returned whatever they hold (provenance.md section 2 item 6).",
      "type": "object",
      "required": ["result"],
      "properties": {
        "result": {"$ref": "vocabulary/provenance.json#/$defs/review_result"},
        "reviewer": {"$ref": "record.writer.json#/$defs/json_value"},
        "orcid": {"$ref": "record.writer.json#/$defs/json_value"},
        "date": {"$ref": "record.writer.json#/$defs/json_value"},
        "independent_of_extraction": {"$ref": "record.writer.json#/$defs/json_value"},
        "checklist": {"$ref": "record.writer.json#/$defs/json_value"}
      },
      "additionalProperties": false
    },
    "returned_label": {
      "description": "A result's label: one of section 2's, or the field's label (record_format.md section 4.1).",
      "anyOf": [
        {"$ref": "vocabulary/labels.json#/$defs/result_label"},
        {"$ref": "vocabulary/fields.json#/$defs/label"}
      ]
    },
    "assumption": {
      "description": "The declaration a value rests on, as the request gives it, basis aside (read_side_contract.md section 2): a nominal's value, or an extrapolation's method and law.",
      "oneOf": [{"$ref": "#/$defs/nominal_assumption"}, {"$ref": "#/$defs/extrapolation_assumption"}]
    },
    "nominal_assumption": {
      "description": "A nominal's value.",
      "type": "object",
      "required": ["acceptance", "value"],
      "properties": {
        "acceptance": {"const": "nominal"},
        "value": {"type": "number"}
      },
      "additionalProperties": false
    },
    "extrapolation_assumption": {
      "description": "An extrapolation's own members as the request gives them, basis aside: its method and law.",
      "type": "object",
      "required": ["acceptance", "method", "law"],
      "properties": {
        "acceptance": {"const": "extrapolation"},
        "method": {"$ref": "vocabulary/acceptances.json#/$defs/extrapolation_method"},
        "law": {"type": "string", "minLength": 1}
      },
      "additionalProperties": false
    }
  }
}
