mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
rename Medic in Prescription and refactor code
This commit is contained in:
parent
179175cccd
commit
e1d2c197cc
9 changed files with 166 additions and 152 deletions
|
@ -15,8 +15,8 @@ import androidx.appcompat.app.ActionBar;
|
|||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import net.foucry.pilldroid.dao.MedicDAO;
|
||||
import net.foucry.pilldroid.models.Medic;
|
||||
import net.foucry.pilldroid.dao.PrescriptionsDAO;
|
||||
import net.foucry.pilldroid.models.Prescription;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class DrugDetailActivity extends AppCompatActivity {
|
|||
|
||||
private static final String TAG = DrugDetailActivity.class.getName();
|
||||
|
||||
Medic aMedic;
|
||||
Prescription aPrescription;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -38,8 +38,8 @@ public class DrugDetailActivity extends AppCompatActivity {
|
|||
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
assert bundle != null;
|
||||
aMedic = (Medic) bundle.get("medic");
|
||||
Log.d(TAG, "aMedic == " + aMedic);
|
||||
aPrescription = (Prescription) bundle.get("medic");
|
||||
Log.d(TAG, "aPrescription == " + aPrescription);
|
||||
|
||||
setContentView(R.layout.drug_detail_activity);
|
||||
Toolbar toolbar = findViewById(detail_toolbar);
|
||||
|
@ -65,7 +65,7 @@ public class DrugDetailActivity extends AppCompatActivity {
|
|||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(false);
|
||||
actionBar.setTitle(aMedic.getName());
|
||||
actionBar.setTitle(aPrescription.getName());
|
||||
}
|
||||
|
||||
// savedInstanceState is non-null when there is fragment state
|
||||
|
@ -81,7 +81,7 @@ public class DrugDetailActivity extends AppCompatActivity {
|
|||
// Create the detail fragment and add it to the activity
|
||||
// using a fragment transaction.
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putSerializable("medic", aMedic);
|
||||
arguments.putSerializable("medic", aPrescription);
|
||||
DrugDetailFragment fragment = new DrugDetailFragment();
|
||||
fragment.setArguments(arguments);
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
|
@ -109,11 +109,11 @@ public class DrugDetailActivity extends AppCompatActivity {
|
|||
private void getMDrugChanges() {
|
||||
Log.d(TAG, "Time to save new values");
|
||||
|
||||
PilldroidDatabase prescriptions = null;
|
||||
PrescriptionDatabase prescriptions = null;
|
||||
assert false;
|
||||
MedicDAO medicDAO = prescriptions.getMedicDAO();
|
||||
PrescriptionsDAO prescriptionsDAO = prescriptions.getMedicDAO();
|
||||
|
||||
Medic newMedic = medicDAO.getMedicByCIP13(aMedic.getCip13());
|
||||
Prescription newPrescription = prescriptionsDAO.getMedicByCIP13(aPrescription.getCip13());
|
||||
|
||||
View stockView;
|
||||
View takeView;
|
||||
|
@ -136,18 +136,18 @@ public class DrugDetailActivity extends AppCompatActivity {
|
|||
TextView warningTextView = warningView.findViewById(R.id.value);
|
||||
String warningValue = warningTextView.getText().toString();
|
||||
|
||||
newMedic.setStock(Float.parseFloat(stockValue));
|
||||
newMedic.setTake(Float.parseFloat(takeValue));
|
||||
newMedic.setWarning(Integer.parseInt(warningValue));
|
||||
newMedic.setAlert(Integer.parseInt(alertValue));
|
||||
newMedic.getDateEndOfStock();
|
||||
newPrescription.setStock(Float.parseFloat(stockValue));
|
||||
newPrescription.setTake(Float.parseFloat(takeValue));
|
||||
newPrescription.setWarning(Integer.parseInt(warningValue));
|
||||
newPrescription.setAlert(Integer.parseInt(alertValue));
|
||||
newPrescription.getDateEndOfStock();
|
||||
|
||||
if (aMedic.equals(newMedic)) {
|
||||
Log.d(TAG, "medic and newMedic are Equals");
|
||||
if (aPrescription.equals(newPrescription)) {
|
||||
Log.d(TAG, "medic and newPrescription are Equals");
|
||||
} else {
|
||||
Log.d(TAG, "medic and newMedic are NOT Equals");
|
||||
newMedic.setLast_update(new Date().getTime());
|
||||
medicDAO.update(newMedic);
|
||||
Log.d(TAG, "medic and newPrescription are NOT Equals");
|
||||
newPrescription.setLast_update(new Date().getTime());
|
||||
prescriptionsDAO.update(newPrescription);
|
||||
//dbHelper.updateDrug(newDrug);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import androidx.fragment.app.Fragment;
|
|||
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||
|
||||
import net.foucry.pilldroid.models.Medic;
|
||||
import net.foucry.pilldroid.models.Prescription;
|
||||
|
||||
/**
|
||||
* A fragment representing a single Drug detail screen.
|
||||
|
@ -25,12 +25,12 @@ public class DrugDetailFragment extends Fragment {
|
|||
* The fragment argument representing the item ID that this fragment
|
||||
* represents.
|
||||
*/
|
||||
public static final String ARG_ITEM_ID = "medic";
|
||||
public static final String ARG_ITEM_ID = "prescription";
|
||||
|
||||
/**
|
||||
* The dummy content this fragment is presenting.
|
||||
*/
|
||||
private Medic medic;
|
||||
private Prescription prescription;
|
||||
|
||||
/**
|
||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||
|
@ -48,13 +48,13 @@ public class DrugDetailFragment extends Fragment {
|
|||
// Load the dummy content specified by the fragment
|
||||
// arguments. In a real-world scenario, use a Loader
|
||||
// to load content from a content provider.
|
||||
medic = (Medic) getArguments().getSerializable(ARG_ITEM_ID);
|
||||
prescription = (Prescription) getArguments().getSerializable(ARG_ITEM_ID);
|
||||
|
||||
Activity activity = this.getActivity();
|
||||
assert activity != null;
|
||||
CollapsingToolbarLayout appBarLayout = activity.findViewById(R.id.toolbar_layout);
|
||||
if (appBarLayout != null) {
|
||||
appBarLayout.setTitle(medic.getName());
|
||||
appBarLayout.setTitle(prescription.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,31 +71,31 @@ public class DrugDetailFragment extends Fragment {
|
|||
View alertView;
|
||||
|
||||
// Show the dummy content as text in a TextView.
|
||||
if (medic != null) {
|
||||
if (prescription != null) {
|
||||
// Find each component of rootView
|
||||
nameView = detailView.findViewById(R.id.name_cell);
|
||||
TextView nameLabel = nameView.findViewById(R.id.label);
|
||||
TextView nameValue = nameView.findViewById(R.id.value);
|
||||
nameLabel.setText(R.string.drug_name_label);
|
||||
nameValue.setText(medic.getName());
|
||||
nameValue.setText(prescription.getName());
|
||||
|
||||
presentationView = detailView.findViewById(R.id.presentation_cell);
|
||||
TextView presentationLabel = presentationView.findViewById(R.id.label);
|
||||
TextView presentationValue = presentationView.findViewById(R.id.value);
|
||||
presentationLabel.setText(R.string.drug_presentation_label);
|
||||
presentationValue.setText(medic.getPresentation());
|
||||
presentationValue.setText(prescription.getPresentation());
|
||||
|
||||
adminModeView = detailView.findViewById(R.id.administration_cell);
|
||||
TextView adminModeLabel = adminModeView.findViewById(R.id.label);
|
||||
TextView adminModeValue = adminModeView.findViewById(R.id.value);
|
||||
adminModeLabel.setText(R.string.drug_administrationMode_label);
|
||||
adminModeValue.setText(medic.getAdministration_mode());
|
||||
adminModeValue.setText(prescription.getAdministration_mode());
|
||||
|
||||
stockView = detailView.findViewById(R.id.stock_cell);
|
||||
TextView stockLibelle = (stockView.findViewById(R.id.label));
|
||||
TextView stockValue = stockView.findViewById(R.id.value);
|
||||
stockLibelle.setText(R.string.drug_current_stock_label);
|
||||
stockValue.setText(Utils.fmt(medic.getStock()));
|
||||
stockValue.setText(Utils.fmt(prescription.getStock()));
|
||||
stockValue.setHint(R.string.drug_current_stock_label);
|
||||
stockValue.setSelectAllOnFocus(true);
|
||||
|
||||
|
@ -103,8 +103,8 @@ public class DrugDetailFragment extends Fragment {
|
|||
TextView takeLabel = takeView.findViewById(R.id.label);
|
||||
TextView takeValue = (takeView.findViewById(R.id.value));
|
||||
takeLabel.setText(R.string.drug_take_label);
|
||||
//takeValue.setText(Double.toString(medic.getTake()));
|
||||
takeValue.setText(Utils.fmt(medic.getTake()));
|
||||
//takeValue.setText(Double.toString(prescription.getTake()));
|
||||
takeValue.setText(Utils.fmt(prescription.getTake()));
|
||||
takeValue.setHint(R.string.drug_take_label);
|
||||
takeValue.setSelectAllOnFocus(true);
|
||||
|
||||
|
@ -112,8 +112,8 @@ public class DrugDetailFragment extends Fragment {
|
|||
TextView warningLibelle = warningView.findViewById(R.id.label);
|
||||
TextView warningValue = warningView.findViewById(R.id.value);
|
||||
warningLibelle.setText(R.string.drug_warningThreshold_label);
|
||||
//warningValue.setText(Integer.toString(medic.getWarnThreshold()));
|
||||
warningValue.setText(Utils.fmt(medic.getWarning()));
|
||||
//warningValue.setText(Integer.toString(prescription.getWarnThreshold()));
|
||||
warningValue.setText(Utils.fmt(prescription.getWarning()));
|
||||
warningValue.setHint(R.string.drug_warningThreshold_label);
|
||||
warningValue.setSelectAllOnFocus(true);
|
||||
|
||||
|
@ -121,8 +121,8 @@ public class DrugDetailFragment extends Fragment {
|
|||
TextView alertLibelle = alertView.findViewById(R.id.label);
|
||||
TextView alertValue = alertView.findViewById(R.id.value);
|
||||
alertLibelle.setText(R.string.drug_alertThreshold_label);
|
||||
//alertValue.setText(Integer.toString(medic.getAlertThreshold()));
|
||||
alertValue.setText(Utils.fmt(medic.getAlert()));
|
||||
//alertValue.setText(Integer.toString(prescription.getAlertThreshold()));
|
||||
alertValue.setText(Utils.fmt(prescription.getAlert()));
|
||||
alertValue.setHint(R.string.drug_alertThreshold_label);
|
||||
alertValue.setSelectAllOnFocus(true);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.text.Editable;
|
||||
|
@ -36,8 +37,8 @@ import androidx.room.Room;
|
|||
import com.google.zxing.client.android.Intents;
|
||||
import com.journeyapps.barcodescanner.ScanOptions;
|
||||
|
||||
import net.foucry.pilldroid.dao.MedicDAO;
|
||||
import net.foucry.pilldroid.models.Medic;
|
||||
import net.foucry.pilldroid.dao.PrescriptionsDAO;
|
||||
import net.foucry.pilldroid.models.Prescription;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
@ -63,10 +64,10 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
private ActivityResultLauncher<ScanOptions> mBarcodeScannerLauncher;
|
||||
private static final String TAG = DrugListActivity.class.getName();
|
||||
|
||||
public PilldroidDatabase prescriptions;
|
||||
public PilldroidDatabase medications;
|
||||
public PrescriptionDatabase prescriptions;
|
||||
public PrescriptionDatabase medications;
|
||||
|
||||
private List<Medic> medics; // used for prescriptions
|
||||
private List<Prescription> prescriptionList; // used for prescriptions
|
||||
|
||||
private SimpleItemRecyclerViewAdapter mAdapter;
|
||||
|
||||
|
@ -74,33 +75,46 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
if(BuildConfig.DEBUG) {
|
||||
String manufacturer = Build.MANUFACTURER;
|
||||
String model = Build.MODEL;
|
||||
int version = Build.VERSION.SDK_INT;
|
||||
String versionRelease = Build.VERSION.RELEASE;
|
||||
|
||||
Log.e(TAG, "manufacturer " + manufacturer
|
||||
+ " \n model " + model
|
||||
+ " \n version " + version
|
||||
+ " \n versionRelease " + versionRelease
|
||||
);
|
||||
}
|
||||
|
||||
medications = Room
|
||||
.databaseBuilder(getApplicationContext(), PilldroidDatabase.class, "medications")
|
||||
.databaseBuilder(getApplicationContext(), PrescriptionDatabase.class, "medications")
|
||||
.createFromAsset("drugs.db")
|
||||
.build();
|
||||
|
||||
// Manually migrate old database to room
|
||||
MedicDAO medicDAO = prescriptions.getMedicDAO();
|
||||
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
|
||||
DBHelper dbHelper = new DBHelper(this);
|
||||
if (dbHelper.getCount() !=0) {
|
||||
List<Drug> drugs=dbHelper.getAllDrugs();
|
||||
for (int count=0; count < dbHelper.getCount(); count++) {
|
||||
Drug drug = drugs.get(count);
|
||||
Medic medic = new Medic();
|
||||
Prescription prescription = new Prescription();
|
||||
|
||||
if(medicDAO.getMedicByCIP13(drug.getCip13()) == null) {
|
||||
medic.setName(drug.getName());
|
||||
medic.setCip13(drug.getCip13());
|
||||
medic.setCis(drug.getCis());
|
||||
medic.setPresentation(drug.getPresentation());
|
||||
medic.setAdministration_mode(drug.getAdministration_mode());
|
||||
medic.setStock((float) drug.getStock());
|
||||
medic.setTake((float) drug.getTake());
|
||||
medic.setWarning(drug.getWarnThreshold());
|
||||
medic.setAlert(drug.getAlertThreshold());
|
||||
medic.setLast_update(drug.getDateLastUpdate());
|
||||
if(prescriptionsDAO.getMedicByCIP13(drug.getCip13()) == null) {
|
||||
prescription.setName(drug.getName());
|
||||
prescription.setCip13(drug.getCip13());
|
||||
prescription.setCis(drug.getCis());
|
||||
prescription.setPresentation(drug.getPresentation());
|
||||
prescription.setAdministration_mode(drug.getAdministration_mode());
|
||||
prescription.setStock((float) drug.getStock());
|
||||
prescription.setTake((float) drug.getTake());
|
||||
prescription.setWarning(drug.getWarnThreshold());
|
||||
prescription.setAlert(drug.getAlertThreshold());
|
||||
prescription.setLast_update(drug.getDateLastUpdate());
|
||||
|
||||
medicDAO.insert(medic);
|
||||
prescriptionsDAO.insert(prescription);
|
||||
}
|
||||
else {
|
||||
Log.i(TAG, "Already in the database");
|
||||
|
@ -132,7 +146,7 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
|
||||
// Create Room database
|
||||
prescriptions = Room
|
||||
.databaseBuilder(getApplicationContext(), PilldroidDatabase.class, "prescriptions")
|
||||
.databaseBuilder(getApplicationContext(), PrescriptionDatabase.class, "prescriptions")
|
||||
.allowMainThreadQueries()
|
||||
.build();
|
||||
|
||||
|
@ -147,30 +161,30 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
if (DEMO) {
|
||||
MedicDAO medicDAO = prescriptions.getMedicDAO();
|
||||
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
|
||||
|
||||
if (medicDAO.getMedicCount() == 0) {
|
||||
if (prescriptionsDAO.getMedicCount() == 0) {
|
||||
final int min_stock = 5;
|
||||
final int max_stock = 50;
|
||||
final int min_take = 0;
|
||||
final int max_take = 3;
|
||||
|
||||
for (int i = 1; i < 9; i++) {
|
||||
Medic medic = new Medic();
|
||||
medic.setName("Medicament test " + i);
|
||||
medic.setCip13("340093000001" + i);
|
||||
medic.setCis("6000001" + i);
|
||||
medic.setAdministration_mode("oral");
|
||||
medic.setPresentation("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)");
|
||||
medic.setStock((float) intRandomExclusive(min_stock, max_stock));
|
||||
medic.setTake((float) intRandomExclusive(min_take, max_take));
|
||||
medic.setWarning(14);
|
||||
medic.setAlert(7);
|
||||
medic.setLast_update(UtilDate.dateAtNoon(new Date()).getTime());
|
||||
Prescription prescription = new Prescription();
|
||||
prescription.setName("Medicament test " + i);
|
||||
prescription.setCip13("340093000001" + i);
|
||||
prescription.setCis("6000001" + i);
|
||||
prescription.setAdministration_mode("oral");
|
||||
prescription.setPresentation("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)");
|
||||
prescription.setStock((float) intRandomExclusive(min_stock, max_stock));
|
||||
prescription.setTake((float) intRandomExclusive(min_take, max_take));
|
||||
prescription.setWarning(14);
|
||||
prescription.setAlert(7);
|
||||
prescription.setLast_update(UtilDate.dateAtNoon(new Date()).getTime());
|
||||
|
||||
medicDAO.insert(medic);
|
||||
prescriptionsDAO.insert(prescription);
|
||||
}
|
||||
List<Medic> prescriptions = medicDAO.getAllMedics();
|
||||
List<Prescription> prescriptions = prescriptionsDAO.getAllMedics();
|
||||
System.out.println(prescriptions);
|
||||
Log.d(TAG, "prescriptions ==" + prescriptions);
|
||||
}
|
||||
|
@ -225,8 +239,8 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
// Get Drug from database
|
||||
MedicDAO medicationDAO = medications.getMedicDAO();
|
||||
final Medic scannedMedication = medicationDAO.getMedicByCIP13(cip13);
|
||||
PrescriptionsDAO medicationDAO = medications.getMedicDAO(); // TODO
|
||||
final Prescription scannedMedication = medicationDAO.getMedicByCIP13(cip13);
|
||||
|
||||
// add Drug to prescription database
|
||||
askToAddInDB(scannedMedication);
|
||||
|
@ -239,8 +253,8 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
|
||||
public void constructDrugsList() {
|
||||
|
||||
MedicDAO medicDAO = prescriptions.getMedicDAO();
|
||||
medics = medicDAO.getAllMedics();
|
||||
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
|
||||
prescriptionList = prescriptionsDAO.getAllMedics();
|
||||
|
||||
View mRecyclerView = findViewById(R.id.drug_list);
|
||||
assert mRecyclerView != null;
|
||||
|
@ -320,10 +334,10 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
.setPositiveButton("OK", (dialog, id) -> {
|
||||
String cip13 = editText.getText().toString();
|
||||
|
||||
MedicDAO medicationsDAO = medications.getMedicDAO();
|
||||
Medic aMedic = medicationsDAO.getMedicByCIP13(cip13);
|
||||
//Medic aMedic = medications.getDrugByCIP13(cip13);
|
||||
askToAddInDB(aMedic);
|
||||
PrescriptionsDAO medicationsDAO = medications.getMedicDAO(); // TODO
|
||||
Prescription aPrescription = medicationsDAO.getMedicByCIP13(cip13);
|
||||
//Prescription aPrescription = medications.getDrugByCIP13(cip13);
|
||||
askToAddInDB(aPrescription);
|
||||
})
|
||||
.setNegativeButton("Cancel",
|
||||
(dialog, id) -> dialog.cancel());
|
||||
|
@ -354,14 +368,14 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
* Ask if the drug found in the database should be include in the
|
||||
* user database
|
||||
*
|
||||
* @param aMedic Medic- medication to be added
|
||||
* @param aPrescription Prescription- medication to be added
|
||||
*/
|
||||
private void askToAddInDB(Medic aMedic) {
|
||||
private void askToAddInDB(Prescription aPrescription) {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
|
||||
dlg.setTitle(getString(R.string.app_name));
|
||||
|
||||
if (aMedic != null) {
|
||||
String msg = aMedic.getName() + " " + getString(R.string.msgFound);
|
||||
if (aPrescription != null) {
|
||||
String msg = aPrescription.getName() + " " + getString(R.string.msgFound);
|
||||
|
||||
dlg.setMessage(msg);
|
||||
dlg.setNegativeButton(getString(R.string.button_cancel), (dialog, which) -> {
|
||||
|
@ -369,7 +383,7 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
});
|
||||
dlg.setPositiveButton(getString(R.string.button_ok), (dialog, which) -> {
|
||||
// Add Drug to DB then try to show it
|
||||
addDrugToList(aMedic);
|
||||
addDrugToList(aPrescription);
|
||||
});
|
||||
} else {
|
||||
dlg.setMessage(getString(R.string.msgNotFound));
|
||||
|
@ -397,18 +411,18 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
/**
|
||||
* Add New drug to the user database
|
||||
*
|
||||
* @param aMedic Medic - medication to be added
|
||||
* @param aPrescription Prescription - medication to be added
|
||||
*/
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void addDrugToList(Medic aMedic) {
|
||||
aMedic.getDateEndOfStock();
|
||||
mAdapter.addItem(aMedic);
|
||||
private void addDrugToList(Prescription aPrescription) {
|
||||
aPrescription.getDateEndOfStock();
|
||||
mAdapter.addItem(aPrescription);
|
||||
|
||||
Log.d(TAG, "Call DrugDetailActivity");
|
||||
Context context = this;
|
||||
Intent intent = new Intent(context, DrugDetailActivity.class);
|
||||
intent.putExtra("medic", (Parcelable) aMedic);
|
||||
intent.putExtra("medic", (Parcelable) aPrescription);
|
||||
|
||||
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
|
||||
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
|
||||
|
@ -431,7 +445,7 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
*/
|
||||
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext()));
|
||||
mAdapter = new SimpleItemRecyclerViewAdapter(medics);
|
||||
mAdapter = new SimpleItemRecyclerViewAdapter(prescriptionList);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
|
@ -441,19 +455,19 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
public class SimpleItemRecyclerViewAdapter extends
|
||||
RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> {
|
||||
|
||||
private final List<Medic> mValues;
|
||||
private final List<Prescription> mValues;
|
||||
|
||||
SimpleItemRecyclerViewAdapter(List<Medic> items) {
|
||||
SimpleItemRecyclerViewAdapter(List<Prescription> items) {
|
||||
mValues = items;
|
||||
}
|
||||
|
||||
void addItem(Medic scannedMedic) {
|
||||
MedicDAO medicDAO = prescriptions.getMedicDAO();
|
||||
if (medicDAO.getMedicByCIP13(scannedMedic.getCip13()) == null) {
|
||||
mValues.add(scannedMedic);
|
||||
void addItem(Prescription scannedPrescription) {
|
||||
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
|
||||
if (prescriptionsDAO.getMedicByCIP13(scannedPrescription.getCip13()) == null) {
|
||||
mValues.add(scannedPrescription);
|
||||
//notifyDataSetChanged();
|
||||
notifyItemInserted(mValues.size());
|
||||
medicDAO.insert(scannedMedic);
|
||||
prescriptionsDAO.insert(scannedPrescription);
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), "already in the database", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
@ -494,10 +508,10 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
holder.mView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Medic aMedic = mValues.get(position);
|
||||
Prescription aPrescription = mValues.get(position);
|
||||
Context context = v.getContext();
|
||||
Intent intent = new Intent(context, DrugDetailActivity.class);
|
||||
intent.putExtra("medic", (Parcelable) aMedic);
|
||||
intent.putExtra("medic", (Parcelable) aPrescription);
|
||||
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
|
||||
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
|
||||
|
||||
|
@ -520,10 +534,10 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
holder.mView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Medic medic = mValues.get(position);
|
||||
Prescription prescription = mValues.get(position);
|
||||
Context context = v.getContext();
|
||||
Intent intent = new Intent(context, DrugDetailActivity.class);
|
||||
intent.putExtra("medic", medic);
|
||||
intent.putExtra("prescription", prescription);
|
||||
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
|
||||
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
|
||||
|
||||
|
@ -543,7 +557,7 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
final TextView mContentView;
|
||||
final TextView mEndOfStock;
|
||||
final ImageView mIconView;
|
||||
public Medic mItem;
|
||||
public Prescription mItem;
|
||||
|
||||
ViewHolder(View view) {
|
||||
super(view);
|
||||
|
|
|
@ -4,18 +4,18 @@ import androidx.room.AutoMigration;
|
|||
import androidx.room.Database;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
import net.foucry.pilldroid.dao.MedicDAO;
|
||||
import net.foucry.pilldroid.models.Medic;
|
||||
import net.foucry.pilldroid.dao.PrescriptionsDAO;
|
||||
import net.foucry.pilldroid.models.Prescription;
|
||||
|
||||
@Database(
|
||||
version = 3,
|
||||
entities = {Medic.class},
|
||||
entities = {Prescription.class},
|
||||
autoMigrations = {
|
||||
@AutoMigration(from = 1, to = 2),
|
||||
@AutoMigration(from = 2, to = 3),
|
||||
}
|
||||
)
|
||||
|
||||
public abstract class PilldroidDatabase extends RoomDatabase {
|
||||
public abstract MedicDAO getMedicDAO();
|
||||
public abstract class PrescriptionDatabase extends RoomDatabase {
|
||||
public abstract PrescriptionsDAO getPrescriptionsDAO();
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package net.foucry.pilldroid.dao;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
|
||||
import net.foucry.pilldroid.models.Medic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface MedicDAO {
|
||||
@Insert
|
||||
void insert(Medic... medics);
|
||||
|
||||
@Update
|
||||
void update(Medic... medics);
|
||||
|
||||
@Delete
|
||||
void delete(Medic medic);
|
||||
|
||||
@Query("SELECT * FROM medics")
|
||||
List<Medic> getAllMedics();
|
||||
|
||||
@Query("SELECT * FROM medics WHERE cip13 = :cip13")
|
||||
Medic getMedicByCIP13(String cip13);
|
||||
|
||||
@Query("SELECT count(*) FROM medics")
|
||||
int getMedicCount();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package net.foucry.pilldroid.dao;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
|
||||
import net.foucry.pilldroid.models.Prescription;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface PrescriptionsDAO {
|
||||
@Insert
|
||||
void insert(Prescription... prescriptions);
|
||||
|
||||
@Update
|
||||
void update(Prescription... prescriptions);
|
||||
|
||||
@Delete
|
||||
void delete(Prescription prescription);
|
||||
|
||||
@Query("SELECT * FROM prescriptions")
|
||||
List<Prescription> getAllMedics();
|
||||
|
||||
@Query("SELECT * FROM prescriptions WHERE cip13 = :cip13")
|
||||
Prescription getMedicByCIP13(String cip13);
|
||||
|
||||
@Query("SELECT count(*) FROM prescriptions")
|
||||
int getMedicCount();
|
||||
}
|
||||
|
||||
|
|
@ -10,8 +10,8 @@ import java.io.Serializable;
|
|||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity(tableName = "medics")
|
||||
public class Medic implements Serializable {
|
||||
@Entity(tableName = "prescriptions")
|
||||
public class Prescription implements Serializable {
|
||||
@PrimaryKey
|
||||
@NonNull private String cis;
|
||||
private String cip13;
|
|
@ -9,8 +9,8 @@ I made a lot a tests but there must stay some bugs.
|
|||
find the code.
|
||||
|
||||
## What is not implemented
|
||||
- removing of a medic from the list;
|
||||
- take medic reminder. It will be never been implemented (by me).
|
||||
- removing of a prescription from the list;
|
||||
- take prescription reminder. It will be never been implemented (by me).
|
||||
|
||||
**ATTENTION**, Pilldroid does not manage creams, liquids
|
||||
(like insulin).
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<<<<<<< HEAD
|
||||
<strong>Pilldroid</strong> is a theoretical medics manager. It for French people
|
||||
<strong>Pilldroid</strong> is a theoretical prescriptions manager. It for French people
|
||||
only.
|
||||
|
||||
<strong>Why for french people only?</strong>
|
||||
<p>Pilldroid use a medics databases that come from French government website, with
|
||||
<strong>Pilldroid</strong> is a theoretical medics manager. It for French people
|
||||
<p>Pilldroid use a prescriptions databases that come from French government website, with
|
||||
<strong>Pilldroid</strong> is a theoretical prescriptions manager. It for French people
|
||||
only.
|
||||
|
||||
medics which are refund by french health care national insurance (Sécurité
|
||||
prescriptions which are refund by french health care national insurance (Sécurité
|
||||
Sociale).</p>
|
||||
|
||||
<strong>What is the Pilldroid's license?</strong>
|
||||
|
|
Loading…
Reference in a new issue