---
title: 'Day 2: The Locker Becomes a Hospital'
series: Building the Caladrius PHR with agents
part: 2
series_total: 15
date: '2026-11-19'
reading_time: 14 min
description: The day the health locker learned to act as a provider in its own right,
  linking the records it holds to a person's ABHA address and serving them to other
  requesters under consent, while the stub ABDM learned to play every other party
  in the exchange.
canonical_url: https://caladriushealth.ai/solutions/phr-build-diary/day-2-the-locker-becomes-a-hospital/
publisher: Caladrius Health AI Studio
---

# Day 2: The Locker Becomes a Hospital

The day the health locker learned to act as a provider in its own right, linking the records it holds to a person's ABHA address and serving them to other requesters under consent, while the stub ABDM learned to play every other party in the exchange.

*The PHR is built by a small Caladrius team (Giri, Krishna, Preetha and me) working with AI agents; each post ends with what the day meant for each of our areas.*

Day 1 was loud: 32 pull requests, a sandbox run, six deploy failures. Day 2 was quieter on the surface, with nine
pull requests into `dev` and one promotion to QA, but it carried the most architecture of the week so far. By the end
of Friday the health locker could do something it couldn't do in the morning: act as a **health information provider
(HIP)** in its own right, linking the records it holds to the person's ABHA address and serving them to other
requesters under consent.

The other half of the day went into the stub [ABDM](https://caladriushealth.ai/what-is-abdm/). To test a locker that plays several roles, the stub had to play
every other party in the exchange: the consent manager, a facility at a counter, other lockers, and a hospital pushing
records. This post covers both halves, and why they had to happen on the same day.

---

## 1. Why a health locker is also a HIP

ABDM's P4 milestone is the health locker: a long-term store of a person's records, under their control. In HIE-CM v3
a locker plays three roles at once, and our sandbox service is registered as all three:

| Role | What the locker does in it |
|---|---|
| **Health locker** | Is set up by the person on their ABHA address; holds a subscription and an auto-approval policy |
| **HIU** (health information user) | Fetches records from hospitals under consent, and stores them |
| **HIP** (health information provider) | Links what it holds to the person's ABHA address, and serves it to other requesters under consent |

The first two existed from Day 0. The third was missing, which meant a document the person uploaded to the locker
stayed in the locker. No other app or hospital could ask for it, even with the person's consent. In a national
exchange, that makes the locker a dead end.

The day started with good news from NHA's side: our sandbox service had been enabled as a **health locker** on its
bridge. We checked it from the QA API with a gateway token only, nothing personal: the bridge services listed HIP, HIU
and HEALTH_LOCKER, and the sandbox's directory of lockers included ours, one of 666. The plan's step P4-7 moved from
blocked to in progress.

## 2. Linking as a HIP: the link token and HIP-initiated linking

The plugin's M2 skill describes how a hospital links care contexts to a patient: it asks the gateway for a **link
token** for that patient, then sends **HIP-initiated linking** for every care context it wants linked, in one call. The
locker now does exactly that, with the locker's service id as the HIP id.

- **What gets linked.** An upload (with its own reference) or a record the locker fetched under its own consent (a new
  reference). Records the person pulled through "Pull Records" are not re-linked; they already belong to a hospital
  that is linked.
- **Only for people who chose the locker.** An account that hasn't set this PHR up as its locker gets nothing linked.
- **A small leased queue.** A job runner asks for the token (or reuses a live one), then links. Callbacks are matched on
  the original request id; each callback is one transaction plus one audit row. Refusals keep their own code on their
  own row, so two different errors on the same care context stay distinguishable. Some refusals drop the token and
  start again; others back off. After a fixed number of attempts the job stops.
- **The token at rest is encrypted** (AES-256-GCM) and held only while it is issued. One live token per account and
  HIP.
- **Demographics are read per call and never stored.** The link-token request needs the person's name, gender, year
  of birth and ABHA identifiers. They are read from P1's encrypted rows for each call, never stored a second time and
  never logged. A database test scans the new tables and the audit log for the token, address, number and name.

The upload response gained one additive field: `linking: "queued" | "not-linked"`. The app ignored it on Day 2. It
would matter on Day 5, when the upload screen told people that linking "comes in a later release" while the API was
already doing it.

One change touched callback authentication, which is S1: the two HIP callbacks carry `X-HIP-ID` instead of
`X-HIU-ID`, so the check reads the facility header the specification names for those paths. Every other check is
unchanged, and the pull request asked the reviewer, explicitly, to read that file.

## 3. Serving as a HIP: from a consent to an encrypted push

Linking makes records discoverable. Serving them is the other half: another HIU raises a consent, the person grants
it, and ABDM asks the locker, as the HIP, for the records. An agent built it the same evening, from the M2 skill's
scaffold and design notes.

```
consent manager ──hip/notify (GRANTED)──▶ locker   store the artefact, if every check passes
HIU ──▶ consent manager ──health-information/request──▶ locker   check, then acknowledge
locker ──encrypted push (one page per record)──▶ HIU's dataPushUrl
locker ──notify TRANSFERRED / FAILED──▶ consent manager
```

The checks are where the work was:

- **Storing a consent.** A GRANTED notification is stored only when the HIP id is ours, every patient reference is the
  locker's own reference for that account, the patient matches that account's ABHA address, the erase date is in the
  future, and at least one named care context is one the locker has actually linked. Only those care contexts are kept.
  The artefact is encrypted at rest.
- **Accepting a data request.** The consent must be held, granted and before its erase date. The key material must be
  ECDH on Curve25519 with a 32-byte nonce and an unexpired key, and the push URL must be acceptable. The date range is
  clipped to the artefact's range. Anything else is refused at once, with ABDM's own error code.
- **Pushing.** For each covered record (the artefact's care contexts, its record types, the clipped range) the job
  re-checks the artefact **before every page**, decrypts the stored record, builds a FHIR bundle (stored bundles go as
  they are; other uploads are wrapped in a `HealthDocumentRecord` bundle, validated with no findings), encrypts it and
  pushes it.
- **Fresh keys per page.** The Fidelius encryption reuses our existing ECDH code with a **new key pair and nonce for
  every page**. The private half never leaves the function that uses it.
- **The push itself** goes straight to the requester's push URL, refuses redirects, and only to HTTPS DNS names.

**Revoked or expired consent.** We had to decide what a revocation means for the locker as a HIP, and wrote the
decision into the contract: everything under that consent stops at once. Open transfers are marked failed and
notified, later requests are refused, the artefact is purged, and a push in flight stops before its next page. The job
runner also expires lapsed artefacts on its own; a HIP is expected to track expiry. What is **not** erased is the
locker's own copy of the records. The consent was the requester's permission to receive them, not the locker's
permission to hold them.

Every step writes an audit entry: consent stored, request accepted or denied with its code, one row per record sent
(naming the requester and the consent), the transfer, the notify and the expiry.

## 4. The PHR's own auto-approval policy

A QA capability report from the night before listed the gaps between the demo and the API build. Gap 2: the API build
couldn't create the PHR's own **auto-approval policy**, so NHA's mandatory P3 cases on it never ran.

The specification made this awkward. ABDM's auto-approve call answers 202 with no body, and ABDM publishes no list of
policies. So how does the app show whether a policy exists? The agent found the answer in the P4 operations: a
locker's settings list its `autoApprovals[]`, each with the HIU it belongs to. The API reads the policy back from the
PHR's own locker settings and keeps no record of it on our side. ABDM is the source of truth; we don't keep a second
copy that can drift.

A review finding was fixed in the same change: onboarding asked "Allow automatic retrieval?", and the API build ignored
the answer. Now a separate "yes" sets the policy up. ABDM's P3 documentation says to ask the two questions
(subscribe, and auto-approve) separately, so the app does.

One question was left for the sandbox and written into the plan: would the PHR's own locker settings list the policy
for an address that hadn't set the PHR up as its locker? Day 3 answered it, and the answer changed the design.

## 5. Teaching the stub to play everyone

The QA functional run of the night before had passed **5 of P4's 41 mandatory cases** on the API build. Most of the
others weren't failing; they couldn't run at all, because the stub ABDM had no health-locker world. Four
pull requests fixed that, each giving the stub another role.

**A facility at a counter.** Scan and share has a human step in the middle: the hospital scans the QR code the person
shows. The stub now plays that facility. ABDM's profile QR is served as a valid PNG carrying an opaque scan id; the
test reads the image the app shows and hands it to the stub facility, which reads the signed-in address and name from
it within ten seconds. A code ABDM didn't issue reads as nothing. The facility's bridge records every share it
receives, so the spec can assert that **Cancel sends nothing** and **Share sends exactly one profile** and shows the
token. ABDM publishes no facility-to-PHR call after the scan, so the stub doesn't invent one.

**A health programme.** PHR_APP_400 links vaccination doses with an OTP, fetches them under the PHR's own consent once
the person approves, and opens a dose. The stub's programme pushes NRCES `ImmunizationRecord` bundles built from the
documentation server's own example, validated with no findings.

**A world of lockers.** A new module plays the locker directory (ours plus two invented lockers), setting up a locker,
the lockers on an address, a locker's settings, consent and subscription requests by status, and enabling or disabling
a locker's policy. It also plays the PHR's own P3 subscription (init, the person's approval, notifications when a
hospital links a visit) and one consent-manager rule: a locker's consent request inside an active auto-approval policy
is granted without asking.

**State that survives a reset, like ABDM's.** What the PHR set up (lockers, policies, subscriptions) survives the
stub's reset endpoint, because it survives on ABDM and the API's database isn't reset between tests either. The demo's
seed comes back on every reset. A new endpoint hands out a fresh, synthetic first-sign-in address when a test needs
one.

With that, almost every `@not-api` tag for P4 went away (50301 and 50302 remain). New specs cover requests by status, editing the locker's subscription,
turning automatic retrieval off, Get Data, the three ways a consent ends (denied, expired, revoked, with records
erased) and a hospital linking a new visit.

**A new spec found a real bug.** Linked Facility kept reading "Up to date" for a facility whose latest consent had been
revoked or had expired after its last transfer, even though the revocation had erased those records. That is consent
state shown wrongly to the person, so the fix was classified S1. The facility now reads "Consent revoked" or "Request
expired".

### 5.1 When the test merged before its run finished

One of those pull requests merged before its API-build run had finished, and the run then failed three of its new
specs. None was an app bug:

- the stub facility read the shared profile from `patient` while the PHR sends it, per the schema, as
  `profile.patient`;
- a spec checked help text hidden behind "About this screen";
- the API remembers which doses it has linked, so a second test found no doses left to link.

The fix took an hour. The rule it led to took longer to stick: on a branch that changes specs or the stub, run the
functional suite by hand **before** merging, not after.

## 6. Smaller fixes, same pattern

- **ABDM refusals are not 500s.** Two refusals on the ABHA card had reached people as "internal error" fourteen times
  on QA that day: one meaning "this address has no KYC" and one meaning "sign in again, your profile changed". They are
  now named conflicts, with a **Link ABHA number** button on the card for the first. ABDM's code and filtered message
  still show under our text, under the project's one written exception to "generic errors only".
- **A flaky audit test.** A test asserted that audit entries never contained four digits from a synthetic Aadhaar
  number. Random UUIDs sometimes do. It now matches the whole synthetic number, spaced or not: the same guarantee,
  without the flake.

## 7. Parallel agents, clean boundaries

Four agents worked on the same codebase on Day 2: the locker as HIP (linking), the locker as HIP (serving),
auto-approval, and the stub's locker world. They didn't step on each other because each brief said what the others
owned. The stub's locker work left the locker-as-HIP cases tagged with a precise reason
(`LOCKER_AS_HIP_NOT_ON_API`, "not built in the API yet") until the linking landed, instead of guessing at an API that didn't exist yet. The
HIP-serving work left the stub alone because no spec needed it yet.

That's the same lesson as the four parallel milestone builds on Day 0, one level down: parallel agents work when each
one knows **where its work ends** and what to leave for someone else.

## 8. What I learned on Day 2

- **A role you skip becomes a dead end.** The locker as a HIP wasn't on anyone's screen, and NHA's cases for it are
  marked "not run" for a PHR in the plugin. Without it, an upload could never leave the locker under consent. Reading
  the specification for roles, not screens, found it.
- **Let the authority keep the state.** For the auto-approval policy we read ABDM's answer back instead of keeping our
  own copy. Fewer tables, and nothing to drift.
- **A stub is a product too.** The stub ABDM now plays a consent manager, a facility, a programme, a locker directory
  and a hospital. It needs the same care as the app: its own modules, its own sections, state that behaves like ABDM's,
  and validation of everything it sends.
- **Write the consent decisions down.** "A revocation stops the transfer but doesn't erase the locker's copy" is the
  kind of decision an agent can't make on its own and shouldn't. It's now a paragraph in the contract, with its reason.

*Next, Day 3 (31 October): the first real callbacks reach QA, and the sandbox disagrees with the specification about
one capital letter.*

## The team behind Day 2

The PHR is built by a small Caladrius team working with AI agents:

- **Giri**: CEO; Cally taxonomy and intent framework
- **Krishna**: development, infrastructure and go-live
- **Preetha**: narrative engineer, personas
- **Manish** (me): CTO and CPO, enabling the Caladrius Health AI PHR and the AI Studio framework

### Cally: taxonomy and intent (Giri)

Day 2 added no Cally code beyond one test fix, but it widened what Cally will later have to understand. The locker now plays three roles:
health locker, a requester of records, and a provider that links what it holds and serves it to others under consent.
A question such as "who can see the document I uploaded?" has a different answer for each role, and the intent
framework has to tell them apart.

The day also wrote consent decisions into the contract in plain words: a revocation stops sharing at once but doesn't
erase the locker's own copy, and the auto-approval policy is read back from ABDM rather than kept twice. For the Cally
taxonomy those written decisions are the source to answer from, so nothing has to be guessed.

### Development, infrastructure and go-live (Krishna)

Day 2 was quieter for delivery, nine pull requests into `dev` and one promotion to QA, but it moved a go-live step:
the sandbox service was enabled as a health locker, checked from the QA API with a gateway token only, and the plan's
locker step moved from blocked to in progress. Linking runs through a small leased job queue with backoff and a limit
on attempts.

Four pull requests gave the stub ABDM a locker world, a facility, a programme and other lockers, so P4's cases
could run on the API build at all. One of them merged before its run finished, which led to a working rule for this
area: run the functional suite by hand before merging a branch that changes specs or the stub.

### Narrative and personas (Preetha)

The people behind Day 2 are a person who uploads a document and expects another hospital to be able to ask for it, a
hospital desk scanning a QR code at a counter, and a person whose vaccination doses come from a health programme. The stub ABDM gained invented lockers and a fresh synthetic address for each new sign-in a test needs.

The words on screen changed where they misled. Linked Facility said "Up to date" for a facility whose consent had been
revoked; it now says "Consent revoked" or "Request expired". Two ABHA card refusals had reached people as "internal
error"; they now say what happened, with a **Link ABHA number** button where that is the next step.

### Product and technology direction (Manish)

The decision I spent most time on was what a revocation means for the locker as a provider. I chose that it stops every
transfer under that consent and purges the artefact, but keeps the locker's own copy, because the consent was the
requester's permission to receive, not the locker's permission to hold. It's in the contract with its reason.

I also chose to let ABDM keep the auto-approval state rather than hold a copy that could drift (a decision first
recorded on Day 0), and to ask the two
onboarding questions separately, as ABDM's P3 documentation says. Running four agents at once worked because each
brief said what the others owned.

## Further reading

- [Caladrius Health](https://caladriushealth.ai/), the company behind the PHR
- [The Caladrius platform brief](https://caladriushealth.ai/platform/brief/): AI Studio, [Cally](https://caladriushealth.ai/platform/brief/#cally), the [Health Vault](https://caladriushealth.ai/platform/brief/#vault), the [design system](https://caladriushealth.ai/platform/brief/#design-system) and [security by design](https://caladriushealth.ai/platform/brief/#security)
- [Caladrius Pulse](https://caladriushealth.ai/blog/), our blog, including the ABDM series ([What is ABDM?](https://caladriushealth.ai/what-is-abdm/)) and the NHCX series ([What is NHCX?](https://caladriushealth.ai/what-is-nhcx/))
