Build diary Day 2

Day 2: The Locker Becomes a Hospital

Built with Giridhar, Venkatakrishna and Preetha

Building the Caladrius PHR with agents Part 2 of 15

14 min read

Hand-drawn sketch of a filing cabinet with an ABHA tag, a record sliding out of an open drawer, and notes reading ABHA linked, Now a HIP and Consent first

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. 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.

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.

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.

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:

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 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

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

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:

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

See all 16 parts