mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
Use new Medic object for both presciptions (the list of medications user take, and medications, the complete database;
Need a migration between version 1 an 2 of the database schema
This commit is contained in:
parent
35085f19c7
commit
9fa217d587
7 changed files with 241 additions and 104 deletions
88
app/schemas/net.foucry.pilldroid.PilldroidDatabase/2.json
Normal file
88
app/schemas/net.foucry.pilldroid.PilldroidDatabase/2.json
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 2,
|
||||||
|
"identityHash": "ed6d0a13273d73ba9fcec1f374251efa",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "medics",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`cis` TEXT NOT NULL, `cip13` TEXT, `name` TEXT, `administration_mode` TEXT, `presentation` TEXT, `stock` REAL, `take` REAL, `warning` INTEGER, `alert` INTEGER, `last_update` INTEGER, PRIMARY KEY(`cis`))",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "cis",
|
||||||
|
"columnName": "cis",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "cip13",
|
||||||
|
"columnName": "cip13",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "name",
|
||||||
|
"columnName": "name",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "administration_mode",
|
||||||
|
"columnName": "administration_mode",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "presentation",
|
||||||
|
"columnName": "presentation",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "stock",
|
||||||
|
"columnName": "stock",
|
||||||
|
"affinity": "REAL",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "take",
|
||||||
|
"columnName": "take",
|
||||||
|
"affinity": "REAL",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "warning",
|
||||||
|
"columnName": "warning",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "alert",
|
||||||
|
"columnName": "alert",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "last_update",
|
||||||
|
"columnName": "last_update",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"cis"
|
||||||
|
],
|
||||||
|
"autoGenerate": false
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"views": [],
|
||||||
|
"setupQueries": [
|
||||||
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ed6d0a13273d73ba9fcec1f374251efa')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,9 @@ import java.util.Date;
|
||||||
|
|
||||||
import static net.foucry.pilldroid.R.id.detail_toolbar;
|
import static net.foucry.pilldroid.R.id.detail_toolbar;
|
||||||
|
|
||||||
|
import net.foucry.pilldroid.dao.MedicDAO;
|
||||||
|
import net.foucry.pilldroid.models.Medic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An activity representing a single Drug detail screen. This
|
* An activity representing a single Drug detail screen. This
|
||||||
* activity is only used narrow width devices. On tablet-size devices,
|
* activity is only used narrow width devices. On tablet-size devices,
|
||||||
|
@ -27,7 +30,7 @@ public class DrugDetailActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private static final String TAG = DrugDetailActivity.class.getName();
|
private static final String TAG = DrugDetailActivity.class.getName();
|
||||||
|
|
||||||
Drug drug;
|
Medic aMedic;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -38,10 +41,10 @@ public class DrugDetailActivity extends AppCompatActivity {
|
||||||
/* fetching the string passed with intent using ‘extras’*/
|
/* fetching the string passed with intent using ‘extras’*/
|
||||||
|
|
||||||
assert bundle != null;
|
assert bundle != null;
|
||||||
drug = (Drug) bundle.getSerializable("drug");
|
aMedic = (Medic) bundle.getSerializable("medic");
|
||||||
|
|
||||||
assert drug != null;
|
assert aMedic != null;
|
||||||
Log.d(TAG, "drug == " + drug);
|
Log.d(TAG, "aMedic == " + aMedic);
|
||||||
|
|
||||||
/* fetching the string passed with intent using ‘bundle’*/
|
/* fetching the string passed with intent using ‘bundle’*/
|
||||||
|
|
||||||
|
@ -69,7 +72,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(drug.getName());
|
actionBar.setTitle(aMedic.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// savedInstanceState is non-null when there is fragment state
|
// savedInstanceState is non-null when there is fragment state
|
||||||
|
@ -114,9 +117,12 @@ 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;
|
||||||
DBHelper dbHelper = new DBHelper(this);
|
DBHelper dbHelper = new DBHelper(this);
|
||||||
|
assert false;
|
||||||
|
MedicDAO medicDAO = prescriptions.getMedicDAO();
|
||||||
|
|
||||||
Drug newDrug = dbHelper.getDrugByCIP13(drug.getCip13());
|
Medic newMedic = medicDAO.getMedicByCIP13(aMedic.getCip13());
|
||||||
|
|
||||||
View stockView;
|
View stockView;
|
||||||
View takeView;
|
View takeView;
|
||||||
|
@ -139,18 +145,19 @@ 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();
|
||||||
|
|
||||||
newDrug.setStock(Double.parseDouble(stockValue));
|
newMedic.setStock(Double.parseDouble(stockValue));
|
||||||
newDrug.setTake(Double.parseDouble(takeValue));
|
newMedic.setTake(Double.parseDouble(takeValue));
|
||||||
newDrug.setWarnThreshold(Integer.parseInt(warningValue));
|
newMedic.setWarning(Integer.parseInt(warningValue));
|
||||||
newDrug.setAlertThreshold(Integer.parseInt(alertValue));
|
newMedic.setAlert(Integer.parseInt(alertValue));
|
||||||
newDrug.setDateEndOfStock();
|
newMedic.getDateEndOfStock();
|
||||||
|
|
||||||
if (drug.equals(newDrug)) {
|
if (aMedic.equals(newMedic)) {
|
||||||
Log.d(TAG, "drug and newDrug are Equals");
|
Log.d(TAG, "medic and newMedic are Equals");
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "drug and newDrug are NOT Equals");
|
Log.d(TAG, "medic and newMedic are NOT Equals");
|
||||||
newDrug.setDateLastUpdate(new Date().getTime());
|
newMedic.setLast_update(new Date().getTime());
|
||||||
dbHelper.updateDrug(newDrug);
|
medicDAO.update(newMedic);
|
||||||
|
//dbHelper.updateDrug(newDrug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ 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.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Parcelable;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -52,12 +53,7 @@ import net.foucry.pilldroid.models.Medic;
|
||||||
* item details side-by-side using two vertical panes.
|
* item details side-by-side using two vertical panes.
|
||||||
*/
|
*/
|
||||||
public class DrugListActivity extends AppCompatActivity {
|
public class DrugListActivity extends AppCompatActivity {
|
||||||
/**
|
// Used for dev and debug
|
||||||
* Whether or not the activity is in two-pane mode, i.e. running on a tablet
|
|
||||||
* device.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO: Change DEMO/DBDEMO form static to non-static. In order to create fake data at only at launch time
|
|
||||||
final Boolean DEMO = true;
|
final Boolean DEMO = true;
|
||||||
final Boolean DBDEMO = false;
|
final Boolean DBDEMO = false;
|
||||||
|
|
||||||
|
@ -66,24 +62,34 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
public final String BARCODE_CONTENT = "Barcode Content";
|
public final String BARCODE_CONTENT = "Barcode Content";
|
||||||
|
|
||||||
private ActivityResultLauncher<ScanOptions> mBarcodeScannerLauncher;
|
private ActivityResultLauncher<ScanOptions> mBarcodeScannerLauncher;
|
||||||
|
private static final String TAG = DrugListActivity.class.getName();
|
||||||
|
|
||||||
|
private DBHelper dbHelper;
|
||||||
|
private DBDrugs dbDrug;
|
||||||
|
public PilldroidDatabase prescriptions;
|
||||||
|
public PilldroidDatabase medications;
|
||||||
|
|
||||||
/**
|
private List<Medic> medics; // used for prescriptions
|
||||||
* Start tutorial
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
private SimpleItemRecyclerViewAdapter mAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
|
||||||
|
medications = Room
|
||||||
|
.databaseBuilder(getApplicationContext(), PilldroidDatabase.class, "medications")
|
||||||
|
.createFromAsset("drugs.db")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// remove old notification
|
||||||
Log.d(TAG, "Remove old notification and old job");
|
Log.d(TAG, "Remove old notification and old job");
|
||||||
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
if (nm != null) {
|
if (nm != null) {
|
||||||
nm.cancelAll();
|
nm.cancelAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
// tutorial
|
// start tutorial
|
||||||
Log.i(TAG, "Launch tutorial");
|
Log.i(TAG, "Launch tutorial");
|
||||||
startActivity(new Intent(this, WelcomeActivity.class));
|
startActivity(new Intent(this, WelcomeActivity.class));
|
||||||
}
|
}
|
||||||
|
@ -93,37 +99,13 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String TAG = DrugListActivity.class.getName();
|
|
||||||
|
|
||||||
private DBHelper dbHelper;
|
|
||||||
private DBDrugs dbDrug;
|
|
||||||
|
|
||||||
private List<Drug> drugs;
|
|
||||||
|
|
||||||
private SimpleItemRecyclerViewAdapter mAdapter;
|
|
||||||
|
|
||||||
public void constructDrugsList() {
|
|
||||||
dbHelper = new DBHelper(getApplicationContext());
|
|
||||||
|
|
||||||
if (!(drugs == null)) {
|
|
||||||
if (!drugs.isEmpty()) {
|
|
||||||
drugs.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
drugs = dbHelper.getAllDrugs();
|
|
||||||
|
|
||||||
View mRecyclerView = findViewById(R.id.drug_list);
|
|
||||||
assert mRecyclerView != null;
|
|
||||||
setupRecyclerView((RecyclerView) mRecyclerView);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// Create Room database
|
// Create Room database
|
||||||
PilldroidDatabase prescription = Room
|
prescriptions = Room
|
||||||
.databaseBuilder(getApplicationContext(), PilldroidDatabase.class, "prescriptions")
|
.databaseBuilder(getApplicationContext(), PilldroidDatabase.class, "prescriptions")
|
||||||
.allowMainThreadQueries()
|
.allowMainThreadQueries()
|
||||||
.build();
|
.build();
|
||||||
|
@ -147,7 +129,7 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DEMO) {
|
if (DEMO) {
|
||||||
MedicDAO medicDAO = prescription.getMedicDAO();
|
MedicDAO medicDAO = prescriptions.getMedicDAO();
|
||||||
|
|
||||||
final int min_stock = 5;
|
final int min_stock = 5;
|
||||||
final int max_stock = 50;
|
final int max_stock = 50;
|
||||||
|
@ -161,16 +143,17 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
medic.setCis("6000001" + i);
|
medic.setCis("6000001" + i);
|
||||||
medic.setAdministration_mode("oral");
|
medic.setAdministration_mode("oral");
|
||||||
medic.setPresentation("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)");
|
medic.setPresentation("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)");
|
||||||
medic.setStock((long) intRandomExclusive(min_stock, max_stock));
|
medic.setStock((double) intRandomExclusive(min_stock, max_stock));
|
||||||
medic.setTake((long) intRandomExclusive(min_take, max_take));
|
medic.setTake((double) intRandomExclusive(min_take, max_take));
|
||||||
medic.setWarning(14);
|
medic.setWarning(14);
|
||||||
medic.setAlert(7);
|
medic.setAlert(7);
|
||||||
medic.setLast_update(UtilDate.dateAtNoon(new Date()).getTime());
|
medic.setLast_update(UtilDate.dateAtNoon(new Date()).getTime());
|
||||||
|
|
||||||
medicDAO.insertAll(medic);
|
medicDAO.insert(medic);
|
||||||
}
|
}
|
||||||
List<Medic> prescriptions = medicDAO.getMedics();
|
List<Medic> prescriptions = medicDAO.getAllMedics();
|
||||||
System.out.println(prescriptions);
|
System.out.println(prescriptions);
|
||||||
|
Log.d(TAG, "prescriptions ==" + prescriptions);
|
||||||
/*
|
/*
|
||||||
if (dbHelper.getCount() == 0) {
|
if (dbHelper.getCount() == 0) {
|
||||||
|
|
||||||
|
@ -269,10 +252,12 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Drug from database
|
// Get Drug from database
|
||||||
final Drug scannedDrug = dbDrug.getDrugByCIP13(cip13);
|
//final Drug scannedDrug = dbDrug.getDrugByCIP13(cip13);
|
||||||
|
MedicDAO medicationDAO = medications.getMedicDAO();
|
||||||
|
final Medic scannedMedication = medicationDAO.getMedicByCIP13(cip13);
|
||||||
|
|
||||||
// add Drug to prescription database
|
// add Drug to prescription database
|
||||||
askToAddInDB(scannedDrug);
|
askToAddInDB(scannedMedication);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,6 +266,24 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
constructDrugsList();
|
constructDrugsList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void constructDrugsList() {
|
||||||
|
|
||||||
|
MedicDAO medicDAO = prescriptions.getMedicDAO();
|
||||||
|
medics = medicDAO.getAllMedics();
|
||||||
|
|
||||||
|
/*dbHelper = new DBHelper(getApplicationContext());
|
||||||
|
|
||||||
|
if (!(drugs == null)) {
|
||||||
|
if (!drugs.isEmpty()) {
|
||||||
|
drugs.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
drugs = dbHelper.getAllDrugs();*/
|
||||||
|
|
||||||
|
View mRecyclerView = findViewById(R.id.drug_list);
|
||||||
|
assert mRecyclerView != null;
|
||||||
|
setupRecyclerView((RecyclerView) mRecyclerView);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
|
@ -369,8 +372,10 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
.setPositiveButton("OK", (dialog, id) -> {
|
.setPositiveButton("OK", (dialog, id) -> {
|
||||||
String cip13 = editText.getText().toString();
|
String cip13 = editText.getText().toString();
|
||||||
|
|
||||||
Drug aDrug = dbDrug.getDrugByCIP13(cip13);
|
MedicDAO medicationsDAO = medications.getMedicDAO();
|
||||||
askToAddInDB(aDrug);
|
Medic aMedic = medicationsDAO.getMedicByCIP13(cip13);
|
||||||
|
//Medic aMedic = medications.getDrugByCIP13(cip13);
|
||||||
|
askToAddInDB(aMedic);
|
||||||
})
|
})
|
||||||
.setNegativeButton("Cancel",
|
.setNegativeButton("Cancel",
|
||||||
(dialog, id) -> dialog.cancel());
|
(dialog, id) -> dialog.cancel());
|
||||||
|
@ -401,14 +406,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 aDrug Drug- drug to be added
|
* @param aMedic Medic- medication to be added
|
||||||
*/
|
*/
|
||||||
private void askToAddInDB(Drug aDrug) {
|
private void askToAddInDB(Medic aMedic) {
|
||||||
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 (aDrug != null) {
|
if (aMedic != null) {
|
||||||
String msg = aDrug.getName() + " " + getString(R.string.msgFound);
|
String msg = aMedic.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) -> {
|
||||||
|
@ -416,7 +421,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(aDrug);
|
addDrugToList(aMedic);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
dlg.setMessage(getString(R.string.msgNotFound));
|
dlg.setMessage(getString(R.string.msgNotFound));
|
||||||
|
@ -444,18 +449,18 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
/**
|
/**
|
||||||
* Add New drug to the user database
|
* Add New drug to the user database
|
||||||
*
|
*
|
||||||
* @param aDrug Drug - drug to be added
|
* @param aMedic Medic - medication to be added
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private void addDrugToList(Drug aDrug) {
|
private void addDrugToList(Medic aMedic) {
|
||||||
aDrug.setDateEndOfStock();
|
aMedic.getDateEndOfStock();
|
||||||
mAdapter.addItem(aDrug);
|
mAdapter.addItem(aMedic);
|
||||||
|
|
||||||
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("drug", aDrug);
|
intent.putExtra("medic", (Parcelable) aMedic);
|
||||||
|
|
||||||
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);
|
||||||
|
@ -478,27 +483,29 @@ 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(drugs);
|
mAdapter = new SimpleItemRecyclerViewAdapter(medics);
|
||||||
recyclerView.setAdapter(mAdapter);
|
recyclerView.setAdapter(mAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SimpleItemRecyclerViewAdapter
|
* SimpleItemRecyclerViewAdapter
|
||||||
*/
|
*/
|
||||||
public class SimpleItemRecyclerViewAdapter extends RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> {
|
public class SimpleItemRecyclerViewAdapter extends
|
||||||
|
RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> {
|
||||||
|
|
||||||
private final List<Drug> mValues;
|
private final List<Medic> mValues;
|
||||||
|
|
||||||
SimpleItemRecyclerViewAdapter(List<Drug> items) {
|
SimpleItemRecyclerViewAdapter(List<Medic> items) {
|
||||||
mValues = items;
|
mValues = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addItem(Drug scannedDrug) {
|
void addItem(Medic scannedMedic) {
|
||||||
if (!dbHelper.isDrugExist(scannedDrug.getCip13())) {
|
MedicDAO medicDAO = prescriptions.getMedicDAO();
|
||||||
mValues.add(scannedDrug);
|
if (medicDAO.getMedicByCIP13(scannedMedic.getCip13()) == null) {
|
||||||
|
mValues.add(scannedMedic);
|
||||||
//notifyDataSetChanged();
|
//notifyDataSetChanged();
|
||||||
notifyItemInserted(mValues.size());
|
notifyItemInserted(mValues.size());
|
||||||
dbHelper.addDrug(scannedDrug);
|
medicDAO.insert(scannedMedic);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getApplicationContext(), "already in the database", Toast.LENGTH_LONG).show();
|
Toast.makeText(getApplicationContext(), "already in the database", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
@ -539,10 +546,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) {
|
||||||
Drug drug = mValues.get(position);
|
Medic aMedic = 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("drug", drug);
|
intent.putExtra("medic", (Parcelable) aMedic);
|
||||||
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);
|
||||||
|
|
||||||
|
@ -565,10 +572,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) {
|
||||||
Drug drug = mValues.get(position);
|
Medic medic = 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("drug", drug);
|
intent.putExtra("medic", (Parcelable) medic);
|
||||||
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);
|
||||||
|
|
||||||
|
@ -588,7 +595,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 Drug mItem;
|
public Medic mItem;
|
||||||
|
|
||||||
ViewHolder(View view) {
|
ViewHolder(View view) {
|
||||||
super(view);
|
super(view);
|
||||||
|
|
|
@ -6,7 +6,7 @@ import androidx.room.RoomDatabase;
|
||||||
import net.foucry.pilldroid.dao.MedicDAO;
|
import net.foucry.pilldroid.dao.MedicDAO;
|
||||||
import net.foucry.pilldroid.models.Medic;
|
import net.foucry.pilldroid.models.Medic;
|
||||||
|
|
||||||
@Database(entities = {Medic.class}, version = 1)
|
@Database(entities = {Medic.class}, version = 2)
|
||||||
|
|
||||||
public abstract class PilldroidDatabase extends RoomDatabase {
|
public abstract class PilldroidDatabase extends RoomDatabase {
|
||||||
public abstract MedicDAO getMedicDAO();
|
public abstract MedicDAO getMedicDAO();
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.util.Locale;
|
||||||
/**
|
/**
|
||||||
* Created by jacques on 05/05/16.
|
* Created by jacques on 05/05/16.
|
||||||
*/
|
*/
|
||||||
class UtilDate {
|
public class UtilDate {
|
||||||
|
|
||||||
private static final String TAG = UtilDate.class.getName();
|
private static final String TAG = UtilDate.class.getName();
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class UtilDate {
|
||||||
* @return date the same date as input but at noon (12:00:00 PM)
|
* @return date the same date as input but at noon (12:00:00 PM)
|
||||||
* set date time at Noon
|
* set date time at Noon
|
||||||
*/
|
*/
|
||||||
static Date dateAtNoon(Date aDate) {
|
public static Date dateAtNoon(Date aDate) {
|
||||||
|
|
||||||
Log.d(TAG, "dateAtNoon " + aDate);
|
Log.d(TAG, "dateAtNoon " + aDate);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package net.foucry.pilldroid.dao;
|
package net.foucry.pilldroid.dao;
|
||||||
|
|
||||||
|
import static net.foucry.pilldroid.UtilDate.dateAtNoon;
|
||||||
|
|
||||||
import androidx.room.Dao;
|
import androidx.room.Dao;
|
||||||
import androidx.room.Delete;
|
import androidx.room.Delete;
|
||||||
import androidx.room.Insert;
|
import androidx.room.Insert;
|
||||||
|
@ -8,12 +10,15 @@ import androidx.room.Update;
|
||||||
|
|
||||||
import net.foucry.pilldroid.models.Medic;
|
import net.foucry.pilldroid.models.Medic;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
public interface MedicDAO {
|
public interface MedicDAO {
|
||||||
@Insert
|
@Insert
|
||||||
void insertAll(Medic... medics);
|
void insert(Medic... medics);
|
||||||
|
|
||||||
|
|
||||||
@Update
|
@Update
|
||||||
void update(Medic... medics);
|
void update(Medic... medics);
|
||||||
|
@ -23,7 +28,7 @@ public interface MedicDAO {
|
||||||
|
|
||||||
|
|
||||||
@Query("SELECT * FROM medics")
|
@Query("SELECT * FROM medics")
|
||||||
List<Medic> getMedics();
|
List<Medic> getAllMedics();
|
||||||
|
|
||||||
/* @Query("SELECT * FROM medics WHERE id = :id")
|
/* @Query("SELECT * FROM medics WHERE id = :id")
|
||||||
Medic getMedicBy(Long id);*/
|
Medic getMedicBy(Long id);*/
|
||||||
|
@ -34,3 +39,5 @@ public interface MedicDAO {
|
||||||
@Query("SELECT count(*) FROM medics")
|
@Query("SELECT count(*) FROM medics")
|
||||||
int getMedicCount();
|
int getMedicCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
package net.foucry.pilldroid.models;
|
package net.foucry.pilldroid.models;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.room.Entity;
|
import androidx.room.Entity;
|
||||||
import androidx.room.PrimaryKey;
|
import androidx.room.PrimaryKey;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
import net.foucry.pilldroid.UtilDate;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
@Entity(tableName = "medics")
|
@Entity(tableName = "medics")
|
||||||
public class Medic {
|
public class Medic {
|
||||||
|
@ -12,8 +17,8 @@ public class Medic {
|
||||||
private String name;
|
private String name;
|
||||||
private String administration_mode;
|
private String administration_mode;
|
||||||
private String presentation;
|
private String presentation;
|
||||||
private Long stock;
|
private Double stock;
|
||||||
private Long take;
|
private Double take;
|
||||||
private Integer warning;
|
private Integer warning;
|
||||||
private Integer alert;
|
private Integer alert;
|
||||||
private Long last_update;
|
private Long last_update;
|
||||||
|
@ -28,7 +33,6 @@ public class Medic {
|
||||||
this.cis = cis;
|
this.cis = cis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setCip13(String cip13) {
|
public void setCip13(String cip13) {
|
||||||
this.cip13 = cip13;
|
this.cip13 = cip13;
|
||||||
}
|
}
|
||||||
|
@ -37,31 +41,30 @@ public class Medic {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAdministration_mode(String administration_mode) {
|
public void setAdministration_mode(String administration_mode) {
|
||||||
|
|
||||||
this.administration_mode = administration_mode;
|
this.administration_mode = administration_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPresentation(String presentation) {
|
public void setPresentation(String presentation) {
|
||||||
this.presentation = presentation;
|
this.presentation = presentation;
|
||||||
}
|
}
|
||||||
public void setStock(Long stock) {
|
public void setStock(Double stock) {
|
||||||
this.stock = stock;
|
this.stock = stock;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTake(Long take) {
|
public void setTake(Double take) {
|
||||||
this.take = take;
|
this.take = take;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWarning(Integer warning) {
|
public void setWarning(Integer warning) {
|
||||||
this.warning = warning;
|
this.warning = warning;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAlert(Integer alert) {
|
public void setAlert(Integer alert) {
|
||||||
this.alert = alert;
|
this.alert = alert;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLast_update(Long last_update) {
|
public void setLast_update(Long last_update) {
|
||||||
this.last_update = last_update;
|
this.last_update = last_update;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +73,8 @@ public void setLast_update(Long last_update) {
|
||||||
return this.id;
|
return this.id;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
public String getCis() {
|
@NonNull
|
||||||
|
public String getCis() {
|
||||||
return this.cis;
|
return this.cis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,11 +98,11 @@ public String getCis() {
|
||||||
return presentation;
|
return presentation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getStock() {
|
public Double getStock() {
|
||||||
return stock;
|
return stock;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getTake() {
|
public Double getTake() {
|
||||||
return take;
|
return take;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +113,30 @@ public String getCis() {
|
||||||
public Long getLast_update() {
|
public Long getLast_update() {
|
||||||
return last_update;
|
return last_update;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getAlertThreshold() {
|
||||||
|
return this.alert;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWarnThreshold() {
|
||||||
|
return this.warning;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDateEndOfStock() {
|
||||||
|
int numberDayOfTake;
|
||||||
|
if (this.getTake() > 0) {
|
||||||
|
numberDayOfTake = (int) Math.floor(this.getStock() / this.getTake());
|
||||||
|
} else {
|
||||||
|
numberDayOfTake = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Date aDate = UtilDate.dateAtNoon(new Date());
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(aDate);
|
||||||
|
calendar.add(Calendar.DAY_OF_YEAR, numberDayOfTake);
|
||||||
|
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue