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

OpenSRP / opensrp-client-immunization / #901

pending completion
#901

push

github-actions

web-flow
Merge pull request #191 from opensrp/issue189-2

Migrate core dependencies

5141 of 6670 relevant lines covered (77.08%)

0.77 hits per line

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

28.38
opensrp-immunization/src/main/java/org/smartregister/immunization/domain/VaccinateFormSubmissionWrapper.java
1
package org.smartregister.immunization.domain;
2

3
import org.apache.commons.lang3.StringUtils;
4
import org.joda.time.DateTime;
5
import org.json.JSONObject;
6
import org.smartregister.immunization.db.VaccineRepo;
7
import org.smartregister.immunization.util.VaccinateActionUtils;
8

9
import java.io.Serializable;
10
import java.util.Date;
11
import java.util.HashMap;
12
import java.util.Map;
13

14
import timber.log.Timber;
15

16
/**
17
 * Created by keyman on 22/11/2016.
18
 */
19
public class VaccinateFormSubmissionWrapper implements Serializable {
20

21
    private String formData;
22

23
    private String entityId;
24

25
    private String formName;
26

27
    private String metaData;
28

29
    private String category;
30

31
    private HashMap<String, VaccineWrapper> map;
32

33
    public VaccinateFormSubmissionWrapper(String formData, String entityId, String formName, String metaData,
34
                                          String category) {
1✔
35
        this.formData = formData;
1✔
36
        this.entityId = entityId;
1✔
37
        this.formName = formName;
1✔
38
        this.metaData = metaData;
1✔
39
        this.category = category;
1✔
40
    }
1✔
41

42
    public void add(VaccineWrapper tag) {
43
        if (tag.getUpdatedVaccineDate() != null) {
1✔
44
            map().put(tag.getId(), tag);
1✔
45
        }
46
    }
1✔
47

48
    public HashMap<String, VaccineWrapper> map() {
49
        if (map == null) {
1✔
50
            map = new HashMap<String, VaccineWrapper>();
1✔
51
        }
52
        return map;
1✔
53
    }
54

55
    public void remove(VaccineWrapper tag) {
56
        map().remove(tag.getId());
1✔
57
    }
1✔
58

59
    public String updateFormSubmission() {
60
        try {
61
            if (updates() <= 0)
1✔
62
                return null;
1✔
63

64

65
            String parent = "";
×
66
            if ("child".equals(category)) {
×
67
                parent = "Child_Vaccination_Followup";
×
68
            } else if ("woman".equals(category)) {
×
69
                parent = "Woman_TT_Followup_Form";
×
70
            }
71

72
            JSONObject formSubmission = new JSONObject(formData);
×
73

74
            JSONObject encounterJson = VaccinateActionUtils.find(formSubmission, parent);
×
75

76
            String vaccines = "";
×
77
            String vaccines2 = "";
×
78

79
            for (Map.Entry<String, VaccineWrapper> entry : map().entrySet()) {
×
80

81
                VaccineWrapper tag = entry.getValue();
×
82
                String formatedDate = tag.getUpdatedVaccineDate().toString("yyyy-MM-dd");
×
83

84
                VaccineRepo.Vaccine vaccine = tag.getVaccine();
×
85
                String lastChar = vaccine.name().substring(vaccine.name().length() - 1);
×
86

87
                if (!tag.isToday()) {
×
88
                    String fieldName = vaccine.name() + "_retro";
×
89

90
                    JSONObject parentJson = null;
×
91
                    if ("child".equals(category)) {
×
92
                        parentJson = VaccinateActionUtils.find(encounterJson, "vaccines_group");
×
93
                    } else if ("woman".equals(category)) {
×
94
                        parentJson = encounterJson;
×
95
                    }
96

97
                    if (parentJson != null) {
×
98
                        VaccinateActionUtils.updateJson(parentJson, fieldName, formatedDate);
×
99
                        if (StringUtils.isNumeric(lastChar)) {
×
100
                            VaccinateActionUtils.updateJson(parentJson, vaccine.name() + "_dose", lastChar);
×
101
                        }
102
                        vaccines += vaccine.name() + " ";
×
103
                    }
104
                } else {
×
105
                    VaccinateActionUtils.updateJson(encounterJson, vaccine.name(), formatedDate);
×
106
                    if (StringUtils.isNumeric(lastChar)) {
×
107
                        VaccinateActionUtils.updateJson(encounterJson, vaccine.name() + "_dose_today", lastChar);
×
108
                    }
109
                    vaccines2 += vaccine.name() + " ";
×
110
                }
111
            }
×
112

113

114
            if (StringUtils.isNotBlank(vaccines)) {
×
115
                vaccines = vaccines.trim();
×
116
                VaccinateActionUtils.updateJson(encounterJson, "vaccines", vaccines);
×
117
            }
118

119
            if (StringUtils.isNotBlank(vaccines2)) {
×
120
                vaccines2 = vaccines2.trim();
×
121
                VaccinateActionUtils.updateJson(encounterJson, "vaccines_2", vaccines2);
×
122
            }
123

124
            VaccinateActionUtils.updateJson(encounterJson, "address_change", "no");
×
125
            VaccinateActionUtils.updateJson(encounterJson, "reminders_approval", "no");
×
126

127
            DateTime currentDateTime = new DateTime(new Date());
×
128
            VaccinateActionUtils.updateJson(encounterJson, "start", currentDateTime.toString("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
×
129
            VaccinateActionUtils.updateJson(encounterJson, "end", currentDateTime.toString("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
×
130
            VaccinateActionUtils.updateJson(encounterJson, "today", currentDateTime.toString("yyyy-MM-dd"));
×
131

132
            VaccinateActionUtils.updateJson(encounterJson, "deviceid", "Error: could not determine deviceID");
×
133
            VaccinateActionUtils.updateJson(encounterJson, "subscriberid", "no subscriberid property in enketo");
×
134
            VaccinateActionUtils.updateJson(encounterJson, "simserial", "no simserial property in enketo");
×
135
            VaccinateActionUtils.updateJson(encounterJson, "phonenumber", "no phonenumber property in enketo");
×
136

137

138
            String data = formSubmission.toString();
×
139
            return data;
×
140
        } catch (Exception e) {
×
141
            Timber.e(e);
×
142
        }
143
        return null;
×
144
    }
145

146
    public int updates() {
147
        return map().size();
1✔
148
    }
149

150
    public String getEntityId() {
151
        return entityId;
1✔
152
    }
153

154
    public String getFormName() {
155
        return formName;
1✔
156
    }
157

158
    public JSONObject getOverrides() {
159
        return VaccinateActionUtils.retrieveFieldOverides(metaData);
1✔
160
    }
161

162
}
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