Search in sources :

Example 1 with Item

use of de.symeda.sormas.app.component.Item in project SORMAS-Project by hzi-braunschweig.

the class CaseEditHospitalizationFragment method onLayoutBinding.

@Override
public void onLayoutBinding(final FragmentCaseEditHospitalizationLayoutBinding contentBinding) {
    setUpControlListeners();
    CaseValidator.initializeHospitalizationValidation(contentBinding, caze);
    List<Item> hospitalizationReasons = DataUtils.getEnumItems(HospitalizationReasonType.class, true);
    contentBinding.setData(record);
    contentBinding.setCaze(caze);
    contentBinding.setPreviousHospitalizationList(getPreviousHospitalizations());
    contentBinding.setPrevHosItemClickCallback(onPrevHosItemClickListener);
    getContentBinding().setPreviousHospitalizationBindCallback(this::setFieldVisibilitiesAndAccesses);
    contentBinding.caseHospitalizationHospitalizationReason.initializeSpinner(hospitalizationReasons);
    contentBinding.caseHospitalizationHospitalizedPreviously.addValueChangedListener(field -> {
        YesNoUnknown value = (YesNoUnknown) field.getValue();
        contentBinding.prevHospitalizationsLayout.setVisibility(value == YesNoUnknown.YES ? View.VISIBLE : View.GONE);
        if (value != YesNoUnknown.YES) {
            clearPreviousHospitalizations();
        }
        verifyPrevHospitalizationStatus();
    });
}
Also used : Item(de.symeda.sormas.app.component.Item) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown)

Example 2 with Item

use of de.symeda.sormas.app.component.Item in project SORMAS-Project by hzi-braunschweig.

the class CaseListActivity method addFiltersToPageMenu.

@Override
public void addFiltersToPageMenu() {
    View caseListFilterView = getLayoutInflater().inflate(R.layout.filter_case_list_layout, null);
    filterBinding = DataBindingUtil.bind(caseListFilterView);
    List<Item> diseases = DataUtils.toItems(DiseaseConfigurationCache.getInstance().getAllDiseases(true, true, true));
    filterBinding.diseaseFilter.initializeSpinner(diseases);
    List<Item> classifications = DataUtils.getEnumItems(CaseClassification.class);
    filterBinding.classificationFilter.initializeSpinner(classifications);
    List<Item> outcomes = DataUtils.getEnumItems(CaseOutcome.class);
    filterBinding.outcomeFilter.initializeSpinner(outcomes);
    if (UserRole.isPortHealthUser(ConfigProvider.getUser().getUserRoles())) {
        filterBinding.originFilter.setVisibility(GONE);
    } else {
        List<Item> caseOrigins = DataUtils.getEnumItems(CaseOrigin.class);
        filterBinding.originFilter.initializeSpinner(caseOrigins);
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    List<Item> epiWeeks = DataUtils.toItems(DateHelper.createEpiWeekList(calendar.get(Calendar.YEAR), calendar.get(Calendar.WEEK_OF_YEAR)));
    filterBinding.epiWeekFromFilter.initializeSpinner(epiWeeks);
    filterBinding.epiWeekToFilter.initializeSpinner(epiWeeks);
    pageMenu.addFilter(caseListFilterView);
    filterBinding.applyFilters.setOnClickListener(e -> {
        showPreloader();
        pageMenu.hideAll();
        model.notifyCriteriaUpdated();
    });
    filterBinding.resetFilters.setOnClickListener(e -> {
        showPreloader();
        pageMenu.hideAll();
        model.getCaseCriteria().setTextFilter(null);
        model.getCaseCriteria().setDisease(null);
        model.getCaseCriteria().setCaseClassification(null);
        model.getCaseCriteria().setOutcome(null);
        model.getCaseCriteria().setEpiWeekFrom(null);
        model.getCaseCriteria().setEpiWeekTo(null);
        model.getCaseCriteria().setCaseOrigin(null);
        filterBinding.invalidateAll();
        filterBinding.executePendingBindings();
        model.notifyCriteriaUpdated();
    });
}
Also used : PageMenuItem(de.symeda.sormas.app.component.menu.PageMenuItem) Item(de.symeda.sormas.app.component.Item) Calendar(java.util.Calendar) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) Date(java.util.Date)

Example 3 with Item

use of de.symeda.sormas.app.component.Item in project SORMAS-Project by hzi-braunschweig.

the class LocationDialog method initializeContentView.

@Override
protected void initializeContentView(ViewDataBinding rootBinding, ViewDataBinding buttonPanelBinding) {
    List<Item> initialContinents = InfrastructureDaoHelper.loadContinents();
    List<Item> initialSubcontinents = InfrastructureDaoHelper.loadSubcontinents();
    List<Item> initialCountries = InfrastructureDaoHelper.loadCountries();
    List<Item> initialRegions = InfrastructureDaoHelper.loadRegionsByServerCountry();
    List<Item> initialDistricts = InfrastructureDaoHelper.loadDistricts(data.getRegion());
    List<Item> initialCommunities = InfrastructureDaoHelper.loadCommunities(data.getDistrict());
    List<Item> initialFacilities = InfrastructureDaoHelper.loadFacilities(data.getDistrict(), data.getCommunity(), data.getFacilityType());
    List<Item> facilityTypeGroupList = DataUtils.toItems(Arrays.asList(FacilityTypeGroup.values()), true);
    List<Item> facilityTypeList = data.getFacilityType() != null ? DataUtils.toItems(FacilityType.getTypes(data.getFacilityType().getFacilityTypeGroup())) : null;
    InfrastructureDaoHelper.initializeHealthFacilityDetailsFieldVisibility(contentBinding.locationFacility, contentBinding.locationFacilityDetails);
    if (data.getCountry() == null) {
        String serverCountryName = ConfigProvider.getServerCountryName();
        for (Item countryItem : initialCountries) {
            Country country = (Country) countryItem.getValue();
            if (country != null && serverCountryName != null && serverCountryName.equalsIgnoreCase(country.getName())) {
                data.setCountry(country);
                break;
            }
        }
    }
    InfrastructureFieldsDependencyHandler.instance.initializeFacilityFields(data, this.contentBinding.locationContinent, initialContinents, data.getContinent(), this.contentBinding.locationSubcontinent, initialSubcontinents, data.getSubcontinent(), this.contentBinding.locationCountry, initialCountries, data.getCountry(), this.contentBinding.locationRegion, initialRegions, data.getRegion(), this.contentBinding.locationDistrict, initialDistricts, data.getDistrict(), this.contentBinding.locationCommunity, initialCommunities, data.getCommunity(), null, null, this.contentBinding.facilityTypeGroup, facilityTypeGroupList, this.contentBinding.locationFacilityType, facilityTypeList, this.contentBinding.locationFacility, initialFacilities, data.getFacility(), this.contentBinding.locationFacilityDetails, true);
    setFieldVisibilitiesAndAccesses(LocationDto.class, contentBinding.mainContent);
    if (!isFieldAccessible(LocationDto.class, LocationDto.COMMUNITY)) {
        this.contentBinding.locationRegion.setEnabled(false);
        this.contentBinding.locationDistrict.setEnabled(false);
    }
    contentBinding.locationAreaType.initializeSpinner(DataUtils.getEnumItems(AreaType.class));
    // "Pick GPS Coordinates" confirmation dialog
    this.contentBinding.pickGpsCoordinates.setOnClickListener(v -> {
        final ConfirmationDialog confirmationDialog = new ConfirmationDialog(getActivity(), R.string.heading_confirmation_dialog, R.string.confirmation_pick_gps, R.string.yes, R.string.no);
        confirmationDialog.setPositiveCallback(() -> {
            android.location.Location phoneLocation = LocationService.instance().getLocation(getActivity());
            if (phoneLocation != null) {
                contentBinding.locationLatitude.setDoubleValue(phoneLocation.getLatitude());
                contentBinding.locationLongitude.setDoubleValue(phoneLocation.getLongitude());
                contentBinding.locationLatLonAccuracy.setFloatValue(phoneLocation.getAccuracy());
            } else {
                NotificationHelper.showDialogNotification(LocationDialog.this, NotificationType.WARNING, R.string.message_gps_problem);
            }
        });
        confirmationDialog.show();
    });
    if (data.getId() == null) {
        setLiveValidationDisabled(true);
    }
    if (data.getFacility() == null) {
        contentBinding.locationFacilityDetails.setVisibility(GONE);
    } else {
        contentBinding.facilityTypeGroup.setValue(data.getFacilityType().getFacilityTypeGroup());
    }
    if (data.getFacilityType() != null) {
        contentBinding.locationFacilityType.setValue(data.getFacilityType());
        contentBinding.facilityTypeGroup.setValue(data.getFacilityType().getFacilityTypeGroup());
    } else {
        setFacilityContactPersonFieldsVisible(false, true);
    }
    contentBinding.locationFacilityType.addValueChangedListener(field -> {
        if (field.getValue() == null) {
            setFacilityContactPersonFieldsVisible(false, true);
        } else {
            setFacilityContactPersonFieldsVisible(true, true);
        }
    });
    contentBinding.locationFacility.addValueChangedListener(field -> {
        final Facility facility = (Facility) field.getValue();
        // field.isDirty() always return true making it not usable in our case
        if (this.previousFacility != null && this.previousFacility.equals(facility)) {
            // The field didn't changed
            return;
        }
        this.previousFacility = facility;
        if (facility != null && (StringUtils.isNotEmpty(facility.getCity()) || StringUtils.isNotEmpty(facility.getPostalCode()) || StringUtils.isNotEmpty(facility.getStreet()) || StringUtils.isNotEmpty(facility.getHouseNumber()) || StringUtils.isNotEmpty(facility.getAdditionalInformation()) || facility.getAreaType() != null || facility.getLatitude() != null || facility.getLongitude() != null || (StringUtils.isNotEmpty(facility.getContactPersonFirstName()) && StringUtils.isNotEmpty(facility.getContactPersonLastName())))) {
            if ((StringUtils.isNotEmpty(contentBinding.locationCity.getValue()) && !contentBinding.locationCity.getValue().equals(facility.getCity())) || (StringUtils.isNotEmpty(contentBinding.locationPostalCode.getValue()) && !contentBinding.locationPostalCode.getValue().equals(facility.getPostalCode())) || (StringUtils.isNotEmpty(contentBinding.locationStreet.getValue()) && !contentBinding.locationStreet.getValue().equals(facility.getStreet())) || (StringUtils.isNotEmpty(contentBinding.locationHouseNumber.getValue()) && !contentBinding.locationHouseNumber.getValue().equals(facility.getHouseNumber())) || (StringUtils.isNotEmpty(contentBinding.locationAdditionalInformation.getValue()) && !contentBinding.locationAdditionalInformation.getValue().equals(facility.getAdditionalInformation())) || (contentBinding.locationAreaType.getValue() != null && contentBinding.locationAreaType.getValue() != facility.getAreaType()) || (StringUtils.isNotEmpty(contentBinding.locationContactPersonFirstName.getValue()) && StringUtils.isNotEmpty(contentBinding.locationContactPersonLastName.getValue())) || (StringUtils.isNotEmpty(contentBinding.locationLatitude.getValue()) && !Double.valueOf(contentBinding.locationLatitude.getValue()).equals(facility.getLatitude())) || (StringUtils.isNotEmpty(contentBinding.locationLongitude.getValue()) && !Double.valueOf(contentBinding.locationLongitude.getValue()).equals(facility.getLongitude()))) {
                ConfirmationDialog confirmationDialog = new ConfirmationDialog(getActivity(), R.string.heading_location, -1, R.string.yes, R.string.no);
                confirmationDialog.getConfig().setSubHeading(I18nProperties.getString(Strings.confirmationLocationFacilityAddressOverride));
                confirmationDialog.setPositiveCallback(() -> overrideLocationDetailsWithFacilityOnes(facility));
                confirmationDialog.show();
            } else {
                overrideLocationDetailsWithFacilityOnes(facility);
            }
        }
    });
    ValidationHelper.initEmailValidator(contentBinding.locationContactPersonEmail);
    ValidationHelper.initPhoneNumberValidator(contentBinding.locationContactPersonPhone);
}
Also used : Item(de.symeda.sormas.app.component.Item) Country(de.symeda.sormas.app.backend.region.Country) Facility(de.symeda.sormas.app.backend.facility.Facility) AreaType(de.symeda.sormas.api.infrastructure.area.AreaType) LocationDto(de.symeda.sormas.api.location.LocationDto)

Example 4 with Item

use of de.symeda.sormas.app.component.Item in project SORMAS-Project by hzi-braunschweig.

the class ControlSpinnerAdapter method getView.

@Override
@NonNull
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
    final View view;
    final TextView textView;
    if (convertView == null) {
        view = inflater.inflate(this.layoutResourceId, parent, false);
    } else {
        view = convertView;
    }
    final Item item = getItem(position);
    textView = (TextView) view.findViewById(textViewResourceId);
    if (item != null) {
        textView.setText(item.toString());
    }
    if (textView != null && (StringUtils.isEmpty(textView.getText()))) {
        if (spinner.getHint() != null) {
            textView.setHint(spinner.getHint());
        } else {
            textView.setHint(getContext().getResources().getString(R.string.hint_select_entry));
        }
        textView.setTextColor(getContext().getResources().getColor(R.color.hintText));
    }
    return view;
}
Also used : Item(de.symeda.sormas.app.component.Item) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) NonNull(androidx.annotation.NonNull)

Example 5 with Item

use of de.symeda.sormas.app.component.Item in project SORMAS-Project by hzi-braunschweig.

the class ControlSpinnerField method setFieldValue.

@Override
protected void setFieldValue(Object value) {
    if (input == null) {
        return;
    }
    if (value == null) {
        removeSelection();
        return;
    }
    SpinnerAdapter adapter = input.getAdapter();
    valueOnBind = value;
    if (adapter != null) {
        for (int i = 0; i < adapter.getCount(); i++) {
            Object itemValue = ((Item) adapter.getItem(i)).getValue();
            if (value.equals(itemValue)) {
                input.setSelection(i);
                break;
            }
        }
    } else {
        removeSelection();
    }
}
Also used : SpinnerAdapter(android.widget.SpinnerAdapter) Item(de.symeda.sormas.app.component.Item)

Aggregations

Item (de.symeda.sormas.app.component.Item)27 View (android.view.View)7 PageMenuItem (de.symeda.sormas.app.component.menu.PageMenuItem)7 District (de.symeda.sormas.app.backend.region.District)6 ArrayList (java.util.ArrayList)6 AdapterView (android.widget.AdapterView)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 Facility (de.symeda.sormas.app.backend.facility.Facility)5 InfrastructureDaoHelper.isEmptyDistrict (de.symeda.sormas.app.util.InfrastructureDaoHelper.isEmptyDistrict)5 InfrastructureDaoHelper.isUnknownDistrict (de.symeda.sormas.app.util.InfrastructureDaoHelper.isUnknownDistrict)5 InfrastructureDaoHelper.unknownDistrict (de.symeda.sormas.app.util.InfrastructureDaoHelper.unknownDistrict)5 FacilityType (de.symeda.sormas.api.infrastructure.facility.FacilityType)4 InfrastructureDaoHelper.isEmptyFacility (de.symeda.sormas.app.util.InfrastructureDaoHelper.isEmptyFacility)4 InfrastructureDaoHelper.isUnknownFacility (de.symeda.sormas.app.util.InfrastructureDaoHelper.isUnknownFacility)4 InfrastructureDaoHelper.unknownFacility (de.symeda.sormas.app.util.InfrastructureDaoHelper.unknownFacility)4 TypeOfPlace (de.symeda.sormas.api.event.TypeOfPlace)3 Region (de.symeda.sormas.app.backend.region.Region)3 TextView (android.widget.TextView)2 FacilityTypeGroup (de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup)2 Campaign (de.symeda.sormas.app.backend.campaign.Campaign)2