Skip to content

Commit a92beb1

Browse files
committed
patchups
1 parent d6a4131 commit a92beb1

4 files changed

Lines changed: 53 additions & 36 deletions

File tree

openmrs-client/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ dependencies {
133133
def material_version = "1.2.0-alpha03"
134134
def worker_manager_version = "2.3.3"
135135

136-
implementation "androidx.work:work-runtime:$versions_work"
136+
implementation "androidx.work:work-runtime:$worker_manager_version"
137137
implementation 'com.google.code.gson:gson:2.8.5'
138138
implementation "androidx.appcompat:appcompat:$appcompat_version"
139139
androidTestImplementation(

openmrs-client/src/main/java/org/openmrs/mobile/api/repository/PatientRepository.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,18 @@ public class PatientRepository extends RetrofitRepository {
6969
private PatientDAO patientDao;
7070
private LocationRepository locationRepository;
7171
private RestApi restApi;
72-
private WorkManager mWorkManager=null;
72+
private WorkManager mWorkManager = null;
7373

7474
//constructor specifically for update which uses a workManager Implementation
75-
public PatientRepository(Context appContext){
75+
public PatientRepository(Context appContext) {
7676
this.logger = new OpenMRSLogger();
7777
this.patientDao = new PatientDAO();
7878
this.locationRepository = new LocationRepository();
7979
this.restApi = RestServiceBuilder.createService(RestApi.class);
80-
this.mWorkManager=WorkManager.getInstance(appContext);
80+
this.mWorkManager = WorkManager.getInstance(appContext);
8181
}
8282

83-
public PatientRepository(){
83+
public PatientRepository() {
8484
this.logger = new OpenMRSLogger();
8585
this.patientDao = new PatientDAO();
8686
this.locationRepository = new LocationRepository();
@@ -134,7 +134,7 @@ public void onResponse(@NonNull Call<PatientDto> call, @NonNull Response<Patient
134134
uploadPatientPhoto(patient);
135135

136136
new PatientDAO().updatePatient(patient.getId(), patient);
137-
if(!patient.getEncounters().equals(""))
137+
if (!patient.getEncounters().equals(""))
138138
addEncounters(patient);
139139

140140
deferred.resolve(patient);
@@ -144,7 +144,7 @@ public void onResponse(@NonNull Call<PatientDto> call, @NonNull Response<Patient
144144
}
145145

146146
} else {
147-
ToastUtil.error("Patient[" + patient.getId() + "] cannot be synced due to server error"+ response.message());
147+
ToastUtil.error("Patient[" + patient.getId() + "] cannot be synced due to server error" + response.message());
148148
deferred.reject(new RuntimeException("Patient cannot be synced due to server error: " + response.errorBody().toString()));
149149
if (callbackListener != null) {
150150
callbackListener.onErrorResponse(response.message());
@@ -184,12 +184,13 @@ private void uploadPatientPhoto(final Patient patient) {
184184
public void onResponse(@NonNull Call<PatientPhoto> call, @NonNull Response<PatientPhoto> response) {
185185
logger.i(response.message());
186186
if (!response.isSuccessful()) {
187-
ToastUtil.error("Patient photo cannot be synced due to server error: "+ response.message());
187+
ToastUtil.error("Patient photo cannot be synced due to server error: " + response.message());
188188
}
189189
}
190+
190191
@Override
191192
public void onFailure(@NonNull Call<PatientPhoto> call, @NonNull Throwable t) {
192-
ToastUtil.notify("Patient photo cannot be synced due to error: " + t.toString() );
193+
ToastUtil.notify("Patient photo cannot be synced due to error: " + t.toString());
193194
}
194195
});
195196
}
@@ -209,7 +210,7 @@ public void registerPatient(final Patient patient, @Nullable final DefaultRespon
209210
/**
210211
* Update Patient
211212
*/
212-
public void updatePatient(final Patient patient,@Nullable final DefaultResponseCallbackListener callbackListener) {
213+
public void updatePatient(final Patient patient, @Nullable final DefaultResponseCallbackListener callbackListener) {
213214
PatientDto patientDto = patient.getPatientDto();
214215
if (NetworkUtils.isOnline()) {
215216
Call<PatientDto> call = restApi.updatePatient(patientDto, patient.getUuid(), "full");
@@ -251,10 +252,10 @@ public void onFailure(@NonNull Call<PatientDto> call, @NonNull Throwable t) {
251252
});
252253
} else {
253254
//add patient to the local database
254-
patientDao.updatePatient(patient.getId(),patient);
255+
patientDao.updatePatient(patient.getId(), patient);
255256

256257
// enqueue the work to workManager
257-
Data data = new Data.Builder().putString(PatientTable.Column.ID,patient.getId().toString()).build();
258+
Data data = new Data.Builder().putString(PatientTable.Column.ID, patient.getId().toString()).build();
258259
Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();
259260
mWorkManager.enqueue(new OneTimeWorkRequest.Builder(UpdateWorker.class).setConstraints(constraints).setInputData(data).build());
260261

@@ -284,19 +285,19 @@ public void onResponse(@NonNull Call<PatientDto> call, @NonNull Response<Patient
284285
}
285286
});
286287
callbackListener.onPatientDownloaded(newPatientDto.getPatient());
287-
}
288-
else {
288+
} else {
289289
callbackListener.onErrorResponse(response.message());
290290
}
291291
}
292+
292293
@Override
293294
public void onFailure(@NonNull Call<PatientDto> call, @NonNull Throwable t) {
294295
callbackListener.onErrorResponse(t.getMessage());
295296
}
296297
});
297298
}
298-
299-
public SimplePromise<Bitmap> downloadPatientPhotoByUuid(String uuid) {
299+
300+
public SimplePromise<Bitmap> downloadPatientPhotoByUuid(String uuid) {
300301
final SimpleDeferredObject<Bitmap> deferredObject = new SimpleDeferredObject<>();
301302
Call<ResponseBody> call = restApi.downloadPatientPhoto(uuid);
302303
call.enqueue(new Callback<ResponseBody>() {
@@ -317,6 +318,7 @@ public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<Respo
317318
deferredObject.reject(throwable);
318319
}
319320
}
321+
320322
@Override
321323
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
322324
deferredObject.reject(t);
@@ -326,17 +328,16 @@ public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
326328
}
327329

328330
private void addEncounters(Patient patient) {
329-
String enc=patient.getEncounters();
331+
String enc = patient.getEncounters();
330332
List<Long> list = new ArrayList<>();
331333
for (String s : enc.split(","))
332334
list.add(Long.parseLong(s));
333335

334336

335-
for(long id:list)
336-
{
337+
for (long id : list) {
337338
Encountercreate encountercreate = new Select()
338339
.from(Encountercreate.class)
339-
.where("id = ?",id)
340+
.where("id = ?", id)
340341
.executeSingle();
341342
encountercreate.setPatient(patient.getUuid());
342343
encountercreate.save();
@@ -376,7 +377,7 @@ private SimplePromise<IdentifierType> getPatientIdentifierTypeUuid() {
376377
public void onResponse(@NonNull Call<Results<IdentifierType>> call, @NonNull Response<Results<IdentifierType>> response) {
377378
Results<IdentifierType> idresList = response.body();
378379
for (IdentifierType result : idresList.getResults()) {
379-
if(result.getDisplay().equals("OpenMRS ID")) {
380+
if (result.getDisplay().equals("OpenMRS ID")) {
380381
deferred.resolve(result);
381382
return;
382383
}

openmrs-client/src/main/java/org/openmrs/mobile/api/workers/UpdateWorker.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1+
/*
2+
* The contents of this file are subject to the OpenMRS Public License
3+
* Version 1.0 (the "License"); you may not use this file except in
4+
* compliance with the License. You may obtain a copy of the License at
5+
* http://license.openmrs.org
6+
* Software distributed under the License is distributed on an "AS IS"
7+
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
8+
* License for the specific language governing rights and limitations
9+
* under the License.
10+
*
11+
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
12+
*/
13+
114
package org.openmrs.mobile.api.workers;
215

316
import android.content.Context;
17+
import android.content.res.Resources;
418
import android.os.Handler;
519
import android.os.Looper;
620
import android.os.Message;
7-
import android.widget.Switch;
821
import androidx.annotation.NonNull;
922
import androidx.annotation.Nullable;
1023
import androidx.work.Worker;
1124
import androidx.work.WorkerParameters;
25+
import org.openmrs.mobile.R;
1226
import org.openmrs.mobile.api.RestApi;
1327
import org.openmrs.mobile.api.RestServiceBuilder;
1428
import org.openmrs.mobile.application.OpenMRSLogger;
@@ -27,8 +41,8 @@
2741
public class UpdateWorker extends Worker {
2842
private static final int ON_SUCCESS = 1;
2943
private static final int ON_FAILURE = 2;
30-
private static final int ON_SUCCESS_PHOTO_UPDATE = 3;
31-
private static final int ON_FAILURE_PHOTO_UPDATE = 4;
44+
private static final int ON_UNSUCCESSFUL_RESPONSE_PHOTO_UPDATE = 3;
45+
private static final int ON_FAILURE_RESPONSE_PHOTO_UPDATE = 4;
3246

3347
private RestApi restApi;
3448
private OpenMRSLogger logger;
@@ -46,19 +60,18 @@ public void handleMessage(Message msg) {
4660
switch (msg.what) {
4761
case ON_SUCCESS:
4862
String updateSuccessPatientName = (String) msg.obj;
49-
ToastUtil.success("Patient " + UpdateSuccessPatientName + " updated");
63+
ToastUtil.success(Resources.getSystem().getString(R.string.patient_update_successful, updateSuccessPatientName));
5064
break;
5165
case ON_FAILURE:
52-
String UpdateFailedPatientName = (String) msg.obj;
53-
ToastUtil.error("Patient " + UpdateFailedPatientName + " cannot be updated due to server error will retry sync ");
66+
String updateFailedPatientName = (String) msg.obj;
67+
ToastUtil.error(Resources.getSystem().getString(R.string.patient_update_unsuccessful, updateFailedPatientName));
5468
break;
55-
case ON_SUCCESS_PHOTO_UPDATE:
69+
case ON_UNSUCCESSFUL_RESPONSE_PHOTO_UPDATE:
5670
responseMessage = (String) msg.obj;
57-
ToastUtil.error("Patient photo cannot be synced due to server error: " + responseMessage);
58-
break;
59-
case ON_FAILURE_PHOTO_UPDATE:
71+
ToastUtil.error(Resources.getSystem().getString(R.string.patient_photo_update_unsuccessful, responseMessage));
72+
case ON_FAILURE_RESPONSE_PHOTO_UPDATE:
6073
responseMessage = (String) msg.obj;
61-
ToastUtil.notify("Patient photo cannot be synced due to error: " + responseMessage);
74+
ToastUtil.notify(Resources.getSystem().getString(R.string.patient_photo_update_unsuccessful, responseMessage));
6275
}
6376
super.handleMessage(msg);
6477
}
@@ -78,7 +91,6 @@ public Result doWork() {
7891
@Override
7992
public void onResponse() {
8093
result[0] = true;
81-
8294
Message msg = new Message();
8395
msg.obj = patientTobeUpdated.getPerson().getName().getNameString();
8496
msg.what = ON_SUCCESS;
@@ -88,7 +100,6 @@ public void onResponse() {
88100
@Override
89101
public void onErrorResponse(String errorMessage) {
90102
result[0] = false;
91-
92103
Message msg = new Message();
93104
msg.obj = patientTobeUpdated.getPerson().getName().getNameString();
94105
msg.what = ON_FAILURE;
@@ -148,7 +159,7 @@ public void onResponse(@NonNull Call<PatientPhoto> call, @NonNull Response<Patie
148159
if (!response.isSuccessful()) {
149160
Message msg = new Message();
150161
msg.obj = response.message();
151-
msg.what = ON_SUCCESS_PHOTO_UPDATE;
162+
msg.what = ON_UNSUCCESSFUL_RESPONSE_PHOTO_UPDATE;
152163
mHandler.sendMessage(msg);
153164
}
154165
}
@@ -157,7 +168,7 @@ public void onResponse(@NonNull Call<PatientPhoto> call, @NonNull Response<Patie
157168
public void onFailure(@NonNull Call<PatientPhoto> call, @NonNull Throwable t) {
158169
Message msg = new Message();
159170
msg.obj = t.toString();
160-
msg.what = ON_SUCCESS_PHOTO_UPDATE;
171+
msg.what = ON_FAILURE_RESPONSE_PHOTO_UPDATE;
161172
mHandler.sendMessage(msg);
162173
}
163174
});

openmrs-client/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@
152152
<string name="download_started">"Downloading…"</string>
153153
<string name="action_starting_visit">"Starting Visit"</string>
154154

155+
<!--SyncedPatient Activity-->
156+
<string name="patient_update_successful" translatable="false">Patient %1$s Updated</string>
157+
<string name="patient_update_unsuccessful" translatable="false">Patient %1$s cannot be updated due to server error will retry sync</string>
158+
<string name="patient_photo_update_unsuccessful" translatable="false">Patient photo cannot be synced due to server error: %1$s</string>
159+
155160
<!-- fragment_patient_details layout -->
156161
<string name="patient_identifier"># %1$s</string>
157162
<string name="patient_details_photo_label">Photo</string>

0 commit comments

Comments
 (0)