Skip to content

Instantly share code, notes, and snippets.

@ppazos
Created August 11, 2025 22:12
Show Gist options
  • Save ppazos/64d4fffac81726f32885ca37a43762ba to your computer and use it in GitHub Desktop.
Save ppazos/64d4fffac81726f32885ca37a43762ba to your computer and use it in GitHub Desktop.
Read all the names and extensions from given and family names from a patient resource instance in HAPI FHIR.
Patient fhirPatient = ...
for (HumanName name : fhirPatient.getName())
{
// family names with extensions
StringType familyElement = name.getFamilyElement();
if (familyElement != null) {
System.out.println("Family: " + familyElement.getValue());
for (Extension ext : familyElement.getExtension()) {
System.out.println(" Family Extension: " + ext.getUrl() + " = " + ext.getValue());
}
}
// Given names with extensions
for (StringType givenElement : name.getGiven()) {
System.out.println("Given: " + givenElement.getValue());
for (Extension ext : givenElement.getExtension()) {
System.out.println(" Given Extension: " + ext.getUrl() + " = " + ext.getValue());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment