FHIR profiles tighten the base spec: an Implementation Guide (IG) like
US Core adds constraints on top of a base resource. Before a server accepts a
Patient, it validates the resource against the US Core Patient profile.
This kata is the offline, deterministic version of Batch-1 Day 6, Week 2, Assignment 6 (running US Core IG validation on a HAPI R5 server): instead of calling a live validator, you implement a tiny slice of the profile rules yourself.
The Patient is modeled as a java.util.Map<String,Object>. You validate three
simplified US Core Patient constraints and return the errors in a fixed order.
Implement UsCoreValidator with:
static List<String> validate(Map<String,Object> patient) β return the error
messages in the order below, or an empty list when the patient is valid.Checks run in this exact order, and each contributes at most one message:
identifier must be a non-empty List (min cardinality 1).
Missing or empty β Patient.identifier: minimum cardinality 1 not met
name must be a non-empty List (min cardinality 1).
Missing or empty β Patient.name: minimum cardinality 1 not met
gender must be a String in the value set {male, female, other, unknown}
(min cardinality 1).
Patient.gender: minimum cardinality 1 not met
Patient.gender: code '<value>' is not in the value set
A fully valid patient returns an empty list.
Sign up to Exercism to learn and master FHIR with 9 exercises, and real human mentoring, all for free.