use of de.symeda.sormas.api.labmessage.LabMessageDto in project SORMAS-Project by hzi-braunschweig.
the class RelatedLabMessageHandler method getRelatedEntities.
// related entities
public RelatedEntities getRelatedEntities(LabMessageDto labMessage) {
String reportId = labMessage.getReportId();
String labSampleId = labMessage.getLabSampleId();
if (StringUtils.isBlank(reportId) || StringUtils.isBlank(labSampleId)) {
return null;
}
List<SampleDto> relatedSamples = FacadeProvider.getSampleFacade().getByLabSampleId(labSampleId);
if (relatedSamples.size() != 1) {
return null;
}
SampleDto relatedSample = relatedSamples.get(0);
List<LabMessageDto> relatedLabMessages = FacadeProvider.getLabMessageFacade().getForSample(relatedSample.toReference()).stream().filter(otherLabMessage -> reportId.equals(otherLabMessage.getReportId()) && LabMessageStatus.PROCESSED.equals(otherLabMessage.getStatus())).collect(Collectors.toList());
PersonDto relatedPerson;
if (relatedSample.getAssociatedCase() != null) {
relatedPerson = FacadeProvider.getPersonFacade().getByContext(PersonContext.CASE, relatedSample.getAssociatedCase().getUuid());
} else if (relatedSample.getAssociatedContact() != null) {
relatedPerson = FacadeProvider.getPersonFacade().getByContext(PersonContext.CONTACT, relatedSample.getAssociatedContact().getUuid());
} else {
relatedPerson = FacadeProvider.getPersonFacade().getByContext(PersonContext.EVENT_PARTICIPANT, relatedSample.getAssociatedEventParticipant().getUuid());
}
List<PathogenTestDto> relatedPathogenTests = new ArrayList<>();
List<TestReportDto> unmatchedTestReports = new ArrayList<>();
boolean pathogenTestMisMatch = false;
List<TestReportDto> testReports = labMessage.getTestReports();
List<PathogenTestDto> samplePathogenTests = FacadeProvider.getPathogenTestFacade().getAllBySample(relatedSample.toReference());
for (TestReportDto testReport : testReports) {
List<PathogenTestDto> matchedPathogenTests = StringUtils.isBlank(testReport.getExternalId()) ? Collections.emptyList() : samplePathogenTests.stream().filter(pt -> matchPathogenTest(testReport, pt)).collect(Collectors.toList());
if (matchedPathogenTests.isEmpty()) {
unmatchedTestReports.add(testReport);
} else if (matchedPathogenTests.size() == 1) {
relatedPathogenTests.add(matchedPathogenTests.get(0));
} else {
unmatchedTestReports.add(testReport);
pathogenTestMisMatch = true;
}
}
return new RelatedEntities(relatedSample, relatedPerson, relatedPathogenTests, unmatchedTestReports, pathogenTestMisMatch, CollectionUtils.isNotEmpty(relatedLabMessages));
}
use of de.symeda.sormas.api.labmessage.LabMessageDto in project SORMAS-Project by hzi-braunschweig.
the class LabMessageController method showCorrectionWindow.
private <T> void showCorrectionWindow(LabMessageDto labMessage, String titleTag, CorrectionPanel<T> correctionPanel, Consumer<T> save, RelatedLabMessageHandlerChain chain) {
Window window = VaadinUiUtil.createPopupWindow();
correctionPanel.setCancelListener((e) -> {
chain.cancel();
window.close();
});
correctionPanel.setDiscardListener(() -> {
if (FacadeProvider.getLabMessageFacade().isProcessed(labMessage.getUuid())) {
showAlreadyProcessedPopup(null, false);
correctionPanel.disableContinueButtons();
} else {
chain.next(false);
window.close();
}
});
correctionPanel.setCommitListener((updated) -> {
if (FacadeProvider.getLabMessageFacade().isProcessed(labMessage.getUuid())) {
showAlreadyProcessedPopup(null, false);
correctionPanel.disableContinueButtons();
} else {
save.accept(updated);
chain.next(true);
window.close();
}
});
window.addCloseListener(e -> {
if (!chain.done()) {
chain.cancel();
}
});
HorizontalLayout toolbar = new HorizontalLayout(ButtonHelper.createIconButton(null, VaadinIcons.EYE, e -> showLabMessage(labMessage.getUuid(), false, null)));
toolbar.setMargin(new MarginInfo(true, true, false, true));
VerticalLayout content = new VerticalLayout(toolbar, correctionPanel);
content.setMargin(false);
content.setSpacing(false);
content.setExpandRatio(toolbar, 0);
content.setExpandRatio(correctionPanel, 1);
content.setSizeFull();
window.setContent(content);
window.setSizeFull();
window.setCaption(I18nProperties.getString(titleTag));
UI.getCurrent().addWindow(window);
}
use of de.symeda.sormas.api.labmessage.LabMessageDto in project SORMAS-Project by hzi-braunschweig.
the class RelatedLabMessageHandler method handle.
public CompletionStage<HandlerResult> handle(LabMessageDto labMessage) {
RelatedEntities relatedEntities = getRelatedEntities(labMessage);
if (relatedEntities == null) {
return CompletableFuture.completedFuture(HandlerResult.NOT_HANDLED);
}
LabMessageMapper mapper = LabMessageMapper.forLabMessage(labMessage);
ChainHandler chainHandler = new ChainHandler();
Supplier<CompletionStage<Boolean>> correctionFlowConfirmationSupplier = createCachedCorrectionFlowConfirmationSupplier();
CompletionStage<HandlerResult> correctionFlow = CompletableFuture.completedFuture(HandlerResult.NOT_HANDLED);
if (relatedEntities.relatedLabMessagesFound && !relatedEntities.pathogenTestMisMatch) {
correctionFlow = correctionFlow.thenCompose(result -> handlePersonCorrection(labMessage, relatedEntities.person, mapper, correctionFlowConfirmationSupplier, result, chainHandler)).thenCompose((personCorrectionResult) -> handleSampleCorrection(labMessage, relatedEntities.sample, mapper, correctionFlowConfirmationSupplier, personCorrectionResult, chainHandler));
for (PathogenTestDto p : relatedEntities.pathogenTests) {
Optional<TestReportDto> testReport = labMessage.getTestReports().stream().filter(t -> matchPathogenTest(t, p)).findFirst();
if (testReport.isPresent()) {
correctionFlow = correctionFlow.thenCompose((testCorrectionResult) -> handlePathogenTestCorrection(labMessage, testReport.get(), p, mapper, correctionFlowConfirmationSupplier, testCorrectionResult, chainHandler));
}
}
for (TestReportDto r : relatedEntities.unmatchedTestReports) {
correctionFlow = correctionFlow.thenCompose((result) -> {
if (result == HandlerResult.HANDLED) {
// do not handle pathogen test creation if there were no corrections in the lab message
return handlePathogenTestCreation(labMessage, r, relatedEntities.sample, correctionFlowConfirmationSupplier, chainHandler);
}
return CompletableFuture.completedFuture(result);
});
}
}
return correctionFlow.thenCompose((result) -> {
if (result == HandlerResult.HANDLED) {
// ask to continue post processing
return continueProcessingConfirmation.apply(labMessage, relatedEntities.sample.toReference()).thenCompose((doPostProcess) -> CompletableFuture.completedFuture(CorrectionResult.of(result, doPostProcess)));
}
// if no corrections found, then continue
return CompletableFuture.completedFuture(CorrectionResult.of(result, true));
}).thenCompose((correctionResult) -> {
if (correctionResult.shouldContinue) {
return shortcutFlowConfirmation.apply(relatedEntities.relatedLabMessagesFound).thenCompose(confirmed -> {
if (confirmed) {
return chainHandler.run((chain) -> shortcutHandler.handle(labMessage, relatedEntities.sample, chain)).thenCompose(handled -> CompletableFuture.completedFuture(HandlerResult.HANDLED));
}
return CompletableFuture.completedFuture(HandlerResult.CONTINUE);
});
}
return CompletableFuture.completedFuture(correctionResult.result);
}).exceptionally(e -> {
if (e.getCause() instanceof CancellationException) {
return chainHandler.savePerformed ? HandlerResult.CANCELED_WITH_UPDATES : HandlerResult.CANCELED;
}
throw (RuntimeException) e;
});
}
use of de.symeda.sormas.api.labmessage.LabMessageDto in project SORMAS-Project by hzi-braunschweig.
the class LabMessageFacadeEjb method toDto.
public LabMessageDto toDto(LabMessage source) {
if (source == null) {
return null;
}
LabMessageDto target = new LabMessageDto();
DtoHelper.fillDto(target, source);
target.setType(source.getType());
target.setLabMessageDetails(source.getLabMessageDetails());
target.setLabSampleId(source.getLabSampleId());
target.setTestedDisease(source.getTestedDisease());
target.setMessageDateTime(source.getMessageDateTime());
target.setPersonBirthDateDD(source.getPersonBirthDateDD());
target.setPersonBirthDateMM(source.getPersonBirthDateMM());
target.setPersonBirthDateYYYY(source.getPersonBirthDateYYYY());
target.setPersonCity(source.getPersonCity());
target.setPersonFirstName(source.getPersonFirstName());
target.setPersonHouseNumber(source.getPersonHouseNumber());
target.setPersonLastName(source.getPersonLastName());
target.setPersonPostalCode(source.getPersonPostalCode());
target.setPersonSex(source.getPersonSex());
target.setPersonStreet(source.getPersonStreet());
target.setPersonPhone(source.getPersonPhone());
target.setPersonEmail(source.getPersonEmail());
target.setLabCity(source.getLabCity());
target.setLabExternalId(source.getLabExternalId());
target.setLabName(source.getLabName());
target.setLabPostalCode(source.getLabPostalCode());
target.setStatus(source.getStatus());
target.setSampleDateTime(source.getSampleDateTime());
target.setSampleMaterial(source.getSampleMaterial());
target.setSampleMaterialText(source.getSampleMaterialText());
target.setSampleReceivedDate(source.getSampleReceivedDate());
target.setSpecimenCondition(source.getSpecimenCondition());
if (source.getTestReports() != null) {
target.setTestReports(source.getTestReports().stream().map(t -> TestReportFacadeEjb.toDto(t)).collect(toList()));
}
target.setReportId(source.getReportId());
target.setSampleOverallTestResult(source.getSampleOverallTestResult());
if (source.getSample() != null) {
target.setSample(source.getSample().toReference());
}
if (source.getAssignee() != null) {
target.setAssignee(source.getAssignee().toReference());
}
return target;
}
use of de.symeda.sormas.api.labmessage.LabMessageDto in project SORMAS-Project by hzi-braunschweig.
the class SampleServiceTest method testSamplePermanentDeletion.
@Test
public void testSamplePermanentDeletion() {
TestDataCreator.RDCF rdcf = creator.createRDCF();
UserDto user = creator.createUser(rdcf, UserRole.ADMIN, UserRole.NATIONAL_USER);
PersonDto person = creator.createPerson();
CaseDataDto caze = creator.createCase(user.toReference(), person.toReference(), rdcf);
SampleDto sample = creator.createSample(caze.toReference(), user.toReference(), rdcf.facility);
SampleDto referralSample = creator.createSample(caze.toReference(), user.toReference(), rdcf.facility, s -> s.setReferredTo(sample.toReference()));
creator.createPathogenTest(sample.toReference(), caze);
creator.createAdditionalTest(sample.toReference());
LabMessageDto labMessage = creator.createLabMessage(lm -> lm.setSample(sample.toReference()));
getSampleFacade().deleteSample(sample.toReference(), new DeletionDetails(DeletionReason.OTHER_REASON, "test reason"));
Sample sampleEntity = getSampleService().getByUuid(sample.getUuid());
List<PathogenTest> pathogenTests = getPathogenTestService().getAll();
assertEquals(2, getSampleService().count());
assertTrue(sampleEntity.isDeleted());
assertEquals(1, pathogenTests.size());
assertTrue(pathogenTests.get(0).isDeleted());
assertEquals(1, getAdditionalTestService().count());
assertNull(getSampleService().getByUuid(referralSample.getUuid()).getReferredTo());
assertNull(getLabMessageService().getByUuid(labMessage.getUuid()).getSample());
getSampleService().deletePermanent(getEntityAttached(sampleEntity));
assertEquals(1, getSampleService().count());
assertEquals(0, getPathogenTestService().count());
assertEquals(0, getAdditionalTestService().count());
assertEquals(1, getLabMessageService().count());
}
Aggregations