-
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
Changes from 88 commits
463956b
1fdc9e0
2b17133
80b83cf
e032788
65d36d0
df9bd62
48c16b7
4da233e
ff830ba
3a7c375
553d2e2
7a5be66
af99965
5032009
f5afeb8
fd5bf52
5b51bde
a08509e
983e4ab
84dce4a
79dffa3
d511258
cc146ea
71cdc9f
b978804
57f792f
5aeea1e
4370cba
4002ef9
b4abbbc
38b9eef
5641eb7
c2433e3
05b6209
545ecab
dd1a5fc
fb9d12d
663c0a3
2f29e6c
13c6ea7
6a270e4
92b9c30
a1163fc
297b9d7
5f5d31a
6bf1f21
f11a18b
52dda17
3a16cbf
03eea81
d81a55b
05887ca
22c05ea
2082116
1ef50df
cccf39c
844cb90
fdc3bd7
eb8eb57
1f4bfbe
bfff936
84cc604
e0ffd56
0518832
b168f8b
e589b9b
b4090a6
656e384
5a854f1
913631b
ea96588
9b83a08
97d6bd4
baf4a8a
58eb397
b7a998d
b53d885
f630524
99f4f83
75738f2
9051dbb
69b58ca
93c2eb9
b7e60d6
fea624b
db4bec9
efddaef
47656e5
c07f007
30ad880
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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,18 @@ | |
| 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); | ||
| observations = assignDummySpecimensToObservationsWithNoSpecimen(observations, specimens); | ||
|
|
||
| List<Observation> observationsExcludingFilingComments = observations.stream() | ||
| .filter(Predicate.not(DiagnosticReportMapper::isFilingComment)) | ||
| .toList(); | ||
|
|
||
| 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 +120,60 @@ | |
| .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 | ||
|
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. Where in the |
||
| 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)) | ||
|
Check warning on line 162 in service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/DiagnosticReportMapper.java
|
||
| .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 was deleted.
| 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" } | ||
| ] | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.