Search in sources :

Example 1 with CaseOrigin

use of de.symeda.sormas.api.caze.CaseOrigin in project SORMAS-Project by hzi-braunschweig.

the class CasePartialUpdateTest method testResetValue.

@Test
public void testResetValue() {
    TestDataCreator.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);
    caze.setCaseOrigin(CaseOrigin.IN_COUNTRY);
    caze.setAdditionalDetails("additional details");
    caze = getCaseFacade().save(caze);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode caseJson = mapper.convertValue(caze, JsonNode.class);
    // check if the reference person uuid is the same in the converted json
    CaseOrigin actualCaseOrigin = Enum.valueOf(CaseOrigin.class, caseJson.get("caseOrigin").textValue());
    String actualAdditionalDetails = caseJson.get("additionalDetails").textValue();
    assertEquals(CaseOrigin.IN_COUNTRY, actualCaseOrigin);
    assertEquals(caze.getAdditionalDetails(), actualAdditionalDetails);
    ((ObjectNode) caseJson).putNull("caseOrigin");
    ((ObjectNode) caseJson).putNull("additionalDetails");
    assertTrue(caseJson.get("caseOrigin").isNull());
    assertTrue(caseJson.get("additionalDetails").isNull());
    // remove from json some nodes
    ((ObjectNode) caseJson).remove("caseClassification");
    ((ObjectNode) caseJson).remove("district");
    ((ObjectNode) caseJson).remove("community");
    ((ObjectNode) caseJson).remove("healthFacility");
    ((ObjectNode) caseJson).remove("epiData");
    ((ObjectNode) caseJson).remove("surveillanceOfficer");
    ((ObjectNode) caseJson).remove("symptoms");
    assertNull(caseJson.get("caseClassification"));
    // call the partial update
    CaseDataDto casePostUpdated = getCaseFacade().postUpdate(caze.getUuid(), caseJson);
    // check if the fields has been set to null
    assertNull(casePostUpdated.getAdditionalDetails());
    assertNull(casePostUpdated.getCaseOrigin());
    // check if the fields that were not in the json file has not be deleted
    assertEquals(CaseClassification.PROBABLE, caze.getCaseClassification());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) JsonNode(com.fasterxml.jackson.databind.JsonNode) Date(java.util.Date) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 2 with CaseOrigin

use of de.symeda.sormas.api.caze.CaseOrigin in project SORMAS-Project by hzi-braunschweig.

the class CaseFilterForm method applyDependenciesOnFieldChange.

@Override
protected void applyDependenciesOnFieldChange(String propertyId, Property.ValueChangeEvent event) {
    super.applyDependenciesOnFieldChange(propertyId, event);
    final CaseCriteria criteria = getValue();
    final ComboBox regionField = getField(CaseDataDto.REGION);
    final ComboBox districtField = getField(CaseDataDto.DISTRICT);
    final ComboBox communityField = getField(CaseDataDto.COMMUNITY);
    final ComboBox facilityTypeGroupField = getField(CaseCriteria.FACILITY_TYPE_GROUP);
    final ComboBox facilityTypeField = getField(CaseCriteria.FACILITY_TYPE);
    final ComboBox facilityField = getField(CaseDataDto.HEALTH_FACILITY);
    final ComboBox pointOfEntryField = getField(CaseDataDto.POINT_OF_ENTRY);
    final ComboBox caseOriginField = getField(CaseDataDto.CASE_ORIGIN);
    final UserDto user = currentUserDto();
    final DistrictReferenceDto currentDistrict = user.getDistrict() != null ? user.getDistrict() : (DistrictReferenceDto) districtField.getValue();
    final CaseOrigin currentCaseOrigin = caseOriginField != null ? (CaseOrigin) getField(CaseDataDto.CASE_ORIGIN).getValue() : CaseOrigin.POINT_OF_ENTRY;
    switch(propertyId) {
        case CaseDataDto.REGION:
            {
                final RegionReferenceDto region = user.getRegion() != null ? user.getRegion() : (RegionReferenceDto) event.getProperty().getValue();
                if (!DataHelper.equal(region, criteria.getRegion())) {
                    final ComboBox officerField = getField(CaseDataDto.SURVEILLANCE_OFFICER);
                    officerField.removeAllItems();
                    if (region != null) {
                        enableFields(districtField);
                        FieldHelper.updateItems(districtField, FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
                        disableFields(pointOfEntryField);
                        clearAndDisableFields(communityField, facilityField, facilityTypeField, facilityTypeGroupField);
                        addOfficers(officerField, region);
                    } else {
                        clearAndDisableFields(districtField, communityField, facilityField, facilityTypeField, facilityTypeGroupField);
                        disableFields(pointOfEntryField);
                        addOfficers(officerField, user.getRegion());
                    }
                }
                break;
            }
        case CaseDataDto.DISTRICT:
            {
                final DistrictReferenceDto newDistrict = (DistrictReferenceDto) event.getProperty().getValue();
                if (!DataHelper.equal(newDistrict, criteria.getDistrict())) {
                    final ComboBox officerField = getField(CaseDataDto.SURVEILLANCE_OFFICER);
                    officerField.removeAllItems();
                    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()));
                        if (pointOfEntryField != null && currentCaseOrigin == CaseOrigin.POINT_OF_ENTRY) {
                            pointOfEntryField.setEnabled(true);
                            FieldHelper.updateItems(pointOfEntryField, FacadeProvider.getPointOfEntryFacade().getAllActiveByDistrict(newDistrict.getUuid(), true));
                        }
                        officerField.addItems(FacadeProvider.getUserFacade().getUserRefsByDistrict(newDistrict, false, UserRole.SURVEILLANCE_OFFICER));
                    } else {
                        clearAndDisableFields(communityField, pointOfEntryField, facilityField, facilityTypeField, facilityTypeGroupField);
                        final RegionReferenceDto region = regionField != null ? (RegionReferenceDto) regionField.getValue() : null;
                        addOfficers(officerField, region != null ? region : user.getRegion());
                    }
                }
                break;
            }
        case CaseDataDto.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 CaseCriteria.FACILITY_TYPE_GROUP:
            {
                FacilityTypeGroup typeGroup = (FacilityTypeGroup) event.getProperty().getValue();
                if (!DataHelper.equal(typeGroup, criteria.getFacilityTypeGroup())) {
                    if (typeGroup != null) {
                        enableFields(CaseDataDto.FACILITY_TYPE);
                        FieldHelper.updateEnumData(facilityTypeField, FacilityType.getAccommodationTypes(typeGroup));
                        facilityField.setValue(null);
                    } else {
                        clearAndDisableFields(facilityTypeField, facilityField);
                    }
                }
                break;
            }
        case CaseCriteria.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 CaseCriteria.BIRTHDATE_MM:
            {
                Integer birthMM = (Integer) event.getProperty().getValue();
                ComboBox birthDayDD = getField(CaseCriteria.BIRTHDATE_DD);
                birthDayDD.setEnabled(birthMM != null);
                FieldHelper.updateItems(birthDayDD, DateHelper.getDaysInMonth((Integer) getField(CaseCriteria.BIRTHDATE_MM).getValue(), (Integer) getField(CaseCriteria.BIRTHDATE_YYYY).getValue()));
                break;
            }
        case CaseDataDto.CASE_ORIGIN:
            {
                if (pointOfEntryField != null) {
                    CaseOrigin caseOrigin = (CaseOrigin) event.getProperty().getValue();
                    if (caseOrigin == CaseOrigin.POINT_OF_ENTRY && currentDistrict != null) {
                        pointOfEntryField.setEnabled(true);
                        FieldHelper.updateItems(pointOfEntryField, FacadeProvider.getPointOfEntryFacade().getAllActiveByDistrict(currentDistrict.getUuid(), true));
                    } else {
                        clearAndDisableFields(CaseDataDto.POINT_OF_ENTRY);
                    }
                }
                break;
            }
        case CaseDataDto.DISEASE:
            {
                ComboBox field = getField(CaseDataDto.DISEASE_VARIANT);
                Disease disease = (Disease) event.getProperty().getValue();
                if (disease == null) {
                    FieldHelper.updateItems(field, Collections.emptyList());
                    FieldHelper.setEnabled(false, field);
                } else {
                    List<DiseaseVariant> diseaseVariants = FacadeProvider.getCustomizableEnumFacade().getEnumValues(CustomizableEnumType.DISEASE_VARIANT, disease);
                    FieldHelper.updateItems(field, diseaseVariants);
                    FieldHelper.setEnabled(CollectionUtils.isNotEmpty(diseaseVariants), field);
                }
            }
    }
}
Also used : CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Disease(de.symeda.sormas.api.Disease) ComboBox(com.vaadin.v7.ui.ComboBox) UserDto(de.symeda.sormas.api.user.UserDto) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) List(java.util.List) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin)

Aggregations

CaseOrigin (de.symeda.sormas.api.caze.CaseOrigin)2 UserDto (de.symeda.sormas.api.user.UserDto)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ComboBox (com.vaadin.v7.ui.ComboBox)1 Disease (de.symeda.sormas.api.Disease)1 CaseCriteria (de.symeda.sormas.api.caze.CaseCriteria)1 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)1 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)1 FacilityType (de.symeda.sormas.api.infrastructure.facility.FacilityType)1 FacilityTypeGroup (de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup)1 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)1 PersonDto (de.symeda.sormas.api.person.PersonDto)1 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)1 TestDataCreator (de.symeda.sormas.backend.TestDataCreator)1 Date (java.util.Date)1 List (java.util.List)1 Test (org.junit.Test)1