NIAD-3471 Support multiple given names in practitioner XML#1292
Open
MartinWheelerMT wants to merge 6 commits into
Open
NIAD-3471 Support multiple given names in practitioner XML#1292MartinWheelerMT wants to merge 6 commits into
MartinWheelerMT wants to merge 6 commits into
Conversation
- Changed EN.given field from String to List<String> to support multiple given name elements - Updated AgentDirectoryMapper to iterate over all given names and add each to FHIR HumanName - Added helper method getGivenNamesAsString() to concatenate multiple given names for text field - Updated hasNoName() to correctly check for given names in List structure - Updated JAXB schema test to work with List<String> given names - Added convenience method getFirstGiven() for backward compatibility - Added unit tests for multiple given names scenarios (with and without family name).
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the HL7 v3 JAXB schema model and translator mapping so practitioner names can capture multiple <given> elements and map them into FHIR HumanName.given correctly.
Changes:
- Updated
org.hl7.v3.ENto storegivenasList<String>(instead of a singleString) and adjusted schema unmarshalling test expectations. - Updated
AgentDirectoryMapperto add all given names intoHumanName.given, and to build thetextfield from concatenated given names when there is no family name. - Added/updated unit tests for multi-given scenarios; refactored a participant reference helper; added a changelog entry.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| schema/src/main/java/org/hl7/v3/EN.java | Changes JAXB model to support multiple given names via List<String>. |
| schema/src/test/java/JaxbTest.java | Updates assertions to match the new list-based given model. |
| gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/AgentDirectoryMapper.java | Maps multiple given names into FHIR and concatenates given names for HumanName.text. |
| gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/mapper/AgentDirectoryMapperTest.java | Adds tests for multiple given names and related scenarios. |
| gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/util/ParticipantReferenceUtil.java | Refactors participant2 reference mapping to a fluent Optional chain. |
| CHANGELOG.md | Documents the multiple-given-name mapping fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
166
to
172
| private static boolean hasNoName(PN name) { | ||
| var hasGiven = name != null && name.getGiven() != null && !name.getGiven().isEmpty(); | ||
| return name == null | ||
| || (StringUtils.isBlank(name.getFamily()) | ||
| && StringUtils.isBlank(name.getGiven()) | ||
| && !hasGiven | ||
| && StringUtils.isBlank(name.getPrefix())); | ||
| } |
Comment on lines
+255
to
+259
| @Test | ||
| public void When_MapAgentWithMultipleGivenAndFamilyName_Expect_AllGivenNamesInArray() { | ||
| var agentDirectoryXml = """ | ||
| <agentDirectory xmlns="urn:hl7-org:v3" classCode="AGNT"> | ||
| <part typeCode="PART"> |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
|
Images built and published to ECR using a Build Id of PR-1159-d5c5092 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Why
The adapter was unable to handle XML containing multiple fields for practitioner names. When an XML part contained multiple given names like:
The JSON output would only include a single given name:
{ "name": [{ "use": "official", "family": "Clarkson", "given": ["E"] // Only one given name captured }] }Root Cause
The JAXB-generated schema classes in org.hl7.v3.EN (which PN extends) only supported a single String field for given names:
protected String given;This meant when the XML was unmarshalled, JAXB could only capture one element, even though the XML schema (datatypes.xsd) defines the name parts as a element with maxOccurs="unbounded", allowing multiple instances.
Solution
1. Modified EN Class (schema/src/main/java/org/hl7/v3/EN.java)
Changed the given field to support multiple values:
// Before:
protected String given;// After:
protected List<String> given;Updated the getter method to return a List:
Added a convenience method for backward compatibility:
2. Updated AgentDirectoryMapper (gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/AgentDirectoryMapper.java)
Modified the mapper to iterate over all given names and add them to the FHIR HumanName:
Added a helper method to concatenate given names for the text field when there's no family name:
3. Updated Tests
Updated JaxbTest (schema/src/test/java/JaxbTest.java)
Changed the test to check for a list of given names:
// Before:
assertThat(person.getName().getGiven()).isEqualTo("Peter");// After:
assertThat(person.getName().getGiven()).hasSize(1);assertThat(person.getName().getGiven().getFirst()).isEqualTo("Peter");Updated and Added Tests in AgentDirectoryMapperTest
Updated the test When_MapAgentDirectoryOnlyAgentPersonWithNameElementWithOnlyGiven_Expect_TextSetToGiven() to correctly test the scenario with both multiple given names and a family name.
Added new test When_MapAgentDirectoryOnlyAgentPersonWithMultipleGivenNamesNoFamily_Expect_TextSetToGiven() to test the case where there are multiple given names but no family name.
Added new test When_MapAgentWithMultipleGivenAndFamilyName_Expect_AllGivenNamesInArray() to test the exact user scenario with ID and all assertions.
Expected Output After Fix
For the XML example provided:
The JSON output is now:
{ "resource": { "resourceType": "Practitioner", "id": "CD8E40B3-6A3C-11F1-AE7C-00155D75C807", "meta": { "profile": ["https://fhir.nhs.uk/STU3/StructureDefinition/CareConnect-GPC-Practitioner-1"] }, "name": [{ "use": "official", "family": "Clarkson", "given": ["Minire", "E"] }] } }The changes are backward compatible:
Type of change
Please delete options that are not relevant.
Checklist:
Co-authored-by: GitHub Copilot noreply@github.com