diff --git a/.idea/misc.xml b/.idea/misc.xml
index 27310f6..cf12a8b 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -27,17 +27,7 @@
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/app/src/main/java/com/project/mednudge/AddEditMedicine.java b/app/src/main/java/com/project/mednudge/AddEditMedicine.java
index 74ac07f..5a42e0e 100644
--- a/app/src/main/java/com/project/mednudge/AddEditMedicine.java
+++ b/app/src/main/java/com/project/mednudge/AddEditMedicine.java
@@ -1,7 +1,5 @@
package com.project.mednudge;
-import android.content.Context;
-import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
@@ -11,6 +9,15 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
+import android.widget.Spinner;
+import android.widget.Toast;
+
+import com.google.firebase.database.DatabaseReference;
+import com.google.firebase.database.FirebaseDatabase;
public class AddEditMedicine extends Fragment implements View.OnClickListener {
@@ -18,11 +25,20 @@ public class AddEditMedicine extends Fragment implements View.OnClickListener {
FragmentTransaction fragmentTransaction;
Fragment fragment;
Toolbar toolbar;
+ DatabaseReference mDatabase;
+ EditText editMedicineName;
+ EditText editPrescribedBy;
+ EditText editDose;
+ Spinner editUnit;
+ RadioGroup editInstruction;
+ RadioButton instruction1;
+ EditText editRemark;
+ View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
- View view=inflater.inflate(R.layout.fragment_add_edit_medicine, container, false);
+ view=inflater.inflate(R.layout.fragment_add_edit_medicine, container, false);
alarm=(Button) view.findViewById(R.id.button);
alarm.setOnClickListener(this);
toolbar=(Toolbar)view.findViewById(R.id.toolbar);
@@ -30,15 +46,46 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
activity.setSupportActionBar(toolbar);
activity.getSupportActionBar().setTitle("Add Medicine");
activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ mDatabase = FirebaseDatabase.getInstance().getReference("medicines");
+ editMedicineName=(EditText)view.findViewById(R.id.medicine_name);
+ editPrescribedBy=(EditText)view.findViewById(R.id.prescribed_by);
+ editDose=(EditText)view.findViewById(R.id.edit_dose);
+ editUnit=(Spinner)view.findViewById(R.id.select_unit);
+ editInstruction=(RadioGroup)view.findViewById(R.id.instruction);
+ editRemark=(EditText)view.findViewById(R.id.remark);
return view;
}
public void onClick(View v)
{
+ ImageView medicineImage=null;
+ String medicineName = editMedicineName.getText().toString().trim();
+ String prescribedBy = editPrescribedBy.getText().toString().trim();
+ String dose=editDose.getText().toString().trim()+" "+editUnit.getSelectedItem().toString();
+ int selectedId = editInstruction.getCheckedRadioButtonId();
+
+ // find the radiobutton by returned id
+ instruction1 = (RadioButton) view.findViewById(selectedId);
+ String instruction=(String)instruction1.getText();
+ String remark=editRemark.getText().toString().trim();
+
+
+
+// Creating new user node, which returns the unique key value
+// new user node would be /users/$userid/
+ String medicineId = mDatabase.push().getKey();
+
+// creating user object
+ Medicine medicine = new Medicine(medicineId,medicineImage,medicineName,prescribedBy,dose,instruction,remark);
+
+// pushing user to 'users' node using the userId
+ mDatabase.child(medicineId).setValue(medicine);
+ Toast.makeText(getContext(),"Medicine Added",Toast.LENGTH_SHORT);
fragmentTransaction = getFragmentManager().beginTransaction();
fragment = new Alarm();//the fragment you want to show
fragmentTransaction.replace(R.id.content_frame, fragment);//R.id.content_frame is the layout you want to replace
+ fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
diff --git a/app/src/main/java/com/project/mednudge/Login.java b/app/src/main/java/com/project/mednudge/Login.java
index 820795c..4c9865c 100644
--- a/app/src/main/java/com/project/mednudge/Login.java
+++ b/app/src/main/java/com/project/mednudge/Login.java
@@ -30,6 +30,7 @@ public void onClick(View v) {
fragmentTransaction = getFragmentManager().beginTransaction();
fragment = new DoctorPatientSignup();//the fragment you want to show
fragmentTransaction.replace(R.id.content_frame, fragment);//R.id.content_frame is the layout you want to replace
+ fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
@@ -46,11 +47,13 @@ public void onClick(View v)
case R.id.button2: fragmentTransaction = getFragmentManager().beginTransaction();
fragment = new DoctorProfile();//the fragment you want to show
fragmentTransaction.replace(R.id.content_frame, fragment);//R.id.content_frame is the layout you want to replace
+ fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
break;
case R.id.button3: fragmentTransaction = getFragmentManager().beginTransaction();
fragment = new PatientProfile();//the fragment you want to show
fragmentTransaction.replace(R.id.content_frame, fragment);//R.id.content_frame is the layout you want to replace
+ fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
break;
}
diff --git a/app/src/main/java/com/project/mednudge/MainActivity.java b/app/src/main/java/com/project/mednudge/MainActivity.java
index 1dcf107..6f4191b 100644
--- a/app/src/main/java/com/project/mednudge/MainActivity.java
+++ b/app/src/main/java/com/project/mednudge/MainActivity.java
@@ -21,7 +21,14 @@ protected void onCreate(Bundle savedInstanceState) {
public void onBackPressed()
{
- super.onBackPressed();
+ int count=getFragmentManager().getBackStackEntryCount();
+ if (count==0) {
+ super.onBackPressed();
+ }
+ else
+ {
+ getFragmentManager().popBackStack();
+ }
}
}
diff --git a/app/src/main/java/com/project/mednudge/Medicine.java b/app/src/main/java/com/project/mednudge/Medicine.java
new file mode 100644
index 0000000..ecd5a1a
--- /dev/null
+++ b/app/src/main/java/com/project/mednudge/Medicine.java
@@ -0,0 +1,59 @@
+package com.project.mednudge;
+
+import android.widget.ImageView;
+
+/**
+ * Created by MEGHA on 09-11-2017.
+ */
+
+public class Medicine {
+ ImageView medicineImage;
+ String medicineId;
+ String medicineName;
+ String doctorName;
+ String dose;
+ String instruction;
+ String remark;
+ public Medicine(){
+
+ }
+ public Medicine(String medicineId, ImageView medicineImage, String medicineName, String doctorName, String dose, String instruction, String remark)
+ {
+ this.medicineId=medicineId;
+ this.medicineImage=medicineImage;
+ this.medicineName=medicineName;
+ this.doctorName=doctorName;
+ this.dose=dose;
+ this.instruction=instruction;
+ this.remark=remark;
+ }
+ public String getMedicineId()
+ {
+ return medicineId;
+ }
+public ImageView getMedicineImage()
+{
+ return medicineImage;
+}
+public String getMedicineName()
+{
+ return medicineName;
+}
+public String getDoctorName()
+{
+ return doctorName;
+ }
+ public String getDose()
+ {
+ return dose;
+ }
+ public String getInstruction()
+ {
+ return instruction;
+ }
+ public String getRemark()
+ {
+ return remark;
+ }
+
+}
diff --git a/app/src/main/java/com/project/mednudge/PatientProfile.java b/app/src/main/java/com/project/mednudge/PatientProfile.java
index 771b6ec..6e9c286 100644
--- a/app/src/main/java/com/project/mednudge/PatientProfile.java
+++ b/app/src/main/java/com/project/mednudge/PatientProfile.java
@@ -61,6 +61,7 @@ public void onClick(View v) {
fragmentTransaction = getFragmentManager().beginTransaction();
fragment = new History();//the fragment you want to show
fragmentTransaction.replace(R.id.content_frame, fragment);//R.id.content_frame is the layout you want to replace
+ fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
break;
@@ -69,6 +70,7 @@ public void onClick(View v) {
fragmentTransaction = getFragmentManager().beginTransaction();
fragment = new AddEditMedicine();//the fragment you want to show
fragmentTransaction.replace(R.id.content_frame, fragment);//R.id.content_frame is the layout you want to replace
+ fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
break;
case R.id.fab3:
@@ -76,6 +78,7 @@ public void onClick(View v) {
fragmentTransaction = getFragmentManager().beginTransaction();
fragment = new Prescription();//the fragment you want to show
fragmentTransaction.replace(R.id.content_frame, fragment);//R.id.content_frame is the layout you want to replace
+ fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
break;
}
diff --git a/app/src/main/res/layout/fragment_add_edit_medicine.xml b/app/src/main/res/layout/fragment_add_edit_medicine.xml
index dbfb3e5..571d882 100644
--- a/app/src/main/res/layout/fragment_add_edit_medicine.xml
+++ b/app/src/main/res/layout/fragment_add_edit_medicine.xml
@@ -51,7 +51,7 @@
android:layout_below="@+id/card_view"
android:layout_marginTop="40dp"
android:ems="10"
- android:hint="Mediciene Name"
+ android:hint="Medicine Name"
android:textColor="@color/black"
android:textSize="15sp" />