• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OpenSRP / opensrp-client-immunization / #898

pending completion
#898

push

github-actions

web-flow
Merge pull request #195 from opensrp/check-vaccine-duplicates

Add Duplicate Vaccines & Recurring Service Record Checks

5076 of 6673 relevant lines covered (76.07%)

0.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

39.44
opensrp-immunization/src/main/java/org/smartregister/immunization/util/RecurringServiceUtils.java
1
package org.smartregister.immunization.util;
2

3
import android.os.Handler;
4
import android.os.Looper;
5
import android.view.View;
6

7
import org.smartregister.domain.Alert;
8
import org.smartregister.immunization.ImmunizationLibrary;
9
import org.smartregister.immunization.domain.ServiceRecord;
10
import org.smartregister.immunization.domain.ServiceWrapper;
11
import org.smartregister.immunization.repository.RecurringServiceRecordRepository;
12
import org.smartregister.immunization.view.ServiceGroup;
13
import org.smartregister.immunization.view.ServiceRowGroup;
14

15
import java.util.ArrayList;
16
import java.util.List;
17

18
/**
19
 * Created by keyman on 23/05/2017.
20
 */
21
public class RecurringServiceUtils {
1✔
22

23
    public static void updateServiceGroupViews(View view, ArrayList<ServiceWrapper> wrappers,
24
                                               List<ServiceRecord> serviceRecordList, List<Alert> alertList) {
25
        updateServiceGroupViews(view, wrappers, serviceRecordList, alertList, false);
×
26
    }
×
27

28
    public static void updateServiceGroupViews(View view, final ArrayList<ServiceWrapper> wrappers,
29
                                               final List<ServiceRecord> serviceRecordList, final List<Alert> alertList,
30
                                               final boolean undo) {
31
        if (view == null || wrappers == null || wrappers.isEmpty()) {
×
32
            return;
×
33
        }
34

35
        if (view instanceof ServiceGroup) {
×
36
            final ServiceGroup serviceGroup = (ServiceGroup) view;
×
37
            serviceGroup.setModalOpen(false);
×
38

39
            if (Looper.myLooper() == Looper.getMainLooper()) {
×
40
                //if (undo) {
41
                serviceGroup.setServiceRecordList(serviceRecordList);
×
42
                serviceGroup.getServiceCardAdapter().updateServiceRecordList(serviceRecordList);
×
43
                serviceGroup.setAlertList(alertList);
×
44
                serviceGroup.getServiceCardAdapter().updateAlertList(alertList);
×
45
                serviceGroup.updateAllWrapperStatus();
×
46
                //}
47
                serviceGroup.updateViews();
×
48
            } else {
49
                Handler handler = new Handler(Looper.getMainLooper());
×
50
                handler.post(new Runnable() {
×
51
                    @Override
52
                    public void run() {
53
                        //if (undo) {
54
                        serviceGroup.setServiceRecordList(serviceRecordList);
×
55
                        serviceGroup.setAlertList(alertList);
×
56
                        serviceGroup.updateAllWrapperStatus();
×
57
                        //}
58
                        serviceGroup.updateViews();
×
59
                    }
×
60
                });
61
            }
62

63
        } else if (view instanceof ServiceRowGroup) {
×
64
            final ServiceRowGroup serviceRowGroup = (ServiceRowGroup) view;
×
65
            serviceRowGroup.setModalOpen(false);
×
66

67
            if (Looper.myLooper() == Looper.getMainLooper()) {
×
68
                if (undo) {
×
69
                    serviceRowGroup.setServiceRecordList(serviceRecordList);
×
70
                    serviceRowGroup.updateWrapperStatus(wrappers.get(0));
×
71
                }
72
                serviceRowGroup.updateViews(wrappers);
×
73

74
            } else {
75
                Handler handler = new Handler(Looper.getMainLooper());
×
76
                handler.post(new Runnable() {
×
77
                    @Override
78
                    public void run() {
79
                        if (undo) {
×
80
                            serviceRowGroup.setServiceRecordList(serviceRecordList);
×
81
                            serviceRowGroup.updateWrapperStatus(wrappers.get(0));
×
82
                        }
83
                        serviceRowGroup.updateViews(wrappers);
×
84
                    }
×
85
                });
86
            }
87
        }
88
    }
×
89

90

91
    public static ServiceGroup getLastOpenedServiceView(List<ServiceGroup> serviceGroups) {
92
        if (serviceGroups == null) {
1✔
93
            return null;
×
94
        }
95

96
        for (ServiceGroup serviceGroup : serviceGroups) {
1✔
97
            if (serviceGroup.isModalOpen()) {
1✔
98
                return serviceGroup;
1✔
99
            }
100
        }
1✔
101

102
        return null;
×
103
    }
104

105
    public static void saveService(ServiceWrapper tag, String baseEntityId, String providerId, String locationId,
106
                                   String team, String teamId, String childLocationId) {
107
        if (tag.getUpdatedVaccineDate() == null) {
1✔
108
            return;
×
109
        }
110

111
        RecurringServiceRecordRepository recurringServiceRecordRepository = ImmunizationLibrary.getInstance()
1✔
112
                .recurringServiceRecordRepository();
1✔
113

114
        ServiceRecord serviceRecord = new ServiceRecord();
1✔
115
        if (tag.getDbKey() != null) {
1✔
116
            serviceRecord = recurringServiceRecordRepository.find(tag.getDbKey());
×
117
            serviceRecord.setDate(tag.getUpdatedVaccineDate().toDate());
×
118
        } else {
119
            serviceRecord.setDate(tag.getUpdatedVaccineDate().toDate());
1✔
120

121
            serviceRecord.setBaseEntityId(baseEntityId);
1✔
122
            serviceRecord.setRecurringServiceId(tag.getTypeId());
1✔
123
            serviceRecord.setDate(tag.getUpdatedVaccineDate().toDate());
1✔
124
            serviceRecord.setAnmId(providerId);
1✔
125
            serviceRecord.setValue(tag.getValue());
1✔
126
            serviceRecord.setLocationId(locationId);
1✔
127

128
            serviceRecord.setTeam(team);
1✔
129
            serviceRecord.setTeamId(teamId);
1✔
130
            serviceRecord.setChildLocationId(childLocationId);
1✔
131
        }
132

133
        ServiceRecord existingServiceRecord = recurringServiceRecordRepository.findByBaseEntityIdAndRecurringServiceId(
1✔
134
                serviceRecord.getBaseEntityId(),
1✔
135
                serviceRecord.getRecurringServiceId()
1✔
136
        );
137
        if (existingServiceRecord != null) {
1✔
138
            serviceRecord.setId(existingServiceRecord.getId());
×
139
        }
140

141
        recurringServiceRecordRepository.add(serviceRecord);
1✔
142

143
        tag.setDbKey(serviceRecord.getId());
1✔
144
    }
1✔
145
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc