Search in sources :

Example 21 with User

use of de.symeda.sormas.app.backend.user.User in project SORMAS-Project by hzi-braunschweig.

the class SampleDtoHelper method fillInnerFromAdo.

@Override
public void fillInnerFromAdo(SampleDto target, Sample source) {
    if (source.getAssociatedCase() != null) {
        Case associatedCase = DatabaseHelper.getCaseDao().queryForId(source.getAssociatedCase().getId());
        target.setAssociatedCase(CaseDtoHelper.toReferenceDto(associatedCase));
    } else {
        target.setAssociatedCase(null);
    }
    if (source.getReportingUser() != null) {
        User user = DatabaseHelper.getUserDao().queryForId(source.getReportingUser().getId());
        target.setReportingUser(UserDtoHelper.toReferenceDto(user));
    } else {
        target.setReportingUser(null);
    }
    if (source.getLab() != null) {
        Facility lab = DatabaseHelper.getFacilityDao().queryForId(source.getLab().getId());
        target.setLab(FacilityDtoHelper.toReferenceDto(lab));
    } else {
        target.setLab(null);
    }
    if (source.getReferredToUuid() != null) {
        target.setReferredTo(new SampleReferenceDto(source.getReferredToUuid()));
    } else {
        target.setReferredTo(null);
    }
    target.setLabDetails(source.getLabDetails());
    target.setLabSampleID(source.getLabSampleID());
    target.setFieldSampleID(source.getFieldSampleID());
    target.setSampleDateTime(source.getSampleDateTime());
    target.setReportDateTime(source.getReportDateTime());
    target.setSampleMaterial(source.getSampleMaterial());
    target.setSampleMaterialText(source.getSampleMaterialText());
    target.setSamplePurpose(source.getSamplePurpose());
    target.setShipmentDate(source.getShipmentDate());
    target.setShipmentDetails(source.getShipmentDetails());
    target.setReceivedDate(source.getReceivedDate());
    target.setSpecimenCondition(source.getSpecimenCondition());
    target.setNoTestPossibleReason(source.getNoTestPossibleReason());
    target.setComment(source.getComment());
    target.setSampleSource(source.getSampleSource());
    target.setShipped(source.isShipped());
    target.setReceived(source.isReceived());
    target.setPathogenTestResult(source.getPathogenTestResult());
    target.setPathogenTestingRequested(source.getPathogenTestingRequested());
    target.setAdditionalTestingRequested(source.getAdditionalTestingRequested());
    target.setRequestedPathogenTests(source.getRequestedPathogenTests());
    target.setRequestedAdditionalTests(source.getRequestedAdditionalTests());
    target.setRequestedOtherPathogenTests(source.getRequestedOtherPathogenTests());
    target.setRequestedOtherAdditionalTests(source.getRequestedOtherAdditionalTests());
    target.setReportLat(source.getReportLat());
    target.setReportLon(source.getReportLon());
    target.setReportLatLonAccuracy(source.getReportLatLonAccuracy());
    target.setSamplingReason(source.getSamplingReason());
    target.setSamplingReasonDetails(source.getSamplingReasonDetails());
    if (source.getSormasToSormasOriginInfo() != null) {
        target.setSormasToSormasOriginInfo(sormasToSormasOriginInfoDtoHelper.adoToDto(source.getSormasToSormasOriginInfo()));
    }
    target.setPseudonymized(source.isPseudonymized());
}
Also used : SampleReferenceDto(de.symeda.sormas.api.sample.SampleReferenceDto) User(de.symeda.sormas.app.backend.user.User) Facility(de.symeda.sormas.app.backend.facility.Facility) Case(de.symeda.sormas.app.backend.caze.Case)

Example 22 with User

use of de.symeda.sormas.app.backend.user.User in project SORMAS-Project by hzi-braunschweig.

the class ReportFragment method showReportData.

protected void showReportData() {
    User user = ConfigProvider.getUser();
    EpiWeek epiWeek = getEpiWeek();
    EpiWeekFilterOption filterOption = getEpiWeekFilterOption();
    if (epiWeek == null || !ConfigProvider.hasUserRight(UserRight.WEEKLYREPORT_CREATE)) {
        setVisibilityForNoData();
    } else {
        WeeklyReport weeklyReport = DatabaseHelper.getWeeklyReportDao().queryByEpiWeekAndUser(epiWeek, user);
        if (EpiWeekFilterOption.THIS_WEEK.equals(filterOption)) {
            // table is shown if the report for the last week has been confirmed; no buttons
            reportDate = getResources().getString(R.string.hint_report_not_submitted);
            setVisibilityForTable(false);
            showPendingReport();
        } else if (EpiWeekFilterOption.LAST_WEEK.equals(filterOption)) {
            // table is shown, buttons are shown if the report has not been confirmed yet
            if (weeklyReport == null) {
                setVisibilityForTable(true);
                reportDate = getResources().getString(R.string.hint_report_not_submitted);
                showPendingReport();
            } else {
                setVisibilityForTable(false);
                reportDate = DateFormatHelper.formatLocalDate(weeklyReport.getReportDateTime());
                showWeeklyReport(weeklyReport);
            }
        } else {
            // any other week;
            if (weeklyReport == null) {
                if (DateHelper.isEpiWeekAfter(DateHelper.getEpiWeek(new Date()), epiWeek)) {
                    // 'no data' hint is shown for dates in the future
                    setVisibilityForNoData();
                    reportDate = "";
                    showNoReport();
                } else {
                    // table is shown for dates in the past
                    setVisibilityForTable(true);
                    reportDate = getResources().getString(R.string.hint_report_not_submitted);
                    showPendingReport();
                }
            } else {
                setVisibilityForTable(false);
                reportDate = DateFormatHelper.formatLocalDate(weeklyReport.getReportDateTime());
                showWeeklyReport(weeklyReport);
            }
        }
    }
}
Also used : User(de.symeda.sormas.app.backend.user.User) WeeklyReport(de.symeda.sormas.app.backend.report.WeeklyReport) Date(java.util.Date) EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Example 23 with User

use of de.symeda.sormas.app.backend.user.User in project SORMAS-Project by hzi-braunschweig.

the class RetroProvider method buildRetrofit.

public static Retrofit buildRetrofit(String serverUrl) {
    Gson gson = initGson();
    // Basic auth as explained in https://futurestud.io/tutorials/android-basic-authentication-with-retrofit
    String authToken = Credentials.basic(ConfigProvider.getUsername(), ConfigProvider.getPassword());
    AuthenticationInterceptor interceptor = new AuthenticationInterceptor(authToken);
    OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
    httpClient.connectTimeout(20, TimeUnit.SECONDS);
    httpClient.readTimeout(300, TimeUnit.SECONDS);
    httpClient.writeTimeout(60, TimeUnit.SECONDS);
    // adds "Accept-Encoding: gzip" by default
    httpClient.addInterceptor(interceptor);
    // adds "mobile-sync: true" by default
    httpClient.addInterceptor(chain -> {
        Request original = chain.request();
        Request.Builder builder = original.newBuilder().header("mobile-sync", String.valueOf(true));
        Request request = builder.build();
        return chain.proceed(request);
    });
    // header for logging purposes
    httpClient.addInterceptor(chain -> {
        Request original = chain.request();
        Request.Builder builder = original.newBuilder();
        User user = ConfigProvider.getUser();
        if (user != null) {
            builder.header("User", DataHelper.getShortUuid(user.getUuid()));
            // not sure if this is a good solution
            builder.header("Connection", String.valueOf(lastConnectionId));
        }
        builder.method(original.method(), original.body());
        return chain.proceed(builder.build());
    });
    return new Retrofit.Builder().baseUrl(serverUrl).addConverterFactory(GsonConverterFactory.create(gson)).client(httpClient.build()).build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) User(de.symeda.sormas.app.backend.user.User) GsonBuilder(com.google.gson.GsonBuilder) Request(okhttp3.Request) Gson(com.google.gson.Gson)

Example 24 with User

use of de.symeda.sormas.app.backend.user.User in project SORMAS-Project by hzi-braunschweig.

the class AggregateReportsFragment method showReportData.

private void showReportData() {
    User user = ConfigProvider.getUser();
    EpiWeek epiWeek = (EpiWeek) contentBinding.aggregateReportsWeek.getValue();
    reports = DatabaseHelper.getAggregateReportDao().getReportsByEpiWeekAndUser(epiWeek, user);
    contentBinding.reportContent.removeAllViews();
    Date latestLocalChangeDate = null;
    for (AggregateReport report : reports) {
        LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        RowReportAggregateLayoutBinding binding = DataBindingUtil.inflate(inflater, R.layout.row_report_aggregate_layout, contentBinding.reportContent, true);
        binding.setData(report);
        if (latestLocalChangeDate == null || (report.getLocalChangeDate() != null && latestLocalChangeDate.before(report.getLocalChangeDate()))) {
            latestLocalChangeDate = report.getLocalChangeDate();
        }
    }
    Resources r = getResources();
    if (latestLocalChangeDate == null) {
        getSubHeadingHandler().updateSubHeadingTitle(r.getString(R.string.hint_case_numbers_not_submitted));
    } else {
        getSubHeadingHandler().updateSubHeadingTitle(String.format(r.getString(R.string.caption_latest_submission), DateFormatHelper.formatLocalDateTime(latestLocalChangeDate)));
    }
}
Also used : User(de.symeda.sormas.app.backend.user.User) LayoutInflater(android.view.LayoutInflater) AggregateReport(de.symeda.sormas.app.backend.report.AggregateReport) RowReportAggregateLayoutBinding(de.symeda.sormas.app.databinding.RowReportAggregateLayoutBinding) Resources(android.content.res.Resources) Date(java.util.Date) EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Example 25 with User

use of de.symeda.sormas.app.backend.user.User in project SORMAS-Project by hzi-braunschweig.

the class ReportOverviewFragment method showWeeklyReportOverview.

/**
 * Shows an overview of all informant reports for the user's district
 */
private void showWeeklyReportOverview() {
    if (ConfigProvider.getUser() == null) {
        return;
    }
    if (!(ConfigProvider.hasUserRight(UserRight.WEEKLYREPORT_CREATE) && ConfigProvider.getUser().hasJurisdictionLevel(JurisdictionLevel.DISTRICT))) {
        return;
    }
    getContentBinding().noWeeklyReportData.setVisibility(GONE);
    loadReportTask = new DefaultAsyncTask(getContext()) {

        @Override
        public void onPreExecute() {
            getBaseReportActivity().showPreloader();
        }

        @Override
        public void doInBackground(TaskResultHolder resultHolder) {
            List<WeeklyReportOverviewListItem> list = new ArrayList<>();
            Disease disease = (Disease) getContentBinding().weeklyReportEntryDisease.getValue();
            // confirmed reports
            List<User> informants = DatabaseHelper.getUserDao().getUsersByAssociatedOfficer(ConfigProvider.getUser(), UserRight.WEEKLYREPORT_CREATE);
            for (User informant : informants) {
                WeeklyReport report = DatabaseHelper.getWeeklyReportDao().queryByEpiWeekAndUser(getEpiWeek(), informant);
                if (report != null) {
                    if (disease != null) {
                        WeeklyReportEntry entry = report.getReportEntry(disease);
                        list.add(new WeeklyReportOverviewListItem(report.getHealthFacility(), report.getCommunity(), report.getReportingUser(), entry != null ? entry.getNumberOfCases() : 0, report.getReportDateTime()));
                    } else {
                        list.add(new WeeklyReportOverviewListItem(report.getHealthFacility(), report.getCommunity(), report.getReportingUser(), report.getTotalNumberOfCases(), report.getReportDateTime()));
                    }
                } else {
                    int numberOfCases;
                    if (disease != null) {
                        numberOfCases = DatabaseHelper.getCaseDao().getNumberOfCasesForEpiWeekAndDisease(getEpiWeek(), disease, informant);
                    } else {
                        numberOfCases = DatabaseHelper.getCaseDao().getNumberOfCasesForEpiWeek(getEpiWeek(), informant);
                    }
                    list.add(new WeeklyReportOverviewListItem(informant.getHealthFacility(), informant.getCommunity(), informant, numberOfCases, null));
                }
            }
            resultHolder.forOther().add(list);
        }

        @Override
        protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
            super.onPostExecute(taskResult);
            getBaseActivity().hidePreloader();
            if (taskResult.getResult() == null) {
                return;
            }
            List<WeeklyReportOverviewListItem> list = new ArrayList<>();
            ITaskResultHolderIterator otherIterator = taskResult.getResult().forOther().iterator();
            if (otherIterator.hasNext())
                list = otherIterator.next();
            weeklyReportOverviewAdapter = new WeeklyReportOverviewAdapter(getContext(), list);
            getContentBinding().reportContent.setLayoutManager(linearLayoutManager);
            getContentBinding().reportContent.setAdapter(weeklyReportOverviewAdapter);
            getContentBinding().reportContentFrame.setVisibility(View.VISIBLE);
            weeklyReportOverviewAdapter.notifyDataSetChanged();
        }
    }.executeOnThreadPool();
}
Also used : User(de.symeda.sormas.app.backend.user.User) ITaskResultHolderIterator(de.symeda.sormas.app.core.async.ITaskResultHolderIterator) Disease(de.symeda.sormas.api.Disease) TaskResultHolder(de.symeda.sormas.app.core.async.TaskResultHolder) ArrayList(java.util.ArrayList) DefaultAsyncTask(de.symeda.sormas.app.core.async.DefaultAsyncTask) WeeklyReportEntry(de.symeda.sormas.app.backend.report.WeeklyReportEntry) AsyncTaskResult(de.symeda.sormas.app.core.async.AsyncTaskResult) WeeklyReport(de.symeda.sormas.app.backend.report.WeeklyReport)

Aggregations

User (de.symeda.sormas.app.backend.user.User)50 Case (de.symeda.sormas.app.backend.caze.Case)12 District (de.symeda.sormas.app.backend.region.District)12 Facility (de.symeda.sormas.app.backend.facility.Facility)10 Community (de.symeda.sormas.app.backend.region.Community)9 Person (de.symeda.sormas.app.backend.person.Person)7 Task (de.symeda.sormas.app.backend.task.Task)7 ArrayList (java.util.ArrayList)7 Disease (de.symeda.sormas.api.Disease)6 Contact (de.symeda.sormas.app.backend.contact.Contact)6 Region (de.symeda.sormas.app.backend.region.Region)6 HashSet (java.util.HashSet)6 Test (org.junit.Test)6 UserRole (de.symeda.sormas.api.user.UserRole)5 HealthConditions (de.symeda.sormas.app.backend.clinicalcourse.HealthConditions)5 Location (de.symeda.sormas.app.backend.location.Location)5 CaseDao (de.symeda.sormas.app.backend.caze.CaseDao)4 TaskDao (de.symeda.sormas.app.backend.task.TaskDao)4 Date (java.util.Date)4 ActivityAsCase (de.symeda.sormas.app.backend.activityascase.ActivityAsCase)3