Search in sources :

Example 11 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationFilterForm method applyDependenciesOnFieldChange.

@Override
protected void applyDependenciesOnFieldChange(String propertyId, Property.ValueChangeEvent event) {
    super.applyDependenciesOnFieldChange(propertyId, event);
    final ImmunizationCriteria criteria = getValue();
    final ComboBox districtField = getField(ImmunizationCriteria.DISTRICT);
    final ComboBox communityField = getField(ImmunizationCriteria.COMMUNITY);
    final ComboBox facilityTypeGroupField = getField(ImmunizationCriteria.FACILITY_TYPE_GROUP);
    final ComboBox facilityTypeField = getField(ImmunizationCriteria.FACILITY_TYPE);
    final ComboBox facilityField = getField(ImmunizationCriteria.HEALTH_FACILITY);
    final UserDto user = currentUserDto();
    final DistrictReferenceDto currentDistrict = user.getDistrict() != null ? user.getDistrict() : (DistrictReferenceDto) districtField.getValue();
    switch(propertyId) {
        case ImmunizationCriteria.REGION:
            {
                final RegionReferenceDto region = user.getRegion() != null ? user.getRegion() : (RegionReferenceDto) event.getProperty().getValue();
                if (!DataHelper.equal(region, criteria.getRegion())) {
                    if (region != null) {
                        enableFields(districtField);
                        FieldHelper.updateItems(districtField, FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
                    } else {
                        clearAndDisableFields(districtField);
                    }
                    clearAndDisableFields(communityField, facilityField, facilityTypeField, facilityTypeGroupField);
                }
                break;
            }
        case ImmunizationCriteria.DISTRICT:
            {
                final DistrictReferenceDto newDistrict = (DistrictReferenceDto) event.getProperty().getValue();
                if (!DataHelper.equal(newDistrict, criteria.getDistrict())) {
                    if (newDistrict != null) {
                        enableFields(communityField, facilityTypeGroupField);
                        clearAndDisableFields(facilityField);
                        if (facilityTypeGroupField != null) {
                            if (facilityTypeGroupField.getValue() != null && facilityTypeField.getValue() != null) {
                                FieldHelper.updateItems(facilityField, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(newDistrict, (FacilityType) facilityTypeField.getValue(), true, false));
                                enableFields(facilityField);
                            } else {
                                FieldHelper.updateEnumData(facilityTypeGroupField, FacilityTypeGroup.getAccomodationGroups());
                            }
                        }
                        FieldHelper.updateItems(communityField, FacadeProvider.getCommunityFacade().getAllActiveByDistrict(newDistrict.getUuid()));
                    } else {
                        clearAndDisableFields(communityField, facilityField, facilityTypeField, facilityTypeGroupField);
                    }
                }
                break;
            }
        case ImmunizationCriteria.COMMUNITY:
            {
                CommunityReferenceDto community = (CommunityReferenceDto) event.getProperty().getValue();
                if (!DataHelper.equal(community, criteria.getCommunity())) {
                    if (facilityField != null) {
                        facilityField.setValue(null);
                    }
                    final FacilityType facilityType = facilityTypeField != null ? (FacilityType) facilityTypeField.getValue() : null;
                    if (facilityType == null && facilityField != null) {
                        facilityField.removeAllItems();
                    } else if (facilityField != null) {
                        if (community == null) {
                            FieldHelper.updateItems(facilityField, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(currentDistrict, facilityType, true, false));
                        } else {
                            FieldHelper.updateItems(facilityField, FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(community, facilityType, true, false));
                        }
                    }
                }
                break;
            }
        case ImmunizationCriteria.FACILITY_TYPE_GROUP:
            {
                FacilityTypeGroup typeGroup = (FacilityTypeGroup) event.getProperty().getValue();
                if (!DataHelper.equal(typeGroup, criteria.getFacilityTypeGroup())) {
                    if (typeGroup != null) {
                        enableFields(ImmunizationCriteria.FACILITY_TYPE);
                        FieldHelper.updateEnumData(facilityTypeField, FacilityType.getAccommodationTypes(typeGroup));
                        facilityField.setValue(null);
                    } else {
                        clearAndDisableFields(facilityTypeField, facilityField);
                    }
                }
                break;
            }
        case ImmunizationCriteria.FACILITY_TYPE:
            {
                FacilityType facilityType = (FacilityType) event.getProperty().getValue();
                if (!DataHelper.equal(facilityType, criteria.getFacilityType())) {
                    if (facilityType == null) {
                        clearAndDisableFields(facilityField);
                    } else {
                        enableFields(facilityField);
                        facilityField.setValue(null);
                        CommunityReferenceDto community = (CommunityReferenceDto) communityField.getValue();
                        if (community != null) {
                            FieldHelper.updateItems(facilityField, FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(community, facilityType, true, false));
                        } else if (currentDistrict != null) {
                            FieldHelper.updateItems(facilityField, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(currentDistrict, facilityType, true, false));
                        }
                    }
                }
                break;
            }
        case ImmunizationCriteria.BIRTHDATE_MM:
            {
                Integer birthMM = (Integer) event.getProperty().getValue();
                ComboBox birthDayDD = getField(ImmunizationCriteria.BIRTHDATE_DD);
                birthDayDD.setEnabled(birthMM != null);
                FieldHelper.updateItems(birthDayDD, DateHelper.getDaysInMonth((Integer) getField(ImmunizationCriteria.BIRTHDATE_MM).getValue(), (Integer) getField(ImmunizationCriteria.BIRTHDATE_YYYY).getValue()));
                break;
            }
    }
}
Also used : CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) ImmunizationCriteria(de.symeda.sormas.api.immunization.ImmunizationCriteria) ComboBox(com.vaadin.v7.ui.ComboBox) UserDto(de.symeda.sormas.api.user.UserDto) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 12 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationFilterForm method applyDependenciesOnNewValue.

@Override
protected void applyDependenciesOnNewValue(ImmunizationCriteria criteria) {
    final UserDto user = currentUserDto();
    UserProvider currentUserProvider = UserProvider.getCurrent();
    final JurisdictionLevel userJurisdictionLevel = currentUserProvider != null ? UserRole.getJurisdictionLevel(currentUserProvider.getUserRoles()) : null;
    final ComboBox districtField = getField(ImmunizationCriteria.DISTRICT);
    final ComboBox communityField = getField(ImmunizationCriteria.COMMUNITY);
    final ComboBox facilityTypeGroupField = getField(ImmunizationCriteria.FACILITY_TYPE_GROUP);
    final ComboBox facilityTypeField = getField(ImmunizationCriteria.FACILITY_TYPE);
    final ComboBox facilityField = getField(ImmunizationCriteria.HEALTH_FACILITY);
    // Disable all fields
    clearAndDisableFields(districtField, communityField, facilityTypeGroupField, facilityTypeField, facilityField);
    // Get initial field values according to user and criteria
    final RegionReferenceDto region = user.getRegion() == null ? criteria.getRegion() : user.getRegion();
    final DistrictReferenceDto district = user.getDistrict() == null ? criteria.getDistrict() : user.getDistrict();
    final CommunityReferenceDto community = user.getCommunity() == null ? criteria.getCommunity() : user.getCommunity();
    final FacilityTypeGroup facilityTypeGroup = criteria.getFacilityTypeGroup();
    final FacilityType facilityType = criteria.getFacilityType();
    // district
    if (region != null) {
        enableFields(districtField);
        districtField.addItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
        // community
        if (district != null) {
            districtField.setValue(district);
            communityField.addItems(FacadeProvider.getCommunityFacade().getAllActiveByDistrict(district.getUuid()));
            enableFields(communityField);
            if (community != null) {
                communityField.setValue(community);
            }
        } else {
            clearAndDisableFields(communityField);
        }
    } else {
        clearAndDisableFields(districtField, communityField);
    }
    // facility
    if (userJurisdictionLevel == JurisdictionLevel.HEALTH_FACILITY) {
        facilityField.setValue(user.getHealthFacility());
        disableFields(facilityTypeGroupField, facilityTypeField, facilityField);
    } else if (facilityTypeGroupField != null && district != null) {
        enableFields(facilityTypeGroupField);
        FieldHelper.updateEnumData(facilityTypeGroupField, FacilityTypeGroup.getAccomodationGroups());
        if (facilityTypeGroup != null) {
            facilityTypeGroupField.setValue(facilityTypeGroup);
            enableFields(facilityTypeField);
            FieldHelper.updateEnumData(facilityTypeField, FacilityType.getAccommodationTypes(facilityTypeGroup));
            if (facilityType != null) {
                facilityTypeField.setValue(facilityType);
                enableFields(facilityField);
                if (community != null) {
                    facilityField.addItems(FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(community, facilityType, true, false));
                } else {
                    facilityField.addItems(FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(district, facilityType, true, false));
                }
            } else {
                disableFields(facilityField);
            }
        } else {
            disableFields(facilityTypeField);
        }
    }
    // Disable fields according to user & jurisdiction
    if (userJurisdictionLevel == JurisdictionLevel.DISTRICT) {
        clearAndDisableFields(districtField);
    } else if (userJurisdictionLevel == JurisdictionLevel.COMMUNITY) {
        clearAndDisableFields(districtField, communityField);
    } else if (userJurisdictionLevel == JurisdictionLevel.HEALTH_FACILITY) {
        clearAndDisableFields(districtField, communityField, facilityTypeGroupField, facilityTypeField, facilityField);
    }
    ComboBox birthDateDD = getField(ImmunizationCriteria.BIRTHDATE_DD);
    if (getField(ImmunizationCriteria.BIRTHDATE_YYYY).getValue() != null && getField(ImmunizationCriteria.BIRTHDATE_MM).getValue() != null) {
        birthDateDD.addItems(DateHelper.getDaysInMonth((Integer) getField(ImmunizationCriteria.BIRTHDATE_MM).getValue(), (Integer) getField(ImmunizationCriteria.BIRTHDATE_YYYY).getValue()));
        birthDateDD.setEnabled(true);
    } else {
        birthDateDD.clear();
        birthDateDD.setEnabled(false);
    }
    // Date/Epi week filter
    HorizontalLayout dateFilterLayout = (HorizontalLayout) getMoreFiltersContainer().getComponent(WEEK_AND_DATE_FILTER);
    @SuppressWarnings("unchecked") EpiWeekAndDateFilterComponent<ImmunizationDateType> weekAndDateFilter = (EpiWeekAndDateFilterComponent<ImmunizationDateType>) dateFilterLayout.getComponent(0);
    ImmunizationDateType immunizationDateType = criteria.getImmunizationDateType();
    weekAndDateFilter.getDateTypeSelector().setValue(immunizationDateType);
    weekAndDateFilter.getDateFilterOptionFilter().setValue(criteria.getDateFilterOption());
    Date dateFrom = criteria.getFromDate();
    Date dateTo = criteria.getToDate();
    if (DateFilterOption.EPI_WEEK.equals(criteria.getDateFilterOption())) {
        weekAndDateFilter.getWeekFromFilter().setValue(dateFrom == null ? null : DateHelper.getEpiWeek(dateFrom));
        weekAndDateFilter.getWeekToFilter().setValue(dateTo == null ? null : DateHelper.getEpiWeek(dateTo));
    } else {
        weekAndDateFilter.getDateFromFilter().setValue(dateFrom);
        weekAndDateFilter.getDateToFilter().setValue(dateTo);
    }
}
Also used : ComboBox(com.vaadin.v7.ui.ComboBox) UserDto(de.symeda.sormas.api.user.UserDto) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Date(java.util.Date) HorizontalLayout(com.vaadin.ui.HorizontalLayout) EpiWeekAndDateFilterComponent(de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) UserProvider(de.symeda.sormas.ui.UserProvider) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) ImmunizationDateType(de.symeda.sormas.api.immunization.ImmunizationDateType) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 13 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testGetAllActiveCasesIncludeExtendedChangeDateFiltersPathogenTest.

@Test
public void testGetAllActiveCasesIncludeExtendedChangeDateFiltersPathogenTest() throws InterruptedException {
    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);
    SampleDto sample = creator.createSample(caze.toReference(), user.toReference(), rdcf.facility);
    PathogenTestDto pathogenTestDto = creator.createPathogenTest(sample.toReference(), caze);
    Date date = new Date();
    // the delay is needed in order to ensure the time difference between the date and the case dependent objects update
    Thread.sleep(10L);
    pathogenTestDto.setTestResultText("test result changed");
    getPathogenTestFacade().savePathogenTest(pathogenTestDto);
    assertEquals(0, getCaseFacade().getAllActiveCasesAfter(date).size());
    assertEquals(1, getCaseFacade().getAllActiveCasesAfter(date, true).size());
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 14 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testGetCaseMeasurePerDistrict.

@Test
public void testGetCaseMeasurePerDistrict() {
    List<DataHelper.Pair<DistrictDto, BigDecimal>> caseMeasurePerDistrict = getCaseFacade().getCaseMeasurePerDistrict(null, null, Disease.EVD, CaseMeasure.CASE_COUNT);
    assertTrue(caseMeasurePerDistrict.isEmpty());
    RDCF rdcf1 = creator.createRDCF("Region", "District1", "Community", "Facility");
    RDCF rdcf2 = creator.createRDCF("Region", "District2", "Community", "Facility");
    UserDto user = creator.createUser(rdcf1, UserRole.NATIONAL_USER);
    CaseDataDto caze = creator.createCase(user.toReference(), creator.createPerson("Person", "One").toReference(), rdcf1);
    caseMeasurePerDistrict = getCaseFacade().getCaseMeasurePerDistrict(null, null, Disease.EVD, CaseMeasure.CASE_COUNT);
    assertEquals(1, caseMeasurePerDistrict.size());
    DataHelper.Pair<DistrictDto, BigDecimal> districtCaseCount = caseMeasurePerDistrict.get(0);
    assertEquals(rdcf1.district.getUuid(), districtCaseCount.getElement0().getUuid());
    assertEquals(1, districtCaseCount.getElement1().intValue());
    creator.createCase(user.toReference(), creator.createPerson("Person", "Two").toReference(), rdcf1);
    caseMeasurePerDistrict = getCaseFacade().getCaseMeasurePerDistrict(null, null, Disease.EVD, CaseMeasure.CASE_COUNT);
    assertEquals(1, caseMeasurePerDistrict.size());
    districtCaseCount = caseMeasurePerDistrict.get(0);
    assertEquals(rdcf1.district.getUuid(), districtCaseCount.getElement0().getUuid());
    assertEquals(2, districtCaseCount.getElement1().intValue());
    caze.setDistrict(rdcf2.district);
    getCaseFacade().save(caze);
    creator.createCase(user.toReference(), creator.createPerson("Person", "Three").toReference(), rdcf2);
    caseMeasurePerDistrict = getCaseFacade().getCaseMeasurePerDistrict(null, null, Disease.EVD, CaseMeasure.CASE_COUNT);
    assertEquals(2, caseMeasurePerDistrict.size());
    districtCaseCount = caseMeasurePerDistrict.get(0);
    assertEquals(rdcf1.district.getUuid(), districtCaseCount.getElement0().getUuid());
    assertEquals(1, districtCaseCount.getElement1().intValue());
    districtCaseCount = caseMeasurePerDistrict.get(1);
    assertEquals(rdcf2.district.getUuid(), districtCaseCount.getElement0().getUuid());
    assertEquals(2, districtCaseCount.getElement1().intValue());
}
Also used : DistrictDto(de.symeda.sormas.api.infrastructure.district.DistrictDto) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) UserDto(de.symeda.sormas.api.user.UserDto) DataHelper(de.symeda.sormas.api.utils.DataHelper) BigDecimal(java.math.BigDecimal) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 15 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testGetDuplicateCasesOfSameSexAndDifferentBirthDateIsEmpty.

@Test
public void testGetDuplicateCasesOfSameSexAndDifferentBirthDateIsEmpty() {
    final Date today = 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 cazePerson = creator.createPerson("Case", "Person", Sex.MALE, 1980, 1, 1);
    creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, today, rdcf);
    PersonDto cazePerson2 = creator.createPerson("Case", "Person", Sex.MALE, 1980, 1, 2);
    creator.createCase(user.toReference(), cazePerson2.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, DateUtils.addMinutes(today, -3), rdcf);
    Assert.assertEquals(0, getCaseFacade().getCasesForDuplicateMerging(new CaseCriteria().creationDateFrom(today).creationDateTo(today), true).size());
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

UserDto (de.symeda.sormas.api.user.UserDto)274 Test (org.junit.Test)210 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)160 PersonDto (de.symeda.sormas.api.person.PersonDto)142 Date (java.util.Date)138 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)121 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)64 ContactDto (de.symeda.sormas.api.contact.ContactDto)57 LocalDate (java.time.LocalDate)57 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)56 EventDto (de.symeda.sormas.api.event.EventDto)52 TestDataCreator (de.symeda.sormas.backend.TestDataCreator)47 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)43 AbstractBeanTest (de.symeda.sormas.ui.AbstractBeanTest)43 SampleDto (de.symeda.sormas.api.sample.SampleDto)41 File (java.io.File)41 TestDataCreator (de.symeda.sormas.ui.TestDataCreator)31 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)30 CasePersonDto (de.symeda.sormas.api.caze.CasePersonDto)27 ImportResultStatus (de.symeda.sormas.ui.importer.ImportResultStatus)27