-
Notifications
You must be signed in to change notification settings - Fork 6
NIAD-3217 - Send Observation (Test Result) when they do not have a Specimen attached to them
#963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
91 commits
Select commit
Hold shift + click to select a range
463956b
[NIAD-3217] Add test data
martin-nhs 1fdc9e0
[NIAD-3217] Rename test data filename for clarity
martin-nhs 2b17133
[NIAD-3217] Create initial test skeleton
martin-nhs 80b83cf
Merge branch 'main' into NIAD-3217
martin-nhs e032788
[NIAD-3217] Basic test implementation, fixed test data
martin-nhs 65d36d0
Minor changes.
Alex-Nita df9bd62
Adding JSON and XML files for unit tests
stevenmccullaghmadetech 48c16b7
Adding missing specimen
stevenmccullaghmadetech 4da233e
Adding basic test case
stevenmccullaghmadetech ff830ba
Adjust format of JSON
stevenmccullaghmadetech 3a7c375
Fixed test data
Alex-Nita 553d2e2
Added logic for creating and assigning dummy specimens.
Alex-Nita 7a5be66
Improve test name
stevenmccullaghmadetech af99965
Added better assertion.
Alex-Nita 5032009
Cleaner
stevenmccullaghmadetech f5afeb8
Break lines up for readability.
stevenmccullaghmadetech fd5bf52
Adding conditions for both types of test result, linked and unlinked
stevenmccullaghmadetech 5b51bde
Changed matches to contains
stevenmccullaghmadetech a08509e
Check the ids of dummy specimens map to the expected observations
stevenmccullaghmadetech 983e4ab
Making code more DRY.
stevenmccullaghmadetech 84dce4a
Refactoring the logic for assigning specimens to observations.
Alex-Nita 79dffa3
Merge branch 'NIAD-3217' of https://github.com/NHSDigital/integration…
Alex-Nita d511258
Added check for orphaned results before dummy specimens are assigned.
Alex-Nita cc146ea
Added better marking in tests for mapped specimens.
Alex-Nita 71cdc9f
Fixed test data from ehr extract mapper.
Alex-Nita b978804
Merge branch 'main' into NIAD-3217
Alex-Nita 57f792f
Fixed checkstyle violations
Alex-Nita 5aeea1e
Fixed checkstyle violations in the test file
Alex-Nita 4370cba
Updating test result XML
stevenmccullaghmadetech 4002ef9
Updating test result XML
stevenmccullaghmadetech b4abbbc
Merge branch 'NIAD-3217' of https://github.com/NHSDigital/integration…
Alex-Nita 38b9eef
Reverted some unnecessary changes
Alex-Nita 5641eb7
Reverted unnecessary change
Alex-Nita c2433e3
Reverted unnecessary change
Alex-Nita 05b6209
Reverted unnecessary change
Alex-Nita 545ecab
Scenario: Diagnostic Report with no Specimen or Observation
stevenmccullaghmadetech dd1a5fc
Updating mapped dummy observations test cases
stevenmccullaghmadetech fb9d12d
Linking dummy observations to dummy specimen
stevenmccullaghmadetech 663c0a3
Adding injected dummy specimen
stevenmccullaghmadetech 2f29e6c
Adding injected block from scenario where the only changes made are t…
stevenmccullaghmadetech 13c6ea7
Removing superfluous XML, generated by our other changed tests.
stevenmccullaghmadetech 6a270e4
Removed unused import
Alex-Nita 92b9c30
Adjusting indention
stevenmccullaghmadetech a1163fc
Adjusting indentation
stevenmccullaghmadetech 297b9d7
Adjusting indentation
stevenmccullaghmadetech 5f5d31a
Adjust indentation
stevenmccullaghmadetech 6bf1f21
Adjusting indentation
stevenmccullaghmadetech f11a18b
Adjusting indentation
stevenmccullaghmadetech 52dda17
Adjusting indentation
stevenmccullaghmadetech 3a16cbf
Adjust indentation
stevenmccullaghmadetech 03eea81
Adjusting whitespace
stevenmccullaghmadetech d81a55b
Fixing whitespace
stevenmccullaghmadetech 05887ca
Adjust whitespace
stevenmccullaghmadetech 22c05ea
Adjust Whitespace
Alex-Nita 2082116
Adjust Whitespace
Alex-Nita 1ef50df
Adjust Whitespace
Alex-Nita cccf39c
Adjust Whitespace
Alex-Nita 844cb90
Adjust Whitespace
Alex-Nita fdc3bd7
Adjust whitespace
Alex-Nita eb8eb57
Adjust Whitespace
Alex-Nita 1f4bfbe
Adjust Whitespace
Alex-Nita bfff936
Adjust Whitespace
Alex-Nita 84cc604
Adjust Whitespace
Alex-Nita e0ffd56
Adjusted Whitespace
Alex-Nita 0518832
Adjusted Whitespace
Alex-Nita b168f8b
Adjusted Whitespace
Alex-Nita e589b9b
Adjusted Whitespace
Alex-Nita b4090a6
Adjusted Whitespace
Alex-Nita 656e384
Adjusted Whitespace
Alex-Nita 5a854f1
Adjusted Whitespace
Alex-Nita 913631b
Adjusted Whitespace
Alex-Nita ea96588
Merge remote-tracking branch 'origin/main' into NIAD-3217
adrianclay 9b83a08
Remove test file which appears to be duplicate
adrianclay 97d6bd4
Remove unused test file
adrianclay baf4a8a
Remove unused Observation
adrianclay 58eb397
Remove unused Observation
adrianclay b7a998d
Replaces references to Observation for one which already exists in bu…
adrianclay b53d885
Reverted test test files with filing comments associated with specimens
Alex-Nita f630524
Removed filtering of filing comments from Specimen mapper and added i…
Alex-Nita 99f4f83
Moved filing comment filter to diagnostic report mapper
Alex-Nita 75738f2
Reverted expected-components-1.xml
Alex-Nita 9051dbb
Updated test file
Alex-Nita 69b58ca
Renamed methods.
Alex-Nita 93c2eb9
Renamed Variable
Alex-Nita b7e60d6
Renamed variable
Alex-Nita fea624b
Fixed indentation
Alex-Nita db4bec9
Fixed whitespace
Alex-Nita efddaef
Removed redundant test.
Alex-Nita 47656e5
Add new lines to make test file clearer
adrianclay c07f007
Refactoring
Alex-Nita 30ad880
Added changelog entry
Alex-Nita File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,11 @@ | |
| import static uk.nhs.adaptors.gp2gp.ehr.mapper.CommentType.LABORATORY_RESULT_COMMENT; | ||
| import static uk.nhs.adaptors.gp2gp.ehr.mapper.diagnosticreport.ObservationMapper.NARRATIVE_STATEMENT_TEMPLATE; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.function.Predicate; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
|
|
@@ -73,13 +75,19 @@ public class DiagnosticReportMapper { | |
| private final ConfidentialityService confidentialityService; | ||
|
|
||
| public String mapDiagnosticReportToCompoundStatement(DiagnosticReport diagnosticReport) { | ||
| List<Specimen> specimens = fetchSpecimens(diagnosticReport); | ||
| List<Observation> observations = fetchObservations(diagnosticReport); | ||
| List<Specimen> specimens = fetchSpecimens(diagnosticReport, observations); | ||
| final IdMapper idMapper = messageContext.getIdMapper(); | ||
| markObservationsAsProcessed(idMapper, observations); | ||
|
|
||
| List<Observation> observationsExcludingFilingComments = assignDummySpecimensToObservationsWithNoSpecimen( | ||
| observations.stream() | ||
| .filter(Predicate.not(DiagnosticReportMapper::isFilingComment)) | ||
| .toList(), | ||
| specimens); | ||
|
|
||
| String mappedSpecimens = specimens.stream() | ||
| .map(specimen -> specimenMapper.mapSpecimenToCompoundStatement(specimen, observations, diagnosticReport)) | ||
| .map(specimen -> specimenMapper.mapSpecimenToCompoundStatement(specimen, observationsExcludingFilingComments, diagnosticReport)) | ||
| .collect(Collectors.joining()); | ||
|
|
||
| String reportLevelNarrativeStatements = prepareReportLevelNarrativeStatements(diagnosticReport, observations); | ||
|
|
@@ -113,21 +121,60 @@ private String fetchExtensionId(List<Identifier> identifiers) { | |
| .orElse(StringUtils.EMPTY); | ||
| } | ||
|
|
||
| private List<Specimen> fetchSpecimens(DiagnosticReport diagnosticReport) { | ||
| if (!diagnosticReport.hasSpecimen()) { | ||
| return Collections.singletonList(generateDefaultSpecimen(diagnosticReport)); | ||
| private List<Specimen> fetchSpecimens(DiagnosticReport diagnosticReport, List<Observation> observations) { | ||
|
|
||
| List<Specimen> specimens = new ArrayList<>(); | ||
|
|
||
| // At least one specimen is required to exist for any DiagnosticReport, according to the mim | ||
| if (!diagnosticReport.hasSpecimen() || hasObservationsWithoutSpecimen(observations)) { | ||
| specimens.add(generateDummySpecimen(diagnosticReport)); | ||
| } | ||
|
|
||
| var inputBundleHolder = messageContext.getInputBundleHolder(); | ||
| return diagnosticReport.getSpecimen() | ||
| List<Specimen> nonDummySpecimens = diagnosticReport.getSpecimen() | ||
| .stream() | ||
| .map(specimenReference -> inputBundleHolder.getResource(specimenReference.getReferenceElement())) | ||
| .flatMap(Optional::stream) | ||
| .map(Specimen.class::cast) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| specimens.addAll(nonDummySpecimens); | ||
|
|
||
| return specimens; | ||
|
|
||
| } | ||
|
|
||
| private boolean hasObservationsWithoutSpecimen(List<Observation> observations) { | ||
| return observations | ||
| .stream() | ||
| .filter(observation -> !isFilingComment(observation)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this line is super well tested. |
||
| .anyMatch(observation -> !observation.hasSpecimen()); | ||
| } | ||
|
|
||
| private List<Observation> assignDummySpecimensToObservationsWithNoSpecimen( | ||
| List<Observation> observations, List<Specimen> specimens) { | ||
|
|
||
| if (!hasObservationsWithoutSpecimen(observations)) { | ||
| return observations; | ||
| } | ||
|
|
||
| // The assumption was made that all test results without a specimen will have the same dummy specimen referenced | ||
| Specimen dummySpecimen = specimens.stream() | ||
| .filter(specimen -> specimen.getId().contains(DUMMY_SPECIMEN_ID_PREFIX)) | ||
| .toList().getFirst(); | ||
|
|
||
| Reference dummySpecimenReference = new Reference(dummySpecimen.getId()); | ||
|
|
||
| for (Observation observation : observations) { | ||
| if (!observation.hasSpecimen() && !isFilingComment(observation)) { | ||
| observation.setSpecimen(dummySpecimenReference); | ||
| } | ||
| } | ||
|
|
||
| return observations; | ||
| } | ||
|
|
||
| private Specimen generateDefaultSpecimen(DiagnosticReport diagnosticReport) { | ||
| private Specimen generateDummySpecimen(DiagnosticReport diagnosticReport) { | ||
| Specimen specimen = new Specimen(); | ||
|
|
||
| specimen.setId(DUMMY_SPECIMEN_ID_PREFIX + randomIdGeneratorService.createNewId()); | ||
|
|
||
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
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
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
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
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
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
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
25 changes: 0 additions & 25 deletions
25
...er/diagnosticreport/diagnostic-report-with-one-specimen-and-one-unrelated-observation.xml
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
...gnostic-report-with-one-specimen-one-linked-observation-and-one-unlinked-observation.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| "resourceType": "DiagnosticReport", | ||
| "id": "96B93E28-293D-46E7-B4C2-D477EEBF7098", | ||
| "meta": { | ||
| "profile": [ | ||
| "https://fhir.nhs.uk/STU3/StructureDefinition/CareConnect-GPC-DiagnosticReport-1" | ||
| ] | ||
| }, | ||
| "identifier": [ | ||
| { | ||
| "system": "https://EMISWeb/A82038", | ||
| "value": "96B93E28-293D-46E7-B4C2-D477EEBF7098" | ||
| } | ||
| ], | ||
| "status": "unknown", | ||
| "category": { | ||
| "coding": [ | ||
| { | ||
| "system": "http://hl7.org/fhir/v2/0074", | ||
| "code": "PAT", | ||
| "display": "Pathology (gross & histopath, not surgical)" | ||
| } | ||
| ] | ||
| }, | ||
| "code": { | ||
| "coding": [ | ||
| { | ||
| "system": "http://snomed.info/sct", | ||
| "code": "721981007", | ||
| "display": "Diagnostic studies report" | ||
| } | ||
| ] | ||
| }, | ||
| "subject": { | ||
| "reference": "Patient/DAED5527-1985-45D9-993E-C5FF51F36828" | ||
| }, | ||
| "issued": "2010-02-25T15:41:00+00:00", | ||
| "specimen": [{ | ||
| "reference": "Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-0" | ||
| }], | ||
| "result": [ | ||
| { "reference": "Observation/B7F05EA7-A1A4-48C0-9C4C-CDB5768796B2" }, | ||
| { "reference": "Observation/TestResult-WithoutSpecimenReference" } | ||
| ] | ||
| } |
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where in the
mimdid you see that?