diff --git a/.gitignore b/.gitignore
index aa724b7..23c29da 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,14 @@
*.iml
.gradle
/local.properties
+/.idea/.name
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
+.idea/deploymentTargetDropDown.xml
.DS_Store
/build
/captures
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index a2d7c21..7b46144 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -7,6 +7,7 @@
+
-
+
diff --git a/app/build.gradle b/app/build.gradle
index d1eca40..8f4e97b 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -58,4 +58,6 @@ dependencies {
implementation 'com.squareup.okhttp3:logging-interceptor:4.4.1'
implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
implementation 'com.squareup.picasso:picasso:2.8'
+ implementation "com.squareup.retrofit2:adapter-rxjava2:2.4.0"
+ implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 03cb862..74cbac7 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,6 +5,9 @@
+
+
+
+ android:usesCleartextTraffic="true"
+ android:requestLegacyExternalStorage="true">
@@ -26,6 +30,10 @@
android:name=".Activities.DiagnosisActivity"
android:exported="true">
+
+
-
diff --git a/app/src/main/java/com/ug/air/alrite/APIs/ApiClient.java b/app/src/main/java/com/ug/air/alrite/APIs/ApiClient.java
index 4e07fc6..7ca2dc3 100644
--- a/app/src/main/java/com/ug/air/alrite/APIs/ApiClient.java
+++ b/app/src/main/java/com/ug/air/alrite/APIs/ApiClient.java
@@ -8,15 +8,19 @@
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
+import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;
public class ApiClient {
- private static final String BASE_URL = "http://140.142.142.94/alrite/apis/";
-// private static final String BASE_URL = "http://10.0.2.2:8000/alrite/apis/";
- private static Retrofit retrofit = null;
+ public static final String BASE_URL = "http://140.142.142.94/alrite/apis/";
+ public static final String TEMP_SERV_URL = "http://10.0.2.2:8000";
+ public static final String REMOTE_URL_TEMP = "http://54.190.44.215:8000";
- public static Retrofit getClient() {
+ // private static final String BASE_URL = "http://10.0.2.2:8000/alrite/apis/";
+ private static Retrofit retrofit;
+
+ public static Retrofit getClient(String URL) {
if (retrofit == null){
@@ -33,10 +37,11 @@ public static Retrofit getClient() {
.build();
retrofit = new Retrofit.Builder()
- .baseUrl(BASE_URL)
+ .baseUrl(URL)
.client(okHttpClient)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
+ .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
}
return retrofit;
diff --git a/app/src/main/java/com/ug/air/alrite/APIs/BackendRequests.java b/app/src/main/java/com/ug/air/alrite/APIs/BackendRequests.java
new file mode 100644
index 0000000..7d70cd8
--- /dev/null
+++ b/app/src/main/java/com/ug/air/alrite/APIs/BackendRequests.java
@@ -0,0 +1,21 @@
+package com.ug.air.alrite.APIs;
+
+import com.ug.air.alrite.Utils.BackendPostRequest;
+
+import io.reactivex.Observable;
+import retrofit2.Call;
+import retrofit2.http.Body;
+import retrofit2.http.GET;
+import retrofit2.http.POST;
+import retrofit2.http.Path;
+
+public interface BackendRequests {
+
+ @GET("/alrite/apis/workflows/{workflow_id}/")
+ Call getJson(@Path("workflow_id") String workflow_id);
+
+ @POST("/apis/data/{workflow_id}/{workflow_version}/")
+ Observable postToBackend(@Path("workflow_id") String workflow_id,
+ @Path("workflow_version") String workflow_version,
+ @Body BackendPostRequest body);
+}
diff --git a/app/src/main/java/com/ug/air/alrite/Activities/DiagnosisActivity.java b/app/src/main/java/com/ug/air/alrite/Activities/DiagnosisActivity.java
index dbe362a..08bad53 100644
--- a/app/src/main/java/com/ug/air/alrite/Activities/DiagnosisActivity.java
+++ b/app/src/main/java/com/ug/air/alrite/Activities/DiagnosisActivity.java
@@ -2,28 +2,28 @@
import static com.ug.air.alrite.Activities.FinalActivity.S6;
import static com.ug.air.alrite.Activities.FinalActivity.S7;
-import static com.ug.air.alrite.Activities.PatientActivity.INCOMPLETE;
+import static com.ug.air.alrite.Activities.PatientActivity.ASSESS_INCOMPLETE;
import static com.ug.air.alrite.Fragments.Patient.Allergies.CHOICEY2;
-import static com.ug.air.alrite.Fragments.Patient.Assess.DIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.Assess.FINAL_DIAGNOSIS;
-import static com.ug.air.alrite.Fragments.Patient.Assess.S4;
+import static com.ug.air.alrite.Fragments.Patient.Assess.SEVERE_SYMPTOMS;
import static com.ug.air.alrite.Fragments.Patient.Breathless.S5;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.BRONCHODILATOR;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.BRONCHODILATOR_WAS_GIVEN;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.USED_BRONCHODILATOR;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.DATE;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.DURATION;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.FILENAME;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.USERNAME;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.PATIENT_ASSESSMENT_ID;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.CLINICIAN_USERNAME;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.UUIDS;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator2.BDIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator2.REASON;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator3.B3DIAGNOSIS;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator3.BRONC;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator3.AFTER_BRONCHODILATOR;
import static com.ug.air.alrite.Fragments.Patient.ChestIndrawing.CHOICE7;
import static com.ug.air.alrite.Fragments.Patient.ChestIndrawing.CHOICE72;
import static com.ug.air.alrite.Fragments.Patient.ChestIndrawing.CIDIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.ChestIndrawing.POINT;
import static com.ug.air.alrite.Fragments.Patient.ChestIndrawing.POINT2;
-import static com.ug.air.alrite.Fragments.Patient.Cough.CHOICE2;
+import static com.ug.air.alrite.Fragments.Patient.Cough.DIFFICULTY_BREATHING;
import static com.ug.air.alrite.Fragments.Patient.Cough.NODIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.CoughD.DAY1;
import static com.ug.air.alrite.Fragments.Patient.Eczema.CHOICEX2;
@@ -32,35 +32,31 @@
import static com.ug.air.alrite.Fragments.Patient.HIVCare.CHOICEHC;
import static com.ug.air.alrite.Fragments.Patient.HIVStatus.CHOICE3;
import static com.ug.air.alrite.Fragments.Patient.HIVStatus.HDIAGNOSIS;
-import static com.ug.air.alrite.Fragments.Patient.Initials.CIN;
+import static com.ug.air.alrite.Fragments.Patient.Initials.CHILD_INITIALS;
import static com.ug.air.alrite.Fragments.Patient.Initials.INITIAL_DATE;
-import static com.ug.air.alrite.Fragments.Patient.Initials.PIN;
+import static com.ug.air.alrite.Fragments.Patient.Initials.PARENT_INITIALS;
import static com.ug.air.alrite.Fragments.Patient.Kerosene.ADIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.Kerosene.CHOICET2;
import static com.ug.air.alrite.Fragments.Patient.Kerosene.TUDIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.Nasal.CHOICEGN;
-import static com.ug.air.alrite.Fragments.Patient.Nasal.GNDIAGNOSIS;
-import static com.ug.air.alrite.Fragments.Patient.Oxygen.OXDIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.Oxygen.OXY;
import static com.ug.air.alrite.Fragments.Patient.RRCounter.FASTBREATHING;
import static com.ug.air.alrite.Fragments.Patient.RRCounter.FASTBREATHING2;
import static com.ug.air.alrite.Fragments.Patient.RRCounter.INITIAL_DATE_2;
import static com.ug.air.alrite.Fragments.Patient.RRCounter.SECOND;
-import static com.ug.air.alrite.Fragments.Patient.Sex.AGE;
-import static com.ug.air.alrite.Fragments.Patient.Sex.AGE2;
-import static com.ug.air.alrite.Fragments.Patient.Sex.CHOICE;
+import static com.ug.air.alrite.Fragments.Patient.Sex.AGE_IN_MONTHS;
+import static com.ug.air.alrite.Fragments.Patient.Sex.AGE_IN_YEARS;
+import static com.ug.air.alrite.Fragments.Patient.Sex.SEX;
import static com.ug.air.alrite.Fragments.Patient.Sex.KILO;
import static com.ug.air.alrite.Fragments.Patient.Sex.MDIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.Sex.MUAC;
import static com.ug.air.alrite.Fragments.Patient.Smoke.CHOICET1;
import static com.ug.air.alrite.Fragments.Patient.Stridor.CHOICE6;
-import static com.ug.air.alrite.Fragments.Patient.Stridor.STDIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.Temperature.TDIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.Temperature.TEMP;
import static com.ug.air.alrite.Fragments.Patient.WheezD.CHOICEX;
import static com.ug.air.alrite.Fragments.Patient.WheezY.DAY2;
-import static com.ug.air.alrite.Fragments.Patient.Wheezing.CHECKSTETHO;
-import static com.ug.air.alrite.Fragments.Patient.Wheezing.CHOICE8;
+import static com.ug.air.alrite.Fragments.Patient.Wheezing.WHEEZING_SOUNDS;
import static com.ug.air.alrite.Fragments.Patient.Wheezing.CHOICE82;
import androidx.appcompat.app.AppCompatActivity;
@@ -71,7 +67,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
@@ -111,10 +106,10 @@
public class DiagnosisActivity extends AppCompatActivity {
- LinearLayout linearLayout1, linearLayout2, linearLayout3, linearLayout4;
+ LinearLayout summaryTabLayout, summaryExpandedLayout, diagnosisTabLayout, diagnosisExpandedLayout;
Button btnExit, btnExit2, btnContinue, btnSave;
- ImageView imageView1, imageView2;
- RecyclerView recyclerView1, recyclerView2;
+ ImageView summaryTabIcon, diagnosisTabIcon;
+ RecyclerView summaryListRV, diagnosisListRV;
TextView txtInitials, txtAge, txtGender;
DiagnosisAdapter diagnosisAdapter;
SummaryAdapter summaryAdapter;
@@ -127,7 +122,7 @@ public class DiagnosisActivity extends AppCompatActivity {
public static final String DURATION_2 = "duration_2";
SharedPreferences sharedPreferences, sharedPreferences1;
SharedPreferences.Editor editor, editor1;
- String age, uniqueID, age2, folder, value;
+ String ageInYears, uniqueID, ageInMonths, folder, isPending;
float ag;
Dialog dialog;
RecyclerView recyclerView;
@@ -142,20 +137,23 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_diagnosis);
+ // Get references to page objects
txtAge = findViewById(R.id.patient_age);
txtGender = findViewById(R.id.patient_sex);
txtInitials = findViewById(R.id.initials);
- imageView1 = findViewById(R.id.accordion);
- linearLayout1 = findViewById(R.id.clickable);
- linearLayout2 = findViewById(R.id.summary2);
- recyclerView1 = findViewById(R.id.recyclerView1);
- imageView2 = findViewById(R.id.accordion2);
- linearLayout3 = findViewById(R.id.clickable2);
- linearLayout4 = findViewById(R.id.summary3);
+ summaryTabIcon = findViewById(R.id.accordion);
+ summaryTabLayout = findViewById(R.id.clickable);
+ summaryExpandedLayout = findViewById(R.id.summary2);
+ summaryListRV = findViewById(R.id.recyclerView1);
+ diagnosisTabIcon = findViewById(R.id.accordion2);
+ diagnosisTabLayout = findViewById(R.id.clickable2);
+ diagnosisExpandedLayout = findViewById(R.id.summary3);
btnExit = findViewById(R.id.btnExit);
btnSave = findViewById(R.id.btnExit2);
- recyclerView2 = findViewById(R.id.recyclerView2);
+ diagnosisListRV = findViewById(R.id.recyclerView2);
+ // If we have "filename" then we should get the SharedPreferences object
+ // associated with the filename
Intent intent = getIntent();
if (intent.hasExtra("filename")){
folder = intent.getExtras().getString("filename");
@@ -164,6 +162,10 @@ protected void onCreate(Bundle savedInstanceState) {
String pending = sharedPreferences.getString(PENDING, "");
// String incomplete = sharedPreferences.getString(INCOMPLETE, "");
+ // If we've opened this page before and indicated that we don't want
+ // to exit, then this time we'll be forced to exit.
+ // If we indicated last time that we want to save and exit, then make
+ // sure that we can't press either of those buttons again
if (pending.equals("pending")){
btnSave.setVisibility(View.GONE);
btnExit.setVisibility(View.VISIBLE);
@@ -172,11 +174,16 @@ protected void onCreate(Bundle savedInstanceState) {
btnExit.setVisibility(View.GONE);
}
+ // If we don't have "filename" then we should get the generic shared preferences,
+ // and then check in on what we entered for the bronchodilator
}else{
sharedPreferences = getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);
- String bron = sharedPreferences.getString(BRONCHODILATOR, "");
- String fin = sharedPreferences.getString(BRONC, "");
- if (bron.equals("Bronchodialtor Given") && fin.isEmpty()){
+ String bron = sharedPreferences.getString(USED_BRONCHODILATOR, "");
+ String fin = sharedPreferences.getString(AFTER_BRONCHODILATOR, "");
+
+ // If we used a bronchodilator on the patient, but we haven't checked
+ // in on if it worked or not, then set buttons as visible/not visible
+ if (bron.equals(BRONCHODILATOR_WAS_GIVEN) && fin.isEmpty()){
btnSave.setVisibility(View.GONE);
}else {
btnSave.setVisibility(View.VISIBLE);
@@ -184,73 +191,77 @@ protected void onCreate(Bundle savedInstanceState) {
btnExit.setVisibility(View.VISIBLE);
}
+ // Get an editor for our shared preferences
editor = sharedPreferences.edit();
- String initials = sharedPreferences.getString(CIN, "");
- age2 = sharedPreferences.getString(AGE, "");
- age = sharedPreferences.getString(AGE2, "");
- String[] split = age.split("\\.");
- ag = Float.parseFloat(age2);
- String gender = sharedPreferences.getString(CHOICE, "");
+ // Save the patient's age, for reference in the diagnosis instructions
+ ageInMonths = sharedPreferences.getString(AGE_IN_MONTHS, "");
+
+ // At the top of the page, display the patient's initials, age, and gender
+ String initials = sharedPreferences.getString(CHILD_INITIALS, "");
+ ageInYears = sharedPreferences.getString(AGE_IN_YEARS, "");
+ String[] ageInYearsSplit = ageInYears.split("\\.");
+ String gender = sharedPreferences.getString(SEX, "");
txtInitials.setText(initials);
- txtAge.setText("Age: " + split[0] + " years and " + split[1] + " months");
+ txtAge.setText("Age: " + ageInYearsSplit[0] + " years and " + ageInYearsSplit[1] + " months");
txtGender.setText("Gender: " + gender);
- linearLayout1.setOnClickListener(new View.OnClickListener() {
+ // Click on the summary tab to expand it to show a summary of the patient's health
+ summaryTabLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- if (linearLayout2.getVisibility() == View.GONE){
- linearLayout2.setVisibility(View.VISIBLE);
- imageView1.setImageResource(R.drawable.ic_sub);
+ if (summaryExpandedLayout.getVisibility() == View.GONE){
+ summaryExpandedLayout.setVisibility(View.VISIBLE);
+ summaryTabIcon.setImageResource(R.drawable.ic_sub);
}else{
- linearLayout2.setVisibility(View.GONE);
- imageView1.setImageResource(R.drawable.ic_add);
+ summaryExpandedLayout.setVisibility(View.GONE);
+ summaryTabIcon.setImageResource(R.drawable.ic_add);
}
}
});
- LinearLayoutManager layoutManager1 = new LinearLayoutManager(DiagnosisActivity.this);
+ // Add the list to be expanded + a manager to expand it
+ LinearLayoutManager summaryLayoutManager = new LinearLayoutManager(DiagnosisActivity.this);
summaryAdapter = new SummaryAdapter(buildSummaryList());
- recyclerView1.setAdapter(summaryAdapter);
- recyclerView1.setLayoutManager(layoutManager1);
+ summaryListRV.setAdapter(summaryAdapter);
+ summaryListRV.setLayoutManager(summaryLayoutManager);
- linearLayout3.setOnClickListener(new View.OnClickListener() {
+ // Same for diagnosis tab
+ diagnosisTabLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- if (linearLayout4.getVisibility() == View.GONE){
- linearLayout4.setVisibility(View.VISIBLE);
- imageView2.setImageResource(R.drawable.ic_sub);
+ if (diagnosisExpandedLayout.getVisibility() == View.GONE){
+ diagnosisExpandedLayout.setVisibility(View.VISIBLE);
+ diagnosisTabIcon.setImageResource(R.drawable.ic_sub);
}else{
- linearLayout4.setVisibility(View.GONE);
- imageView2.setImageResource(R.drawable.ic_add);
+ diagnosisExpandedLayout.setVisibility(View.GONE);
+ diagnosisTabIcon.setImageResource(R.drawable.ic_add);
}
}
});
- LinearLayoutManager layoutManager2 = new LinearLayoutManager(DiagnosisActivity.this);
- diagnosisAdapter = new DiagnosisAdapter(buildItemList());
- recyclerView2.setAdapter(diagnosisAdapter);
- recyclerView2.setLayoutManager(layoutManager2);
+ LinearLayoutManager diagnosisLayoutManager = new LinearLayoutManager(DiagnosisActivity.this);
+ diagnosisAdapter = new DiagnosisAdapter(buildDiagnosisList());
+ diagnosisListRV.setAdapter(diagnosisAdapter);
+ diagnosisListRV.setLayoutManager(diagnosisLayoutManager);
+ // Inside of the expanded diagnosis tab, if we click on one of the diagnoses,
+ // expand the tab and give instructions on what to do
diagnosisAdapter.setOnItemClickListener(new DiagnosisAdapter.OnItemClickListener() {
@Override
public void onClick(int position) {
- Diagnosis diagnosis = buildItemList().get(position);
+ Diagnosis diagnosis = buildDiagnosisList().get(position);
String dia = diagnosis.getDiagnosis();
showInstructions(dia);
// Toast.makeText(DiagnosisActivity.this, dia, Toast.LENGTH_SHORT).show();
}
-
- @Override
- public void onClick2(int position) {
-
- }
});
+ // If we click "save and complete" then set PENDING to false and
btnExit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- value = "not pending";
+ isPending = "not pending";
saveForm();
}
});
@@ -258,7 +269,7 @@ public void onClick(View v) {
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- value = "pending";
+ isPending = "pending";
saveForm();
}
});
@@ -310,7 +321,7 @@ public void onClick(View v) {
}
- private List buildItemList() {
+ private List buildDiagnosisList() {
List diagnosisList = new ArrayList<>();
String mDiagnosis = sharedPreferences.getString(MDIAGNOSIS, "");
@@ -332,20 +343,20 @@ private List buildItemList() {
// addToList2("Severe Pneumonia OR very Severe Disease");
// }
- addToList2(oneDiagnosis);
- addToList2(mDiagnosis);
- addToList2(tDiagnosis);
+ addToDiagnosisList(oneDiagnosis);
+ addToDiagnosisList(mDiagnosis);
+ addToDiagnosisList(tDiagnosis);
// addToList2(oxDiagnosis);
- addToList2(noDiagnosis);
- addToList2(hDiagnosis);
+ addToDiagnosisList(noDiagnosis);
+ addToDiagnosisList(hDiagnosis);
// addToList2(stDiagnosis);
// addToList2(gnDiagnosis);
- addToList2(ciDiagnosis);
- addToList2(wDiagnosis);
- addToList2(asDiagnosis);
- addToList2(tuDiagnosis);
- addToList2(b3Diagnosis);
- addToList2(ftDiagnosis);
+ addToDiagnosisList(ciDiagnosis);
+ addToDiagnosisList(wDiagnosis);
+ addToDiagnosisList(asDiagnosis);
+ addToDiagnosisList(tuDiagnosis);
+ addToDiagnosisList(b3Diagnosis);
+ addToDiagnosisList(ftDiagnosis);
for (int i=0; i < messages.size(); i++) {
@@ -369,16 +380,16 @@ private List buildSubItemList(String s) {
private List buildSummaryList(){
summaryList = new ArrayList<>();
- String pin = sharedPreferences.getString(PIN, "");
+ String pin = sharedPreferences.getString(PARENT_INITIALS, "");
String weight = sharedPreferences.getString(KILO, "");
String muac = sharedPreferences.getString(MUAC, "");
- String assess = sharedPreferences.getString(S4, "");
+ String assess = sharedPreferences.getString(SEVERE_SYMPTOMS, "");
String temp = sharedPreferences.getString(TEMP, "");
String feb = sharedPreferences.getString(TOUCH, "");
String ox = sharedPreferences.getString(OXY, "");
- String wheez = sharedPreferences.getString(CHOICE8, "");
+ String wheez = sharedPreferences.getString(WHEEZING_SOUNDS, "");
String wheez2 = sharedPreferences.getString(CHOICE82, "");
- String cough = sharedPreferences.getString(CHOICE2, "");
+ String cough = sharedPreferences.getString(DIFFICULTY_BREATHING, "");
String hiv = sharedPreferences.getString(CHOICE3, "");
String care = sharedPreferences.getString(CHOICEHC, "");
String coughD = sharedPreferences.getString(DAY1, "");
@@ -388,7 +399,7 @@ private List buildSummaryList(){
String nasal = sharedPreferences.getString(CHOICEGN, "");
String chest = sharedPreferences.getString(CHOICE7, "");
String chest2 = sharedPreferences.getString(CHOICE72, "");
- String bronch = sharedPreferences.getString(BRONCHODILATOR, "");
+ String bronch = sharedPreferences.getString(USED_BRONCHODILATOR, "");
String reason = sharedPreferences.getString(REASON, "");
String wheezD = sharedPreferences.getString(CHOICEX, "");
String wheezY = sharedPreferences.getString(DAY2, "");
@@ -398,58 +409,58 @@ private List buildSummaryList(){
String smoke = sharedPreferences.getString(CHOICET1, "");
String kerosene = sharedPreferences.getString(CHOICET2, "");
String fastbreathing2 = sharedPreferences.getString(FASTBREATHING2, "");
- String better = sharedPreferences.getString(BRONC, "");
+ String better = sharedPreferences.getString(AFTER_BRONCHODILATOR, "");
String point1 = sharedPreferences.getString(POINT, "");
String point2 = sharedPreferences.getString(POINT2, "");
String diagnosis = sharedPreferences.getString(S7, "");
String treatment = sharedPreferences.getString(S6, "");
- addToList("Parent's initials", pin);
- addToList("Child's weight", weight);
- addToList("MUAC value", muac);
- addToList("Danger Signs", assess);
- addToList("Child Coughing", cough);
- addToList("Days coughing", coughD);
- addToList("Temperature", temp);
- addToList("Febrile to touch", feb);
- addToList("HIV Status", hiv);
- addToList("Child in HIV Care", care);
- addToList("Oxgyen Saturation", ox);
- addToList("Respiratory Rate", fastbreathing);
- addToList("Child has Stridor", stidor);
- addToList("Child Wheezing", wheez);
+ addToSummaryList("Parent's initials", pin);
+ addToSummaryList("Child's weight", weight);
+ addToSummaryList("MUAC value", muac);
+ addToSummaryList("Danger Signs", assess);
+ addToSummaryList("Child Coughing", cough);
+ addToSummaryList("Days coughing", coughD);
+ addToSummaryList("Temperature", temp);
+ addToSummaryList("Febrile to touch", feb);
+ addToSummaryList("HIV Status", hiv);
+ addToSummaryList("Child in HIV Care", care);
+ addToSummaryList("Oxgyen Saturation", ox);
+ addToSummaryList("Respiratory Rate", fastbreathing);
+ addToSummaryList("Child has Stridor", stidor);
+ addToSummaryList("Child Wheezing", wheez);
// addToList("Stethoscope was used", String.valueOf(steth));
- addToList("Child has grunting or nasal flaring", nasal);
- addToList("Child has chest indrawing", chest);
- addToList("Respiratory score", point1);
- addToList("Bronchodilator", bronch);
- addToList("Reason", reason);
- addToList("Respiratory Rate (After bronchodilator)", fastbreathing2);
- addToList("Child Wheezing", wheez2);
- addToList("Child has chest indrawing", chest2);
- addToList("Child's breathing after bronchodilator", better);
- addToList("Respiratory score 2", point2);
- addToList("Child has breathing difficulty", wheezD);
- addToList("Episodes in the past year", wheezY);
- addToList("Child his breathless", breathless);
- addToList("Child has Eczema", eczema);
- addToList("Child's family has Allergies", allergies);
- addToList("Any family member smoking tobacco", smoke);
- addToList("Any family member using kerosene", kerosene);
- addToList("Clinician's diagnosis", diagnosis);
- addToList("Clinician's treatment", treatment);
+ addToSummaryList("Child has grunting or nasal flaring", nasal);
+ addToSummaryList("Child has chest indrawing", chest);
+ addToSummaryList("Respiratory score", point1);
+ addToSummaryList("Bronchodilator", bronch);
+ addToSummaryList("Reason", reason);
+ addToSummaryList("Respiratory Rate (After bronchodilator)", fastbreathing2);
+ addToSummaryList("Child Wheezing", wheez2);
+ addToSummaryList("Child has chest indrawing", chest2);
+ addToSummaryList("Child's breathing after bronchodilator", better);
+ addToSummaryList("Respiratory score 2", point2);
+ addToSummaryList("Child has breathing difficulty", wheezD);
+ addToSummaryList("Episodes in the past year", wheezY);
+ addToSummaryList("Child his breathless", breathless);
+ addToSummaryList("Child has Eczema", eczema);
+ addToSummaryList("Child's family has Allergies", allergies);
+ addToSummaryList("Any family member smoking tobacco", smoke);
+ addToSummaryList("Any family member using kerosene", kerosene);
+ addToSummaryList("Clinician's diagnosis", diagnosis);
+ addToSummaryList("Clinician's treatment", treatment);
return summaryList;
}
- private void addToList(String s, String pin) {
+ private void addToSummaryList(String s, String pin) {
if (!pin.isEmpty()){
Summary summary = new Summary(s, pin);
summaryList.add(summary);
}
}
- private void addToList2(String s) {
+ private void addToDiagnosisList(String s) {
if (!s.isEmpty()){
messages.add(s);
}
@@ -457,10 +468,10 @@ private void addToList2(String s) {
private void createList(String s) {
String weight = sharedPreferences.getString(KILO, "");
- int ag = Integer.parseInt(age2);
+ int ag = Integer.parseInt(ageInMonths);
if (s.equals("Severe Pneumonia OR very Severe Disease")){
- String st = sharedPreferences.getString(S4, "");
+ String st = sharedPreferences.getString(SEVERE_SYMPTOMS, "");
Instructions instructions = new Instructions();
messageList = instructions.GetInstructions(ag, weight, st);
}
@@ -556,7 +567,7 @@ else if (s.equals("Wheezing illness (Bronchodilator response)")){
private void saveForm() {
- String file = sharedPreferences.getString(FILENAME, "");
+ String file = sharedPreferences.getString(PATIENT_ASSESSMENT_ID, "");
Date currentTime = Calendar.getInstance().getTime();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss", Locale.getDefault());
@@ -571,23 +582,23 @@ private void saveForm() {
getDuration(currentTime);
- editor.putString(USERNAME, username);
+ editor.putString(CLINICIAN_USERNAME, username);
editor.putString(DATE, formattedDate);
editor.putString(UUIDS, uniqueID);
- editor.putString(PENDING, value);
- editor.putString(INCOMPLETE, "complete");
+ editor.putString(PENDING, isPending);
+ editor.putString(ASSESS_INCOMPLETE, "complete");
editor.apply();
String filename = formattedDate + "_" + uniqueID;
- editor.putString(FILENAME, filename);
+ editor.putString(PATIENT_ASSESSMENT_ID, filename);
editor.apply();
// Toast.makeText(this, "empty", Toast.LENGTH_SHORT).show();
doLogic(filename);
}else {
- editor.putString(PENDING, value);
- editor.putString(INCOMPLETE, "complete");
+ editor.putString(PENDING, isPending);
+ editor.putString(ASSESS_INCOMPLETE, "complete");
String filename = formattedDate + "_" + uniqueID;
- editor.putString(FILENAME, filename);
+ editor.putString(PATIENT_ASSESSMENT_ID, filename);
editor.putString(DATE, formattedDate);
editor.apply();
@@ -637,8 +648,12 @@ private void getDuration2(Date currentTime) {
}
private void doLogic(String file) {
+ // Create a new shared preferences object + editor
sharedPreferences1 = getSharedPreferences(file, Context.MODE_PRIVATE);
editor1 = sharedPreferences1.edit();
+
+ // Put all values from the current Shared Preferences object into the shared
+ // preferences for the given file
Map all = sharedPreferences.getAll();
for (Map.Entry x : all.entrySet()) {
if (x.getValue().getClass().equals(String.class)) editor1.putString(x.getKey(), (String)x.getValue());
@@ -660,13 +675,13 @@ private void doLogic(String file) {
}
}
- String bron = sharedPreferences1.getString(BRONCHODILATOR, "");
- String fin = sharedPreferences1.getString(BRONC, "");
+ String bron = sharedPreferences1.getString(USED_BRONCHODILATOR, "");
+ String fin = sharedPreferences1.getString(AFTER_BRONCHODILATOR, "");
Intent intent;
if (bron.equals("Bronchodialtor Given") && fin.isEmpty()){
intent = new Intent(DiagnosisActivity.this, Dashboard.class);
}else{
- if (value.equals("not pending")){
+ if (isPending.equals("not pending")){
intent = new Intent(DiagnosisActivity.this, FinalActivity.class);
intent.putExtra("filename", file);
}else {
diff --git a/app/src/main/java/com/ug/air/alrite/Activities/DiagnosisActivityModified.java b/app/src/main/java/com/ug/air/alrite/Activities/DiagnosisActivityModified.java
new file mode 100644
index 0000000..6a56d26
--- /dev/null
+++ b/app/src/main/java/com/ug/air/alrite/Activities/DiagnosisActivityModified.java
@@ -0,0 +1,362 @@
+package com.ug.air.alrite.Activities;
+
+import static com.ug.air.alrite.Activities.PatientActivity.DIAGNOSES_ID;
+import static com.ug.air.alrite.Activities.PatientActivity.SUMMARY_ID;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.DATE;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.DURATION;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.PATIENT_ASSESSMENT_ID;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.CLINICIAN_USERNAME;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.UUIDS;
+import static com.ug.air.alrite.Fragments.Patient.InitialsModified.CHILD_INITIALS;
+import static com.ug.air.alrite.Fragments.Patient.InitialsModified.INITIAL_DATE;
+import static com.ug.air.alrite.Fragments.Patient.SexModified.AGE_IN_MONTHS;
+import static com.ug.air.alrite.Fragments.Patient.SexModified.AGE_IN_YEARS;
+import static com.ug.air.alrite.Fragments.Patient.SexModified.KILO;
+import static com.ug.air.alrite.Fragments.Patient.SexModified.MUAC;
+import static com.ug.air.alrite.Fragments.Patient.SexModified.SEX;
+
+import android.app.Dialog;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.ug.air.alrite.Adapters.AssessmentAdapter;
+import com.ug.air.alrite.Adapters.DiagnosisAdapter;
+import com.ug.air.alrite.Adapters.SummaryAdapter;
+import com.ug.air.alrite.BuildConfig;
+import com.ug.air.alrite.Models.Assessment;
+import com.ug.air.alrite.Models.Diagnosis;
+import com.ug.air.alrite.Models.Summary;
+import com.ug.air.alrite.R;
+import com.ug.air.alrite.Utils.Credentials;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.nio.file.Files;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
+public class DiagnosisActivityModified extends AppCompatActivity {
+
+ LinearLayout summaryTabLayout, summaryExpandedLayout, diagnosisTabLayout, diagnosisExpandedLayout;
+ Button btnExit, btnExit2, btnContinue, btnSave;
+ ImageView summaryTabIcon, diagnosisTabIcon;
+ RecyclerView summaryListRV, diagnosisListRV;
+ TextView txtInitials, txtAge, txtGender;
+ DiagnosisAdapter diagnosisAdapter;
+ SummaryAdapter summaryAdapter;
+ List summaryList;
+ List messages = new ArrayList<>();;
+ List messageList = new ArrayList<>();;
+ public static final String SHARED_PREFS = "sharedPrefs";
+ SharedPreferences summaryPrefs, diagnosesPrefs;
+ SharedPreferences.Editor summaryEditor, diagnosesEditor;
+ String summaryPrefsID, diagnosesPrefsID;
+ String ageInYears, ageInMonths, isPending;
+ float ag;
+ Dialog dialog;
+ RecyclerView recyclerView;
+ LinearLayout linearLayout_instruction;
+ TextView txtDiagnosis;
+ ArrayList assessments;
+ List messages2;
+ AssessmentAdapter assessmentAdapter;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_diagnosis);
+
+ // Get references to page objects
+ txtAge = findViewById(R.id.patient_age);
+ txtGender = findViewById(R.id.patient_sex);
+ txtInitials = findViewById(R.id.initials);
+ summaryTabIcon = findViewById(R.id.accordion);
+ summaryTabLayout = findViewById(R.id.clickable);
+ summaryExpandedLayout = findViewById(R.id.summary2);
+ summaryListRV = findViewById(R.id.recyclerView1);
+ diagnosisTabIcon = findViewById(R.id.accordion2);
+ diagnosisTabLayout = findViewById(R.id.clickable2);
+ diagnosisExpandedLayout = findViewById(R.id.summary3);
+ btnExit = findViewById(R.id.btnExit);
+ btnSave = findViewById(R.id.btnExit2);
+ diagnosisListRV = findViewById(R.id.recyclerView2);
+
+ // Get an editor for our shared preferences
+ summaryPrefsID = getIntent().getStringExtra(SUMMARY_ID);
+ summaryPrefs = getSharedPreferences(summaryPrefsID, Context.MODE_PRIVATE);
+ summaryEditor = summaryPrefs.edit();
+ diagnosesPrefsID = getIntent().getStringExtra(DIAGNOSES_ID);
+ diagnosesPrefs = getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);
+ diagnosesEditor = diagnosesPrefs.edit();
+
+ // Save the patient's age, for reference in the diagnosis instructions
+ ageInMonths = summaryPrefs.getString(AGE_IN_MONTHS, "");
+
+ // At the top of the page, display the patient's initials, age, and gender
+ String initials = summaryPrefs.getString(CHILD_INITIALS, "");
+ ageInYears = summaryPrefs.getString(AGE_IN_YEARS, "");
+ String[] ageInYearsSplit = ageInYears.split("\\.");
+ String gender = summaryPrefs.getString(SEX, "");
+ txtInitials.setText(initials);
+ txtAge.setText("Age: " + ageInYearsSplit[0] + " years and " + ageInYearsSplit[1] + " months");
+ txtGender.setText("Gender: " + gender);
+
+ // Click on the summary tab to expand it to show a summary of the patient's health
+ summaryTabLayout.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (summaryExpandedLayout.getVisibility() == View.GONE){
+ summaryExpandedLayout.setVisibility(View.VISIBLE);
+ summaryTabIcon.setImageResource(R.drawable.ic_sub);
+ }else{
+ summaryExpandedLayout.setVisibility(View.GONE);
+ summaryTabIcon.setImageResource(R.drawable.ic_add);
+ }
+ }
+ });
+
+ // Add the list to be expanded + a manager to expand it
+ LinearLayoutManager summaryLayoutManager = new LinearLayoutManager(DiagnosisActivityModified.this);
+ summaryAdapter = new SummaryAdapter(buildSummaryList());
+ summaryListRV.setAdapter(summaryAdapter);
+ summaryListRV.setLayoutManager(summaryLayoutManager);
+
+ // Same for diagnosis tab
+ diagnosisTabLayout.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (diagnosisExpandedLayout.getVisibility() == View.GONE){
+ diagnosisExpandedLayout.setVisibility(View.VISIBLE);
+ diagnosisTabIcon.setImageResource(R.drawable.ic_sub);
+ }else{
+ diagnosisExpandedLayout.setVisibility(View.GONE);
+ diagnosisTabIcon.setImageResource(R.drawable.ic_add);
+ }
+ }
+ });
+
+ LinearLayoutManager diagnosisLayoutManager = new LinearLayoutManager(DiagnosisActivityModified.this);
+ diagnosisAdapter = new DiagnosisAdapter(buildDiagnosisList());
+ diagnosisListRV.setAdapter(diagnosisAdapter);
+ diagnosisListRV.setLayoutManager(diagnosisLayoutManager);
+
+ // Inside of the expanded diagnosis tab, if we click on one of the diagnoses,
+ // expand the tab and give instructions on what to do
+ diagnosisAdapter.setOnItemClickListener(new DiagnosisAdapter.OnItemClickListener() {
+ @Override
+ public void onClick(int position) {
+ Diagnosis diagnosis = buildDiagnosisList().get(position);
+ String dia = diagnosis.getDiagnosis();
+ showInstructions(dia);
+// Toast.makeText(DiagnosisActivity.this, dia, Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ // If we click "save and complete" then set PENDING to false and
+ btnExit.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ isPending = "not pending";
+ saveForm();
+ }
+ });
+
+ btnSave.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ isPending = "pending";
+ saveForm();
+ }
+ });
+ }
+
+ private void showInstructions(String dia) {
+ dialog = new Dialog(this);
+ dialog.setContentView(R.layout.assessment_layout);
+ dialog.setCancelable(true);
+ Window window = dialog.getWindow();
+ window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
+
+ linearLayout_instruction = dialog.findViewById(R.id.diagnosis);
+ txtDiagnosis = dialog.findViewById(R.id.txtDiagnosis);
+ recyclerView = dialog.findViewById(R.id.recyclerView1);
+ btnExit2 = dialog.findViewById(R.id.btnSave);
+ btnContinue = dialog.findViewById(R.id.btnContinue);
+
+ linearLayout_instruction.setBackgroundColor(getResources().getColor(R.color.severeDiagnosisColor));
+ txtDiagnosis.setText("Diagnosis: " + dia);
+
+ recyclerView.setHasFixedSize(true);
+ recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
+
+ List assessments = new ArrayList<>();
+ assessmentAdapter = new AssessmentAdapter(assessments);
+
+// messages2 = createList(dia);
+
+ for (int i = 0; i < messageList.size(); i++){
+ Assessment assessment = new Assessment((Integer) messageList.get(i));
+ assessments.add(assessment);
+ }
+ recyclerView.setAdapter(assessmentAdapter);
+
+ btnExit2.setVisibility(View.GONE);
+ btnContinue.setText("Close");
+
+ btnContinue.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dialog.dismiss();
+ }
+ });
+
+ dialog.getWindow().setGravity(Gravity.CENTER);
+ dialog.show();
+
+ }
+
+ /**
+ * Create a list of all of the current diagnoses (in the future, this should
+ * happen within the diagnosis activity)
+ * TODO: implement gathering diagnosis in the editor, then in the app
+ *
+ * @return a list of diagnoses for the patient
+ */
+ private List buildDiagnosisList() {
+ List diagnosisList = new ArrayList<>();
+ return diagnosisList;
+ }
+
+ private List buildSubItemList(String s) {
+ List assessmentList = new ArrayList<>();
+
+ for (int i=0; i < messageList.size(); i++) {
+ Assessment assessment = new Assessment((Integer) messageList.get(i));
+ assessmentList.add(assessment);
+ }
+ return assessmentList;
+ }
+
+ private List buildSummaryList(){
+ summaryList = new ArrayList<>();
+ String weight = summaryPrefs.getString(KILO, "");
+ String muac = summaryPrefs.getString(MUAC, "");
+
+ addToSummaryList("Child's weight", weight);
+ addToSummaryList("MUAC value", muac);
+
+ Map all = summaryPrefs.getAll();
+ System.out.println(all);
+ for (Map.Entry x : all.entrySet()) {
+ // TODO: prevent non-summary results from showing
+ addToSummaryList(x.getKey(), x.getValue().toString());
+ }
+
+ return summaryList;
+ }
+
+ private void addToSummaryList(String s, String pin) {
+ if (!pin.isEmpty()){
+ Summary summary = new Summary(s, pin);
+ summaryList.add(summary);
+ }
+ }
+
+ private void addToDiagnosisList(String s) {
+ if (!s.isEmpty()){
+ messages.add(s);
+ }
+ }
+
+ // TODO: implement logic for revisiting page upon the use of a bronchodilator
+ /**
+ * After confirming the information on the diagnosis page, we complete the assessment
+ * and move to the FinalActivity which confirms the collected information.
+ */
+ private void saveForm() {
+ // We get the current date and time
+ Date currentTime = Calendar.getInstance().getTime();
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss", Locale.getDefault());
+ String formattedDate = df.format(currentTime);
+ enterDurationIntoSharedPrefs(currentTime);
+
+ // We get the current clinician's username
+ Credentials credentials = new Credentials();
+ String username = credentials.creds(DiagnosisActivityModified.this).getUsername();
+
+ // Put the assessment info into the SharedPrefs
+ summaryEditor.putString(CLINICIAN_USERNAME, username);
+ summaryEditor.putString(DATE, formattedDate);
+ summaryEditor.apply();
+
+ // Go to the final activity, since we aren't using a bronchodilator and therefore
+ // aren't revisiting this page (currently)
+ startFinalActivity();
+ }
+
+ private void enterDurationIntoSharedPrefs(Date currentTime) {
+ String initial_date = summaryPrefs.getString(INITIAL_DATE, "");
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss", Locale.getDefault());
+ try {
+ Date d1 = format.parse(initial_date);
+
+ long diff = currentTime.getTime() - d1.getTime();//as given
+
+ long minutes = TimeUnit.MILLISECONDS.toMinutes(diff);
+ String duration = String.valueOf(minutes);
+ summaryEditor.putString(DURATION, duration);
+ summaryEditor.apply();
+ Log.d("Difference in time", "getTimeDifference: " + minutes);
+
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void startFinalActivity() {
+ Intent finalActivityIntent = new Intent(DiagnosisActivityModified.this, FinalActivity.class);
+ finalActivityIntent.putExtra(SUMMARY_ID, summaryPrefsID);
+ finalActivityIntent.putExtra(DIAGNOSES_ID, diagnosesPrefsID);
+ startActivity(finalActivityIntent);
+ }
+
+ @Override
+ public void onBackPressed() {
+ Intent intent = getIntent();
+ if (intent.hasExtra("filename")){
+ Bundle bundle = new Bundle();
+ Intent intent2 = new Intent(this, PatientActivity.class);
+ bundle.putInt("Fragment", 3);
+ intent2.putExtras(bundle);
+ startActivity(intent2);
+ finish();
+ }else{
+ Toast.makeText(this, "Please click the Save button", Toast.LENGTH_SHORT).show();
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/ug/air/alrite/Activities/FinalActivity.java b/app/src/main/java/com/ug/air/alrite/Activities/FinalActivity.java
index 4d8cfae..422943e 100644
--- a/app/src/main/java/com/ug/air/alrite/Activities/FinalActivity.java
+++ b/app/src/main/java/com/ug/air/alrite/Activities/FinalActivity.java
@@ -1,5 +1,9 @@
package com.ug.air.alrite.Activities;
+import static com.ug.air.alrite.Activities.DiagnosisActivityModified.SHARED_PREFS;
+import static com.ug.air.alrite.Activities.PatientActivity.DIAGNOSES_ID;
+import static com.ug.air.alrite.Activities.PatientActivity.SUMMARY_ID;
+
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
@@ -15,26 +19,34 @@
import com.ug.air.alrite.R;
+import org.json.JSONObject;
+
+import java.util.Map;
+
public class FinalActivity extends AppCompatActivity {
CheckBox checkBox1, checkBox2, checkBox3, checkBox4, checkBox5, checkBox6, checkBox7, checkBox8, checkBox9, checkBox10, checkBox11, checkBox12, checkBox13, checkBox14;
EditText etOther1, etOther2;
Button btnSave;
- String s1, s2, diagnosis, treatment, filename;
+ String s1, s2, diagnosis, treatment;
public static final String S6 = "clinician_treatment";
public static final String S7 = "clinician_diagnosis";
- SharedPreferences sharedPreferences;
- SharedPreferences.Editor editor;
+ SharedPreferences summaryPrefs, diagnosesPrefs;
+ SharedPreferences.Editor summaryEditor, diagnosesEditor;
+ String summaryPrefsID, diagnosesPrefsID;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_final);
- filename = getIntent().getStringExtra("filename");
-
- sharedPreferences = getSharedPreferences(filename, Context.MODE_PRIVATE);
- editor = sharedPreferences.edit();
+ // Get an editor for our shared preferences
+ summaryPrefsID = getIntent().getStringExtra(SUMMARY_ID);
+ summaryPrefs = getSharedPreferences(summaryPrefsID, Context.MODE_PRIVATE);
+ summaryEditor = summaryPrefs.edit();
+ diagnosesPrefsID = getIntent().getStringExtra(DIAGNOSES_ID);
+ diagnosesPrefs = getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);
+ diagnosesEditor = diagnosesPrefs.edit();
btnSave = findViewById(R.id.btnExit);
etOther1 = findViewById(R.id.otherText);
@@ -160,10 +172,11 @@ private void checkedList2() {
}
private void saveData() {
- editor.putString(S7, s1);
- editor.putString(S6, s2);
- editor.apply();
- editor.commit();
+ diagnosesEditor.putString(S7, s1);
+ diagnosesEditor.putString(S6, s2);
+ diagnosesEditor.commit();
+
+ // Finally, we can exit: go back to the dashboard home page
startActivity(new Intent(FinalActivity.this, Dashboard.class));
finish();
}
diff --git a/app/src/main/java/com/ug/air/alrite/Activities/PatientActivity.java b/app/src/main/java/com/ug/air/alrite/Activities/PatientActivity.java
index 8afe5da..b3e8d13 100644
--- a/app/src/main/java/com/ug/air/alrite/Activities/PatientActivity.java
+++ b/app/src/main/java/com/ug/air/alrite/Activities/PatientActivity.java
@@ -2,46 +2,57 @@
import static com.ug.air.alrite.Activities.DiagnosisActivity.DATE_2;
import static com.ug.air.alrite.Activities.DiagnosisActivity.DURATION_2;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.BRONCHODILATOR;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.DATE;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.DURATION;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.FILENAME;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.USERNAME;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.PATIENT_ASSESSMENT_ID;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.CLINICIAN_USERNAME;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.UUIDS;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator3.BRONC;
-import static com.ug.air.alrite.Fragments.Patient.Initials.CIN;
+import static com.ug.air.alrite.Fragments.Patient.Initials.CHILD_INITIALS;
import static com.ug.air.alrite.Fragments.Patient.Initials.INITIAL_DATE;
-import static com.ug.air.alrite.Fragments.Patient.Initials.PIN;
+import static com.ug.air.alrite.Fragments.Patient.Initials.PARENT_INITIALS;
+import static com.ug.air.alrite.Fragments.Patient.Initials.STUDY_ID;
+import static com.ug.air.alrite.Fragments.Patient.Initials.STUDY_ID_2;
import static com.ug.air.alrite.Fragments.Patient.RRCounter.FASTBREATHING2;
import static com.ug.air.alrite.Fragments.Patient.RRCounter.INITIAL_DATE_2;
import static com.ug.air.alrite.Fragments.Patient.RRCounter.SECOND;
+import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
-import android.widget.TextView;
-import android.widget.Toast;
-import com.ug.air.alrite.BuildConfig;
+import com.makeramen.roundedimageview.BuildConfig;
import com.ug.air.alrite.Fragments.Patient.ActivePatients;
-import com.ug.air.alrite.Fragments.Patient.HIVStatus;
-import com.ug.air.alrite.Fragments.Patient.Initials;
+import com.ug.air.alrite.Fragments.Patient.InitialsModified;
+import com.ug.air.alrite.Fragments.Patient.MultipleChoiceFragment;
+import com.ug.air.alrite.Fragments.Patient.MultipleSelectionFragment;
import com.ug.air.alrite.Fragments.Patient.OtherPatients;
-import com.ug.air.alrite.Fragments.Patient.Wheezing;
+import com.ug.air.alrite.Fragments.Patient.ParagraphFragment;
+import com.ug.air.alrite.Fragments.Patient.SexModified;
+import com.ug.air.alrite.Fragments.Patient.TextInputFragment;
import com.ug.air.alrite.R;
import com.ug.air.alrite.Utils.Credentials;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.BufferedReader;
import java.io.File;
+import java.nio.file.Files;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
@@ -49,12 +60,16 @@
import java.util.UUID;
import java.util.concurrent.TimeUnit;
-public class PatientActivity extends AppCompatActivity {
+public class PatientActivity extends AppCompatActivity implements
+ MultipleChoiceFragment.onGetResultListener, MultipleSelectionFragment.onGetResultListener,
+ TextInputFragment.onGetResultListener, ParagraphFragment.onGetResultListener {
public static final String SHARED_PREFS = "sharedPrefs";
public static final String INCOMPLETE = "incomplete";
- SharedPreferences sharedPreferences, sharedPreferences1;
- SharedPreferences.Editor editor, editor1;
+
+ public static final String ASSESS_INCOMPLETE = "incomplete";
+ SharedPreferences sharedPreferences, sharedPreferences1, patientSummaryPrefs, patientDiagnosesPrefs, developerPrefs;
+ SharedPreferences.Editor editor, editor1, patientSummaryEditor, patientDiagnosesEditor, developerEditor;
int frag = 0;
@Override
@@ -70,7 +85,12 @@ protected void onCreate(Bundle savedInstanceState) {
frag = intent.getExtras().getInt("Fragment");
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
if (frag == 1){
- fragmentTransaction.add(R.id.fragment_container, new Initials());
+// fragmentTransaction.add(R.id.fragment_container, new Initials());
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ fragmentTransaction.add(R.id.fragment_container, new InitialsModified());
+ } else {
+ System.out.println("Cant read from file because it's too old of an SDK build version");
+ }
}else if (frag == 2){
fragmentTransaction.add(R.id.fragment_container, new ActivePatients());
}else {
@@ -87,8 +107,8 @@ public void onBackPressed() {
finish();
}
else {
- String pin = sharedPreferences.getString(PIN, "");
- String cin = sharedPreferences.getString(CIN, "");
+ String pin = sharedPreferences.getString(PARENT_INITIALS, "");
+ String cin = sharedPreferences.getString(CHILD_INITIALS, "");
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.exit);
@@ -117,7 +137,7 @@ public void onClick(View view) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss", Locale.getDefault());
String formattedDate = df.format(currentTime);
- String file = sharedPreferences.getString(FILENAME, "");
+ String file = sharedPreferences.getString(PATIENT_ASSESSMENT_ID, "");
Credentials credentials = new Credentials();
String username = credentials.creds(PatientActivity.this).getUsername();
@@ -129,7 +149,7 @@ public void onClick(View view) {
String uniqueID = UUID.randomUUID().toString();
editor.putString(DATE, formattedDate);
- editor.putString(USERNAME, username);
+ editor.putString(CLINICIAN_USERNAME, username);
editor.putString(UUIDS, uniqueID);
editor.putString(INCOMPLETE, "incomplete");
editor.apply();
@@ -229,4 +249,618 @@ private void doLogic(String file) {
intent = new Intent(PatientActivity.this, Dashboard.class);
startActivity(intent);
}
+
+
+ /**---------------------------------------------------------------------------------------------
+ *
+ * Decision Tree creation and maintenance functions below vv
+ *
+ *--------------------------------------------------------------------------------------------*/
+
+ // Strings for the JSON identifiers
+ public static final String COMPONENT = "component";
+ public static final String MULTISELECT = "multiselect";
+ public static final String PAGE_ID = "pageID";
+ public static final String PAGES = "pages";
+ public static final String LABEL = "label";
+ public static final String CHOICES = "choices";
+ public static final String TEXT = "text";
+ public static final String LINK = "link";
+ public static final String CONTENT = "content";
+ public static final String MULTIPLE_CHOICE = "MultipleChoice";
+ public static final String TEXT_INPUT = "TextInput";
+ public static final String IS_DIAGNOSIS_PAGE = "isDiagnosisPage";
+ public static final String NULL = "null";
+ public static final String DEFAULT_LINK = "defaultLink";
+ public static final String TARGET_VALUE_ID = "targetValueID";
+ public static final String VALUE_ID = "valueID";
+ public static final String SATISFIED_LINK = "satisfiedLink";
+ public static final String TYPE = "type";
+ public static final String THRESHOLD = "threshold";
+ public static final String PARAGRAPH = "Paragraph";
+ public static final String META = "meta";
+ public static final String VERSION = "version";
+ public static final String NAME = "name";
+ public static final String SUMMARY_ID = "SUMMARY_ID";
+ public static final String DIAGNOSES_ID = "DIAGNOSES_ID";
+
+
+ // Full JSON infos to call getNextPage
+ JSONArray pages;
+ String summaryPrefsID;
+ String diagnosesPrefsID;
+ String developerPrefsID;
+
+ // Information gotten from JSON for the current page
+ // Information gotten from JSON
+ String question;
+ ArrayList choices;
+ ArrayList backstack;
+
+ // Other than question there is more information needed
+ // from the JSON for text input
+ String inputType;
+ public enum INPUT_TYPES {
+ numeric,
+ alphanumeric,
+ text,
+ any;
+ }
+ public enum COMPARISON_TYPES {
+ G(">"),
+ L("<"),
+ GE(">="),
+ LE("<="),
+ EQ("=");
+
+ public final String symbol;
+
+ COMPARISON_TYPES(String symbol) {
+ this.symbol = symbol;
+ }
+ }
+ JSONObject nextPageJSON;
+ String targetValue_id; // for text input
+ String targetValueID; // for multiple selection
+ String paragraph; //Content for paragraph fragment
+
+ /**
+ * Get the copy of the workflow that we have stored on the device and turn it
+ * into a JSONObject
+ */
+ @RequiresApi(api = Build.VERSION_CODES.O)
+ public void getJSONFromBackend() {
+ File assessment = new File(getFilesDir(), "assessment.json");
+
+ try {
+ BufferedReader br = Files.newBufferedReader(assessment.toPath());
+ StringBuilder sb = new StringBuilder();
+ String line;
+ while ((line = br.readLine()) != null) {
+ sb.append(line);
+ }
+
+ String json = sb.toString();
+
+ br.close();
+
+ implementEditableDecisionTree(new JSONObject(json));
+ } catch (Exception e) {
+ System.out.println("did a bad: " + e);
+ }
+ }
+
+ /**
+ * This is the function that is called to set up the process of looping through
+ * the pages until we get to the diagnosis page
+ *
+ * @throws JSONException for working with JSONObject
+ */
+ private void implementEditableDecisionTree(JSONObject json) throws JSONException {
+ backstack = new ArrayList<>();
+ pages = json.getJSONArray(PAGES);
+
+ // This is just an array because it needs to be mutable: think of it as
+ // its own element
+ String nextPage = pages.getJSONObject(0).getString(PAGE_ID);
+
+ // Create a shared preferences object for the current patient
+ // TODO: better security for the SharedPreferences (use EncryptedSharedPreferences)
+ String patientInfoID = createUniquePatientInfoID();
+ summaryPrefsID = patientInfoID + "_Summary";
+ diagnosesPrefsID = patientInfoID + "_Diagnoses";
+ developerPrefsID = patientInfoID + "_DevInfo";
+
+ patientSummaryPrefs = getSharedPreferences(summaryPrefsID, Context.MODE_PRIVATE);
+ patientSummaryEditor = patientSummaryPrefs.edit();
+
+ patientDiagnosesPrefs = getSharedPreferences(diagnosesPrefsID, Context.MODE_PRIVATE);
+ patientDiagnosesEditor = patientDiagnosesPrefs.edit();
+ // MUST INCLUDE THIS: code in OtherPatients was written with the intent that there
+ // would be at least one diagnosis lol
+ patientDiagnosesEditor.putString(DIAGNOSES_ID, diagnosesPrefsID);
+ patientDiagnosesEditor.apply();
+
+ developerPrefs = getSharedPreferences(developerPrefsID, Context.MODE_PRIVATE);
+ developerEditor = developerPrefs.edit();
+ developerEditor.putString(VERSION, json.getJSONObject(META).getString(VERSION));
+ developerEditor.putString(NAME, json.getString(NAME));
+ developerEditor.apply();
+
+ // Clear out the old editor so that it can be used again for a new patient
+ Map currPatientInfos = sharedPreferences.getAll();
+ for (String info : currPatientInfos.keySet()) {
+ if (info.equals("app_version") || info.equals(STUDY_ID) || info.equals(STUDY_ID_2)
+ || info.equals("age") || info.equals("start_date")) {
+ developerEditor.putString(info, (String) currPatientInfos.get(info));
+ } else {
+ patientSummaryEditor.putString(info, (String) currPatientInfos.get(info));
+ }
+ }
+ patientSummaryEditor.apply();
+ developerEditor.apply();
+ editor.clear().apply();
+
+ // Continue looping through each page in sequence: depending on the component,
+ // inflate a new fragment for that component type
+ // If the next page is the final page, exit the loop
+ getNextPage(nextPage);
+ }
+
+ /**
+ * This will add the given fragment to the back stack, and do a transaction
+ * which replaces the current fragment with the given fragment
+ *
+ * @param fragment the fragment to swap to
+ */
+ private void completeFragmentTransaction(Fragment fragment) {
+ // Begin the transaction
+ FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+ // Replace the contents of the container with the new fragment
+ ft.replace(R.id.fragment_container, fragment);
+ // Complete the changes added above
+ ft.addToBackStack(null);
+ ft.commit();
+ }
+
+ /**
+ * Given a page from the json object, we create the fragment for that page and
+ * populate it with the necessary information.
+ *
+ * @param nextPageID the ID of the next page to be displayed in the app
+ * @throws JSONException if the json is mad at you for calling it improperly
+ */
+ private void getNextPage(String nextPageID) throws JSONException {
+ // Add the new page to the backstack, if it's not already there somewhere
+ if (!backstack.contains(nextPageID)) {
+ backstack.add(nextPageID);
+ }
+
+ // Get all of the items that should be displayed on the page
+ nextPageJSON = pages.getJSONObject(findIndexInPagesGivenPageId(nextPageID));
+ JSONArray nextPageContent = nextPageJSON.getJSONArray(CONTENT);
+
+ // If the next page would be the final page, then the assessment is over!
+ // So, start up the diagnosis activity
+ if ((Boolean) nextPageJSON.get(IS_DIAGNOSIS_PAGE)) {
+ exitActivity();
+ return;
+ }
+
+ // Since we're not implementing multiple types of data input per page at
+ // the moment, we should default to having the index be 0:
+ int contentIndex = 0;
+
+ // Then, for each component that we're given within the page, display a
+ // fragment for that component.
+ JSONObject nextPageComponent = nextPageContent.getJSONObject(contentIndex);
+ String nextPageComponentType = nextPageComponent.getString(COMPONENT);
+
+ if (nextPageComponentType.equals(MULTIPLE_CHOICE)) {
+ // Multiselect and multiple choice options:
+ boolean isMultiSelect = nextPageComponent.getBoolean(MULTISELECT);
+ String valueID = getValueID(nextPageJSON, contentIndex);
+ if (isMultiSelect) {
+ createMultiSelectFragment(nextPageComponent, valueID);
+ } else {
+ createMultipleChoiceFragment(nextPageComponent, valueID);
+ }
+
+ // Text input option:
+ } else if (nextPageComponentType.equals(TEXT_INPUT)) {
+ String valueID = getValueID(nextPageJSON, contentIndex);
+ createTextInputFragment(nextPageComponent, valueID);
+
+ // Paragraph option:
+ } else if (nextPageComponentType.equals(PARAGRAPH)) {
+ createParagraphFragment(nextPageComponent);
+
+ // There was an issue with identifying the page... just go to the next page instead
+ } else {
+ System.out.println("should never get here lol: just go to the next page");
+ getNextPage(nextPageJSON.getString(DEFAULT_LINK));
+ }
+ }
+
+ /**
+ * Start the Diagnosis activity that directly follows from this one, and exit
+ * the activity.
+ */
+ private void exitActivity() {
+ Intent intent = new Intent(PatientActivity.this, DiagnosisActivityModified.class);
+ intent.putExtra(SUMMARY_ID, summaryPrefsID);
+ intent.putExtra(DIAGNOSES_ID, diagnosesPrefsID);
+
+ startActivity(intent);
+ this.finish();
+ }
+
+ /**
+ * NOTE: THIS SHOULD ONLY BE USED FOR SINGLE-LAYER ARRAYS
+ *
+ * @param jsonArray
+ * @return
+ * @throws JSONException
+ */
+ private ArrayList JSONArrayToListOfJSONObjects(JSONArray jsonArray) throws JSONException {
+ ArrayList ret = new ArrayList<>();
+ for (int i = 0; i < jsonArray.length(); i++) {
+ ret.add(jsonArray.getJSONObject(i));
+ }
+ return ret;
+ }
+
+ private void createMultipleChoiceFragment(JSONObject nextPageComponent, String valueID) throws JSONException {
+ // Collect the important arguments from the component
+ question = nextPageComponent.getString(LABEL);
+ choices = JSONArrayToListOfJSONObjects(nextPageComponent.getJSONArray(CHOICES));
+
+ // Get the new page's fragment, and set a listener for when the next button
+ // is clicked
+ MultipleChoiceFragment mc_fragment =
+ MultipleChoiceFragment.newInstance(question, choices, valueID, summaryPrefsID);
+
+ // Replace and commit the fragment
+ completeFragmentTransaction(mc_fragment);
+ }
+
+ /**
+ * Creating the Fragment for Text Input
+ *
+ * @throws JSONException because we use json objects
+ */
+ private void createTextInputFragment(JSONObject nextPageComponent, String valueID) throws JSONException {
+ // Collect the important arguments from the component
+ question = nextPageComponent.getString(LABEL);
+ inputType = nextPageComponent.getString(TYPE);
+ targetValue_id = valueID;
+
+ // Get the new page's fragment, and set a listener for when the next button
+ // is clicked
+ TextInputFragment ti_fragment =
+ TextInputFragment.newInstance(question, inputType, valueID, summaryPrefsID);
+
+ // Replace and commit the fragment
+ completeFragmentTransaction(ti_fragment);
+ }
+
+ /**
+ * Fragment for multiple selection
+ *
+ * @throws JSONException because we use json objects
+ */
+ private void createMultiSelectFragment(JSONObject page, String valueID) throws JSONException {
+ question = page.getString(LABEL);
+ choices = JSONArrayToListOfJSONObjects(page.getJSONArray(CHOICES));
+ targetValueID = page.getString(VALUE_ID);
+
+ // Get the new page's fragment
+ // set a listener for when the next button is clicked
+ MultipleSelectionFragment ms_fragment =
+ MultipleSelectionFragment.newInstance(question, choices, valueID, summaryPrefsID);
+
+ // Replace and commit the fragment
+ completeFragmentTransaction(ms_fragment);
+ }
+
+ /**
+ * Create the ParagraphFragment
+ *
+ * @param nextPageComponent the component to be displayed on screen
+ * @throws JSONException because json
+ */
+ private void createParagraphFragment(JSONObject nextPageComponent) throws JSONException {
+ paragraph = nextPageComponent.getString(TEXT);
+
+ // Get the new page's fragment, and set a listener for when the next button
+ // is clicked
+ ParagraphFragment p_fragment = ParagraphFragment.newInstance(paragraph);
+
+ // Replace and commit the fragment
+ completeFragmentTransaction(p_fragment);
+ }
+
+ /**
+ * Listener for clicking the next button: we can move to the correct next
+ * page, as given by the user's sent JSON. This one is specifically for the
+ * multiple choice fragment.
+ *
+ * @param choiceIndex the radiobutton choice that the user picked
+ * @throws JSONException because we use json objects
+ */
+ @Override
+ public void getResultFromMultipleChoiceFragment(int choiceIndex) throws JSONException {
+ // Enter the diagnosis into the editor
+ String diagnosis = choices.get(choiceIndex).getString(TEXT);
+ enterStringIntoSummaryEditor(nextPageJSON, diagnosis);
+
+ // If the link is null, then we should go to the default page
+ String nextPageName = choices.get(choiceIndex).getString(LINK);
+ if (nextPageName.equals(NULL)) {
+ nextPageName = nextPageJSON.getString(DEFAULT_LINK);
+ }
+
+ // Decide on the next page based on the result
+ try {
+ getNextPage(nextPageName);
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void getResultFromMultipleSelectionFragment(ArrayList chosenOptionIds) throws JSONException {
+ // add the selected choices to the diagnosis
+
+ String NextPage;
+
+ if (chosenOptionIds.isEmpty()) {
+ NextPage = nextPageJSON.getString(DEFAULT_LINK);
+ }
+ else {
+ String allDiagnoses = "";
+ for (int i = 0; i < chosenOptionIds.size(); i++) {
+ allDiagnoses += choices.get(chosenOptionIds.get(i) - 1).getString(TEXT);
+ if (i != chosenOptionIds.size() - 1) {
+ allDiagnoses += "\n";
+ }
+ // Enter the diagnosis into the editor
+ }
+ enterStringIntoSummaryEditor(nextPageJSON, allDiagnoses);
+
+ JSONObject foundLink = getContentFromPageID(nextPageJSON, targetValueID);
+ if (foundLink == null) {
+ NextPage = nextPageJSON.getString(DEFAULT_LINK);
+ } else {
+ NextPage = foundLink.getString(SATISFIED_LINK);
+ }
+ }
+
+ // Decide on the next page based on the result
+ try {
+ getNextPage(NextPage);
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void getResultFromTextInputFragment(String inputted) throws JSONException {
+ // First, we get the next page where this will lead eventually, or the default
+ ArrayList foundLinks = getContentFromPageIDArray(nextPageJSON, targetValue_id);
+ String nextPage = nextPageJSON.getString(DEFAULT_LINK);
+
+ // Next, we get the type of the object that was passed up from the TextInput:
+ // was it a number, or a string?
+ if (inputType.equals(INPUT_TYPES.numeric.name())) {
+ // If it was a number, we can then go through and run all of the comparison types for
+ // each comparison logic component
+ Float diagnosis = Float.valueOf(inputted);
+ if(!foundLinks.isEmpty()) {
+ for (JSONObject foundLink : foundLinks) {
+ String compType = foundLink.getString(TYPE);
+ float threshold = Float.parseFloat(foundLink.getString(THRESHOLD));
+ // greater than
+ if ((compType.equals(COMPARISON_TYPES.G.symbol) && diagnosis < threshold)
+ || (compType.equals(COMPARISON_TYPES.L.symbol) && diagnosis < threshold)
+ || (compType.equals(COMPARISON_TYPES.GE.symbol) && diagnosis >= threshold)
+ || (compType.equals(COMPARISON_TYPES.LE.symbol) && diagnosis <= threshold)
+ || (compType.equals(COMPARISON_TYPES.EQ.symbol) && diagnosis == threshold)) {
+ nextPage = foundLink.getString(SATISFIED_LINK);
+ break;
+ }
+ }
+ }
+ enterFloatIntoSummaryEditor(nextPageJSON, diagnosis);
+ } else {
+ // In the case that we're comparing strings, we'll compare equality with .equals,
+ // and the other ones it doesn't make sense to compare, so we'll just say that
+ // it doesn't work
+ if(!foundLinks.isEmpty()) {
+ for (JSONObject foundLink : foundLinks) {
+ String compType = foundLink.getString(TYPE);
+ String other = foundLink.getString(THRESHOLD);
+ // all cases where equals is included
+ if ((compType.equals(COMPARISON_TYPES.GE.symbol) ||
+ compType.equals(COMPARISON_TYPES.LE.symbol) ||
+ compType.equals(COMPARISON_TYPES.EQ.symbol)) &&
+ inputted.equals(other)) {
+
+ nextPage = foundLink.getString(SATISFIED_LINK);
+ break;
+
+ // If we don't have an equals, just go to the default page
+ }
+ }
+ }
+ enterStringIntoSummaryEditor(nextPageJSON, inputted);
+ }
+
+ // Finally, we go to the decided next page
+ try {
+ getNextPage(nextPage);
+ } catch(JSONException e) {
+ throw new RuntimeException();
+ }
+ }
+
+ @Override
+ public void getResultFromParagraphFragment() throws JSONException {
+ String nextPage = nextPageJSON.getString(DEFAULT_LINK);
+ try {
+ getNextPage(nextPage);
+ } catch(JSONException e) {
+ throw new RuntimeException();
+ }
+ }
+
+ /**
+ * Takes the page id and returns where we wish to go
+ *
+ * @param pageid the page ID we wish to use
+ * @param targetValueID the valueID of the current component that we are using
+ * @return
+ */
+ public JSONObject getContentFromPageID(JSONObject pageid, String targetValueID) throws JSONException {
+ JSONArray contentVal;
+ if(pageid != null) {
+ try {
+ // Get the content from the JSONArray
+ contentVal = pageid.getJSONArray(CONTENT);
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+ for(int i = 0; i < contentVal.length(); i++) {
+ // Check to see if the ID's match up
+ // With the build in has method
+ JSONObject RetrievedTargetID = ((JSONObject)contentVal.get(i));
+ if ( RetrievedTargetID.has(TARGET_VALUE_ID)) {
+ if(RetrievedTargetID.get(TARGET_VALUE_ID).equals(targetValueID)) {
+ return RetrievedTargetID;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Takes the page id and returns a list of targetids
+ *
+ * @param pageid the page ID we wish to use
+ * @param targetValueID the valueID of the current component that we are using
+ * @return
+ */
+ public ArrayList getContentFromPageIDArray(JSONObject pageid, String targetValueID) throws JSONException {
+ JSONArray contentVal;
+ ArrayList RetrievedTargetIDs = new ArrayList<>();
+ if(pageid != null) {
+ try {
+ // Get the content from the JSONArray
+ contentVal = pageid.getJSONArray(CONTENT);
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+ for(int i = 0; i < contentVal.length(); i++) {
+ // Check to see if the ID's match up
+ // With the build in has method
+ JSONObject RetrievedTargetID = ((JSONObject)contentVal.get(i));
+ if ( RetrievedTargetID.has(TARGET_VALUE_ID)) {
+ if(RetrievedTargetID.get(TARGET_VALUE_ID).equals(targetValueID)) {
+ RetrievedTargetIDs.add(RetrievedTargetID);
+ }
+ }
+ }
+ }
+ return RetrievedTargetIDs;
+ }
+
+ /**
+ * Listener for clicking the back button: calls up the next page based on the
+ * current backstack of pages
+ *
+ * @throws JSONException if the json hates you
+ */
+ @Override
+ public void getLastPage() throws JSONException {
+ // Get the last page JSON object that we put on to the backstack
+ backstack.remove(backstack.size() - 1);
+
+ // go to the SexModified , if it's the first page
+ if (backstack.isEmpty()) {
+ completeFragmentTransaction(new SexModified());
+ return;
+ }
+
+ String backPageName = backstack.get(backstack.size() - 1);
+
+ getNextPage(backPageName);
+ }
+
+ private int findIndexInPagesGivenPageId(String pageID) throws JSONException {
+ for (int i = 0; i < pages.length(); i++) {
+ JSONObject currPage = pages.getJSONObject(i);
+ String pageName = currPage.getString("pageID");
+ if (pageID.equals(pageName)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Abstracts away the process of adding a symptom to the sharedPreference object
+ *
+ * @param page is the page in the workflow that we're entering a symptom for
+ * @param symptom is the associated string to enter in given the page
+ * @throws JSONException because we look at JSON
+ */
+ public void enterStringIntoSummaryEditor(JSONObject page, String symptom) throws JSONException {
+ // Enter the diagnosis into the editor
+ patientSummaryEditor.putString(getValueID(page, 0), symptom);
+ patientSummaryEditor.apply();
+ }
+
+ /**
+ * Abstracts away the process of adding a symptom to the sharedPreference object
+ *
+ * @param page is the page in the workflow that we're entering a symptom for
+ * @param symptom is the associated float to enter in given the page
+ * @throws JSONException because we look at JSON
+ */
+ public void enterFloatIntoSummaryEditor(JSONObject page, Float symptom) throws JSONException {
+ // Enter the diagnosis into the editor
+ patientSummaryEditor.putFloat(getValueID(page, 0), symptom);
+ patientSummaryEditor.apply();
+ }
+
+ /**
+ * Function to get the ValueID (official name for a piece of content)
+ *
+ * @param page is the page in the workflow that the valueID is on
+ * @param contentIndex is the index within the content array that this valueID refers to
+ * @return a string that is the valueID
+ */
+ public String getValueID(JSONObject page, int contentIndex) throws JSONException {
+ return page.getJSONArray(CONTENT).getJSONObject(contentIndex).getString(VALUE_ID);
+ }
+
+ /**
+ * Create a unique ID which is used for uniquely storing patient data on the
+ * current device
+ *
+ * @return the unique ID
+ */
+ public String createUniquePatientInfoID() {
+ String patientInitials = sharedPreferences.getString(CHILD_INITIALS, "");
+ Date currentTime = Calendar.getInstance().getTime();
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss", Locale.getDefault());
+ String formattedDate = df.format(currentTime);
+
+ return patientInitials + "_" + formattedDate;
+ }
+
+ public Boolean isDiagnosisPage(JSONObject page) throws JSONException {
+ return (Boolean) page.get(IS_DIAGNOSIS_PAGE);
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/ug/air/alrite/Activities/SplashActivity.java b/app/src/main/java/com/ug/air/alrite/Activities/SplashActivity.java
index c03fbfc..a5aec0d 100644
--- a/app/src/main/java/com/ug/air/alrite/Activities/SplashActivity.java
+++ b/app/src/main/java/com/ug/air/alrite/Activities/SplashActivity.java
@@ -1,33 +1,40 @@
package com.ug.air.alrite.Activities;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.REASSESS;
-
+import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
-import androidx.fragment.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
-import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.widget.LinearLayout;
+import com.ug.air.alrite.APIs.ApiClient;
+import com.ug.air.alrite.APIs.BackendRequests;
import com.ug.air.alrite.BuildConfig;
import com.ug.air.alrite.Database.DatabaseHelper;
-import com.ug.air.alrite.Fragments.navigation.AccountFragment;
import com.ug.air.alrite.R;
import com.ug.air.alrite.Utils.Counter;
import com.ug.air.alrite.Utils.Credentials;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.BufferedWriter;
import java.io.File;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
public class SplashActivity extends AppCompatActivity {
@@ -47,6 +54,9 @@ public class SplashActivity extends AppCompatActivity {
public static final String WHEEZING_COUNT = "wheezing_count";
public static final String CHESTINDRWAING_COUNT = "chest_indrawing_count";
public static final String ECZEMA_COUNT = "eczema_count";
+
+ // TODO: change this if you want to get from online
+ Boolean shouldGetNewAssessmentOnStartup = true;
SharedPreferences sharedPreferences;
SharedPreferences.Editor editor;
@@ -62,7 +72,6 @@ protected void onCreate(Bundle savedInstanceState) {
logo = findViewById(R.id.logo);
databaseHelper = new DatabaseHelper(this);
-
}
@Override
@@ -104,23 +113,73 @@ private void createFileCounter() {
editor.apply();
}
checkDatabase();
+ getCurrentAssessmentIfConnectedToInternet();
}
private void checkDatabase() {
File src = new File("/data/data/" + BuildConfig.APPLICATION_ID + "/databases/alrite.db");
- if (src.exists()){
+ if (src.exists()) {
Credentials credentials = new Credentials();
String username = credentials.creds(this).getUsername();
- if (!username.equals("None")){
+ if (!username.equals("None")) {
Counter counter = new Counter();
counter.Count(this, APP_OPENING_COUNT);
}
- }else {
+ } else {
databaseHelper.insertData(1, "None", "None", "None", "None", "None", "None");
}
i = new Intent(SplashActivity.this, Dashboard.class);
startActivity(i);
finish();
}
+
+ private void getCurrentAssessmentIfConnectedToInternet() {
+ if (isNetworkAvailable() && shouldGetNewAssessmentOnStartup) {
+ BackendRequests dtJson = ApiClient.getClient(ApiClient.REMOTE_URL_TEMP).create(BackendRequests.class);
+ Call call = dtJson.getJson("June_6_Demo");
+ call.enqueue(new Callback() {
+ @Override
+ public void onResponse(@NonNull Call call, @NonNull Response response) {
+ if (!response.isSuccessful()) {
+ System.out.println("no site, plase try again");
+ return;
+ }
+
+ // We've received a response! We can turn this into a JSONObject
+ // and store the result locally
+ try {
+ assert response.body() != null;
+ JSONObject json = new JSONObject(response.body());
+
+ File directory = getFilesDir();
+ File assessment = new File(directory, "assessment.json");
+ if (assessment.exists()) {
+ assessment.delete();
+ assessment = new File(directory, "assessment.json");
+ }
+ Writer output = null;
+ output = new BufferedWriter(new FileWriter(assessment));
+ output.write(json.toString());
+ output.close();
+
+ } catch (JSONException | IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void onFailure(Call call, Throwable t) {
+ throw new RuntimeException(t);
+ }
+ });
+ }
+ }
+
+ private boolean isNetworkAvailable() {
+ ConnectivityManager connectivityManager
+ = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo activeNetworkInfo = connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null;
+ return activeNetworkInfo != null && activeNetworkInfo.isConnected();
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/ug/air/alrite/Activities/TextInputExample.json b/app/src/main/java/com/ug/air/alrite/Activities/TextInputExample.json
new file mode 100644
index 0000000..56233d0
--- /dev/null
+++ b/app/src/main/java/com/ug/air/alrite/Activities/TextInputExample.json
@@ -0,0 +1,177 @@
+{
+ "name": "IMCI",
+ "pages": [
+ {
+ "pageID": "page_1",
+ "title": "Patient Details",
+ "content": [
+ {
+ "label": "Enter parent or guardian's initials:",
+ "type": "default",
+ "valueID": "guardian_initials",
+ "component": "TextInput"
+ },
+ {
+ "label": "Enter child's initials:",
+ "type": "default",
+ "valueID": "child_initials",
+ "component": "TextInput"
+ }
+ ],
+ "defaultLink": "page_2",
+ "isDiagnosisPage": false
+ },
+ {
+ "pageID": "page_2",
+ "title": "Patient Details",
+ "content": [
+ {
+ "label": "What is the child's sex?",
+ "valueID": "patient_sex",
+ "multiselect": false,
+ "choices": [
+ {
+ "text": "Male",
+ "value": "male",
+ "link": "null"
+ },
+ {
+ "text": "Female",
+ "value": "female",
+ "link": "null"
+ }
+ ],
+ "component": "MultipleChoice"
+ },
+ {
+ "label": "How old is the child?",
+ "type": "numeric",
+ "valueID": "child_age",
+ "units": "years",
+ "component": "TextInput"
+ },
+ {
+ "label": "What is the child's weight?",
+ "type": "numeric",
+ "valueID": "child_weight",
+ "units": "kg",
+ "component": "TextInput"
+ }
+ ],
+ "defaultLink": "page_3",
+ "isDiagnosisPage": false
+ },
+ {
+ "pageID": "page_3",
+ "title": "Assess Patient",
+ "content": [
+ {
+ "label": "What symptoms does the child have?",
+ "valueID": "child_symptoms",
+ "multiselect": true,
+ "choices": [
+ {
+ "text": "Unable to drink or breastfeed",
+ "value": "unable to drink",
+ "link": "page_1"
+ },
+ {
+ "text": "Vomiting everything",
+ "value": "vomiting",
+ "link": "page_1"
+ },
+ {
+ "text": "Unresponsive, no awareness of surroundings",
+ "value": "unresponsive",
+ "link": "page_1"
+ },
+ {
+ "text": "Convulsions (uncontrolled jerking / seizures)",
+ "value": "convlusions",
+ "link": "page_1"
+ }
+ ],
+ "component": "MultipleChoice"
+ },
+ {
+ "type": "at_least_one",
+ "targetValueID": "child_symptoms",
+ "satisfiedLink": "page_8",
+ "component": "Selection"
+ }
+ ],
+ "defaultLink": "page_6",
+ "isDiagnosisPage": false
+ },
+ {
+ "pageID": "page_8",
+ "title": "Severe Disease",
+ "content": [
+ {
+ "text": "Give the first dose of antibiotic-intramuscular injection, Ampicillin and Gentamicin. Oral amoxicillin otherwise.",
+ "component": "Paragraph"
+ },
+ {
+ "text": "For AMPICILLIN: Dilute 500mg vial with 2.1ml sterile water (500mg/2.5ml). Give 5ml ONE TIME via intramuscular injection. If referral is not possible or delayed, repeat the same dose of AMPICILLIN every 6 hours.",
+ "component": "Paragraph"
+ },
+ {
+ "text": "For GENTAMICIN: (2ml/40mg/ml vial). Give 2.8-35.ml ONE TIME via intramuscular injection. If referral is not possible or delayed, repeat gentamicin once daily.",
+ "component": "Paragraph"
+ },
+ {
+ "text": "If wheezing now, give salbutamol 4-6 puffs with spacer or 1 nebulization (2.5-5mg) if available while awaiting referral. Do not delay referral.",
+ "component": "Paragraph"
+ }
+ ],
+ "defaultLink": "page_6",
+ "isDiagnosisPage": false
+ },
+ {
+ "pageID": "page_6",
+ "title": "Patient's History (1/3)",
+ "content": [
+ {
+ "label": "Does the child have a cough or difficulty breathing?",
+ "valueID": "child_has_cough",
+ "multiselect": false,
+ "choices": [
+ {
+ "text": "Yes",
+ "value": "true",
+ "link": "null"
+ },
+ {
+ "text": "No",
+ "value": "false",
+ "link": "null"
+ }
+ ],
+ "component": "MultipleChoice"
+ }
+ ],
+ "defaultLink": "page_7",
+ "isDiagnosisPage": false
+ },
+ {
+ "pageID": "page_7",
+ "title": "Patient's History (2/3)",
+ "content": [],
+ "defaultLink": "page_4",
+ "isDiagnosisPage": false
+ },
+ {
+ "pageID": "page_4",
+ "title": "Diagnosis Page",
+ "content": [],
+ "defaultLink": "page_1",
+ "isDiagnosisPage": true
+ }
+ ],
+ "meta": {
+ "version": 4,
+ "apipath": "/alrite/apis/workflows/IMCI/4/",
+ "time_created": "2023-05-11 19:44:23.369807+00:00",
+ "created_by": null
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/ug/air/alrite/Activities/example.json b/app/src/main/java/com/ug/air/alrite/Activities/example.json
new file mode 100644
index 0000000..5a677ac
--- /dev/null
+++ b/app/src/main/java/com/ug/air/alrite/Activities/example.json
@@ -0,0 +1,92 @@
+{
+ "pages":
+ [
+ {
+ "pageID": "page_1",
+ "pageTitle": "smoke_tobacco",
+ "content":
+ [
+ {
+ "type": "multiple-choice",
+ "text": "Does anyone in the child's home smoke tobacco?",
+ "choices":
+ [
+ {
+ "text": "Yes",
+ "link": "page_2",
+ "valueID": "yes"
+ },
+ {
+ "text": "No",
+ "link": "page_3",
+ "valueID": "no"
+ },
+ {
+ "text": "Not sure",
+ "link": "page_3",
+ "valueID": "unsure"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "pageID": "page_2",
+ "pageTitle": "kerosene",
+ "content":
+ [
+ {
+ "type": "multiple-choice",
+ "text": "Does any of the family members use kerosene, charcoal, or other biomass in the home?",
+ "choices":
+ [
+ {
+ "text": "Yes",
+ "link": "final_page",
+ "valueID": "yes"
+ },
+ {
+ "text": "No",
+ "link": "final_page",
+ "valueID": "no"
+ },
+ {
+ "text": "Not sure",
+ "link": "final_page",
+ "valueID": "unsure"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "pageID": "page_3",
+ "pageTitle": "allergies",
+ "content":
+ [
+ {
+ "type": "multiple-choice",
+ "text": "Has the child’s parents or siblings had similar breathing problems, other diseases with breathing problems or allergies?",
+ "choices":
+ [
+ {
+ "text": "Yes",
+ "link": "final_page",
+ "valueID": "yes"
+ },
+ {
+ "text": "No",
+ "link": "final_page",
+ "valueID": "no"
+ },
+ {
+ "text": "Not sure",
+ "link": "final_page",
+ "valueID": "unsure"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/ug/air/alrite/Adapters/DiagnosisAdapter.java b/app/src/main/java/com/ug/air/alrite/Adapters/DiagnosisAdapter.java
index 01d1880..a7b12c1 100644
--- a/app/src/main/java/com/ug/air/alrite/Adapters/DiagnosisAdapter.java
+++ b/app/src/main/java/com/ug/air/alrite/Adapters/DiagnosisAdapter.java
@@ -33,7 +33,6 @@ public void setOnItemClickListener(OnItemClickListener listener){
public interface OnItemClickListener {
void onClick(int position);
- void onClick2(int position);
}
@NonNull
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/ActivePatients.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/ActivePatients.java
index e3e7a93..3e57758 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/ActivePatients.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/ActivePatients.java
@@ -1,21 +1,19 @@
package com.ug.air.alrite.Fragments.Patient;
-import static com.ug.air.alrite.Activities.PatientActivity.INCOMPLETE;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.BRONCHODILATOR;
+import static com.ug.air.alrite.Activities.PatientActivity.ASSESS_INCOMPLETE;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.BRONCHODILATOR_WAS_GIVEN;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.USED_BRONCHODILATOR;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.DATE;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.REASSESS;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator2.REASON;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator3.BRONC;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator3.FINAL;
-import static com.ug.air.alrite.Fragments.Patient.Initials.CIN;
-import static com.ug.air.alrite.Fragments.Patient.Initials.PIN;
-import static com.ug.air.alrite.Fragments.Patient.Sex.AGE;
-import static com.ug.air.alrite.Fragments.Patient.Sex.AGE2;
-import static com.ug.air.alrite.Fragments.Patient.Sex.CHOICE;
+import static com.ug.air.alrite.Fragments.Patient.Bronchodilator3.AFTER_BRONCHODILATOR;
+import static com.ug.air.alrite.Fragments.Patient.Initials.CHILD_INITIALS;
+import static com.ug.air.alrite.Fragments.Patient.Initials.PARENT_INITIALS;
+import static com.ug.air.alrite.Fragments.Patient.Sex.AGE_IN_YEARS;
+import static com.ug.air.alrite.Fragments.Patient.Sex.SEX;
import android.content.Context;
-import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
@@ -32,8 +30,6 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
-import com.ug.air.alrite.Activities.Dashboard;
-import com.ug.air.alrite.Activities.DiagnosisActivity;
import com.ug.air.alrite.Adapters.PatientAdapter;
import com.ug.air.alrite.BuildConfig;
import com.ug.air.alrite.Models.Item;
@@ -45,21 +41,19 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
-import java.util.Collections;
import java.util.Date;
-import java.util.Objects;
import java.util.concurrent.TimeUnit;
public class ActivePatients extends Fragment {
View view;
- RecyclerView recyclerView;
+ RecyclerView rvActivePatients;
EditText etSearch;
- ImageView back;
- ArrayList- items;
+ ImageView buttonBack;
+ ArrayList
- patientsList;
PatientAdapter patientAdapter;
- String cin, pin, gender, age, search, dat;
- ArrayList types, files, file;
+ String childInitials, parentInitials, gender, age, search, date;
+ ArrayList pToReassessInitialsList, files, patientsToReassessList;
SharedPreferences sharedPreferences;
SharedPreferences.Editor editor;
@@ -69,9 +63,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_active_patients, container, false);
- recyclerView = view.findViewById(R.id.recyclerView3);
+ rvActivePatients = view.findViewById(R.id.recyclerView3);
etSearch = view.findViewById(R.id.search);
- back = view.findViewById(R.id.back);
+ buttonBack = view.findViewById(R.id.back);
// back.setOnClickListener(new View.OnClickListener() {
// @Override
@@ -80,25 +74,25 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
// }
// });
- back.setVisibility(View.GONE);
+ buttonBack.setVisibility(View.GONE);
- recyclerView.setHasFixedSize(true);
- recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
+ rvActivePatients.setHasFixedSize(true);
+ rvActivePatients.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
- items = new ArrayList<>();
+ patientsList = new ArrayList<>();
files = new ArrayList();
accessSharedFile();
etSearch.addTextChangedListener(textWatcher);
- patientAdapter = new PatientAdapter(getActivity(), items);
- recyclerView.setAdapter(patientAdapter);
+ patientAdapter = new PatientAdapter(getActivity(), patientsList);
+ rvActivePatients.setAdapter(patientAdapter);
patientAdapter.setOnItemClickListener(new PatientAdapter.OnItemClickListener() {
@Override
public void onItemClick(int position) {
- Patient patient = (Patient) items.get(position).getObject();
+ Patient patient = (Patient) patientsList.get(position).getObject();
String name = patient.getFilename();
boolean reassess = patient.isReassess();
if (reassess){
@@ -131,28 +125,28 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
public void onTextChanged(CharSequence s, int start, int before, int count) {
search = etSearch.getText().toString();
if (!search.isEmpty()) {
- items.clear();
- for(String type : types){
+ patientsList.clear();
+ for(String type : pToReassessInitialsList){
String ty = type.toLowerCase();
if (ty.contains(search)){
- int index = types.indexOf(type);
- String fileName = file.get(index);
+ int index = pToReassessInitialsList.indexOf(type);
+ String fileName = patientsToReassessList.get(index);
sharedPreferences = requireActivity().getSharedPreferences(fileName, Context.MODE_PRIVATE);
- cin = sharedPreferences.getString(CIN, "");
- pin = sharedPreferences.getString(PIN, "");
- age = sharedPreferences.getString(AGE2, "");
- gender = sharedPreferences.getString(CHOICE, "");
- dat = sharedPreferences.getString(DATE, "");
+ childInitials = sharedPreferences.getString(CHILD_INITIALS, "");
+ parentInitials = sharedPreferences.getString(PARENT_INITIALS, "");
+ age = sharedPreferences.getString(AGE_IN_YEARS, "");
+ gender = sharedPreferences.getString(SEX, "");
+ date = sharedPreferences.getString(DATE, "");
boolean reassess = sharedPreferences.getBoolean(REASSESS, false);
String[] split = age.split("\\.");
String ag = split[0] + " years and " + split[1] + " months";
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
- Date date = df.parse(dat);
+ Date date = df.parse(ActivePatients.this.date);
SimpleDateFormat df1 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm");
String formattedDate = df1.format(date);
- Patient patient = new Patient("Age: " + ag, "Gender: " + gender, cin, "Parent/Guardian: " + pin, formattedDate, fileName, reassess);
- items.add(new Item(0, patient));
+ Patient patient = new Patient("Age: " + ag, "Gender: " + gender, childInitials, "Parent/Guardian: " + parentInitials, formattedDate, fileName, reassess);
+ patientsList.add(new Item(0, patient));
// patientAdapter.notifyDataSetChanged();
} catch (ParseException e) {
e.printStackTrace();
@@ -162,7 +156,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
}
patientAdapter.notifyDataSetChanged();
}else {
- items.clear();
+ patientsList.clear();
accessSharedFile();
patientAdapter.notifyDataSetChanged();
}
@@ -174,38 +168,53 @@ public void afterTextChanged(Editable s) {
}
};
+ /**
+ *
+ */
private void accessSharedFile() {
- File src = new File("/data/data/" + BuildConfig.APPLICATION_ID + "/shared_prefs");
- if (src.exists()){
- File[] contents = src.listFiles();
+ // Get the shared preferences folder on the current device
+ File sharedPrefsFolder = new File("/data/data/" + BuildConfig.APPLICATION_ID + "/shared_prefs");
+ if (sharedPrefsFolder.exists()){
+ File[] sharedPrefsFiles = sharedPrefsFolder.listFiles();
// Toast.makeText(getActivity(), "" + contents, Toast.LENGTH_SHORT).show();
- if (contents.length != 0) {
- types = new ArrayList();
- file = new ArrayList();
- for (File f : contents) {
+ if (sharedPrefsFiles.length != 0) {
+ pToReassessInitialsList = new ArrayList();
+ patientsToReassessList = new ArrayList();
+
+ // Go through each file in the shared preferences folder
+ for (File f : sharedPrefsFiles) {
if (f.isFile()) {
- String name = f.getName().toString();
- if (!name.equals("sharedPrefs.xml") && !name.equals("counter_file.xml")){
- String names = name.replace(".xml", "");
- sharedPreferences = requireActivity().getSharedPreferences(names, Context.MODE_PRIVATE);
+ String filename = f.getName().toString();
+ if (!filename.equals("sharedPrefs.xml") && !filename.equals("counter_file.xml")){
+ // Get a file from the folder for a patient, and get the name itself
+ // and the shared preferences object + editor for that file
+ String patientFilename = filename.replace(".xml", "");
+ sharedPreferences = requireActivity().getSharedPreferences(patientFilename, Context.MODE_PRIVATE);
editor = sharedPreferences.edit();
- String bron = sharedPreferences.getString(BRONCHODILATOR, "");
- String fin = sharedPreferences.getString(BRONC, "");
- String incomplete = sharedPreferences.getString(INCOMPLETE, "");
- if (bron.equals("Bronchodialtor Given") && fin.isEmpty()){
- file.add(names);
- cin = sharedPreferences.getString(CIN, "");
- pin = sharedPreferences.getString(PIN, "");
- age = sharedPreferences.getString(AGE2, "");
- gender = sharedPreferences.getString(CHOICE, "");
- dat = sharedPreferences.getString(DATE, "");
+
+ // Look in the shared preferences for if we used a bronchodilator
+ // or not, and how it turned out if we did, and if we finished
+ // the assessment or not.
+ String givenBronch = sharedPreferences.getString(USED_BRONCHODILATOR, "");
+ String afterBronch = sharedPreferences.getString(AFTER_BRONCHODILATOR, "");
+ String assessIncomplete = sharedPreferences.getString(ASSESS_INCOMPLETE, "");
+
+ // If we gave the bronchodilator but never checked final condition,
+ //
+ if (givenBronch.equals(BRONCHODILATOR_WAS_GIVEN) && afterBronch.isEmpty()){
+ patientsToReassessList.add(patientFilename);
+ childInitials = sharedPreferences.getString(CHILD_INITIALS, "");
+ parentInitials = sharedPreferences.getString(PARENT_INITIALS, "");
+ age = sharedPreferences.getString(AGE_IN_YEARS, "");
+ gender = sharedPreferences.getString(SEX, "");
+ date = sharedPreferences.getString(DATE, "");
boolean reassess = sharedPreferences.getBoolean(REASSESS, false);
- types.add(cin);
+ pToReassessInitialsList.add(childInitials);
String[] split = age.split("\\.");
String ag = split[0] + " years and " + split[1] + " months";
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
- Date date = df.parse(dat);
+ Date date = df.parse(this.date);
SimpleDateFormat df1 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm");
String formattedDate = df1.format(date);
@@ -215,15 +224,15 @@ private void accessSharedFile() {
if (minutes >= 15 && minutes < 240){
editor.putBoolean(REASSESS, true);
editor.apply();
- Patient patient = new Patient("Age: " + ag, "Gender: " + gender, cin, "Parent/Guardian: " + pin, formattedDate, names, reassess);
- items.add(new Item(0, patient));
+ Patient patient = new Patient("Age: " + ag, "Gender: " + gender, childInitials, "Parent/Guardian: " + parentInitials, formattedDate, patientFilename, reassess);
+ patientsList.add(new Item(0, patient));
}else if (minutes >= 240){
- editor.putString(BRONCHODILATOR, "Bronchodialtor Not Given");
+ editor.putString(USED_BRONCHODILATOR, "Bronchodialtor Not Given");
editor.putString(REASON, "A 4 hour time period elapsed");
editor.apply();
}else {
- Patient patient = new Patient("Age: " + ag, "Gender: " + gender, cin, "Parent/Guardian: " + pin, formattedDate, names, reassess);
- items.add(new Item(0, patient));
+ Patient patient = new Patient("Age: " + ag, "Gender: " + gender, childInitials, "Parent/Guardian: " + parentInitials, formattedDate, patientFilename, reassess);
+ patientsList.add(new Item(0, patient));
}
} catch (ParseException e) {
e.printStackTrace();
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Assess.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Assess.java
index 3f51579..fa3d943 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Assess.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Assess.java
@@ -1,6 +1,6 @@
package com.ug.air.alrite.Fragments.Patient;
-import static com.ug.air.alrite.Fragments.Patient.Sex.AGE;
+import static com.ug.air.alrite.Fragments.Patient.Sex.AGE_IN_MONTHS;
import static com.ug.air.alrite.Fragments.Patient.Sex.KILO;
import android.app.Dialog;
@@ -40,7 +40,7 @@
public class Assess extends Fragment {
View view;
- Button back, next, btnExit, btnContinue;
+ Button buttonBack, buttonNext, btnExit, btnContinue;
CheckBox drink, vomit, resp, convu, none;
String s = "";
Boolean check1, check2, check3, check4, check5;
@@ -54,14 +54,14 @@ public class Assess extends Fragment {
String diagnosis;
public static final String SHARED_PREFS = "sharedPrefs";
- public static final String CHECK1 = "check1";
- public static final String CHECK2 = "check2";
- public static final String CHECK3 = "check3";
- public static final String CHECK4 = "check4";
- public static final String CHECK5 = "check5";
+ public static final String CANT_DRINK = "check1";
+ public static final String VOMITING = "check2";
+ public static final String UNRESPONSIVE = "check3";
+ public static final String CONVULSIONS = "check4";
+ public static final String NONE = "check5";
public static final String DATE = "date";
- public static final String S4 = "symptoms";
- public static final String FINAL_DIAGNOSIS= "diagnosis_1";
+ public static final String SEVERE_SYMPTOMS = "symptoms";
+ public static final String FINAL_DIAGNOSIS= "diagnosis_severe_pneumonia_disease";
public static final String DIAGNOSIS = "diagnosis";
SharedPreferences sharedPreferences, sharedPreferences1;
SharedPreferences.Editor editor, editor1;
@@ -72,8 +72,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_assess, container, false);
- back = view.findViewById(R.id.back);
- next = view.findViewById(R.id.next);
+ buttonBack = view.findViewById(R.id.back);
+ buttonNext = view.findViewById(R.id.next);
drink = view.findViewById(R.id.drink);
vomit = view.findViewById(R.id.vomit);
none = view.findViewById(R.id.none);
@@ -159,14 +159,14 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});
- next.setOnClickListener(new View.OnClickListener() {
+ buttonNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
checkedList();
}
});
- back.setOnClickListener(new View.OnClickListener() {
+ buttonBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction fr = requireActivity().getSupportFragmentManager().beginTransaction();
@@ -213,12 +213,12 @@ private void checkedList() {
private void saveData() {
- editor.putBoolean(CHECK1, drink.isChecked());
- editor.putBoolean(CHECK2, vomit.isChecked());
- editor.putBoolean(CHECK3, resp.isChecked());
- editor.putBoolean(CHECK4, convu.isChecked());
- editor.putBoolean(CHECK5, none.isChecked());
- editor.putString(S4, s);
+ editor.putBoolean(CANT_DRINK, drink.isChecked());
+ editor.putBoolean(VOMITING, vomit.isChecked());
+ editor.putBoolean(UNRESPONSIVE, resp.isChecked());
+ editor.putBoolean(CONVULSIONS, convu.isChecked());
+ editor.putBoolean(NONE, none.isChecked());
+ editor.putString(SEVERE_SYMPTOMS, s);
editor.apply();
@@ -226,11 +226,11 @@ private void saveData() {
}
private void loadData() {
- check1 = sharedPreferences.getBoolean(CHECK1, false);
- check2 = sharedPreferences.getBoolean(CHECK2, false);
- check3 = sharedPreferences.getBoolean(CHECK3, false);
- check4 = sharedPreferences.getBoolean(CHECK4, false);
- check5 = sharedPreferences.getBoolean(CHECK5, false);
+ check1 = sharedPreferences.getBoolean(CANT_DRINK, false);
+ check2 = sharedPreferences.getBoolean(VOMITING, false);
+ check3 = sharedPreferences.getBoolean(UNRESPONSIVE, false);
+ check4 = sharedPreferences.getBoolean(CONVULSIONS, false);
+ check5 = sharedPreferences.getBoolean(NONE, false);
}
private void updateViews() {
@@ -250,79 +250,9 @@ private void checkIfNone() {
fr.replace(R.id.fragment_container, new Cough());
fr.addToBackStack(null);
fr.commit();
- }else{
- displayDialog();
}
}
- private void displayDialog() {
- dialog = new Dialog(getActivity());
- dialog.setContentView(R.layout.assessment_layout);
- dialog.setCancelable(true);
- Window window = dialog.getWindow();
- window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
-
- linearLayout_instruction = dialog.findViewById(R.id.diagnosis);
- txtDiagnosis = dialog.findViewById(R.id.txtDiagnosis);
- recyclerView = dialog.findViewById(R.id.recyclerView1);
- btnExit = dialog.findViewById(R.id.btnSave);
- btnContinue = dialog.findViewById(R.id.btnContinue);
-
- linearLayout_instruction.setBackgroundColor(getResources().getColor(R.color.severeDiagnosisColor));
- txtDiagnosis.setText(R.string.severe);
- diagnosis = txtDiagnosis.getText().toString();
- diagnosis = diagnosis.replace("Diagnosis: ", "");
-
- recyclerView.setHasFixedSize(true);
- recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
-
- assessments = new ArrayList<>();
- assessmentAdapter = new AssessmentAdapter(assessments);
-
- String age = sharedPreferences.getString(AGE, "");
- String weight = sharedPreferences.getString(KILO, "");
- int ag = Integer.parseInt(age);
-
- Instructions instructions = new Instructions();
- messages = instructions.GetInstructions(ag, weight, s);
-
- for (int i = 0; i < messages.size(); i++){
- Assessment assessment = new Assessment((Integer) messages.get(i));
- assessments.add(assessment);
- }
- recyclerView.setAdapter(assessmentAdapter);
-
- btnExit.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finalDiagnosis();
- editor.putString(DIAGNOSIS, diagnosis);
- editor.apply();
- dialog.dismiss();
-// Toast.makeText(getActivity(), diagnosis, Toast.LENGTH_SHORT).show();
- startActivity(new Intent(getActivity(), DiagnosisActivity.class));
- }
- });
-
- btnContinue.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finalDiagnosis();
- editor.putString(DIAGNOSIS, diagnosis);
- editor.apply();
- dialog.dismiss();
- FragmentTransaction fr = requireActivity().getSupportFragmentManager().beginTransaction();
- fr.replace(R.id.fragment_container, new Cough());
- fr.addToBackStack(null);
- fr.commit();
- }
- });
-
-// dialog.getWindow().setLayout(650, WindowManager.LayoutParams.MATCH_PARENT);
- dialog.getWindow().setGravity(Gravity.CENTER);
- dialog.show();
- }
-
private void finalDiagnosis() {
editor.putString(FINAL_DIAGNOSIS, "Severe Pneumonia OR very Severe Disease");
editor.apply();
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Breathless.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Breathless.java
index 364d187..a5e2a19 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Breathless.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Breathless.java
@@ -1,6 +1,5 @@
package com.ug.air.alrite.Fragments.Patient;
-import static com.ug.air.alrite.Fragments.Patient.Sex.AGE;
import static com.ug.air.alrite.Fragments.Patient.WheezY.DAY2;
import android.content.Context;
@@ -20,8 +19,6 @@
import com.ug.air.alrite.R;
-import java.util.Objects;
-
public class Breathless extends Fragment {
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Bronchodilator.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Bronchodilator.java
index 310008b..9804741 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Bronchodilator.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Bronchodilator.java
@@ -1,7 +1,6 @@
package com.ug.air.alrite.Fragments.Patient;
import static com.ug.air.alrite.Activities.SplashActivity.BRONCHODILATOR_COUNT;
-import static com.ug.air.alrite.Activities.SplashActivity.STRIDOR_COUNT;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator2.BDIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator2.REASON;
import static com.ug.air.alrite.Fragments.Patient.Initials.INITIAL_DATE;
@@ -19,10 +18,8 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.work.Data;
-import androidx.work.ExistingPeriodicWorkPolicy;
import androidx.work.ExistingWorkPolicy;
import androidx.work.OneTimeWorkRequest;
-import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkManager;
import androidx.work.WorkRequest;
@@ -36,11 +33,9 @@
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
-import android.widget.Toast;
import android.widget.VideoView;
import com.ug.air.alrite.Activities.DiagnosisActivity;
-import com.ug.air.alrite.Activities.PatientActivity;
import com.ug.air.alrite.Adapters.AssessmentAdapter;
import com.ug.air.alrite.Models.Assessment;
import com.ug.air.alrite.R;
@@ -66,7 +61,9 @@ public class Bronchodilator extends Fragment {
Dialog dialog;
String bronchodilator, uniqueID, filename;
TextView txtMessage;
- public static final String BRONCHODILATOR = "bronchodilator";
+ public static final String BRONCHODILATOR_WAS_GIVEN = "Bronchodialtor Given";
+ public static final String BRONCHODILATOR_NOT_GIVEN = "Bronchodialtor Not Given";
+ public static final String USED_BRONCHODILATOR = "bronchodilator";
public static final String REASSESS = "reassess";
// public static final String BACKGROUND = "background";
public static final String SHARED_PREFS = "sharedPrefs";
@@ -74,9 +71,9 @@ public class Bronchodilator extends Fragment {
SharedPreferences sharedPreferences, sharedPreferences2;
SharedPreferences.Editor editor, editor2;
public static final String DATE = "end_date";
- public static final String FILENAME = "filename";
+ public static final String PATIENT_ASSESSMENT_ID = "filename";
public static final String UUIDS = "patient_uuid";
- public static final String USERNAME = "clinician";
+ public static final String CLINICIAN_USERNAME = "clinician";
public static final String DURATION = "duration";
TextView txtDisease, txtDefinition, txtOk, txtDiagnosis;
LinearLayout linearLayoutDisease;
@@ -112,23 +109,25 @@ public void onClick(View view) {
}
});
+ // The patient was given a bronchodilator
btnGiven.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
editor.remove(BDIAGNOSIS);
editor.remove(REASON);
- bronchodilator = "Bronchodialtor Given";
- editor.putString(BRONCHODILATOR, bronchodilator);
+ bronchodilator = BRONCHODILATOR_WAS_GIVEN;
+ editor.putString(USED_BRONCHODILATOR, bronchodilator);
editor.apply();
showDialog();
}
});
+ // The patient was not given a bronchodilator
btnNot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- bronchodilator = "Bronchodialtor Not Given";
- editor.putString(BRONCHODILATOR, bronchodilator);
+ bronchodilator = BRONCHODILATOR_NOT_GIVEN;
+ editor.putString(USED_BRONCHODILATOR, bronchodilator);
editor.apply();
FragmentTransaction fr = requireActivity().getSupportFragmentManager().beginTransaction();
fr.replace(R.id.fragment_container, new Bronchodilator2());
@@ -240,7 +239,7 @@ private void startBackGroundTask() {
Credentials credentials = new Credentials();
String username = credentials.creds(getActivity()).getUsername();
- editor.putString(USERNAME, username);
+ editor.putString(CLINICIAN_USERNAME, username);
uniqueID = UUID.randomUUID().toString();
@@ -248,7 +247,7 @@ private void startBackGroundTask() {
editor.putString(UUIDS, uniqueID);
filename = formattedDate + "_" + uniqueID;
- editor.putString(FILENAME, filename);
+ editor.putString(PATIENT_ASSESSMENT_ID, filename);
editor.apply();
Data inputData = new Data.Builder()
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Bronchodilator2.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Bronchodilator2.java
index 4d6bd78..7787217 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Bronchodilator2.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Bronchodilator2.java
@@ -1,9 +1,9 @@
package com.ug.air.alrite.Fragments.Patient;
-import static com.ug.air.alrite.Fragments.Patient.Cough.CHOICE2;
+import static com.ug.air.alrite.Fragments.Patient.Cough.DIFFICULTY_BREATHING;
import static com.ug.air.alrite.Fragments.Patient.CoughD.DAY1;
-import static com.ug.air.alrite.Fragments.Patient.Sex.AGE;
-import static com.ug.air.alrite.Fragments.Patient.Wheezing.CHOICE8;
+import static com.ug.air.alrite.Fragments.Patient.Sex.AGE_IN_MONTHS;
+import static com.ug.air.alrite.Fragments.Patient.Wheezing.WHEEZING_SOUNDS;
import android.app.Dialog;
import android.content.Context;
@@ -50,7 +50,7 @@ public class Bronchodilator2 extends Fragment {
EditText etOther;
public static final String SHARED_PREFS = "sharedPrefs";
public static final String REASON = "bronchodilator_not_given_reason";
- public static final String BDIAGNOSIS = "diagnosis_8";
+ public static final String BDIAGNOSIS = "bronchodilator_diagnosis";
SharedPreferences sharedPreferences, sharedPreferences1;
SharedPreferences.Editor editor, editor1;
String diagnosis;
@@ -150,8 +150,8 @@ private void saveData(String s) {
editor.putString(REASON, s);
editor.apply();
- String cough = sharedPreferences.getString(CHOICE2, "");
- String wheezing = sharedPreferences.getString(CHOICE8, "");
+ String cough = sharedPreferences.getString(DIFFICULTY_BREATHING, "");
+ String wheezing = sharedPreferences.getString(WHEEZING_SOUNDS, "");
String days = sharedPreferences.getString(DAY1, "");
day = Long.parseLong(days);
@@ -229,7 +229,7 @@ private void showDialog2() {
linearLayout_instruction.setBackgroundColor(getResources().getColor(R.color.moderateDiagnosisColor));
txtDiagnosis.setText(R.string.wheez_ill);
- String age = sharedPreferences.getString(AGE, "");
+ String age = sharedPreferences.getString(AGE_IN_MONTHS, "");
float ag = Float.parseFloat(age);
if (ag < 2){
messages = Arrays.asList(R.string.wheez_ill1, R.string.wheez_ill2, R.string.wheez_ill3,
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Bronchodilator3.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Bronchodilator3.java
index 3699a43..e41f13a 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Bronchodilator3.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Bronchodilator3.java
@@ -2,10 +2,9 @@
import static com.ug.air.alrite.Fragments.Patient.ChestIndrawing.POINT;
import static com.ug.air.alrite.Fragments.Patient.ChestIndrawing.POINT2;
-import static com.ug.air.alrite.Fragments.Patient.Cough.CHOICE2;
+import static com.ug.air.alrite.Fragments.Patient.Cough.DIFFICULTY_BREATHING;
import static com.ug.air.alrite.Fragments.Patient.CoughD.DAY1;
-import static com.ug.air.alrite.Fragments.Patient.Sex.AGE;
-import static com.ug.air.alrite.Fragments.Patient.Wheezing.CHOICE8;
+import static com.ug.air.alrite.Fragments.Patient.Sex.AGE_IN_MONTHS;
import static com.ug.air.alrite.Fragments.Patient.Wheezing.CHOICE82;
import android.app.Dialog;
@@ -65,7 +64,7 @@ public class Bronchodilator3 extends Fragment {
private static final int YES = 0;
private static final int NO = 1;
private static final int NOT = 2;
- public static final String BRONC = "after_bronchodilator";
+ public static final String AFTER_BRONCHODILATOR = "after_bronchodilator";
public static final String FINAL = "final";
public static final String B3DIAGNOSIS = "diagnosis_9";
public static final String SHARED_PREFS = "sharedPrefs";
@@ -135,10 +134,10 @@ public void onClick(View v) {
}
private void saveData() {
- editor.putString(BRONC, value9);
+ editor.putString(AFTER_BRONCHODILATOR, value9);
editor.apply();
- String cough = sharedPreferences.getString(CHOICE2, "");
+ String cough = sharedPreferences.getString(DIFFICULTY_BREATHING, "");
String wheezing = sharedPreferences.getString(CHOICE82, "");
String days = sharedPreferences.getString(DAY1, "");
String point1 = sharedPreferences.getString(POINT, "");
@@ -221,7 +220,7 @@ private void showDialog(int value) {
}else if (value == 3){
linearLayout_instruction.setBackgroundColor(getResources().getColor(R.color.mildDiagnosisColor));
txtDiagnosis.setText(R.string.wheez_ill);
- String age = sharedPreferences.getString(AGE, "");
+ String age = sharedPreferences.getString(AGE_IN_MONTHS, "");
float ag = Float.parseFloat(age);
if (ag < 2){
messages = Arrays.asList(R.string.wheez_ill1, R.string.wheez_ill2, R.string.wheez_ill3,
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/ChestIndrawing.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/ChestIndrawing.java
index e7a35f7..8521628 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/ChestIndrawing.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/ChestIndrawing.java
@@ -1,26 +1,19 @@
package com.ug.air.alrite.Fragments.Patient;
import static com.ug.air.alrite.Activities.SplashActivity.CHESTINDRWAING_COUNT;
-import static com.ug.air.alrite.Activities.SplashActivity.STRIDOR_COUNT;
-import static com.ug.air.alrite.Activities.SplashActivity.WHEEZING_COUNT;
import static com.ug.air.alrite.Fragments.Patient.Assess.DIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.Assess.FINAL_DIAGNOSIS;
-import static com.ug.air.alrite.Fragments.Patient.Assess.S4;
-import static com.ug.air.alrite.Fragments.Patient.Cough.CHOICE2;
+import static com.ug.air.alrite.Fragments.Patient.Assess.SEVERE_SYMPTOMS;
+import static com.ug.air.alrite.Fragments.Patient.Cough.DIFFICULTY_BREATHING;
import static com.ug.air.alrite.Fragments.Patient.HIVStatus.HDIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.Nasal.CHOICEGN;
import static com.ug.air.alrite.Fragments.Patient.Nasal.GNDIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.Oxygen.OXDIAGNOSIS;
-import static com.ug.air.alrite.Fragments.Patient.RRCounter.RATE;
-import static com.ug.air.alrite.Fragments.Patient.RRCounter.RATE2;
import static com.ug.air.alrite.Fragments.Patient.RRCounter.SECOND;
-import static com.ug.air.alrite.Fragments.Patient.Sex.AGE;
-import static com.ug.air.alrite.Fragments.Patient.Sex.KILO;
import static com.ug.air.alrite.Fragments.Patient.Stridor.STDIAGNOSIS;
-import static com.ug.air.alrite.Fragments.Patient.Wheezing.CHOICE8;
+import static com.ug.air.alrite.Fragments.Patient.Wheezing.WHEEZING_SOUNDS;
import static com.ug.air.alrite.Fragments.Patient.CoughD.DAY1;
import static com.ug.air.alrite.Fragments.Patient.RRCounter.FASTBREATHING;
-import static com.ug.air.alrite.Fragments.Patient.Wheezing.CHOICE82;
import android.app.Dialog;
import android.content.Context;
@@ -32,11 +25,9 @@
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
-import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -59,8 +50,6 @@
import com.ug.air.alrite.Utils.Counter;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
public class ChestIndrawing extends Fragment {
@@ -154,7 +143,7 @@ public void onClick(View v) {
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- String assess = sharedPreferences.getString(S4, "");
+ String assess = sharedPreferences.getString(SEVERE_SYMPTOMS, "");
FragmentTransaction fr = requireActivity().getSupportFragmentManager().beginTransaction();
if (second.isEmpty()){
@@ -187,7 +176,7 @@ private void saveData() {
if (second.isEmpty()){
editor.putString(CHOICE7, value8);
editor.apply();
- String assess = sharedPreferences.getString(S4, "");
+ String assess = sharedPreferences.getString(SEVERE_SYMPTOMS, "");
if (!assess.equals("None of these")){
startActivity(new Intent(getActivity(), DiagnosisActivity.class));
@@ -277,7 +266,7 @@ public void onClick(View v) {
}
private void makeAssessment(){
- String cough = sharedPreferences.getString(CHOICE2, "");
+ String cough = sharedPreferences.getString(DIFFICULTY_BREATHING, "");
String fDiagnosis = sharedPreferences.getString(DIAGNOSIS, "");
String oxDiagnosis = sharedPreferences.getString(OXDIAGNOSIS, "");
String stDiagnosis = sharedPreferences.getString(STDIAGNOSIS, "");
@@ -285,7 +274,7 @@ private void makeAssessment(){
String hDiagnosis = sharedPreferences.getString(HDIAGNOSIS, "");
String oneDiagnosis = sharedPreferences.getString(FINAL_DIAGNOSIS, "");
fastBreathing = sharedPreferences.getString(FASTBREATHING, "");
- wheezing = sharedPreferences.getString(CHOICE8, "");
+ wheezing = sharedPreferences.getString(WHEEZING_SOUNDS, "");
String days = sharedPreferences.getString(DAY1, "");
day = Long.parseLong(days);
boolean cx = oneDiagnosis.isEmpty() && hDiagnosis.isEmpty();
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Cough.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Cough.java
index 1c5b90a..aaa54ee 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Cough.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Cough.java
@@ -1,9 +1,7 @@
package com.ug.air.alrite.Fragments.Patient;
-import static com.ug.air.alrite.Fragments.Patient.Assess.DATE;
-import static com.ug.air.alrite.Fragments.Patient.Assess.DIAGNOSIS;
import static com.ug.air.alrite.Fragments.Patient.Assess.FINAL_DIAGNOSIS;
-import static com.ug.air.alrite.Fragments.Patient.Assess.S4;
+import static com.ug.air.alrite.Fragments.Patient.Assess.SEVERE_SYMPTOMS;
import android.app.Dialog;
import android.content.Context;
@@ -29,21 +27,14 @@
import android.widget.TextView;
import android.widget.Toast;
-import com.ug.air.alrite.Activities.Dashboard;
import com.ug.air.alrite.Activities.DiagnosisActivity;
import com.ug.air.alrite.Adapters.AssessmentAdapter;
import com.ug.air.alrite.Models.Assessment;
import com.ug.air.alrite.R;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.UUID;
public class Cough extends Fragment {
@@ -55,7 +46,7 @@ public class Cough extends Fragment {
String value3 = "none";
private static final int YES = 0;
private static final int NO = 1;
- public static final String CHOICE2 = "difficulty_breathing";
+ public static final String DIFFICULTY_BREATHING = "difficulty_breathing";
public static final String NODIAGNOSIS = "diagnosis_3";
public static final String SHARED_PREFS = "sharedPrefs";
Dialog dialog;
@@ -130,7 +121,7 @@ public void onClick(View v) {
}
private void saveData() {
- editor.putString(CHOICE2, value3);
+ editor.putString(DIFFICULTY_BREATHING, value3);
editor.apply();
if (value3.equals("No")){
@@ -139,7 +130,7 @@ private void saveData() {
editor.remove(NODIAGNOSIS);
editor.apply();
}
- String assess = sharedPreferences.getString(S4, "");
+ String assess = sharedPreferences.getString(SEVERE_SYMPTOMS, "");
if (!assess.equals("None of these")){
startActivity(new Intent(getActivity(), DiagnosisActivity.class));
}else {
@@ -157,7 +148,7 @@ private void saveData() {
private void loadData() {
SharedPreferences sharedPreferences = this.getActivity().getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);
- value3 = sharedPreferences.getString(CHOICE2, "");
+ value3 = sharedPreferences.getString(DIFFICULTY_BREATHING, "");
}
private void updateViews() {
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/CoughD.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/CoughD.java
index 4fc7278..56b0ed9 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/CoughD.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/CoughD.java
@@ -1,50 +1,27 @@
package com.ug.air.alrite.Fragments.Patient;
-import static com.ug.air.alrite.Fragments.Patient.Assess.DATE;
-import static com.ug.air.alrite.Fragments.Patient.Assess.DIAGNOSIS;
-import static com.ug.air.alrite.Fragments.Patient.Assess.S4;
+import static com.ug.air.alrite.Fragments.Patient.Assess.SEVERE_SYMPTOMS;
import android.app.Dialog;
import android.content.Context;
-import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
-import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
-import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.view.Window;
-import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
-import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
-import com.ug.air.alrite.Activities.Dashboard;
-import com.ug.air.alrite.Adapters.AssessmentAdapter;
-import com.ug.air.alrite.Models.Assessment;
import com.ug.air.alrite.R;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Objects;
-import java.util.UUID;
-
public class CoughD extends Fragment {
@@ -137,7 +114,7 @@ private void saveData() {
int dt = Integer.parseInt(day1);
- String assess = sharedPreferences.getString(S4, "");
+ String assess = sharedPreferences.getString(SEVERE_SYMPTOMS, "");
if (!assess.equals("None of these")){
FragmentTransaction fr = requireActivity().getSupportFragmentManager().beginTransaction();
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/FTouch.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/FTouch.java
index b2347b8..ebe2b18 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/FTouch.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/FTouch.java
@@ -1,12 +1,11 @@
package com.ug.air.alrite.Fragments.Patient;
-import static com.ug.air.alrite.Fragments.Patient.Assess.S4;
-import static com.ug.air.alrite.Fragments.Patient.Sex.AGE;
+import static com.ug.air.alrite.Fragments.Patient.Assess.SEVERE_SYMPTOMS;
+import static com.ug.air.alrite.Fragments.Patient.Sex.AGE_IN_MONTHS;
import static com.ug.air.alrite.Fragments.Patient.Sex.KILO;
import android.app.Dialog;
import android.content.Context;
-import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
@@ -28,16 +27,13 @@
import android.widget.TextView;
import android.widget.Toast;
-import com.ug.air.alrite.Activities.DiagnosisActivity;
import com.ug.air.alrite.Adapters.AssessmentAdapter;
import com.ug.air.alrite.Models.Assessment;
import com.ug.air.alrite.R;
import com.ug.air.alrite.Utils.Calculations.Instructions;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
-import java.util.Objects;
public class FTouch extends Fragment {
@@ -129,7 +125,7 @@ private void saveData() {
editor.putString(TOUCH, value6);
editor.apply();
- String assess = sharedPreferences.getString(S4, "");
+ String assess = sharedPreferences.getString(SEVERE_SYMPTOMS, "");
if (value6.equals("Yes") && !assess.equals("None of these")){
showDialog();
}else {
@@ -183,7 +179,7 @@ private void showDialog() {
assessments = new ArrayList<>();
assessmentAdapter = new AssessmentAdapter(assessments);
- String age = sharedPreferences.getString(AGE, "");
+ String age = sharedPreferences.getString(AGE_IN_MONTHS, "");
String weight = sharedPreferences.getString(KILO, "");
int ag = Integer.parseInt(age);
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Fever.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Fever.java
index 600d7ab..6b9f0b2 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Fever.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Fever.java
@@ -1,6 +1,6 @@
package com.ug.air.alrite.Fragments.Patient;
-import static com.ug.air.alrite.Fragments.Patient.Assess.S4;
+import static com.ug.air.alrite.Fragments.Patient.Assess.SEVERE_SYMPTOMS;
import static com.ug.air.alrite.Fragments.Patient.HIVCare.CHOICEHC;
import android.content.Context;
@@ -20,8 +20,6 @@
import com.ug.air.alrite.R;
-import java.util.Objects;
-
public class Fever extends Fragment {
@@ -90,7 +88,7 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
- String assess = sharedPreferences.getString(S4, "");
+ String assess = sharedPreferences.getString(SEVERE_SYMPTOMS, "");
String care = sharedPreferences.getString(CHOICEHC, "");
FragmentTransaction fr = requireActivity().getSupportFragmentManager().beginTransaction();
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Initials.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Initials.java
index 989aae2..5bdd11e 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Initials.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Initials.java
@@ -18,28 +18,24 @@
import android.widget.Toast;
import com.ug.air.alrite.Activities.Dashboard;
-import com.ug.air.alrite.BuildConfig;
-import com.ug.air.alrite.Database.DatabaseHelper;
import com.ug.air.alrite.R;
import com.ug.air.alrite.Utils.Credentials;
-import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
-import java.util.Objects;
public class Initials extends Fragment {
View view;
- EditText etCin, etPin, etStudy, etCode;
+ EditText etChildInitials, etParentInitials, etStudy, etCode;
Button back, next;
- String cin, pin, formattedDate, studyId, code, h_code, counter, filename;
- public static final String CIN = "patient_initials";
+ String childInitials, parentInitials, formattedDate, studyId, code, h_code, counter, filename;
+ public static final String CHILD_INITIALS = "patient_initials";
public static final String VERSION = "app_version";
- public static final String PIN = "parent_initials";
+ public static final String PARENT_INITIALS = "parent_initials";
public static final String STUDY_ID = "study_id";
public static final String STUDY_ID_2 = "study_id_2";
public static final String INITIAL_DATE = "start_date";
@@ -54,14 +50,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_initials, container, false);
- etCin = view.findViewById(R.id.cin);
+ etChildInitials = view.findViewById(R.id.cin);
etCode = view.findViewById(R.id.code);
etStudy = view.findViewById(R.id.studyId);
- etPin = view.findViewById(R.id.pin);
+ etParentInitials = view.findViewById(R.id.pin);
next = view.findViewById(R.id.next);
back = view.findViewById(R.id.back);
Intent intent = getActivity().getIntent();
+ // If ____, then we can combine the data for
+ // Otherwise, just get the current activity's shared preferences
if (intent.hasExtra("filename")) {
filename = intent.getExtras().getString("filename");
sharedPreferences1 = requireActivity().getSharedPreferences(filename, Context.MODE_PRIVATE);
@@ -79,20 +77,26 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
sharedPreferences = requireActivity().getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);
}
+ // Get an editor for the shared preferences
editor = sharedPreferences.edit();
+ // Get the parent's initials and the child's initials and store them in
+ // the fragment, if they exist: otherwise ""
loadData();
+
+ // Get the credentials for the current user, and set the current variables
+ // to those values
updateViews();
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- cin = etCin.getText().toString();
- pin = etPin.getText().toString();
+ childInitials = etChildInitials.getText().toString();
+ parentInitials = etParentInitials.getText().toString();
studyId = etStudy.getText().toString();
- if (cin.isEmpty() || pin.isEmpty() || studyId.equals("0") || studyId.isEmpty()){
+ if (childInitials.isEmpty() || parentInitials.isEmpty() || studyId.equals("0") || studyId.isEmpty()){
Toast.makeText(getActivity(), "Please fill in all the fields", Toast.LENGTH_SHORT).show();
}else {
saveData();
@@ -114,8 +118,8 @@ private void saveData() {
String new_study = etCode.getText().toString();
new_study = new_study + "_" + studyId;
- editor.putString(CIN, cin);
- editor.putString(PIN, pin);
+ editor.putString(CHILD_INITIALS, childInitials);
+ editor.putString(PARENT_INITIALS, parentInitials);
editor.putString(VERSION, "2");
editor.putString(STUDY_ID_2, studyId);
editor.putString(STUDY_ID, new_study);
@@ -147,15 +151,15 @@ private void saveData() {
}
private void loadData() {
- pin = sharedPreferences.getString(PIN, "");
- cin = sharedPreferences.getString(CIN, "");
+ parentInitials = sharedPreferences.getString(PARENT_INITIALS, "");
+ childInitials = sharedPreferences.getString(CHILD_INITIALS, "");
studyId = sharedPreferences.getString(STUDY_ID_2, "");
formattedDate = sharedPreferences.getString(INITIAL_DATE, "");
}
private void updateViews() {
- etPin.setText(pin);
- etCin.setText(cin);
+ etParentInitials.setText(parentInitials);
+ etChildInitials.setText(childInitials);
Credentials credentials = new Credentials();
credentials.creds2(getActivity());
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/InitialsModified.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/InitialsModified.java
new file mode 100644
index 0000000..2cfe3a6
--- /dev/null
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/InitialsModified.java
@@ -0,0 +1,160 @@
+package com.ug.air.alrite.Fragments.Patient;
+
+import static com.ug.air.alrite.Fragments.Patient.RRCounter.SECOND;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Toast;
+
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentTransaction;
+
+import com.ug.air.alrite.Activities.Dashboard;
+import com.ug.air.alrite.R;
+import com.ug.air.alrite.Utils.Credentials;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Map;
+
+public class InitialsModified extends Fragment {
+
+ View view;
+ EditText etChildInitials, etParentInitials, etStudy, etCode;
+ Button back, next;
+ String childInitials, parentInitials, formattedDate, studyId, code, h_code, counter, filename;
+ public static final String CHILD_INITIALS = "Patient Initials";
+ public static final String VERSION = "app_version";
+ public static final String PARENT_INITIALS = "Parent Initials";
+ public static final String STUDY_ID = "study_id";
+ public static final String STUDY_ID_2 = "study_id_2";
+ public static final String INITIAL_DATE = "start_date";
+ public static final String SHARED_PREFS = "sharedPrefs";
+ SharedPreferences sharedPreferences, sharedPreferences1;
+ SharedPreferences.Editor editor;
+
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ view = inflater.inflate(R.layout.fragment_initials, container, false);
+
+ etChildInitials = view.findViewById(R.id.cin);
+ etCode = view.findViewById(R.id.code);
+ etStudy = view.findViewById(R.id.studyId);
+ etParentInitials = view.findViewById(R.id.pin);
+ next = view.findViewById(R.id.next);
+ back = view.findViewById(R.id.back);
+
+ Intent intent = getActivity().getIntent();
+ sharedPreferences = requireActivity().getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);
+ editor = sharedPreferences.edit();
+
+ // Get the parent's initials and the child's initials and store them in
+ // the fragment, if they exist: otherwise ""
+ loadData();
+
+ // Get the credentials for the current user, and set the current variables
+ // to those values
+ updateViews();
+
+ next.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+
+ childInitials = etChildInitials.getText().toString();
+ parentInitials = etParentInitials.getText().toString();
+ studyId = etStudy.getText().toString();
+
+ if (childInitials.isEmpty() || parentInitials.isEmpty() || studyId.equals("0") || studyId.isEmpty()){
+ Toast.makeText(getActivity(), "Please fill in all the fields", Toast.LENGTH_SHORT).show();
+ }else {
+ saveData();
+ }
+ }
+ });
+
+ back.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ startActivity(new Intent(getActivity(), Dashboard.class));
+ }
+ });
+
+ return view;
+ }
+
+ private void saveData() {
+
+ String new_study = etCode.getText().toString();
+ new_study = new_study + "_" + studyId;
+ editor.putString(CHILD_INITIALS, childInitials);
+ editor.putString(PARENT_INITIALS, parentInitials);
+ editor.putString(VERSION, "2");
+ editor.putString(STUDY_ID_2, studyId);
+ editor.putString(STUDY_ID, new_study);
+ if (formattedDate.isEmpty()){
+ Date currentTime = Calendar.getInstance().getTime();
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss", Locale.getDefault());
+ String formattedDate = df.format(currentTime);
+
+ editor.putString(INITIAL_DATE, formattedDate);
+ }
+ editor.apply();
+
+ int count = Integer.valueOf(counter);
+ int count2 = Integer.valueOf(studyId);
+
+// Toast.makeText(getActivity(), count + " " + count2, Toast.LENGTH_SHORT).show();
+
+ if (count == count2){
+ count = count+1;
+ String ct = String.valueOf(count);
+ Credentials credentials = new Credentials();
+ credentials.counting(getActivity(), ct);
+ }
+
+ FragmentTransaction fr = requireActivity().getSupportFragmentManager().beginTransaction();
+ fr.replace(R.id.fragment_container, new SexModified());
+ fr.addToBackStack(null);
+ fr.commit();
+ }
+
+ private void loadData() {
+ parentInitials = sharedPreferences.getString(PARENT_INITIALS, "");
+ childInitials = sharedPreferences.getString(CHILD_INITIALS, "");
+ studyId = sharedPreferences.getString(STUDY_ID_2, "");
+ formattedDate = sharedPreferences.getString(INITIAL_DATE, "");
+ }
+
+ private void updateViews() {
+ etParentInitials.setText(parentInitials);
+ etChildInitials.setText(childInitials);
+
+ Credentials credentials = new Credentials();
+ credentials.creds2(getActivity());
+ code = credentials.creds2(getActivity()).getCode();
+ h_code = credentials.creds2(getActivity()).getH_code();
+ counter = credentials.creds2(getActivity()).getCounter();
+ etCode.setText("AL"+h_code + "" + code);
+ etCode.setEnabled(false);
+
+ if (studyId.isEmpty()){
+ etStudy.setText(counter);
+ }else{
+ etStudy.setText(studyId);
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/MultipleChoiceFragment.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/MultipleChoiceFragment.java
new file mode 100644
index 0000000..b384ee7
--- /dev/null
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/MultipleChoiceFragment.java
@@ -0,0 +1,209 @@
+package com.ug.air.alrite.Fragments.Patient;
+
+import static com.ug.air.alrite.Activities.PatientActivity.SUMMARY_ID;
+import static com.ug.air.alrite.Activities.PatientActivity.VALUE_ID;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.fragment.app.Fragment;
+
+import com.ug.air.alrite.Activities.PatientActivity;
+import com.ug.air.alrite.R;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+
+public class MultipleChoiceFragment extends Fragment {
+
+ public interface onGetResultListener {
+ void getResultFromMultipleChoiceFragment(int choiceIndex) throws JSONException;
+ void getLastPage() throws JSONException;
+ }
+ onGetResultListener getResultListener;
+
+ public static final String SHARED_PREFS = "sharedPrefs";
+ public static final String QUESTION = "question";
+ public static final String CHOICES = "choices";
+ public static final String VALUE_ID = "valueID";
+ public static final String DEFAULT = "**default string**";
+ String previousResponse;
+ String question;
+ ArrayList choices;
+ String valueID;
+ String summaryPrefsID;
+ View view;
+ RadioGroup choiceGroup;
+ ArrayList choiceButtonList;
+ Button backButton, nextButton;
+ SharedPreferences sharedPreferences;
+ SharedPreferences.Editor editor;
+
+ /**
+ * This is where we do what we usually do in the onAttach section, except that
+ * we also add a listener for sending the result of the Multiple Choice up to
+ * the activity
+ *
+ * @param activity the PatientActivity that we're running this fragment on
+ */
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ try {
+ getResultListener = (onGetResultListener) activity;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(activity.toString() + " must implement onSomeEventListener");
+ }
+ }
+
+ /**
+ * This creates a new MultipleChoiceFragment with a separate constructor, so
+ * that we can retain the given information and return the fragment
+ *
+ * @param question the question at the top of the page
+ * @param choices the given choices for the user to choose from
+ * @return the fragment to be used in the future
+ */
+ public static MultipleChoiceFragment newInstance(String question, ArrayList choices, String valueID, String summaryPrefsID) throws JSONException {
+ MultipleChoiceFragment mfc = new MultipleChoiceFragment();
+ Bundle args = new Bundle();
+ args.putString(QUESTION, question);
+ ArrayList text_choices = getTextFromChoices(choices);
+ args.putStringArrayList(CHOICES, text_choices);
+ args.putString(VALUE_ID, valueID);
+ args.putString(SUMMARY_ID, summaryPrefsID);
+ mfc.setArguments(args);
+ return mfc;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Idk exactly what this does right now, but it sets up the view and the stored information
+ view = inflater.inflate(R.layout.multiple_choice, container, false);
+ sharedPreferences = requireActivity().getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);
+ editor = sharedPreferences.edit();
+
+ // Retrieve the information for the question/choices of the page
+ assert getArguments() != null;
+ question = getArguments().getString(QUESTION);
+ choices = getArguments().getStringArrayList(CHOICES);
+ valueID = getArguments().getString(VALUE_ID);
+ summaryPrefsID = getArguments().getString(SUMMARY_ID);
+
+ // Then, set the information for each question/choice to line up with our givens
+ TextView questionDisplay = view.findViewById(R.id.mc_question);
+ questionDisplay.setText(question);
+
+ // Create the RadioGroup and RadioButtons that will be displayed on the page
+ // within the given multiple_choice_layout on the layout for the fragment
+ LinearLayout multipleChoiceLayout = view.findViewById(R.id.multiple_choice_layout);
+ choiceGroup = new RadioGroup(this.getContext());
+ multipleChoiceLayout.addView(choiceGroup);
+ choiceButtonList = new ArrayList<>();
+ for (String choiceText : choices) {
+ RadioButton but = new RadioButton(this.getContext());
+ choiceGroup.addView(but);
+ but.setText(choiceText);
+ choiceButtonList.add(but);
+ }
+
+ // All of the buttons/things that we'll need to reference
+ nextButton = view.findViewById(R.id.next);
+ backButton = view.findViewById(R.id.back);
+
+ // If we've already seen this page, reload our past choices
+ // loadSelectedChoiceIfAlreadySelected();
+
+ // This is a listener for, if the next button is pressed, whether we can go
+ // on or not, and what information should be sent up
+ nextButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // First, we check that at least one option was selected
+ // if not, then we create a popup which tells the user to select at
+ // least one option
+ int chosenOption = choiceGroup.getCheckedRadioButtonId();
+ if (chosenOption == -1) {
+ Toast.makeText(getActivity(), "Please select at least one of the options", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ // Get the index of the choice in the set of buttons, starting at index 0
+ for (int i = 0; i < choiceButtonList.size(); i++) {
+ RadioButton choiceButton = choiceButtonList.get(i);
+ if (choiceButton.getId() == chosenOption) {
+ // Send the result back up to main: a listener there will trigger
+ // and start the next fragment sequence up
+ try {
+ getResultListener.getResultFromMultipleChoiceFragment(i);
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+ return;
+ }
+ }
+ }
+ });
+
+ backButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ try {
+ getResultListener.getLastPage();
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+
+ return view;
+ }
+
+ /**
+ * In the case that we're creating this view again after we've already stepped
+ * through this option, pre-select the choice that we already made, so that we
+ * don't get inconsistent answers from this
+ */
+ private void loadSelectedChoiceIfAlreadySelected() {
+ SharedPreferences sharedPreferences =
+ this.getActivity().getSharedPreferences(summaryPrefsID, Context.MODE_PRIVATE);
+ previousResponse = sharedPreferences.getString(valueID, DEFAULT);
+
+ for (int i = 0; i < choices.size(); i++) {
+ if (previousResponse.equals(choices.get(i))) {
+ ((RadioButton) choiceGroup.getChildAt(i)).setChecked(true);
+ return;
+ }
+ }
+ }
+
+ /**
+ * This is used specifically for newInstance, and relies on the JSON being set
+ * up as in the "example.json" file. This will extract all of the text answers
+ * from the given choices list.
+ *
+ * @param list is an ArrayList of JSONObjects (choices)
+ * @return the list of strings of text for each choice, in order
+ */
+ private static ArrayList getTextFromChoices(ArrayList list) throws JSONException {
+ ArrayList ret = new ArrayList<>();
+ for (int i = 0; i < list.size(); i++) {
+ ret.add(list.get(i).getString(PatientActivity.TEXT));
+ }
+ return ret;
+ }
+}
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/MultipleSelectionFragment.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/MultipleSelectionFragment.java
new file mode 100644
index 0000000..88c916e
--- /dev/null
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/MultipleSelectionFragment.java
@@ -0,0 +1,209 @@
+package com.ug.air.alrite.Fragments.Patient;
+
+import static com.ug.air.alrite.Activities.PatientActivity.SUMMARY_ID;
+import static com.ug.air.alrite.Activities.PatientActivity.VALUE_ID;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.LinearLayout;
+import android.widget.RadioButton;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.fragment.app.Fragment;
+
+import com.ug.air.alrite.Activities.PatientActivity;
+import com.ug.air.alrite.R;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+
+public class MultipleSelectionFragment extends Fragment {
+
+ public interface onGetResultListener {
+ void getResultFromMultipleSelectionFragment(ArrayList chosenOptions) throws JSONException;
+ void getLastPage() throws JSONException;
+ }
+ onGetResultListener getResultListener;
+
+ public static final String SHARED_PREFS = "sharedPrefs";
+ public static final String QUESTION = "question";
+ public static final String CHOICES = "choices";
+ public static final String DEFAULT = "**default string**";
+ public static final String VALUE_ID = "valueID";
+ String valueID;
+ String summaryPrefsID;
+ String previousResponse;
+ String question;
+ ArrayList choices; // list of the texts of the checkboxes
+ ArrayList choiceGroup; // list of checkboxes
+ View view;
+ Button backButton, nextButton;
+ SharedPreferences sharedPreferences;
+ SharedPreferences.Editor editor;
+
+ /**
+ * This is where we do what we usually do in the onAttach section, except that
+ * we also add a listener for sending the result of the Multiple Choice up to
+ * the activity
+ *
+ * @param activity the PatientActivity that we're running this fragment on
+ */
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ try {
+ getResultListener = (onGetResultListener) activity;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(activity.toString() + " must implement onSomeEventListener");
+ }
+ }
+
+ /**
+ * This creates a new MultipleSelectionFragment with a separate constructor, so
+ * that we can retain the given information and return the fragment
+ *
+ * @param question the question at the top of the page
+ * @param choices the given choices for the user to choose from
+ * @return the fragment to be used in the future
+ */
+ public static MultipleSelectionFragment newInstance(String question, ArrayList choices, String valueID, String summaryPrefsID) throws JSONException {
+ MultipleSelectionFragment msc = new MultipleSelectionFragment();
+ Bundle args = new Bundle();
+ args.putString(QUESTION, question);
+ ArrayList text_choices = getTextFromChoices(choices);
+ args.putStringArrayList(CHOICES, text_choices);
+ args.putString(VALUE_ID, valueID);
+ args.putString(SUMMARY_ID, summaryPrefsID);
+ msc.setArguments(args);
+ return msc;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ view = inflater.inflate(R.layout.multiple_select, container, false);
+ sharedPreferences = requireActivity().getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);
+ editor = sharedPreferences.edit();
+
+ // Retrieve the information for the question/choices of the page
+ assert getArguments() != null;
+ question = getArguments().getString(QUESTION);
+ choices = getArguments().getStringArrayList(CHOICES); // list of strings
+ valueID = getArguments().getString(VALUE_ID);
+ summaryPrefsID = getArguments().getString(SUMMARY_ID);
+
+ // Then, set the information for each question/choice to line up with our givens
+ TextView questionDisplay = view.findViewById(R.id.mc_question);
+ questionDisplay.setText(question);
+
+ // create buttons in here, and then choose their ids more easily
+ // Currently storing 5 checkboxes will update later
+ // might add more or create optimized loop
+
+ LinearLayout multipleSelectLayout = view.findViewById(R.id.multiple_select_layout);
+
+ choiceGroup = new ArrayList<>();
+ for (String choiceText : choices) {
+ CheckBox c = new CheckBox(this.getContext());
+ multipleSelectLayout.addView(c); //?
+ c.setText(choiceText);
+ choiceGroup.add(c);
+ }
+
+
+ // All of the buttons/things that we'll need to reference
+ nextButton = view.findViewById(R.id.next);
+ backButton = view.findViewById(R.id.back);
+
+ // If we've already seen this page, reload our past choices
+ loadSelectedChoicesIfAlreadySelected();
+
+ // This is a listener for, if the next button is pressed, whether we can go
+ // on or not, and what information should be sent up
+ nextButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // we need to see which choices are selected
+ // store the indices and the result back up to main:
+ // a listener there will trigger and start the next fragment sequence up
+ ArrayList chosenOptionIds = new ArrayList<>();
+ for (int i = 0; i < choiceGroup.size(); i++) {
+ if (choiceGroup.get(i).isChecked()) {
+ // get the index of this choice
+ chosenOptionIds.add(i+1);
+ }
+ }
+
+ try {
+ getResultListener.getResultFromMultipleSelectionFragment(chosenOptionIds);
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+ return;
+ }
+ });
+
+ backButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ try {
+ getResultListener.getLastPage();
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+
+ return view;
+ }
+
+
+ /**
+ * In the case that we're creating this view again after we've already stepped
+ * through this option, pre-select the choice that we already made, so that we
+ * don't get inconsistent answers from this.
+ */
+ private void loadSelectedChoicesIfAlreadySelected() {
+ SharedPreferences sharedPreferences = this.getActivity().getSharedPreferences(summaryPrefsID, Context.MODE_PRIVATE);
+ previousResponse = sharedPreferences.getString(valueID, DEFAULT);
+ String[] selectedOptionsHistory = previousResponse.split("\n"); // split by \n
+
+
+ for (int i = 0; i < choices.size(); i++) {
+ for (String temp : selectedOptionsHistory) {
+ if (temp.equals(choices.get(i))) {
+ ((CheckBox) choiceGroup.get(i)).setChecked(true);
+ }
+ }
+ }
+
+ return;
+ }
+
+ /**
+ * This is used specifically for newInstance, and relies on the JSON being set
+ * up as in the "example.json" file. This will extract all of the text answers
+ * from the given choices list.
+ *
+ * @param list is an ArrayList of JSONObjects (choices)
+ * @return the list of strings of text for each choice, in order
+ */
+ private static ArrayList getTextFromChoices(ArrayList list) throws JSONException {
+ ArrayList ret = new ArrayList<>();
+ for (int i = 0; i < list.size(); i++) {
+ ret.add(list.get(i).getString(PatientActivity.TEXT));
+ }
+ return ret;
+ }
+}
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Nasal.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Nasal.java
index 5fa3397..a11b067 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Nasal.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/Nasal.java
@@ -2,10 +2,9 @@
import static com.ug.air.alrite.Activities.SplashActivity.GRANT_COUNT;
import static com.ug.air.alrite.Activities.SplashActivity.NASAL_COUNT;
-import static com.ug.air.alrite.Activities.SplashActivity.STRIDOR_COUNT;
import static com.ug.air.alrite.Fragments.Patient.Assess.FINAL_DIAGNOSIS;
-import static com.ug.air.alrite.Fragments.Patient.Assess.S4;
-import static com.ug.air.alrite.Fragments.Patient.Sex.AGE;
+import static com.ug.air.alrite.Fragments.Patient.Assess.SEVERE_SYMPTOMS;
+import static com.ug.air.alrite.Fragments.Patient.Sex.AGE_IN_MONTHS;
import static com.ug.air.alrite.Fragments.Patient.Sex.KILO;
import android.app.Dialog;
@@ -13,7 +12,6 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
-import android.net.Uri;
import android.os.Bundle;
import androidx.cardview.widget.CardView;
@@ -213,8 +211,8 @@ private void displayDialog() {
assessments = new ArrayList<>();
assessmentAdapter = new AssessmentAdapter(assessments);
- String age = sharedPreferences.getString(AGE, "");
- String s = sharedPreferences.getString(S4, "");
+ String age = sharedPreferences.getString(AGE_IN_MONTHS, "");
+ String s = sharedPreferences.getString(SEVERE_SYMPTOMS, "");
String weight = sharedPreferences.getString(KILO, "");
int ag = Integer.parseInt(age);
diff --git a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/OtherPatients.java b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/OtherPatients.java
index 5dd379f..fa94680 100644
--- a/app/src/main/java/com/ug/air/alrite/Fragments/Patient/OtherPatients.java
+++ b/app/src/main/java/com/ug/air/alrite/Fragments/Patient/OtherPatients.java
@@ -1,21 +1,22 @@
package com.ug.air.alrite.Fragments.Patient;
import static android.content.Context.MODE_PRIVATE;
-import static com.ug.air.alrite.Activities.DiagnosisActivity.PENDING;
-import static com.ug.air.alrite.Activities.PatientActivity.INCOMPLETE;
+import static com.ug.air.alrite.Activities.PatientActivity.NAME;
+import static com.ug.air.alrite.Activities.PatientActivity.VERSION;
import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.DATE;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator.BRONCHODILATOR;
-import static com.ug.air.alrite.Fragments.Patient.Bronchodilator3.BRONC;
-import static com.ug.air.alrite.Fragments.Patient.Initials.CIN;
-import static com.ug.air.alrite.Fragments.Patient.Initials.PIN;
-import static com.ug.air.alrite.Fragments.Patient.Initials.STUDY_ID;
-import static com.ug.air.alrite.Fragments.Patient.Sex.AGE2;
-import static com.ug.air.alrite.Fragments.Patient.Sex.CHOICE;
+import static com.ug.air.alrite.Fragments.Patient.InitialsModified.CHILD_INITIALS;
+import static com.ug.air.alrite.Fragments.Patient.InitialsModified.PARENT_INITIALS;
+import static com.ug.air.alrite.Fragments.Patient.SexModified.AGE_IN_YEARS;
+import static com.ug.air.alrite.Fragments.Patient.SexModified.SEX;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@@ -23,7 +24,7 @@
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
-import android.util.Log;
+import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -34,8 +35,8 @@
import android.widget.Toast;
import com.ug.air.alrite.APIs.ApiClient;
+import com.ug.air.alrite.APIs.BackendRequests;
import com.ug.air.alrite.APIs.JsonPlaceHolder;
-import com.ug.air.alrite.Activities.Dashboard;
import com.ug.air.alrite.Activities.DiagnosisActivity;
import com.ug.air.alrite.Activities.PatientActivity;
import com.ug.air.alrite.Adapters.PatientAdapter;
@@ -43,21 +44,38 @@
import com.ug.air.alrite.Database.DatabaseHelper;
import com.ug.air.alrite.Models.History;
import com.ug.air.alrite.Models.Item;
-import com.ug.air.alrite.Models.Patient;
import com.ug.air.alrite.R;
+import com.ug.air.alrite.Utils.BackendPostRequest;
import com.ug.air.alrite.Utils.Credentials;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.BufferedReader;
import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Array;
+import java.nio.file.Files;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Objects;
+import io.reactivex.Observable;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.Scheduler;
+import io.reactivex.functions.Consumer;
+import io.reactivex.functions.Function;
+import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
+import okhttp3.internal.concurrent.TaskRunner;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@@ -89,7 +107,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
view = inflater.inflate(R.layout.fragment_other_patients, container, false);
databaseHelper = new DatabaseHelper(getActivity());
- jsonPlaceHolder = ApiClient.getClient().create(JsonPlaceHolder.class);
+ jsonPlaceHolder = ApiClient.getClient(ApiClient.BASE_URL).create(JsonPlaceHolder.class);
recyclerView = view.findViewById(R.id.recyclerView3);
etSearch = view.findViewById(R.id.search);
@@ -124,13 +142,7 @@ public void onRefresh() {
public void onItemClick(int position) {
History history = (History) items.get(position).getObject();
String name = history.getFilename();
- String incomplete = history.getIncomplete();
- if (incomplete.equals("incomplete")){
- intent = new Intent(getActivity(), PatientActivity.class);
- intent.putExtra("Fragment", 1);
- }else {
- intent = new Intent(getActivity(), DiagnosisActivity.class);
- }
+ intent = new Intent(getActivity(), DiagnosisActivity.class);
intent.putExtra("filename", name);
startActivity(intent);
@@ -141,7 +153,17 @@ public void onItemClick(int position) {
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- submitData();
+ if (isNetworkAvailable()) {
+ try {
+ sendAllCompletedAssessmentDataToBackend();
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ Toast.makeText(getActivity(),
+ "Please connect to the internet before submitting.",
+ Toast.LENGTH_SHORT).show();
+ }
}
});
@@ -164,38 +186,36 @@ private void accessSharedFile2(){
}
Collections.reverse(files);
for(String name : files){
- if (!name.equals("sharedPrefs.xml") && !name.equals("counter_file.xml")){
+ if (!name.equals("sharedPrefs.xml") && !name.equals("counter_file.xml")
+ && name.endsWith("_Summary.xml")){
+
String names = name.replace(".xml", "");
SharedPreferences sharedPreferences = this.getActivity().getSharedPreferences(names, Context.MODE_PRIVATE);
- String bron = sharedPreferences.getString(BRONCHODILATOR, "");
- String incomplete = sharedPreferences.getString(INCOMPLETE, "");
- String pending = sharedPreferences.getString(PENDING, "");
- String fin = sharedPreferences.getString(BRONC, "");
- if (bron.isEmpty() || bron.equals("Bronchodialtor Not Given") || !fin.isEmpty()){
- cin = sharedPreferences.getString(CIN, "");
- pin = sharedPreferences.getString(PIN, "");
- age = sharedPreferences.getString(AGE2, "");
- gender = sharedPreferences.getString(CHOICE, "");
- dat = sharedPreferences.getString(DATE, "");
- if (age.isEmpty()){
- ag = "0 years 0 months";
- gender = "";
- }else {
- String[] split = age.split("\\.");
- ag = split[0] + " years and " + split[1] + " months";
- }
-
- try {
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
- Date date = df.parse(dat);
- SimpleDateFormat df1 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm");
- String formattedDate = df1.format(date);
- History history = new History("Age: " + ag, "Gender: " + gender, cin, "Parent/Guardian: " + pin, formattedDate, names, pending, incomplete);
- items.add(new Item(1, history));
- } catch (ParseException e) {
- e.printStackTrace();
- }
+ cin = sharedPreferences.getString(CHILD_INITIALS, "");
+ pin = sharedPreferences.getString(PARENT_INITIALS, "");
+ age = sharedPreferences.getString(AGE_IN_YEARS, "");
+ gender = sharedPreferences.getString(SEX, "");
+ dat = sharedPreferences.getString(DATE, "");
+
+ if (age.isEmpty()){
+ ag = "0 years 0 months";
+ gender = "";
+ }else {
+ String[] split = age.split("\\.");
+ ag = split[0] + " years and " + split[1] + " months";
}
+
+ try {
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
+ Date date = df.parse(dat);
+ SimpleDateFormat df1 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm");
+ String formattedDate = df1.format(date);
+ History history = new History("Age: " + ag, "Gender: " + gender, cin, "Parent/Guardian: " + pin, formattedDate, "fname", "no", "no");
+ items.add(new Item(1, history));
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
}
}
}else {
@@ -204,68 +224,178 @@ private void accessSharedFile2(){
}
}
- private void submitData() {
+ @SuppressLint("CheckResult")
+ private void sendAllCompletedAssessmentDataToBackend() throws JSONException {
+ // Stop user from doing anything to mess this up and show them a progress bar
progressBar.setVisibility(View.VISIBLE);
btnSubmit.setEnabled(false);
- Credentials credentials = new Credentials();
- Cursor res = databaseHelper.getData("1");
- while (res.moveToNext()){
- token = res.getString(2);
+
+ // Get the data with ID = 1 from the local user database, and get the token in that data
+ Cursor localUserData = databaseHelper.getData("1");
+ localUserData.moveToNext();
+ token = localUserData.getString(2);
+
+ // Get the folder of all current assessments that have not been sent to the backend
+ ArrayList assessmentsToBeSent = getValidAssessments();
+
+ // For every pair of patient info, turn them into proper JSONObjects and
+ // put them in the array to be sent to the backend
+ HashMap> requestToApipath = new HashMap<>();
+
+ // Create requests for each pair of patient info
+ for (int i = 0; i < assessmentsToBeSent.size(); i+=3) {
+ // Alphabetical order
+ String developerIDxml = assessmentsToBeSent.get(i);
+ String developerID = developerIDxml.substring(0, developerIDxml.length() - 4);
+ String diagnosesIDxml = assessmentsToBeSent.get(i+1);
+ String diagnosesID = diagnosesIDxml.substring(0, diagnosesIDxml.length() - 4);
+ String summaryIDxml = assessmentsToBeSent.get(i+2);
+ String summaryID = summaryIDxml.substring(0, summaryIDxml.length() - 4);
+ SharedPreferences developerPrefs = getContext().getSharedPreferences(developerID, MODE_PRIVATE);
+ SharedPreferences diagnosesPrefs = getContext().getSharedPreferences(diagnosesID, MODE_PRIVATE);
+ SharedPreferences summaryPrefs = getContext().getSharedPreferences(summaryID, MODE_PRIVATE);
+
+ // TODO: implement diagnoses stuff later
+ // diagnosesPrefs.edit().clear().apply();
+
+ // Get all items from the shared preferences object and create a request with them
+ Map summaryPrefItems = summaryPrefs.getAll();
+ HashMap summaryPrefMap = new HashMap<>();
+ for (String item : summaryPrefItems.keySet()) {
+ summaryPrefMap.put(item, summaryPrefItems.get(item));
+
+ }
+ // summaryPrefs.edit().clear().apply();
+
+ // Add all items from developer preferences into the summary preferences
+ String version = "";
+ String name = "";
+ Map developerPrefItems = developerPrefs.getAll();
+ for (String item : developerPrefItems.keySet()) {
+ if (item.equals(VERSION)) {
+ version = (String) developerPrefItems.get(item);
+ } else if (item.equals(NAME)) {
+ name = (String) developerPrefItems.get(item);
+ } else {
+ summaryPrefMap.put(item, developerPrefItems.get(item));
+ }
+ }
+
+ BackendPostRequest nextRequest = new BackendPostRequest(summaryPrefMap, "");
+ requestToApipath.put(nextRequest, new Pair<>(name, version));
}
- File src = new File("/data/data/" + BuildConfig.APPLICATION_ID + "/shared_prefs");
- if (src.exists()){
- contents = src.listFiles();
- if (contents.length != 0) {
- for (File f : contents) {
- if (f.isFile()) {
- String name = f.getName();
- if (!name.equals("sharedPrefs.xml") && !name.equals("counter_file.xml")) {
- String names = name.replace(".xml", "");
- SharedPreferences sharedPreferences = requireActivity().getSharedPreferences(names, MODE_PRIVATE);
- SharedPreferences.Editor editor = sharedPreferences.edit();
- String bron = sharedPreferences.getString(BRONCHODILATOR, "");
- String fin = sharedPreferences.getString(BRONC, "");
- String pending = sharedPreferences.getString(PENDING, "");
- String incomplete = sharedPreferences.getString(INCOMPLETE, "");
-
- if (!pending.equals("pending") && (bron.isEmpty() || bron.equals("Bronchodialtor Not Given") || !fin.isEmpty())){
- File patient = new File("/data/data/" + BuildConfig.APPLICATION_ID + "/shared_prefs/" + name);
- RequestBody filePart = RequestBody.create(MediaType.parse("*/*"), patient);
- MultipartBody.Part fileUpload = MultipartBody.Part.createFormData("patient", patient.getName() ,filePart);
-
- Call call = jsonPlaceHolder.sendFile("Token " + token, fileUpload);
- call.enqueue(new Callback() {
- @Override
- public void onResponse(Call call, Response response) {
- if (!response.isSuccessful()){
- Log.d("Alrite server issue", "There is an issue with the server" );
- return;
- }
- String message = response.body();
- Log.d("Alrite app: ", "Sever response: " + message);
- patient.delete();
- }
-
- @Override
- public void onFailure(Call call, Throwable t) {
- Log.d("Alrite server issue", "No internet connection" );
-// Toast.makeText(getActivity(), "Please turn on your internet connection", Toast.LENGTH_SHORT).show();
- }
- });
- }
+ System.out.println(requestToApipath);
- }
+ // We'll chunk all of the requests and send them to the backend: if there
+ // were any that didn't go through, we'll not delete the files so that the
+ // user can try again.
+ BackendRequests backendRequests = ApiClient.getClient(ApiClient.REMOTE_URL_TEMP)
+ .create(BackendRequests.class);
+ List> requests = new ArrayList<>();
+ for (BackendPostRequest currRequest : requestToApipath.keySet()) {
+ Pair workflowInfo = Objects.requireNonNull(requestToApipath.get(currRequest));
+ requests.add(backendRequests.postToBackend(workflowInfo.first, workflowInfo.second, currRequest));
+ }
+
+ Observable.zip(
+ requests,
+ (s -> s))
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribeOn(Schedulers.io())
+ .subscribe(
+ // Will be triggered if all requests will end successfully (4xx and 5xx also are successful requests too)
+ new Consumer