Skip to content

Commit

Permalink
Merge branch '#785-Patient_Exit_Survey' into Bug_Fixes_VSO_2
Browse files Browse the repository at this point in the history
  • Loading branch information
nehav39 committed Mar 13, 2020
2 parents 5db60c1 + 821c669 commit 9fd057d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

import com.crashlytics.android.Crashlytics;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -58,6 +62,7 @@ public class PatientSurveyActivity extends AppCompatActivity {
String comments;

SessionManager sessionManager = null;

@Override
public void onBackPressed() {
//do nothing
Expand Down Expand Up @@ -115,13 +120,11 @@ public void onClick(View v) {
public void onClick(View v) {

if (rating != null && !TextUtils.isEmpty(rating)) {
Log.d(TAG, "Rating is "+rating);
Log.d(TAG, "Rating is " + rating);
uploadSurvey();
endVisit();
}
else
{
Toast.makeText(getApplicationContext(),getString(R.string.exit_survey_toast),Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), getString(R.string.exit_survey_toast), Toast.LENGTH_LONG).show();
}

}
Expand Down Expand Up @@ -158,9 +161,17 @@ private void uploadSurvey() {
encounterDTO = new EncounterDTO();
encounterDTO.setUuid(uuid);
encounterDTO.setEncounterTypeUuid(encounterDAO.getEncounterTypeUuid("ENCOUNTER_PATIENT_EXIT_SURVEY"));
encounterDTO.setEncounterTime(AppConstants.dateAndTimeUtils.currentDateTime());

//As per issue #785 - we fixed it by subtracting 1 minute from Encounter Time
try {
encounterDTO.setEncounterTime(fiveMinutesAgo(AppConstants.dateAndTimeUtils.currentDateTime()));
} catch (ParseException e) {
e.printStackTrace();
}

encounterDTO.setVisituuid(visitUuid);
encounterDTO.setProvideruuid(encounterDTO.getProvideruuid()); //handles correct provideruuid for every patient
// encounterDTO.setProvideruuid(encounterDTO.getProvideruuid()); //handles correct provideruuid for every patient
encounterDTO.setProvideruuid(sessionManager.getProviderID()); //handles correct provideruuid for every patient
encounterDTO.setSyncd(false);
encounterDTO.setVoided(0);
try {
Expand Down Expand Up @@ -190,10 +201,17 @@ private void uploadSurvey() {
Crashlytics.getInstance().core.logException(e);
}

// AppConstants.notificationUtils.DownloadDone("Upload survey", "Survey uploaded", 3, PatientSurveyActivity.this);

}

// AppConstants.notificationUtils.DownloadDone("Upload survey", "Survey uploaded", 3, PatientSurveyActivity.this);
public String fiveMinutesAgo(String timeStamp) throws ParseException {

long FIVE_MINS_IN_MILLIS = 5 * 60 * 1000;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
long time = df.parse(timeStamp).getTime();

return df.format(new Date(time - FIVE_MINS_IN_MILLIS));
}

private void endVisit() {
Expand All @@ -202,7 +220,6 @@ private void endVisit() {
visitsDAO.updateVisitEnddate(visitUuid, AppConstants.dateAndTimeUtils.currentDateTime());
} catch (DAOException e) {
Crashlytics.getInstance().core.logException(e);

}

//SyncDAO syncDAO = new SyncDAO();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.util.Log;

import com.crashlytics.android.Crashlytics;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -119,8 +120,10 @@ public List<EncounterDTO> unsyncedEncounters() {
List<EncounterDTO> encounterDTOList = new ArrayList<>();
SQLiteDatabase db = AppConstants.inteleHealthDatabaseHelper.getWriteDb();
db.beginTransaction();
Cursor idCursor = db.rawQuery("SELECT distinct a.uuid,a.visituuid,a.encounter_type_uuid,a.provider_uuid,a.encounter_time,a.voided,a.privacynotice_value FROM tbl_encounter a,tbl_obs b where (a.sync = ? OR a.sync=?) and a.uuid = b.encounteruuid and b.sync='false' AND b.voided='0' ", new String[]{"false", "0"});
//Distinct keyword is used to remove all duplicate records.
Cursor idCursor = db.rawQuery("SELECT distinct a.uuid,a.visituuid,a.encounter_type_uuid,a.provider_uuid,a.encounter_time,a.voided,a.privacynotice_value FROM tbl_encounter a,tbl_obs b WHERE (a.sync = ? OR a.sync=?) AND a.uuid = b.encounteruuid AND b.sync='false' AND b.voided='0' ", new String[]{"false", "0"});
EncounterDTO encounterDTO = new EncounterDTO();
Log.d("RAINBOW: ","RAINBOW: "+idCursor.getCount());
if (idCursor.getCount() != 0) {
while (idCursor.moveToNext()) {
encounterDTO = new EncounterDTO();
Expand All @@ -140,7 +143,8 @@ public List<EncounterDTO> unsyncedEncounters() {
db.setTransactionSuccessful();
db.endTransaction();


Gson gson = new Gson();
Log.d("ENC_GSON: ","ENC_GSON: "+gson.toJson(encounterDTOList));
return encounterDTOList;
}

Expand Down Expand Up @@ -193,8 +197,6 @@ public boolean updateEncounterSync(String synced, String uuid) throws DAOExcepti
throw new DAOException(sql.getMessage());
} finally {
db.endTransaction();


}

return isUpdated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public boolean insertObsToDb(List<ObsDTO> obsDTO) throws DAOException {
values.put("value", ob.getValue());
values.put("modified_date", AppConstants.dateAndTimeUtils.currentDateTime());
values.put("voided", "0");
values.put("sync", "FALSE");
values.put("sync", "false"); //Earlier was set to FALSE which caused the issue.
insertedCount = db.insert("tbl_obs", null, values);
}
db.setTransactionSuccessful();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.util.Log;

import com.crashlytics.android.Crashlytics;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -171,6 +172,8 @@ public PushRequestApiCall frameJson() {
pushRequestApiCall.setPersons(personList);
pushRequestApiCall.setVisits(visitList);
pushRequestApiCall.setEncounters(encounterList);
Gson gson = new Gson();
Log.d("OBS: ","OBS: "+gson.toJson(encounterList));


return pushRequestApiCall;
Expand Down

0 comments on commit 9fd057d

Please sign in to comment.