rename Medic in Prescription and refactor code

This commit is contained in:
jacques 2022-03-16 05:44:19 +01:00
parent 179175cccd
commit e1d2c197cc
9 changed files with 166 additions and 152 deletions

View file

@ -15,8 +15,8 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import net.foucry.pilldroid.dao.MedicDAO; import net.foucry.pilldroid.dao.PrescriptionsDAO;
import net.foucry.pilldroid.models.Medic; import net.foucry.pilldroid.models.Prescription;
import java.util.Date; import java.util.Date;
@ -30,7 +30,7 @@ public class DrugDetailActivity extends AppCompatActivity {
private static final String TAG = DrugDetailActivity.class.getName(); private static final String TAG = DrugDetailActivity.class.getName();
Medic aMedic; Prescription aPrescription;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -38,8 +38,8 @@ public class DrugDetailActivity extends AppCompatActivity {
Bundle bundle = getIntent().getExtras(); Bundle bundle = getIntent().getExtras();
assert bundle != null; assert bundle != null;
aMedic = (Medic) bundle.get("medic"); aPrescription = (Prescription) bundle.get("medic");
Log.d(TAG, "aMedic == " + aMedic); Log.d(TAG, "aPrescription == " + aPrescription);
setContentView(R.layout.drug_detail_activity); setContentView(R.layout.drug_detail_activity);
Toolbar toolbar = findViewById(detail_toolbar); Toolbar toolbar = findViewById(detail_toolbar);
@ -65,7 +65,7 @@ public class DrugDetailActivity extends AppCompatActivity {
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
if (actionBar != null) { if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setTitle(aMedic.getName()); actionBar.setTitle(aPrescription.getName());
} }
// savedInstanceState is non-null when there is fragment state // 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 // Create the detail fragment and add it to the activity
// using a fragment transaction. // using a fragment transaction.
Bundle arguments = new Bundle(); Bundle arguments = new Bundle();
arguments.putSerializable("medic", aMedic); arguments.putSerializable("medic", aPrescription);
DrugDetailFragment fragment = new DrugDetailFragment(); DrugDetailFragment fragment = new DrugDetailFragment();
fragment.setArguments(arguments); fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()
@ -109,11 +109,11 @@ public class DrugDetailActivity extends AppCompatActivity {
private void getMDrugChanges() { private void getMDrugChanges() {
Log.d(TAG, "Time to save new values"); Log.d(TAG, "Time to save new values");
PilldroidDatabase prescriptions = null; PrescriptionDatabase prescriptions = null;
assert false; 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 stockView;
View takeView; View takeView;
@ -136,18 +136,18 @@ public class DrugDetailActivity extends AppCompatActivity {
TextView warningTextView = warningView.findViewById(R.id.value); TextView warningTextView = warningView.findViewById(R.id.value);
String warningValue = warningTextView.getText().toString(); String warningValue = warningTextView.getText().toString();
newMedic.setStock(Float.parseFloat(stockValue)); newPrescription.setStock(Float.parseFloat(stockValue));
newMedic.setTake(Float.parseFloat(takeValue)); newPrescription.setTake(Float.parseFloat(takeValue));
newMedic.setWarning(Integer.parseInt(warningValue)); newPrescription.setWarning(Integer.parseInt(warningValue));
newMedic.setAlert(Integer.parseInt(alertValue)); newPrescription.setAlert(Integer.parseInt(alertValue));
newMedic.getDateEndOfStock(); newPrescription.getDateEndOfStock();
if (aMedic.equals(newMedic)) { if (aPrescription.equals(newPrescription)) {
Log.d(TAG, "medic and newMedic are Equals"); Log.d(TAG, "medic and newPrescription are Equals");
} else { } else {
Log.d(TAG, "medic and newMedic are NOT Equals"); Log.d(TAG, "medic and newPrescription are NOT Equals");
newMedic.setLast_update(new Date().getTime()); newPrescription.setLast_update(new Date().getTime());
medicDAO.update(newMedic); prescriptionsDAO.update(newPrescription);
//dbHelper.updateDrug(newDrug); //dbHelper.updateDrug(newDrug);
} }
} }

View file

@ -11,7 +11,7 @@ import androidx.fragment.app.Fragment;
import com.google.android.material.appbar.CollapsingToolbarLayout; 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. * 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 * The fragment argument representing the item ID that this fragment
* represents. * represents.
*/ */
public static final String ARG_ITEM_ID = "medic"; public static final String ARG_ITEM_ID = "prescription";
/** /**
* The dummy content this fragment is presenting. * The dummy content this fragment is presenting.
*/ */
private Medic medic; private Prescription prescription;
/** /**
* Mandatory empty constructor for the fragment manager to instantiate the * 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 // Load the dummy content specified by the fragment
// arguments. In a real-world scenario, use a Loader // arguments. In a real-world scenario, use a Loader
// to load content from a content provider. // 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(); Activity activity = this.getActivity();
assert activity != null; assert activity != null;
CollapsingToolbarLayout appBarLayout = activity.findViewById(R.id.toolbar_layout); CollapsingToolbarLayout appBarLayout = activity.findViewById(R.id.toolbar_layout);
if (appBarLayout != null) { if (appBarLayout != null) {
appBarLayout.setTitle(medic.getName()); appBarLayout.setTitle(prescription.getName());
} }
} }
} }
@ -71,31 +71,31 @@ public class DrugDetailFragment extends Fragment {
View alertView; View alertView;
// Show the dummy content as text in a TextView. // Show the dummy content as text in a TextView.
if (medic != null) { if (prescription != null) {
// Find each component of rootView // Find each component of rootView
nameView = detailView.findViewById(R.id.name_cell); nameView = detailView.findViewById(R.id.name_cell);
TextView nameLabel = nameView.findViewById(R.id.label); TextView nameLabel = nameView.findViewById(R.id.label);
TextView nameValue = nameView.findViewById(R.id.value); TextView nameValue = nameView.findViewById(R.id.value);
nameLabel.setText(R.string.drug_name_label); nameLabel.setText(R.string.drug_name_label);
nameValue.setText(medic.getName()); nameValue.setText(prescription.getName());
presentationView = detailView.findViewById(R.id.presentation_cell); presentationView = detailView.findViewById(R.id.presentation_cell);
TextView presentationLabel = presentationView.findViewById(R.id.label); TextView presentationLabel = presentationView.findViewById(R.id.label);
TextView presentationValue = presentationView.findViewById(R.id.value); TextView presentationValue = presentationView.findViewById(R.id.value);
presentationLabel.setText(R.string.drug_presentation_label); presentationLabel.setText(R.string.drug_presentation_label);
presentationValue.setText(medic.getPresentation()); presentationValue.setText(prescription.getPresentation());
adminModeView = detailView.findViewById(R.id.administration_cell); adminModeView = detailView.findViewById(R.id.administration_cell);
TextView adminModeLabel = adminModeView.findViewById(R.id.label); TextView adminModeLabel = adminModeView.findViewById(R.id.label);
TextView adminModeValue = adminModeView.findViewById(R.id.value); TextView adminModeValue = adminModeView.findViewById(R.id.value);
adminModeLabel.setText(R.string.drug_administrationMode_label); adminModeLabel.setText(R.string.drug_administrationMode_label);
adminModeValue.setText(medic.getAdministration_mode()); adminModeValue.setText(prescription.getAdministration_mode());
stockView = detailView.findViewById(R.id.stock_cell); stockView = detailView.findViewById(R.id.stock_cell);
TextView stockLibelle = (stockView.findViewById(R.id.label)); TextView stockLibelle = (stockView.findViewById(R.id.label));
TextView stockValue = stockView.findViewById(R.id.value); TextView stockValue = stockView.findViewById(R.id.value);
stockLibelle.setText(R.string.drug_current_stock_label); 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.setHint(R.string.drug_current_stock_label);
stockValue.setSelectAllOnFocus(true); stockValue.setSelectAllOnFocus(true);
@ -103,8 +103,8 @@ public class DrugDetailFragment extends Fragment {
TextView takeLabel = takeView.findViewById(R.id.label); TextView takeLabel = takeView.findViewById(R.id.label);
TextView takeValue = (takeView.findViewById(R.id.value)); TextView takeValue = (takeView.findViewById(R.id.value));
takeLabel.setText(R.string.drug_take_label); takeLabel.setText(R.string.drug_take_label);
//takeValue.setText(Double.toString(medic.getTake())); //takeValue.setText(Double.toString(prescription.getTake()));
takeValue.setText(Utils.fmt(medic.getTake())); takeValue.setText(Utils.fmt(prescription.getTake()));
takeValue.setHint(R.string.drug_take_label); takeValue.setHint(R.string.drug_take_label);
takeValue.setSelectAllOnFocus(true); takeValue.setSelectAllOnFocus(true);
@ -112,8 +112,8 @@ public class DrugDetailFragment extends Fragment {
TextView warningLibelle = warningView.findViewById(R.id.label); TextView warningLibelle = warningView.findViewById(R.id.label);
TextView warningValue = warningView.findViewById(R.id.value); TextView warningValue = warningView.findViewById(R.id.value);
warningLibelle.setText(R.string.drug_warningThreshold_label); warningLibelle.setText(R.string.drug_warningThreshold_label);
//warningValue.setText(Integer.toString(medic.getWarnThreshold())); //warningValue.setText(Integer.toString(prescription.getWarnThreshold()));
warningValue.setText(Utils.fmt(medic.getWarning())); warningValue.setText(Utils.fmt(prescription.getWarning()));
warningValue.setHint(R.string.drug_warningThreshold_label); warningValue.setHint(R.string.drug_warningThreshold_label);
warningValue.setSelectAllOnFocus(true); warningValue.setSelectAllOnFocus(true);
@ -121,8 +121,8 @@ public class DrugDetailFragment extends Fragment {
TextView alertLibelle = alertView.findViewById(R.id.label); TextView alertLibelle = alertView.findViewById(R.id.label);
TextView alertValue = alertView.findViewById(R.id.value); TextView alertValue = alertView.findViewById(R.id.value);
alertLibelle.setText(R.string.drug_alertThreshold_label); alertLibelle.setText(R.string.drug_alertThreshold_label);
//alertValue.setText(Integer.toString(medic.getAlertThreshold())); //alertValue.setText(Integer.toString(prescription.getAlertThreshold()));
alertValue.setText(Utils.fmt(medic.getAlert())); alertValue.setText(Utils.fmt(prescription.getAlert()));
alertValue.setHint(R.string.drug_alertThreshold_label); alertValue.setHint(R.string.drug_alertThreshold_label);
alertValue.setSelectAllOnFocus(true); alertValue.setSelectAllOnFocus(true);
} }

View file

@ -9,6 +9,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; import android.os.Parcelable;
import android.text.Editable; import android.text.Editable;
@ -36,8 +37,8 @@ import androidx.room.Room;
import com.google.zxing.client.android.Intents; import com.google.zxing.client.android.Intents;
import com.journeyapps.barcodescanner.ScanOptions; import com.journeyapps.barcodescanner.ScanOptions;
import net.foucry.pilldroid.dao.MedicDAO; import net.foucry.pilldroid.dao.PrescriptionsDAO;
import net.foucry.pilldroid.models.Medic; import net.foucry.pilldroid.models.Prescription;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
@ -63,10 +64,10 @@ public class DrugListActivity extends AppCompatActivity {
private ActivityResultLauncher<ScanOptions> mBarcodeScannerLauncher; private ActivityResultLauncher<ScanOptions> mBarcodeScannerLauncher;
private static final String TAG = DrugListActivity.class.getName(); private static final String TAG = DrugListActivity.class.getName();
public PilldroidDatabase prescriptions; public PrescriptionDatabase prescriptions;
public PilldroidDatabase medications; public PrescriptionDatabase medications;
private List<Medic> medics; // used for prescriptions private List<Prescription> prescriptionList; // used for prescriptions
private SimpleItemRecyclerViewAdapter mAdapter; private SimpleItemRecyclerViewAdapter mAdapter;
@ -74,33 +75,46 @@ public class DrugListActivity extends AppCompatActivity {
public void onStart() { public void onStart() {
super.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 medications = Room
.databaseBuilder(getApplicationContext(), PilldroidDatabase.class, "medications") .databaseBuilder(getApplicationContext(), PrescriptionDatabase.class, "medications")
.createFromAsset("drugs.db") .createFromAsset("drugs.db")
.build(); .build();
// Manually migrate old database to room // Manually migrate old database to room
MedicDAO medicDAO = prescriptions.getMedicDAO(); PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
DBHelper dbHelper = new DBHelper(this); DBHelper dbHelper = new DBHelper(this);
if (dbHelper.getCount() !=0) { if (dbHelper.getCount() !=0) {
List<Drug> drugs=dbHelper.getAllDrugs(); List<Drug> drugs=dbHelper.getAllDrugs();
for (int count=0; count < dbHelper.getCount(); count++) { for (int count=0; count < dbHelper.getCount(); count++) {
Drug drug = drugs.get(count); Drug drug = drugs.get(count);
Medic medic = new Medic(); Prescription prescription = new Prescription();
if(medicDAO.getMedicByCIP13(drug.getCip13()) == null) { if(prescriptionsDAO.getMedicByCIP13(drug.getCip13()) == null) {
medic.setName(drug.getName()); prescription.setName(drug.getName());
medic.setCip13(drug.getCip13()); prescription.setCip13(drug.getCip13());
medic.setCis(drug.getCis()); prescription.setCis(drug.getCis());
medic.setPresentation(drug.getPresentation()); prescription.setPresentation(drug.getPresentation());
medic.setAdministration_mode(drug.getAdministration_mode()); prescription.setAdministration_mode(drug.getAdministration_mode());
medic.setStock((float) drug.getStock()); prescription.setStock((float) drug.getStock());
medic.setTake((float) drug.getTake()); prescription.setTake((float) drug.getTake());
medic.setWarning(drug.getWarnThreshold()); prescription.setWarning(drug.getWarnThreshold());
medic.setAlert(drug.getAlertThreshold()); prescription.setAlert(drug.getAlertThreshold());
medic.setLast_update(drug.getDateLastUpdate()); prescription.setLast_update(drug.getDateLastUpdate());
medicDAO.insert(medic); prescriptionsDAO.insert(prescription);
} }
else { else {
Log.i(TAG, "Already in the database"); Log.i(TAG, "Already in the database");
@ -132,7 +146,7 @@ public class DrugListActivity extends AppCompatActivity {
// Create Room database // Create Room database
prescriptions = Room prescriptions = Room
.databaseBuilder(getApplicationContext(), PilldroidDatabase.class, "prescriptions") .databaseBuilder(getApplicationContext(), PrescriptionDatabase.class, "prescriptions")
.allowMainThreadQueries() .allowMainThreadQueries()
.build(); .build();
@ -147,30 +161,30 @@ public class DrugListActivity extends AppCompatActivity {
} }
if (DEMO) { 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 min_stock = 5;
final int max_stock = 50; final int max_stock = 50;
final int min_take = 0; final int min_take = 0;
final int max_take = 3; final int max_take = 3;
for (int i = 1; i < 9; i++) { for (int i = 1; i < 9; i++) {
Medic medic = new Medic(); Prescription prescription = new Prescription();
medic.setName("Medicament test " + i); prescription.setName("Medicament test " + i);
medic.setCip13("340093000001" + i); prescription.setCip13("340093000001" + i);
medic.setCis("6000001" + i); prescription.setCis("6000001" + i);
medic.setAdministration_mode("oral"); prescription.setAdministration_mode("oral");
medic.setPresentation("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)"); prescription.setPresentation("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)");
medic.setStock((float) intRandomExclusive(min_stock, max_stock)); prescription.setStock((float) intRandomExclusive(min_stock, max_stock));
medic.setTake((float) intRandomExclusive(min_take, max_take)); prescription.setTake((float) intRandomExclusive(min_take, max_take));
medic.setWarning(14); prescription.setWarning(14);
medic.setAlert(7); prescription.setAlert(7);
medic.setLast_update(UtilDate.dateAtNoon(new Date()).getTime()); 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); System.out.println(prescriptions);
Log.d(TAG, "prescriptions ==" + prescriptions); Log.d(TAG, "prescriptions ==" + prescriptions);
} }
@ -225,8 +239,8 @@ public class DrugListActivity extends AppCompatActivity {
} }
// Get Drug from database // Get Drug from database
MedicDAO medicationDAO = medications.getMedicDAO(); PrescriptionsDAO medicationDAO = medications.getMedicDAO(); // TODO
final Medic scannedMedication = medicationDAO.getMedicByCIP13(cip13); final Prescription scannedMedication = medicationDAO.getMedicByCIP13(cip13);
// add Drug to prescription database // add Drug to prescription database
askToAddInDB(scannedMedication); askToAddInDB(scannedMedication);
@ -239,8 +253,8 @@ public class DrugListActivity extends AppCompatActivity {
public void constructDrugsList() { public void constructDrugsList() {
MedicDAO medicDAO = prescriptions.getMedicDAO(); PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
medics = medicDAO.getAllMedics(); prescriptionList = prescriptionsDAO.getAllMedics();
View mRecyclerView = findViewById(R.id.drug_list); View mRecyclerView = findViewById(R.id.drug_list);
assert mRecyclerView != null; assert mRecyclerView != null;
@ -320,10 +334,10 @@ public class DrugListActivity extends AppCompatActivity {
.setPositiveButton("OK", (dialog, id) -> { .setPositiveButton("OK", (dialog, id) -> {
String cip13 = editText.getText().toString(); String cip13 = editText.getText().toString();
MedicDAO medicationsDAO = medications.getMedicDAO(); PrescriptionsDAO medicationsDAO = medications.getMedicDAO(); // TODO
Medic aMedic = medicationsDAO.getMedicByCIP13(cip13); Prescription aPrescription = medicationsDAO.getMedicByCIP13(cip13);
//Medic aMedic = medications.getDrugByCIP13(cip13); //Prescription aPrescription = medications.getDrugByCIP13(cip13);
askToAddInDB(aMedic); askToAddInDB(aPrescription);
}) })
.setNegativeButton("Cancel", .setNegativeButton("Cancel",
(dialog, id) -> dialog.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 * Ask if the drug found in the database should be include in the
* user database * 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); AlertDialog.Builder dlg = new AlertDialog.Builder(this);
dlg.setTitle(getString(R.string.app_name)); dlg.setTitle(getString(R.string.app_name));
if (aMedic != null) { if (aPrescription != null) {
String msg = aMedic.getName() + " " + getString(R.string.msgFound); String msg = aPrescription.getName() + " " + getString(R.string.msgFound);
dlg.setMessage(msg); dlg.setMessage(msg);
dlg.setNegativeButton(getString(R.string.button_cancel), (dialog, which) -> { 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) -> { dlg.setPositiveButton(getString(R.string.button_ok), (dialog, which) -> {
// Add Drug to DB then try to show it // Add Drug to DB then try to show it
addDrugToList(aMedic); addDrugToList(aPrescription);
}); });
} else { } else {
dlg.setMessage(getString(R.string.msgNotFound)); dlg.setMessage(getString(R.string.msgNotFound));
@ -397,18 +411,18 @@ public class DrugListActivity extends AppCompatActivity {
/** /**
* Add New drug to the user database * Add New drug to the user database
* *
* @param aMedic Medic - medication to be added * @param aPrescription Prescription - medication to be added
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void addDrugToList(Medic aMedic) { private void addDrugToList(Prescription aPrescription) {
aMedic.getDateEndOfStock(); aPrescription.getDateEndOfStock();
mAdapter.addItem(aMedic); mAdapter.addItem(aPrescription);
Log.d(TAG, "Call DrugDetailActivity"); Log.d(TAG, "Call DrugDetailActivity");
Context context = this; Context context = this;
Intent intent = new Intent(context, DrugDetailActivity.class); Intent intent = new Intent(context, DrugDetailActivity.class);
intent.putExtra("medic", (Parcelable) aMedic); intent.putExtra("medic", (Parcelable) aPrescription);
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); 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) { private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext())); recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext()));
mAdapter = new SimpleItemRecyclerViewAdapter(medics); mAdapter = new SimpleItemRecyclerViewAdapter(prescriptionList);
recyclerView.setAdapter(mAdapter); recyclerView.setAdapter(mAdapter);
} }
@ -441,19 +455,19 @@ public class DrugListActivity extends AppCompatActivity {
public class SimpleItemRecyclerViewAdapter extends public class SimpleItemRecyclerViewAdapter extends
RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> { RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> {
private final List<Medic> mValues; private final List<Prescription> mValues;
SimpleItemRecyclerViewAdapter(List<Medic> items) { SimpleItemRecyclerViewAdapter(List<Prescription> items) {
mValues = items; mValues = items;
} }
void addItem(Medic scannedMedic) { void addItem(Prescription scannedPrescription) {
MedicDAO medicDAO = prescriptions.getMedicDAO(); PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
if (medicDAO.getMedicByCIP13(scannedMedic.getCip13()) == null) { if (prescriptionsDAO.getMedicByCIP13(scannedPrescription.getCip13()) == null) {
mValues.add(scannedMedic); mValues.add(scannedPrescription);
//notifyDataSetChanged(); //notifyDataSetChanged();
notifyItemInserted(mValues.size()); notifyItemInserted(mValues.size());
medicDAO.insert(scannedMedic); prescriptionsDAO.insert(scannedPrescription);
} else { } else {
Toast.makeText(getApplicationContext(), "already in the database", Toast.LENGTH_LONG).show(); 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() { holder.mView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Medic aMedic = mValues.get(position); Prescription aPrescription = mValues.get(position);
Context context = v.getContext(); Context context = v.getContext();
Intent intent = new Intent(context, DrugDetailActivity.class); Intent intent = new Intent(context, DrugDetailActivity.class);
intent.putExtra("medic", (Parcelable) aMedic); intent.putExtra("medic", (Parcelable) aPrescription);
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); 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() { holder.mView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Medic medic = mValues.get(position); Prescription prescription = mValues.get(position);
Context context = v.getContext(); Context context = v.getContext();
Intent intent = new Intent(context, DrugDetailActivity.class); Intent intent = new Intent(context, DrugDetailActivity.class);
intent.putExtra("medic", medic); intent.putExtra("prescription", prescription);
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); 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 mContentView;
final TextView mEndOfStock; final TextView mEndOfStock;
final ImageView mIconView; final ImageView mIconView;
public Medic mItem; public Prescription mItem;
ViewHolder(View view) { ViewHolder(View view) {
super(view); super(view);

View file

@ -4,18 +4,18 @@ import androidx.room.AutoMigration;
import androidx.room.Database; import androidx.room.Database;
import androidx.room.RoomDatabase; import androidx.room.RoomDatabase;
import net.foucry.pilldroid.dao.MedicDAO; import net.foucry.pilldroid.dao.PrescriptionsDAO;
import net.foucry.pilldroid.models.Medic; import net.foucry.pilldroid.models.Prescription;
@Database( @Database(
version = 3, version = 3,
entities = {Medic.class}, entities = {Prescription.class},
autoMigrations = { autoMigrations = {
@AutoMigration(from = 1, to = 2), @AutoMigration(from = 1, to = 2),
@AutoMigration(from = 2, to = 3), @AutoMigration(from = 2, to = 3),
} }
) )
public abstract class PilldroidDatabase extends RoomDatabase { public abstract class PrescriptionDatabase extends RoomDatabase {
public abstract MedicDAO getMedicDAO(); public abstract PrescriptionsDAO getPrescriptionsDAO();
} }

View file

@ -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();
}

View file

@ -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();
}

View file

@ -10,16 +10,16 @@ import java.io.Serializable;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
@Entity(tableName = "medics") @Entity(tableName = "prescriptions")
public class Medic implements Serializable { public class Prescription implements Serializable {
@PrimaryKey @PrimaryKey
@NonNull private String cis; @NonNull private String cis;
private String cip13; private String cip13;
private String name; private String name;
private String administration_mode; private String administration_mode;
private String presentation; private String presentation;
private Float stock; private Float stock;
private Float take; private Float take;
private Integer warning; private Integer warning;
private Integer alert; private Integer alert;
private Long last_update; private Long last_update;

View file

@ -9,8 +9,8 @@ I made a lot a tests but there must stay some bugs.
find the code. find the code.
## What is not implemented ## What is not implemented
- removing of a medic from the list; - removing of a prescription from the list;
- take medic reminder. It will be never been implemented (by me). - take prescription reminder. It will be never been implemented (by me).
**ATTENTION**, Pilldroid does not manage creams, liquids **ATTENTION**, Pilldroid does not manage creams, liquids
(like insulin). (like insulin).

View file

@ -1,13 +1,13 @@
<<<<<<< HEAD <<<<<<< 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. only.
<strong>Why for french people only?</strong> <strong>Why for french people only?</strong>
<p>Pilldroid use a medics databases that come from French government website, with <p>Pilldroid use a prescriptions databases that come from French government website, with
<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. 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> Sociale).</p>
<strong>What is the Pilldroid's license?</strong> <strong>What is the Pilldroid's license?</strong>