Refactor AllergyStructureMapper#1430
Draft
MartinWheelerMT wants to merge 4 commits into
Draft
Conversation
* Move pertinent information mapping to separate mapper `PertinentInformationAllergyMapper`, in the same way it is handled for observation values. * Remove enum -> primitive string mapping when building the category and use the fhir model enums for comparison instead. * Inject new mapper into class and use real implementation in tests as classes. * Tidy code for readability.
|
|
There was a problem hiding this comment.
Pull request overview
This PR refactors allergy mapping by extracting “pertinent information” string-building logic out of AllergyStructureMapper into a dedicated PertinentInformationAllergyMapper, and updates the mapper wiring in unit/component/UAT tests accordingly.
Changes:
- Introduced
PertinentInformationAllergyMapperand moved pertinent-information construction logic into it. - Refactored
AllergyStructureMapperto delegate pertinent-information generation and to compare allergy categories using FHIR enums rather than primitive string values. - Updated tests to construct/inject the new mapper when instantiating
AllergyStructureMapper.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/PertinentInformationAllergyMapper.java | New component containing allergy pertinent-information mapping logic. |
| service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AllergyStructureMapper.java | Refactor to delegate pertinent information and use enum-based category checks; constructor updated. |
| service/src/test/java/uk/nhs/adaptors/gp2gp/uat/EhrExtractUATTest.java | Updates test wiring to pass the new mapper into AllergyStructureMapper. |
| service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EncounterComponentsMapperTest.java | Updates mapper construction to include PertinentInformationAllergyMapper. |
| service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/EhrExtractMapperComponentTest.java | Updates mapper construction to include PertinentInformationAllergyMapper. |
| service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AllergyStructureMapperTest.java | Updates AllergyStructureMapper instantiation to include PertinentInformationAllergyMapper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+96
to
+100
| if (allergyIntolerance.hasAsserter()) { | ||
| IIdType reference = allergyIntolerance.getAsserter().getReferenceElement(); | ||
| if (reference.getResourceType().equals(ResourceType.Patient.name())) { | ||
| return PATIENT_ASSERTER; | ||
| } else if (reference.getResourceType().equals(ResourceType.RelatedPerson.name())) { |
Comment on lines
+128
to
+132
| if (allergyIntolerance.hasRecorder()) { | ||
| IIdType reference = allergyIntolerance.getRecorder().getReferenceElement(); | ||
| if (reference.getResourceType().equals(ResourceType.Patient.name())) { | ||
| return PATIENT_RECORDER; | ||
| } |
Comment on lines
118
to
122
| private Optional<String> buildParticipant(Reference reference, ParticipantType participantType) { | ||
| if (reference.getReferenceElement().getResourceType().startsWith(ResourceType.Practitioner.name())) { | ||
| var authorReferenceId = messageContext.getAgentDirectory().getAgentId(reference); | ||
| return Optional.of(participantMapper.mapToParticipant(authorReferenceId, participantType)); | ||
| var resourceType = reference.getReferenceElement().getResourceType(); | ||
| if (!resourceType.startsWith(ResourceType.Practitioner.name())) { | ||
| return Optional.empty(); | ||
| } |
Comment on lines
146
to
149
| private boolean isValidAsserter(AllergyIntolerance allergyIntolerance) { | ||
| return allergyIntolerance.hasAsserter() | ||
| && allergyIntolerance.getAsserter().getReferenceElement().getResourceType().startsWith(ResourceType.Practitioner.name()); | ||
| } |
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
PertinentInformationAllergyMapper, in the same way it is handled for observation values.Why
AllergyStructureMapperwas difficult to read and contained code duplication, along with containing a number of pertinent information builders which could be refactored into another component and injected, in the same style as we handle the pertinent information forObservationvalues.Type of change
Please delete options that are not relevant.
Checklist: