use of de.symeda.sormas.api.sample.AdditionalTestDto in project SORMAS-Project by hzi-braunschweig.
the class AdditionalTestFacadeEjb method toDto.
public static AdditionalTestDto toDto(AdditionalTest source) {
if (source == null) {
return null;
}
AdditionalTestDto target = new AdditionalTestDto();
DtoHelper.fillDto(target, source);
target.setSample(SampleFacadeEjb.toReferenceDto(source.getSample()));
target.setTestDateTime(source.getTestDateTime());
target.setHaemoglobinuria(source.getHaemoglobinuria());
target.setProteinuria(source.getProteinuria());
target.setHematuria(source.getHematuria());
target.setArterialVenousGasPH(source.getArterialVenousGasPH());
target.setArterialVenousGasPco2(source.getArterialVenousGasPco2());
target.setArterialVenousGasPao2(source.getArterialVenousGasPao2());
target.setArterialVenousGasHco3(source.getArterialVenousGasHco3());
target.setGasOxygenTherapy(source.getGasOxygenTherapy());
target.setAltSgpt(source.getAltSgpt());
target.setAstSgot(source.getAstSgot());
target.setCreatinine(source.getCreatinine());
target.setPotassium(source.getPotassium());
target.setUrea(source.getUrea());
target.setHaemoglobin(source.getHaemoglobin());
target.setTotalBilirubin(source.getTotalBilirubin());
target.setConjBilirubin(source.getConjBilirubin());
target.setWbcCount(source.getWbcCount());
target.setPlatelets(source.getPlatelets());
target.setProthrombinTime(source.getPlatelets());
target.setOtherTestResults(source.getOtherTestResults());
return target;
}
use of de.symeda.sormas.api.sample.AdditionalTestDto in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjb method mergeCase.
private void mergeCase(CaseDataDto leadCaseData, CaseDataDto otherCaseData, boolean cloning) {
// 1 Merge Dtos
// 1.1 Case
copyDtoValues(leadCaseData, otherCaseData, cloning);
save(leadCaseData, !cloning, true, true, false);
// 1.2 Person - Only merge when the persons have different UUIDs
if (!cloning && !DataHelper.equal(leadCaseData.getPerson().getUuid(), otherCaseData.getPerson().getUuid())) {
PersonDto leadPerson = personFacade.getPersonByUuid(leadCaseData.getPerson().getUuid());
PersonDto otherPerson = personFacade.getPersonByUuid(otherCaseData.getPerson().getUuid());
personFacade.mergePerson(leadPerson, otherPerson);
} else {
assert (DataHelper.equal(leadCaseData.getPerson().getUuid(), otherCaseData.getPerson().getUuid()));
}
// 2 Change CaseReference
Case leadCase = service.getByUuid(leadCaseData.getUuid());
Case otherCase = service.getByUuid(otherCaseData.getUuid());
// 2.1 Contacts
List<Contact> contacts = contactService.findBy(new ContactCriteria().caze(otherCase.toReference()), null);
for (Contact contact : contacts) {
if (cloning) {
ContactDto newContact = ContactDto.build(leadCase.toReference(), leadCase.getDisease(), leadCase.getDiseaseDetails(), leadCase.getDiseaseVariant());
newContact.setPerson(new PersonReferenceDto(contact.getPerson().getUuid()));
DtoHelper.copyDtoValues(newContact, contactFacade.toDto(contact), cloning);
contactFacade.save(newContact, false, false);
} else {
// simply move existing entities to the merge target
contact.setCaze(leadCase);
contactService.ensurePersisted(contact);
}
}
// 2.2 Samples
List<Sample> samples = sampleService.findBy(new SampleCriteria().caze(otherCase.toReference()), null);
for (Sample sample : samples) {
if (cloning) {
SampleDto newSample = SampleDto.build(sample.getReportingUser().toReference(), leadCase.toReference());
DtoHelper.copyDtoValues(newSample, SampleFacadeEjb.toDto(sample), cloning);
sampleFacade.saveSample(newSample, false, true, true);
// 2.2.1 Pathogen Tests
for (PathogenTest pathogenTest : sample.getPathogenTests()) {
PathogenTestDto newPathogenTest = PathogenTestDto.build(newSample.toReference(), pathogenTest.getLabUser().toReference());
DtoHelper.copyDtoValues(newPathogenTest, PathogenTestFacadeEjbLocal.toDto(pathogenTest), cloning);
sampleTestFacade.savePathogenTest(newPathogenTest);
}
for (AdditionalTest additionalTest : sample.getAdditionalTests()) {
AdditionalTestDto newAdditionalTest = AdditionalTestDto.build(newSample.toReference());
DtoHelper.copyDtoValues(newAdditionalTest, AdditionalTestFacadeEjbLocal.toDto(additionalTest), cloning);
additionalTestFacade.saveAdditionalTest(newAdditionalTest);
}
} else {
// simply move existing entities to the merge target
sample.setAssociatedCase(leadCase);
sampleService.ensurePersisted(sample);
}
}
// 2.3 Tasks
if (!cloning) {
// simply move existing entities to the merge target
List<Task> tasks = taskService.findBy(new TaskCriteria().caze(new CaseReferenceDto(otherCase.getUuid())), true);
for (Task task : tasks) {
task.setCaze(leadCase);
taskService.ensurePersisted(task);
}
}
// 3 Change Therapy Reference
// 3.1 Treatments
List<Treatment> treatments = treatmentService.findBy(new TreatmentCriteria().therapy(new TherapyReferenceDto(otherCase.getTherapy().getUuid())));
TherapyReferenceDto leadCaseTherapyReference = new TherapyReferenceDto(leadCase.getTherapy().getUuid());
for (Treatment treatment : treatments) {
if (cloning) {
TreatmentDto newTreatment = TreatmentDto.build(leadCaseTherapyReference);
DtoHelper.copyDtoValues(newTreatment, TreatmentFacadeEjb.toDto(treatment), cloning);
treatmentFacade.saveTreatment(newTreatment);
} else {
// simply move existing entities to the merge target
treatment.setTherapy(leadCase.getTherapy());
treatmentService.ensurePersisted(treatment);
}
}
// 3.2 Prescriptions
List<Prescription> prescriptions = prescriptionService.findBy(new PrescriptionCriteria().therapy(new TherapyReferenceDto(otherCase.getTherapy().getUuid())));
for (Prescription prescription : prescriptions) {
if (cloning) {
PrescriptionDto newPrescription = PrescriptionDto.buildPrescription(leadCaseTherapyReference);
DtoHelper.copyDtoValues(newPrescription, PrescriptionFacadeEjb.toDto(prescription), cloning);
prescriptionFacade.savePrescription(newPrescription);
} else {
// simply move existing entities to the merge target
prescription.setTherapy(leadCase.getTherapy());
prescriptionService.ensurePersisted(prescription);
}
}
// 4 Change Clinical Course Reference
// 4.1 Clinical Visits
List<ClinicalVisit> clinicalVisits = clinicalVisitService.findBy(new ClinicalVisitCriteria().clinicalCourse(new ClinicalCourseReferenceDto(otherCase.getClinicalCourse().getUuid())));
for (ClinicalVisit clinicalVisit : clinicalVisits) {
if (cloning) {
ClinicalVisitDto newClinicalVisit = ClinicalVisitDto.build(leadCaseData.getClinicalCourse().toReference(), leadCase.getDisease());
DtoHelper.copyDtoValues(newClinicalVisit, ClinicalVisitFacadeEjb.toDto(clinicalVisit), cloning);
clinicalVisitFacade.saveClinicalVisit(newClinicalVisit, leadCase.getUuid(), false);
} else {
// simply move existing entities to the merge target
clinicalVisit.setClinicalCourse(leadCase.getClinicalCourse());
clinicalVisitService.ensurePersisted(clinicalVisit);
}
}
// (set the person and the disease of the visit, saveVisit does the rest)
for (VisitDto otherVisit : otherCase.getVisits().stream().map(VisitFacadeEjb::toDto).collect(Collectors.toList())) {
otherVisit.setPerson(leadCaseData.getPerson());
otherVisit.setDisease(leadCaseData.getDisease());
visitFacade.saveVisit(otherVisit);
}
// 6 Documents
List<Document> documents = documentService.getRelatedToEntity(DocumentRelatedEntityType.CASE, otherCase.getUuid());
for (Document document : documents) {
document.setRelatedEntityUuid(leadCaseData.getUuid());
documentService.ensurePersisted(document);
}
// 7 Persist Event links through eventparticipants
Set<EventParticipant> eventParticipants = otherCase.getEventParticipants();
for (EventParticipant eventParticipant : eventParticipants) {
eventParticipant.setResultingCase(leadCase);
eventParticipantService.ensurePersisted(eventParticipant);
}
otherCase.getEventParticipants().clear();
// 8 Exposures - Make sure there are no two probable infection environments
// if there are more than 2 exposures marked as probable infection environment, find the one that originates from the otherCase and set it to false
// the one originating from the otherCase should always be found at the higher index
List<Exposure> probableExposuresList = leadCase.getEpiData().getExposures().stream().filter(Exposure::isProbableInfectionEnvironment).collect(Collectors.toList());
while (probableExposuresList.size() >= 2) {
// should never be > 2, but still make sure to set all but one exposures to false
probableExposuresList.get(probableExposuresList.size() - 1).setProbableInfectionEnvironment(false);
exposureService.ensurePersisted(probableExposuresList.get(probableExposuresList.size() - 1));
probableExposuresList.remove(probableExposuresList.size() - 1);
}
// 9 Reports
List<SurveillanceReport> surveillanceReports = surveillanceReportService.getByCaseUuids(Collections.singletonList(otherCase.getUuid()));
surveillanceReports.forEach(surveillanceReport -> {
SurveillanceReportDto surveillanceReportDto = SurveillanceReportFacadeEjb.toDto(surveillanceReport);
surveillanceReportDto.setCaze(leadCase.toReference());
surveillanceReportFacade.saveSurveillanceReport(surveillanceReportDto);
});
// 10 Activity as case
final EpiData otherEpiData = otherCase.getEpiData();
if (otherEpiData != null && YesNoUnknown.YES == otherEpiData.getActivityAsCaseDetailsKnown() && CollectionUtils.isNotEmpty(otherEpiData.getActivitiesAsCase())) {
final EpiData leadEpiData = leadCase.getEpiData();
leadEpiData.setActivityAsCaseDetailsKnown(YesNoUnknown.YES);
epiDataService.ensurePersisted(leadEpiData);
}
// Travel entries reference
List<TravelEntry> travelEntries = travelEntryService.getAllByResultingCase(otherCase);
travelEntries.forEach(t -> {
t.setResultingCase(leadCase);
travelEntryService.ensurePersisted(t);
});
}
use of de.symeda.sormas.api.sample.AdditionalTestDto in project SORMAS-Project by hzi-braunschweig.
the class AdditionalTestList method reload.
@Override
public void reload() {
List<AdditionalTestDto> additionalTests = ControllerProvider.getAdditionalTestController().getAdditionalTestsBySample(sampleUuid);
setEntries(additionalTests);
if (!additionalTests.isEmpty()) {
showPage(1);
} else {
listLayout.removeAllComponents();
updatePaginationLayout();
Label noAdditionalTestsLabel = new Label(I18nProperties.getString(Strings.infoNoAdditionalTests));
listLayout.addComponent(noAdditionalTestsLabel);
}
}
use of de.symeda.sormas.api.sample.AdditionalTestDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventFacadeEjbTest method testSaveSharedEventsWithSamples.
@Test
public void testSaveSharedEventsWithSamples() throws SormasToSormasException, SormasToSormasValidationException {
FacilityDto remoteLab = FacilityDto.build();
remoteLab.setName("Test Lab");
FacilityDto localLab = creator.createFacility("Test Lab", rdcf.region, rdcf.district, null, FacilityType.LABORATORY);
EventDto event = createEventDto(rdcf);
UserDto sampleUser = UserDto.build();
EventParticipantDto eventParticipant = createEventParticipantDto(event.toReference(), sampleUser.toReference(), rdcf);
SampleDto sample = createSample(eventParticipant.toReference(), sampleUser.toReference(), remoteLab.toReference());
sample.setLabSampleID("Test lab sample id");
PathogenTestDto pathogenTest = PathogenTestDto.build(sample, sampleUser);
pathogenTest.setTestDateTime(new Date());
pathogenTest.setLab(remoteLab.toReference());
pathogenTest.setTestType(PathogenTestType.RAPID_TEST);
pathogenTest.setTestResult(PathogenTestResultType.PENDING);
AdditionalTestDto additionalTest = AdditionalTestDto.build(sample.toReference());
additionalTest.setTestDateTime(new Date());
additionalTest.setHaemoglobin(0.2F);
additionalTest.setConjBilirubin(0.3F);
SormasToSormasDto shareData = new SormasToSormasDto();
shareData.setOriginInfo(createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, false));
shareData.setEvents(Collections.singletonList(new SormasToSormasEventDto(event)));
shareData.setEventParticipants(Collections.singletonList(new SormasToSormasEventParticipantDto(eventParticipant)));
shareData.setSamples(Collections.singletonList(new SormasToSormasSampleDto(sample, Collections.singletonList(pathogenTest), Collections.singletonList(additionalTest))));
SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
getSormasToSormasEventFacade().saveSharedEntities(encryptedData);
SampleDto savedSample = getSampleFacade().getSampleByUuid(sample.getUuid());
assertThat(savedSample, is(notNullValue()));
assertThat(savedSample.getAssociatedEventParticipant(), is(eventParticipant.toReference()));
assertThat(savedSample.getSampleMaterial(), is(SampleMaterial.BLOOD));
assertThat(savedSample.getLab(), is(localLab.toReference()));
assertThat(savedSample.getLabSampleID(), is("Test lab sample id"));
assertThat(savedSample.getSormasToSormasOriginInfo().getOrganizationId(), is(DEFAULT_SERVER_ID));
assertThat(savedSample.getSormasToSormasOriginInfo().getSenderName(), is("John doe"));
PathogenTestDto savedPathogenTest = getPathogenTestFacade().getByUuid(pathogenTest.getUuid());
assertThat(savedPathogenTest, is(notNullValue()));
assertThat(savedPathogenTest.getLab(), is(localLab.toReference()));
assertThat(savedPathogenTest.getTestType(), is(PathogenTestType.RAPID_TEST));
assertThat(savedPathogenTest.getTestResult(), is(PathogenTestResultType.PENDING));
AdditionalTestDto savedAdditionalTest = getAdditionalTestFacade().getByUuid(additionalTest.getUuid());
assertThat(savedAdditionalTest, is(notNullValue()));
assertThat(savedAdditionalTest.getHaemoglobin(), is(0.2F));
assertThat(savedAdditionalTest.getConjBilirubin(), is(0.3F));
}
use of de.symeda.sormas.api.sample.AdditionalTestDto in project SORMAS-Project by hzi-braunschweig.
the class SampleFacadeEjbTest method testAllSamplesDeletionWithMultipleAdditionalTest.
@Test
public void testAllSamplesDeletionWithMultipleAdditionalTest() {
Date since = new Date();
RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
PersonDto secondCazePerson = creator.createPerson("SecondCase", "SecondPerson");
CaseDataDto secondCaze = creator.createCase(user.toReference(), secondCazePerson.toReference(), Disease.ACUTE_VIRAL_HEPATITIS, CaseClassification.NOT_CLASSIFIED, InvestigationStatus.PENDING, new Date(), rdcf);
SampleDto thirdSample = creator.createSample(secondCaze.toReference(), new Date(), new Date(), user.toReference(), SampleMaterial.BLOOD, rdcf.facility);
SampleDto forthSample = creator.createSample(secondCaze.toReference(), new Date(), new Date(), user.toReference(), SampleMaterial.BLOOD, rdcf.facility);
PathogenTestDto secondSamplePathogenTest = creator.createPathogenTest(thirdSample.toReference(), PathogenTestType.RAPID_TEST, secondCaze.getDisease(), new Date(), rdcf.facility, user.toReference(), PathogenTestResultType.INDETERMINATE, "Indeterminate", true);
PathogenTestDto thirdSamplePathogenTest = creator.createPathogenTest(forthSample.toReference(), PathogenTestType.CQ_VALUE_DETECTION, secondCaze.getDisease(), new Date(), rdcf.facility, user.toReference(), PathogenTestResultType.NOT_DONE, "Not done", true);
AdditionalTestDto secondSampleAdditionalTest = creator.createAdditionalTest(thirdSample.toReference());
AdditionalTestDto thirdSampleAdditionalTest = creator.createAdditionalTest(forthSample.toReference());
// Database should contain the created sample, sample test and additional tests
assertNotNull(getSampleTestFacade().getByUuid(secondSamplePathogenTest.getUuid()));
assertNotNull(getSampleTestFacade().getByUuid(thirdSamplePathogenTest.getUuid()));
assertNotNull(getAdditionalTestFacade().getByUuid(secondSampleAdditionalTest.getUuid()));
assertNotNull(getAdditionalTestFacade().getByUuid(thirdSampleAdditionalTest.getUuid()));
getSampleFacade().deleteAllSamples(Arrays.asList(thirdSample.getUuid(), forthSample.getUuid()));
// Sample and pathogen test should be marked as deleted, additional tests should be deleted
List<String> sampleUuids = getSampleFacade().getDeletedUuidsSince(since);
assertTrue(sampleUuids.contains(thirdSample.getUuid()));
assertTrue(sampleUuids.contains(forthSample.getUuid()));
assertTrue(getSampleTestFacade().getDeletedUuidsSince(since).contains(secondSamplePathogenTest.getUuid()));
assertTrue(getSampleTestFacade().getDeletedUuidsSince(since).contains(thirdSamplePathogenTest.getUuid()));
assertNull(getAdditionalTestFacade().getByUuid(secondSampleAdditionalTest.getUuid()));
assertNull(getAdditionalTestFacade().getByUuid(thirdSampleAdditionalTest.getUuid()));
}
Aggregations