@@ -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 }
0 commit comments