# Personal health record: an Omnigraph use case

*A personal health record your agents can read and keep current*

One person's lab results, readings, targets, hypotheses, medication and vaccine doses, with "off target", "overdue" and "incomplete" worked out on every read.

Build a living personal health record, and the agent workflows around it. It keeps lab results, device readings, targets, hypotheses, what you take and the vaccine doses you were given linked to the documents they came from. Whether a result is off target, a retest is overdue or a vaccine series is incomplete is worked out from the current data each time you ask. Agents read your reports and tell you what is due, on branches you review before anything reaches the record.

| | |
|---|---|
| Category | Personal |
| Graph ID | health |
| Sample data | Noa Brandt, an invented person with two years of results: 266 nodes, 551 edges |
| Schema | 16 node types, 39 edge types |
| Stored queries | 47 reads, 52 writes |
| Source | https://github.com/ModernRelay/omnigraph-cookbooks/tree/main/health-record |

## Node types

### Person

Someone the record is about, or a clinician who appears in it.

- `slug: String` (key)
- `name: String`
- `role: enum(subject, clinician, other)`
- `born_on: Date?`

### Organization

A laboratory, clinic, hospital or pharmacy that produced a document or gave a dose.

- `slug: String` (key)
- `name: String`
- `kind: enum(laboratory, clinic, hospital, pharmacy, other)`

### Visit

An appointment, planned or past. Completing it can record the graph commit the clinician saw.

- `slug: String` (key)
- `title: String`
- `kind: enum(checkup, consultation, lab_draw, procedure, vaccination, telehealth)`
- `scheduled_at: DateTime`
- `status: enum(planned, completed, cancelled)`
- `reason: String?`
- `summary: String?`
- `baseline_commit: String?`

### HealthRecord

A document the record learned from: a lab report, a clinic letter, a vaccination card, a wearable export.

Instruction for agents: File the document first, as raw, with its file. An agent that reads values from it sets extraction to extracted; only a person who has checked the values against the file sets reviewed.

- `slug: String` (key)
- `title: String`
- `kind: enum(lab_report, imaging_report, clinic_letter, prescription, vaccination_record, wearable_export, other)`
- `document_date: Date`
- `received_at: DateTime`
- `extraction: enum(raw, extracted, reviewed)`
- `file: Blob?`
- `notes: String?`

### Measurable

Something that can be measured about a person: a lab analyte, a vital sign, a body composition figure, a daily sleep or activity figure, a symptom score.

- `slug: String` (key)
- `name: String`
- `kind: enum(lab_analyte, vital, body_composition, activity, sleep, symptom, score)`
- `category: String?`
- `canonical_unit: String`
- `aliases: [String]?`
- `description: String?`

### Measurement

One value of one measurable for one person: a lab result as reported, a reading, or a summary over a period.

Instruction for agents: Copy the value, unit, reference range and flag as the source printed them, and keep the printed line in source_line so a reviewer can check it. Set canonical_value only when the unit is the measurable's canonical unit or the conversion is certain. A correction is a new Measurement with status amended that supersedes the old one; never overwrite a reported value.

- `slug: String` (key)
- `measured_at: DateTime`
- `period_start: DateTime?`
- `statistic: enum(point, mean, minimum, maximum, total, median)`
- `value: F64?`
- `comparator: enum(lt, le, gt, ge)?`
- `value_text: String?`
- `unit: String?`
- `canonical_value: F64?`
- `reference_low: F64?`
- `reference_high: F64?`
- `flag: enum(low, normal, high, critical)?`
- `status: enum(preliminary, final, amended, entered_in_error)`
- `fasting: Bool?`
- `device: String?`
- `source_name: String?`
- `source_line: String?`

### ExternalCode

A code from a standard system for a measurable, a condition or a vaccine: LOINC, ICD-10, CVX.

- `slug: String` (key)
- `system: enum(loinc, icd10, cvx, atc, rxnorm, snomed, other)`
- `code: String`
- `display: String?`

### Target

The range a person wants a marker to stay in, with who set it and why. Off target is worked out against the latest result.

- `slug: String` (key)
- `low: F64?`
- `high: F64?`
- `unit: String`
- `set_on: Date`
- `set_by: String`
- `rationale: String?`
- `status: enum(active, retired)`

### Hypothesis

A possible explanation someone holds, with the results that support and contradict it.

Instruction for agents: The status is a person's or a clinician's verdict, never an agent's. Anything an agent proposes stays review_status ai_generated until a person reviews it. Link the results for and against it; do not restate them in the thesis.

- `slug: String` (key)
- `title: String`
- `thesis: String`
- `status: enum(open, supported, rejected, superseded)`
- `review_status: enum(ai_generated, human_reviewed)`
- `raised_on: Date`

### Condition

A disease, a diagnosis or a kind of reaction, as a concept. A person's own case of it is a ConditionOccurrence.

- `slug: String` (key)
- `name: String`
- `category: enum(infectious_disease, cardiovascular, metabolic, endocrine, musculoskeletal, reaction, other)`

### ConditionOccurrence

One person's case of a condition, or one reaction they had, with how certain it is.

- `slug: String` (key)
- `status: enum(suspected, active, resolved, ruled_out)`
- `certainty: enum(self_reported, clinician_suspected, confirmed)`
- `onset_on: Date?`
- `resolved_on: Date?`
- `severity: enum(mild, moderate, severe)?`
- `notes: String?`

### Intervention

Something a person takes or does for their health: a medication, a supplement, a change of diet, exercise or sleep. The markers it is meant to move and the hypothesis behind it hang on this node; the dose is on its episodes.

- `slug: String` (key)
- `name: String`
- `kind: enum(medication, supplement, diet, exercise, sleep, behavioural, procedure, other)`
- `status: enum(planned, active, paused, stopped)`
- `started_at: DateTime?`
- `stopped_at: DateTime?`
- `reason: String?`

### InterventionEpisode

One period of an intervention at one dose and frequency. The current dose is the latest episode's; a change of dose is a new episode, so the intervention keeps its markers and its history.

- `slug: String` (key)
- `dose: String?`
- `frequency: String?`
- `started_at: DateTime`
- `reason: String?`

### Immunization

One vaccine dose given to a person, or one that was due and not given. Which diseases it counts towards, and as which dose of each series, is on its ProtectsAgainst links.

Instruction for agents: One node per dose. A combined vaccine is one Immunization with one ProtectsAgainst link per disease, each with its own dose number. Set origin to what the entry rests on: recall means the person remembers it and no document shows it.

- `slug: String` (key)
- `vaccine: String`
- `product: String?`
- `manufacturer: String?`
- `lot_number: String?`
- `expires_on: Date?`
- `administered_on: Date`
- `date_precision: enum(day, month, year)`
- `site: enum(left_arm, right_arm, left_thigh, right_thigh, other)?`
- `route: enum(intramuscular, subcutaneous, oral, intranasal, intradermal)?`
- `status: enum(completed, not_done, entered_in_error)`
- `status_reason: String?`
- `origin: enum(provider_record, vaccination_card, registry, recall)`

### Recommendation

Something due by a date: a retest, a screening, a vaccine dose or a follow-up, with the authority that set it. Whether it has been met is worked out from the result or the dose linked as fulfilling it.

Instruction for agents: Record a recommendation with who made it. Do not work one out from a national schedule: schedules differ by country, age and history, and deciding which applies is a clinician's call. Link what met it with fulfil_with_result or fulfil_with_dose and leave status open; status records only a person's closure.

- `slug: String` (key)
- `title: String`
- `kind: enum(retest, screening, vaccine_dose, follow_up)`
- `authority: String`
- `earliest_at: DateTime?`
- `due_at: DateTime`
- `latest_at: DateTime?`
- `repeats_every_days: I32?`
- `dose_number: I32?`
- `series_doses: I32?`
- `status: enum(open, done, declined, superseded)`
- `reason: String?`

### Notification

A prompt put in front of the person, with whether it was sent and acknowledged. Its slug says what it is about, so the same prompt cannot be raised twice.

Instruction for agents: Build the slug from the kind and the thing it is about, such as ntf-overdue-rcm-tsh-2026. Raising a slug that already exists is refused, whatever its status: a dismissed prompt stays dismissed.

- `slug: String` (key)
- `title: String`
- `body: String?`
- `kind: enum(retest_due, dose_due, off_target, critical_result, visit_prep, other)`
- `status: enum(pending, sent, acknowledged, dismissed)`
- `raised_at: DateTime`
- `sent_at: DateTime?`
- `channel: String?`
- `acknowledged_at: DateTime?`

## Edge types

- `HealthRecord -[RecordFor]-> Person` Unkeyed: the record is written once.
- `HealthRecord -[RecordFrom]-> Organization` The laboratory or clinic that issued the document.
- `HealthRecord -[RecordOfVisit]-> Visit` The visit the document came out of.
- `Visit -[VisitOf]-> Person` Unkeyed: the record is written once.
- `Visit -[VisitWith]-> Person` The clinician seen.
- `Measurement -[MeasurementOf]-> Measurable`
- `Measurement -[MeasurementFor]-> Person` Unkeyed: the record is written once.
- `Measurement -[MeasurementIn]-> HealthRecord` The document the value was read from. A reading from a device has none.
- `Measurement -[MeasurementSupersedes]-> Measurement` The source corrected an earlier result; the earlier one stays on record.
- `ExternalCode -[CodeForMeasurable]-> Measurable`
- `ExternalCode -[CodeForCondition]-> Condition`
- `ExternalCode -[CodeForImmunization]-> Immunization` The vaccine type given, as a code.
- `Target -[TargetFor]-> Measurable`
- `Target -[TargetOf]-> Person` Unkeyed: the record is written once.
- `Hypothesis -[HypothesisFor]-> Person` Unkeyed: the record is written once.
- `Hypothesis -[HypothesisAbout]-> Measurable` The marker the hypothesis tries to explain.
- `Hypothesis -[SupportedBy]-> Measurement`
- `Hypothesis -[ContradictedBy]-> Measurement`
- `ConditionOccurrence -[OccurrenceOf]-> Condition`
- `ConditionOccurrence -[OccurrenceFor]-> Person` Unkeyed: the record is written once.
- `ConditionOccurrence -[ReactionToIntervention]-> Intervention` The occurrence is attributed to this intervention.
- `ConditionOccurrence -[ReactionToImmunization]-> Immunization` The occurrence followed this dose.
- `Intervention -[InterventionFor]-> Person` Unkeyed: the record is written once.
- `Intervention -[Targets]-> Measurable` The marker the intervention is meant to move.
- `Intervention -[MotivatedBy]-> Hypothesis`
- `Intervention -[Treats]-> ConditionOccurrence`
- `InterventionEpisode -[EpisodeOf]-> Intervention` Unkeyed: an episode is written once.
- `Immunization -[ImmunizationFor]-> Person` Unkeyed: the record is written once.
- `Immunization -[ProtectsAgainst]-> Condition` A disease the dose counts towards, with which dose of that disease's series it is. One combined vaccine carries a different dose number for each disease.
- `Immunization -[AdministeredAt]-> Organization`
- `Immunization -[ImmunizationIn]-> HealthRecord` The document that shows the dose.
- `Recommendation -[RecommendationFor]-> Person` Unkeyed: the record is written once.
- `Recommendation -[RecommendsMeasuring]-> Measurable`
- `Recommendation -[RecommendsVaccineAgainst]-> Condition`
- `Recommendation -[FulfilledByMeasurement]-> Measurement`
- `Recommendation -[FulfilledByImmunization]-> Immunization`
- `Notification -[NotificationFor]-> Person` Unkeyed: the record is written once.
- `Notification -[AboutRecommendation]-> Recommendation`
- `Notification -[AboutMeasurement]-> Measurement`

Full schema: https://github.com/ModernRelay/omnigraph-cookbooks/blob/main/health-record/schema.pg

## Questions it answers

### Which results are outside my own targets?

Latest results outside the person's own active target for that marker.

```gq
query off_target() @description("Latest results outside the person's own active target for that marker.") {
    match {
        $t: Target { status: "active" }
        $t targetOf $p
        $t targetFor $x
        $m measurementFor $p
        $m measurementOf $x
        $m.status != "entered_in_error"
        not { $c measurementSupersedes{1,8} $m  $c.status != "entered_in_error" }
        not { $n measurementOf $x  $n measurementFor $p  $n.status != "entered_in_error"
              not { $d measurementSupersedes{1,8} $n  $d.status != "entered_in_error" }
              $n.measured_at > $m.measured_at }
        ($m.comparator is null and ($m.canonical_value > $t.high or $m.canonical_value < $t.low))
            or (($m.comparator = "lt" or $m.comparator = "le") and $m.canonical_value <= $t.low)
            or (($m.comparator = "gt" or $m.comparator = "ge") and $m.canonical_value >= $t.high)
    }
    return { $p.slug as person, $x.slug as marker, $m.comparator, $m.canonical_value as value, $t.low, $t.high, $t.unit, $m.measured_at, $t.slug as target }
    order { $p.slug asc, $x.slug asc }
    limit 500
}
```

### Did this change move the marker it was meant to move?

Every current result of the markers one intervention targets, marked as before or after it started.

```gq
query intervention_effect($intervention: String) @description("Every current result of the markers one intervention targets, marked as before or after it started.") {
    match {
        $v: Intervention { slug: $intervention }
        $v interventionFor $p
        $v targets $x
        $m measurementOf $x
        $m measurementFor $p
        $m.status != "entered_in_error"
        not { $c measurementSupersedes{1,8} $m  $c.status != "entered_in_error" }
    }
    return { $x.slug as marker, $m.measured_at, $m.canonical_value as value, $x.canonical_unit as unit, $m.measured_at >= $v.started_at as after_start }
    order { $x.slug asc, $m.measured_at asc }
    limit 2000
}
```

### Which vaccine series did I never finish?

Diseases whose latest given dose is not the last of its series.

```gq
query incomplete_series() @description("Diseases whose latest given dose is not the last of its series.") {
    match {
        $i: Immunization
        $i immunizationFor $p
        $i.status = "completed"
        $i $w:protectsAgainst $d
        $w.dose_number < $w.series_doses
        not { $j immunizationFor $p  $j.status = "completed"  $j $v:protectsAgainst $d
              $v.dose_number > $w.dose_number }
    }
    return { $p.slug as person, $d.slug as disease, $w.dose_number as doses_given, $w.series_doses, $i.vaccine, $i.administered_on as last_dose_on }
    order { $d.slug asc }
    limit 500
}
```

### What is overdue?

Recommendations still due whose date has passed.

```gq
query overdue_recommendations() @description("Recommendations still due whose date has passed.") {
    match {
        $r: Recommendation { status: "open" }
        $r.due_at < now()
        not { $r fulfilledByMeasurement $fm  $fm.status != "entered_in_error" }
        not { $r fulfilledByImmunization $fi  $fi.status = "completed" }
        $r recommendationFor $p
    }
    return { $p.slug as person, $r.slug, $r.title, $r.kind, $r.authority, $r.due_at }
    order { $r.due_at asc }
    limit 500
}
```

### Which of my hypotheses does a result contradict?

Hypotheses still open or held as supported that a current result contradicts.

```gq
query contested_hypotheses() @description("Hypotheses still open or held as supported that a current result contradicts.") {
    match {
        $h: Hypothesis
        $h.status = "open" or $h.status = "supported"
        $h contradictedBy $m
        $m.status != "entered_in_error"
        not { $c measurementSupersedes{1,8} $m  $c.status != "entered_in_error" }
        $m measurementOf $x
    }
    return { $h.slug, $h.title, $h.status, $m.slug as result, $x.slug as marker, $m.value, $m.unit, $m.measured_at }
    order { $h.slug asc, $m.measured_at asc }
    limit 500
}
```

## Stored queries

### queries/mutations.gq

- `add_person` (write): Add a person: the subject of a record (role subject) or a clinician.
- `add_organization` (write): Add a laboratory, clinic, hospital or pharmacy.
- `add_marker` (write): Add a marker with the unit its targets and canonical values use.
- `add_marker_code` (write): Record a standard code, such as a LOINC code, for a marker.
- `file_record` (write): File a document for a person, with the file itself, before anything is read from it. Refused if the slug already exists.
- `link_record_source` (write): Say which laboratory or clinic issued a document.
- `link_record_visit` (write): Say which visit a document came out of.
- `mark_extracted` (write): Mark a raw document as read: its values are in the record and await a person's check.
- `mark_reviewed` (write): Mark a document's extracted values as checked against the file. A person's step.
- `record_result` (write): Record one result read from a document, as the document printed it. Refused if the slug already exists, so reading a report twice cannot change a value.
- `record_reading` (write): Record a reading or a period summary from a device or app, with no document behind it.
- `correct_result` (write): Record a source's correction of an earlier result. The earlier result stays on record and stops counting as current.
- `void_result` (write): Mark a result as entered in error, such as one filed under the wrong person. It stays on record and stops counting: a result it had corrected becomes current again, and a recommendation it had met is due again.
- `set_canonical_value` (write): Add the value in the marker's canonical unit to a result that was reported in another unit.
- `set_target` (write): Set the range a person wants a marker to stay in, in the marker's canonical unit, with who set it.
- `retire_target` (write): Stop judging results against a target.
- `raise_hypothesis` (write): Raise a possible explanation about one marker, open until a person or clinician decides.
- `link_support` (write): Link a result as supporting a hypothesis.
- `link_contradiction` (write): Link a result as contradicting a hypothesis.
- `review_hypothesis` (write): Record that a person has read an agent's proposed hypothesis. A person's step.
- `decide_hypothesis` (write): Set a hypothesis to supported, rejected or superseded. A person's or clinician's verdict.
- `start_intervention` (write): Record something a person starts taking or doing, with its first dose period and the marker it is meant to move.
- `add_intervention_marker` (write): Add another marker an intervention is meant to move.
- `link_intervention_hypothesis` (write): Say which hypothesis an intervention acts on.
- `link_intervention_condition` (write): Say which of the person's conditions an intervention is for.
- `stop_intervention` (write): Stop an active or paused intervention.
- `change_dose` (write): Record a change of dose or frequency as a new dose period of the same intervention, which keeps its markers and its history.
- `add_condition` (write): Add a disease, diagnosis or kind of reaction as a concept.
- `record_condition` (write): Record a person's case of a condition, with how certain it is.
- `record_dose_reaction` (write): Record a reaction that followed a vaccine dose.
- `record_intervention_reaction` (write): Record a reaction attributed to something the person takes or does.
- `resolve_condition` (write): Mark a person's condition or reaction as resolved.
- `record_dose` (write): Record one vaccine dose that was given, with the first disease it counts towards and its dose number in that series.
- `add_dose_disease` (write): Add another disease a combined vaccine dose counts towards, with its own dose number.
- `record_dose_not_given` (write): Record a dose that was due and not given, with the reason.
- `link_dose_record` (write): Link a dose to the document that shows it.
- `link_dose_place` (write): Say where a dose was given.
- `add_dose_code` (write): Record the vaccine type of a dose as a code, such as a CVX code.
- `void_dose` (write): Mark a dose as entered in error. It stays on record and stops counting: a recommendation it had met is due again.
- `recommend_retest` (write): Record that a marker should be measured again by a date, with who says so.
- `recommend_dose` (write): Record that a vaccine dose is due by a date, with the authority that set it.
- `recommend_other` (write): Record a screening or a follow-up due by a date.
- `fulfil_with_result` (write): Link the result that met a recommendation. The recommendation stops being due while that result stands, and is due again if the result is later marked as entered in error.
- `fulfil_with_dose` (write): Link the dose that met a dose recommendation. The recommendation stops being due while that dose stands.
- `close_recommendation` (write): Close an open recommendation as declined, superseded, or done where no result or dose in the record shows it. A person's step.
- `schedule_visit` (write): Add a planned visit with the clinician to be seen.
- `complete_visit` (write): Mark a visit as done, with what came of it and the graph commit the clinician saw.
- `raise_notification` (write): Raise a prompt about one recommendation for a person. Refused if the slug already exists, whatever its status.
- `raise_result_notification` (write): Raise a prompt about one result, such as one off target or flagged critical. Refused if the slug already exists, whatever its status.
- `mark_sent` (write): Record that a pending prompt was sent, and on which channel.
- `acknowledge_notification` (write): Record that the person has seen a prompt. A person's step.
- `dismiss_notification` (write): Dismiss a prompt as not needed. It stays on record, so it is not raised again.

### queries/record.gq

- `latest_results`: The latest current result of each marker, per person.
- `out_of_range`: Latest results outside the range their own source printed.
- `off_target`: Latest results outside the person's own active target for that marker.
- `targets`: Each active target beside the latest result it is judged against.
- `marker_history`: Every current result of one marker, oldest first.
- `record_results`: The results read from one document, with the line each was read from.
- `records_awaiting_review`: Documents an agent read values from that no person has checked against the file yet, and documents nothing was read from.
- `unconverted_results`: Current results in a unit other than their marker's canonical unit, with no canonical value: they cannot be judged against a target.
- `corrected_results`: Results a source corrected, each beside the value it replaced. A correction entered in error is left out.
- `preliminary_results`: Results the source marked preliminary that no final result has replaced.
- `detection_limit_results`: Latest results reported at a detection limit, such as "<0.3". They are judged against a range or a target only where the limit settles it.
- `markers`: Every marker with its kind, category and canonical unit.
- `marker_codes`: The standard codes recorded for each marker.
- `search_markers`: Markers matching words in their name or description.
- `unmeasured_markers`: Markers with no current result for anyone.
- `open_recommendations`: Everything still due, soonest first: open, and not met by a valid result or a given dose.
- `overdue_recommendations`: Recommendations still due whose date has passed.
- `targets_without_retest`: Active targets whose marker has no recommendation still due to measure it again.
- `overdue_not_notified`: Overdue recommendations nobody has been told about: no notification about them exists. A dismissed one counts as told.
- `met_by_result`: Recommendations a valid result has met, each with the result.
- `met_by_dose`: Dose recommendations a given dose has met, each with the dose.
- `immunization_history`: Every dose on record, oldest first, with what the entry rests on.
- `doses_by_disease`: For each disease, how many doses were given and the highest dose number reached in its series.
- `incomplete_series`: Diseases whose latest given dose is not the last of its series.
- `undocumented_doses`: Doses no document shows: entered from recall, or with no record linked.
- `doses_not_given`: Doses that were due and not given, with the reason.
- `doses_by_lot`: Every dose given from one lot, for a recall notice. Doses not given or entered in error are left out.
- `disease_doses`: The doses that count towards one disease, in order.
- `reactions`: Reactions on record, each with the dose or the intervention it is attributed to.
- `dose_reactions`: Reactions that followed a vaccine dose.
- `intervention_reactions`: Reactions attributed to something the person takes or does.
- `hypotheses`: Every hypothesis with its standing and whether a person has reviewed it.
- `hypothesis_support`: The current results linked as supporting one hypothesis.
- `hypothesis_contradiction`: The current results linked as contradicting one hypothesis.
- `contested_hypotheses`: Hypotheses still open or held as supported that a current result contradicts.
- `hypotheses_without_evidence`: Open hypotheses with no current result linked for or against them.
- `hypotheses_awaiting_review`: Hypotheses an agent proposed that no person has reviewed.
- `active_interventions`: What the person takes or does now, at its current dose, with the marker each is meant to move.
- `intervention_effect`: Every current result of the markers one intervention targets, marked as before or after it started.
- `interventions_without_followup`: Active interventions whose target marker has not been measured since they started.
- `dose_history`: Every dose period of every intervention, oldest first: a change of dose or frequency starts a new one.
- `active_conditions`: A person's suspected and active conditions, with how certain each is.
- `visits`: Every visit, newest first, with the commit a completed one baselined.
- `upcoming_visits`: Planned visits that have not happened yet, soonest first.
- `visit_records`: The documents that came out of one visit.
- `notification`: One notification by its slug: read it before raising the same prompt again.
- `unacknowledged_notifications`: Prompts raised or sent that the person has not acknowledged or dismissed.

## Run it with your agent

Paste this into a coding agent. It installs Omnigraph if it has to, creates the graph from this cookbook, loads the sample data and runs the queries above.

```text
Read https://www.omnigraph.dev/onboarding.md and set up Omnigraph for me with the Personal health record cookbook: https://github.com/ModernRelay/omnigraph-cookbooks/tree/main/health-record
```

## Run it by hand

These commands create the graph, empty:

```bash
git clone https://github.com/ModernRelay/omnigraph-cookbooks
cd omnigraph-cookbooks
export COOKBOOK=$PWD/health-record
omnigraph cluster validate --config "$COOKBOOK"
omnigraph cluster apply --target "$COOKBOOK" --config "$COOKBOOK" --as act-admin --json
```

The full local setup, which also loads the sample data and serves the graph: https://github.com/ModernRelay/omnigraph-cookbooks/blob/main/docs/local-setup.md

Source: https://www.omnigraph.dev/use-cases/health-record
