Search in sources :

Example 11 with VisitDto

use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjbTest method testGetVisitSummaryExportList.

@Test
public void testGetVisitSummaryExportList() {
    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);
    String userUuid = user.getUuid();
    PersonDto cazePerson = creator.createPerson("Case", "Person");
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    PersonDto contactPerson = creator.createPerson("Contact", "Person");
    ContactDto contact = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
    // Create another contact that should have the same visits as the first one
    ContactDto contact2 = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
    VisitDto visit11 = creator.createVisit(caze.getDisease(), contactPerson.toReference(), new Date(), VisitStatus.COOPERATIVE, VisitOrigin.USER);
    visit11.getSymptoms().setAbdominalPain(SymptomState.YES);
    getVisitFacade().saveVisit(visit11);
    VisitDto visit12 = creator.createVisit(caze.getDisease(), contactPerson.toReference(), DateHelper.subtractDays(new Date(), 1), VisitStatus.COOPERATIVE, VisitOrigin.USER);
    visit12.getSymptoms().setChestPain(SymptomState.YES);
    getVisitFacade().saveVisit(visit12);
    PersonDto contactPersonWithoutFollowUp = creator.createPerson();
    creator.createContact(user.toReference(), contactPersonWithoutFollowUp.toReference());
    PersonDto contactPerson2 = creator.createPerson("Contact2", "Person2");
    ContactDto contact3 = creator.createContact(user.toReference(), user.toReference(), contactPerson2.toReference(), caze, new Date(), null, null);
    VisitDto visit21 = creator.createVisit(caze.getDisease(), contactPerson2.toReference(), new Date(), VisitStatus.COOPERATIVE, VisitOrigin.USER);
    visit21.getSymptoms().setBackache(SymptomState.YES);
    getVisitFacade().saveVisit(visit21);
    final List<VisitSummaryExportDto> results = getContactFacade().getVisitSummaryExportList(null, Collections.emptySet(), 0, 100, Language.EN);
    assertNotNull(results);
    assertEquals(3, results.size());
    final VisitSummaryExportDto exportDto1 = results.get(0);
    assertEquals("Contact", exportDto1.getFirstName());
    assertEquals("Person", exportDto1.getLastName());
    assertEquals(contact.getUuid(), exportDto1.getUuid());
    final List<VisitSummaryExportDetailsDto> visitDetails = exportDto1.getVisitDetails();
    assertNotNull(visitDetails);
    assertEquals(2, visitDetails.size());
    final VisitSummaryExportDetailsDto visitDetail11 = visitDetails.get(0);
    assertEquals(VisitStatus.COOPERATIVE, visitDetail11.getVisitStatus());
    assertNotNull(visitDetail11.getVisitDateTime());
    assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.CHEST_PAIN), visitDetail11.getSymptoms());
    final VisitSummaryExportDetailsDto visitDetail12 = visitDetails.get(1);
    assertEquals(VisitStatus.COOPERATIVE, visitDetail12.getVisitStatus());
    assertNotNull(visitDetail12.getVisitDateTime());
    assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ABDOMINAL_PAIN), visitDetail12.getSymptoms());
    final VisitSummaryExportDto exportDto2 = results.get(1);
    assertEquals("Contact", exportDto2.getFirstName());
    assertEquals("Person", exportDto2.getLastName());
    assertEquals(contact2.getUuid(), exportDto2.getUuid());
    final List<VisitSummaryExportDetailsDto> visitDetails2 = exportDto1.getVisitDetails();
    assertNotNull(visitDetails2);
    assertEquals(2, visitDetails2.size());
    final VisitSummaryExportDetailsDto visitDetail21 = visitDetails2.get(0);
    assertEquals(VisitStatus.COOPERATIVE, visitDetail21.getVisitStatus());
    assertNotNull(visitDetail21.getVisitDateTime());
    assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.CHEST_PAIN), visitDetail21.getSymptoms());
    final VisitSummaryExportDetailsDto visitDetail22 = visitDetails2.get(1);
    assertEquals(VisitStatus.COOPERATIVE, visitDetail22.getVisitStatus());
    assertNotNull(visitDetail22.getVisitDateTime());
    assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ABDOMINAL_PAIN), visitDetail22.getSymptoms());
    final VisitSummaryExportDto exportDto3 = results.get(2);
    assertEquals("Contact2", exportDto3.getFirstName());
    assertEquals("Person2", exportDto3.getLastName());
    assertEquals(contact3.getUuid(), exportDto3.getUuid());
    final List<VisitSummaryExportDetailsDto> visitDetails3 = exportDto3.getVisitDetails();
    assertNotNull(visitDetails3);
    assertEquals(1, visitDetails3.size());
    final VisitSummaryExportDetailsDto visitDetail31 = visitDetails3.get(0);
    assertEquals(VisitStatus.COOPERATIVE, visitDetail31.getVisitStatus());
    assertNotNull(visitDetail31.getVisitDateTime());
    assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.BACKACHE), visitDetail31.getSymptoms());
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) VisitSummaryExportDto(de.symeda.sormas.api.visit.VisitSummaryExportDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Date(java.util.Date) LocalDate(java.time.LocalDate) VisitSummaryExportDetailsDto(de.symeda.sormas.api.visit.VisitSummaryExportDetailsDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 12 with VisitDto

use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.

the class ContactServiceTest method testUpdateFollowUpUntilAndStatus.

@Test
public void testUpdateFollowUpUntilAndStatus() {
    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 cazePerson = creator.createPerson("Case", "Person");
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    PersonDto contactPerson = creator.createPerson("Contact", "Person");
    ContactDto contact = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
    assertEquals(FollowUpStatus.FOLLOW_UP, contact.getFollowUpStatus());
    assertEquals(LocalDate.now().plusDays(21), DateHelper8.toLocalDate(contact.getFollowUpUntil()));
    VisitDto visit = creator.createVisit(caze.getDisease(), contactPerson.toReference(), DateUtils.addDays(new Date(), 21), VisitStatus.UNAVAILABLE, VisitOrigin.USER);
    // Follow-up until should be increased by one day
    contact = getContactFacade().getByUuid(contact.getUuid());
    assertEquals(FollowUpStatus.FOLLOW_UP, contact.getFollowUpStatus());
    assertEquals(LocalDate.now().plusDays(21 + 1), DateHelper8.toLocalDate(contact.getFollowUpUntil()));
    visit.setVisitStatus(VisitStatus.COOPERATIVE);
    visit = getVisitFacade().saveVisit(visit);
    // Follow-up until should be back at the original date and follow-up should be completed
    contact = getContactFacade().getByUuid(contact.getUuid());
    assertEquals(FollowUpStatus.COMPLETED, contact.getFollowUpStatus());
    assertEquals(LocalDate.now().plusDays(21), DateHelper8.toLocalDate(contact.getFollowUpUntil()));
    // Manually overwrite and increase the follow-up until date
    contact.setFollowUpUntil(DateUtils.addDays(new Date(), 23));
    contact.setOverwriteFollowUpUntil(true);
    contact = getContactFacade().save(contact);
    assertEquals(FollowUpStatus.FOLLOW_UP, contact.getFollowUpStatus());
    assertTrue(contact.isOverwriteFollowUpUntil());
    // Add a cooperative visit AFTER the follow-up until date; should set follow-up to completed
    visit.setVisitStatus(VisitStatus.UNAVAILABLE);
    visit.setVisitDateTime(contact.getFollowUpUntil());
    getVisitFacade().saveVisit(visit);
    contact = getContactFacade().getByUuid(contact.getUuid());
    assertEquals(FollowUpStatus.FOLLOW_UP, contact.getFollowUpStatus());
    creator.createVisit(caze.getDisease(), contactPerson.toReference(), DateUtils.addDays(new Date(), 24), VisitStatus.COOPERATIVE, VisitOrigin.USER);
    contact = getContactFacade().getByUuid(contact.getUuid());
    assertEquals(FollowUpStatus.COMPLETED, contact.getFollowUpStatus());
    assertFalse(contact.isOverwriteFollowUpUntil());
    // Increasing the last contact date should extend follow-up
    contact.setLastContactDate(DateHelper.addDays(contact.getLastContactDate(), 10));
    contact = getContactFacade().save(contact);
    assertEquals(FollowUpStatus.FOLLOW_UP, contact.getFollowUpStatus());
    assertEquals(LocalDate.now().plusDays(21 + 10), DateHelper8.toLocalDate(contact.getFollowUpUntil()));
    PersonDto person2 = creator.createPerson();
    ContactDto contact2 = creator.createContact(user.toReference(), person2.toReference());
    contact2.setContactStatus(ContactStatus.CONVERTED);
    contact2 = getContactFacade().save(contact2);
    // Follow-up should be canceled when contact is converted to a case and should have a generated follow-up comment
    assertThat(contact2.getFollowUpStatus(), is(FollowUpStatus.CANCELED));
    assertNotNull(contact2.getFollowUpComment());
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 13 with VisitDto

use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.

the class DevModeView method generateContacts.

private void generateContacts() {
    initializeRandomGenerator();
    ContactGenerationConfig config = contactGeneratorConfigBinder.getBean();
    Disease disease = config.getDisease();
    List<Disease> diseases = disease == null ? FacadeProvider.getDiseaseConfigurationFacade().getAllDiseases(true, true, true) : null;
    if (disease == null) {
        disease = random(diseases);
        Notification.show("", "Automatically chosen disease: " + disease.getName(), Notification.Type.TRAY_NOTIFICATION);
    }
    List<String> personUuids = new ArrayList<>();
    List<CaseReferenceDto> cases = null;
    List<DistrictIndexDto> districts = config.getDistrict() == null ? FacadeProvider.getDistrictFacade().getIndexList(new DistrictCriteria().region(config.getRegion()), 0, Math.min(config.getContactCount() * 2, 50), Arrays.asList(new SortProperty(DistrictDto.NAME))) : null;
    if (!config.isCreateWithoutSourceCases()) {
        cases = FacadeProvider.getCaseFacade().getRandomCaseReferences(new CaseCriteria().region(config.getRegion()).district(config.getDistrict()).disease(disease), config.getContactCount() * 2, random());
        if (cases == null) {
            Notification.show("Error", I18nProperties.getString(Strings.messageMissingCases), Notification.Type.ERROR_MESSAGE);
            return;
        }
    }
    float baseOffset = random().nextFloat();
    int daysBetween = (int) ChronoUnit.DAYS.between(config.startDate, config.endDate);
    long dt = System.nanoTime();
    for (int i = 0; i < config.getContactCount(); i++) {
        fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(disease).andWithCountry(FacadeProvider.getConfigFacade().getCountryLocale());
        LocalDateTime referenceDateTime = getReferenceDateTime(i, config.getContactCount(), baseOffset, disease, config.getStartDate(), daysBetween);
        PersonDto person;
        if (config.isCreateMultipleContactsPerPerson() && !personUuids.isEmpty() && randomPercent(25)) {
            String personUuid = random(personUuids);
            person = FacadeProvider.getPersonFacade().getPersonByUuid(personUuid);
        } else {
            person = PersonDto.build();
            fillEntity(person, referenceDateTime);
            person.setSymptomJournalStatus(null);
            setPersonName(person);
            if (config.isCreateMultipleContactsPerPerson()) {
                personUuids.add(person.getUuid());
            }
        }
        CaseReferenceDto contactCase = null;
        if (!config.isCreateWithoutSourceCases()) {
            contactCase = random(cases);
        }
        ContactDto contact = ContactDto.build();
        contact.setPerson(person.toReference());
        fillEntity(contact, referenceDateTime);
        if (contactCase != null) {
            contact.setCaze(contactCase);
        }
        contact.setDisease(disease);
        if (contact.getDisease() == Disease.OTHER) {
            contact.setDiseaseDetails("RD " + (random().nextInt(20) + 1));
        }
        UserReferenceDto userReference = UserProvider.getCurrent().getUserReference();
        contact.setReportingUser(userReference);
        contact.setReportDateTime(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
        if (districts != null) {
            DistrictIndexDto district = random(districts);
            contact.setRegion(district.getRegion());
            contact.setDistrict(district.toReference());
        } else {
            contact.setRegion(config.getRegion());
            contact.setDistrict(config.getDistrict());
        }
        if (contact.getLastContactDate() != null && contact.getLastContactDate().after(contact.getReportDateTime())) {
            contact.setLastContactDate(contact.getReportDateTime());
        }
        if (FollowUpStatus.CANCELED.equals(contact.getFollowUpStatus()) || FollowUpStatus.LOST.equals(contact.getFollowUpStatus())) {
            contact.setFollowUpComment("-");
        }
        // description
        contact.setDescription("Contact generated using DevMode on " + LocalDate.now());
        FacadeProvider.getPersonFacade().savePerson(person);
        contact = FacadeProvider.getContactFacade().save(contact);
        if (FacadeProvider.getDiseaseConfigurationFacade().hasFollowUp(contact.getDisease())) {
            contact.setFollowUpStatus(random(FollowUpStatus.values()));
        } else {
            contact.setFollowUpStatus(FollowUpStatus.NO_FOLLOW_UP);
        }
        contact.setFollowUpUntil(contact.getFollowUpStatus() == FollowUpStatus.NO_FOLLOW_UP ? null : randomDate(referenceDateTime));
        // Create visits
        if (config.isCreateWithVisits() && FacadeProvider.getDiseaseConfigurationFacade().hasFollowUp(contact.getDisease()) && FollowUpStatus.NO_FOLLOW_UP != contact.getFollowUpStatus()) {
            Date latestFollowUpDate = contact.getFollowUpUntil().before(new Date()) ? contact.getFollowUpUntil() : new Date();
            Date contactStartDate = ContactLogic.getStartDate(contact);
            int followUpCount = random().nextInt(DateHelper.getDaysBetween(contactStartDate, latestFollowUpDate) + 1);
            if (followUpCount > 0) {
                int[] followUpDays = random().ints(1, followUpCount + 1).distinct().limit(followUpCount).toArray();
                List<LocalDateTime> followUpDates = new ArrayList<>();
                for (int day : followUpDays) {
                    followUpDates.add(DateHelper8.toLocalDate(contactStartDate).atStartOfDay().plusDays(day - 1).plusMinutes(random().nextInt(60 * 24 + 1)));
                }
                for (LocalDateTime date : followUpDates) {
                    VisitDto visit = VisitDto.build(contact.getPerson(), contact.getDisease(), VisitOrigin.USER);
                    fillEntity(visit, date);
                    visit.setVisitUser(userReference);
                    visit.setVisitDateTime(DateHelper8.toDate(date));
                    visit.setDisease(contact.getDisease());
                    if (visit.getVisitStatus() == null) {
                        visit.setVisitStatus(VisitStatus.COOPERATIVE);
                    }
                    FacadeProvider.getVisitFacade().saveVisit(visit);
                }
            }
        }
    }
    dt = System.nanoTime() - dt;
    long perContact = dt / config.getContactCount();
    String msg = String.format("Generating %,d contacts took %,d  ms (%,d ms per contact)", config.getContactCount(), dt / 1_000_000, perContact / 1_000_000);
    logger.info(msg);
    Notification.show("", msg, Notification.Type.TRAY_NOTIFICATION);
}
Also used : LocalDateTime(java.time.LocalDateTime) Disease(de.symeda.sormas.api.Disease) DistrictIndexDto(de.symeda.sormas.api.infrastructure.district.DistrictIndexDto) PersonDto(de.symeda.sormas.api.person.PersonDto) ArrayList(java.util.ArrayList) DistrictCriteria(de.symeda.sormas.api.infrastructure.district.DistrictCriteria) Date(java.util.Date) LocalDate(java.time.LocalDate) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SortProperty(de.symeda.sormas.api.utils.SortProperty) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) ContactDto(de.symeda.sormas.api.contact.ContactDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto)

Example 14 with VisitDto

use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.

the class VisitFacadeEjb method toDto.

public static VisitDto toDto(Visit source) {
    if (source == null) {
        return null;
    }
    VisitDto target = new VisitDto();
    DtoHelper.fillDto(target, source);
    target.setDisease(source.getDisease());
    target.setPerson(PersonFacadeEjb.toReferenceDto(source.getPerson()));
    target.setSymptoms(SymptomsFacadeEjb.toDto(source.getSymptoms()));
    target.setVisitDateTime(source.getVisitDateTime());
    target.setVisitRemarks(source.getVisitRemarks());
    target.setVisitStatus(source.getVisitStatus());
    target.setVisitUser(UserFacadeEjb.toReferenceDto(source.getVisitUser()));
    target.setReportLat(source.getReportLat());
    target.setReportLon(source.getReportLon());
    target.setReportLatLonAccuracy(source.getReportLatLonAccuracy());
    target.setOrigin(source.getOrigin());
    return target;
}
Also used : ExternalVisitDto(de.symeda.sormas.api.visit.ExternalVisitDto) VisitDto(de.symeda.sormas.api.visit.VisitDto)

Example 15 with VisitDto

use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.

the class VisitFacadeEjb method saveVisit.

@Override
public VisitDto saveVisit(@Valid VisitDto dto) {
    final String visitUuid = dto.getUuid();
    final Visit existingVisit = visitUuid != null ? visitService.getByUuid(visitUuid) : null;
    final VisitDto existingDto = toDto(existingVisit);
    restorePseudonymizedDto(dto, existingVisit, existingDto);
    this.validate(dto);
    if (dto.getVisitStatus().equals(VisitStatus.COOPERATIVE)) {
        SymptomsHelper.updateIsSymptomatic(dto.getSymptoms());
    } else {
        dto.getSymptoms().setSymptomatic(null);
    }
    Visit entity = fromDto(dto, true);
    visitService.ensurePersisted(entity);
    onVisitChanged(existingDto, entity);
    return convertToDto(entity, Pseudonymizer.getDefault(userService::hasRight));
}
Also used : ExternalVisitDto(de.symeda.sormas.api.visit.ExternalVisitDto) VisitDto(de.symeda.sormas.api.visit.VisitDto)

Aggregations

VisitDto (de.symeda.sormas.api.visit.VisitDto)44 PersonDto (de.symeda.sormas.api.person.PersonDto)27 Test (org.junit.Test)25 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)24 Date (java.util.Date)24 ContactDto (de.symeda.sormas.api.contact.ContactDto)22 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)20 UserDto (de.symeda.sormas.api.user.UserDto)19 ExternalVisitDto (de.symeda.sormas.api.visit.ExternalVisitDto)14 LocalDate (java.time.LocalDate)11 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)10 PersonReferenceDto (de.symeda.sormas.api.person.PersonReferenceDto)8 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)7 SimilarContactDto (de.symeda.sormas.api.contact.SimilarContactDto)7 VisitCriteria (de.symeda.sormas.api.visit.VisitCriteria)7 ArrayList (java.util.ArrayList)7 MapContactDto (de.symeda.sormas.api.contact.MapContactDto)6 ClinicalVisitDto (de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto)5 ContactReferenceDto (de.symeda.sormas.api.contact.ContactReferenceDto)5 SampleDto (de.symeda.sormas.api.sample.SampleDto)4