use of com.vaadin.v7.ui.ComboBox in project SORMAS-Project by hzi-braunschweig.
the class AbstractEditForm method addInfrastructureField.
protected ComboBox addInfrastructureField(String fieldId) {
ComboBox field = addField(fieldId, ComboBox.class);
// Make sure that the ComboBox still contains a pre-selected inactive infrastructure entity
field.addValueChangeListener(e -> {
InfrastructureDataReferenceDto value = (InfrastructureDataReferenceDto) e.getProperty().getValue();
if (value != null && !field.containsId(value)) {
InfrastructureDataReferenceDto inactiveValue = value.clone();
inactiveValue.setCaption(value.getCaption() + " (" + I18nProperties.getString(Strings.inactive) + ")");
field.addItem(inactiveValue);
}
});
return field;
}
use of com.vaadin.v7.ui.ComboBox in project SORMAS-Project by hzi-braunschweig.
the class TreatmentForm method addFields.
@Override
protected void addFields() {
ComboBox treatmentTypeField = addField(TreatmentDto.TREATMENT_TYPE, ComboBox.class);
treatmentTypeField.setImmediate(true);
TextField treatmentDetailsField = addField(TreatmentDto.TREATMENT_DETAILS, TextField.class);
addField(TreatmentDto.TYPE_OF_DRUG, NullableOptionGroup.class);
addField(TreatmentDto.TREATMENT_DATE_TIME, DateTimeField.class);
addField(TreatmentDto.EXECUTING_CLINICIAN, TextField.class);
addField(TreatmentDto.DOSE, TextField.class);
ComboBox routeField = addField(TreatmentDto.ROUTE, ComboBox.class);
addField(TreatmentDto.ROUTE_DETAILS, TextField.class);
addField(TreatmentDto.ADDITIONAL_NOTES, TextArea.class).setRows(6);
initializeAccessAndAllowedAccesses();
setRequired(true, TreatmentDto.TREATMENT_TYPE, TreatmentDto.TREATMENT_DATE_TIME);
if (isEditableAllowed(TreatmentDto.TREATMENT_DETAILS)) {
FieldHelper.setRequiredWhen(getFieldGroup(), treatmentTypeField, Arrays.asList(TreatmentDto.TREATMENT_DETAILS), Arrays.asList(TreatmentType.OTHER, TreatmentType.DRUG_INTAKE));
}
if (isEditableAllowed(TreatmentDto.ROUTE_DETAILS)) {
FieldHelper.setRequiredWhen(getFieldGroup(), routeField, Arrays.asList(TreatmentDto.ROUTE_DETAILS), Arrays.asList(TreatmentRoute.OTHER));
}
FieldHelper.setVisibleWhen(getFieldGroup(), TreatmentDto.ROUTE_DETAILS, TreatmentDto.ROUTE, Arrays.asList(TreatmentRoute.OTHER), true);
FieldHelper.setVisibleWhen(getFieldGroup(), TreatmentDto.TYPE_OF_DRUG, TreatmentDto.TREATMENT_TYPE, Arrays.asList(TreatmentType.DRUG_INTAKE), true);
treatmentTypeField.addValueChangeListener(e -> {
if (e.getProperty().getValue() == TreatmentType.DRUG_INTAKE) {
treatmentDetailsField.setCaption(I18nProperties.getPrefixCaption(TreatmentDto.I18N_PREFIX, TreatmentDto.DRUG_INTAKE_DETAILS));
} else {
treatmentDetailsField.setCaption(I18nProperties.getPrefixCaption(TreatmentDto.I18N_PREFIX, TreatmentDto.TREATMENT_DETAILS));
}
});
}
use of com.vaadin.v7.ui.ComboBox 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;
}
}
}
use of com.vaadin.v7.ui.ComboBox 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);
}
}
use of com.vaadin.v7.ui.ComboBox in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationFilterForm method addMoreFilters.
@Override
public void addMoreFilters(CustomLayout moreFiltersContainer) {
final ComboBox regionFilter = addField(moreFiltersContainer, FieldConfiguration.pixelSized(ImmunizationCriteria.REGION, 140));
regionFilter.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
final ComboBox districtFilter = addField(moreFiltersContainer, FieldConfiguration.pixelSized(ImmunizationCriteria.DISTRICT, 140));
districtFilter.setDescription(I18nProperties.getDescription(Descriptions.descDistrictFilter));
addField(moreFiltersContainer, FieldConfiguration.pixelSized(ImmunizationCriteria.COMMUNITY, 140));
ComboBox typeGroup = addField(moreFiltersContainer, FieldConfiguration.pixelSized(ImmunizationCriteria.FACILITY_TYPE_GROUP, 140));
typeGroup.setInputPrompt(I18nProperties.getCaption(Captions.Facility_typeGroup));
typeGroup.removeAllItems();
FieldHelper.updateEnumData(typeGroup, FacilityTypeGroup.getAccomodationGroups());
ComboBox type = addField(moreFiltersContainer, FieldConfiguration.pixelSized(ImmunizationCriteria.FACILITY_TYPE, 140));
type.setInputPrompt(I18nProperties.getPrefixCaption(FacilityDto.I18N_PREFIX, FacilityDto.TYPE));
type.removeAllItems();
ComboBox facilityField = addField(moreFiltersContainer, FieldConfiguration.pixelSized(ImmunizationCriteria.HEALTH_FACILITY, 140));
facilityField.setDescription(I18nProperties.getDescription(Descriptions.descFacilityFilter));
addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(ImmunizationCriteria.ONLY_PERSONS_WITH_OVERDUE_IMMUNIZATION, I18nProperties.getCaption(Captions.immunizationOnlyPersonsWithOverdueImmunization), null, CssStyles.CHECKBOX_FILTER_INLINE));
moreFiltersContainer.addComponent(buildWeekAndDateFilter(), WEEK_AND_DATE_FILTER);
}
Aggregations