diff --git a/app/src/main/java/net/foucry/pilldroid/DBDrugs.java b/app/src/main/java/net/foucry/pilldroid/DBDrugs.java
index 73ce1c5..1ff6a2a 100644
--- a/app/src/main/java/net/foucry/pilldroid/DBDrugs.java
+++ b/app/src/main/java/net/foucry/pilldroid/DBDrugs.java
@@ -2,6 +2,7 @@ package net.foucry.pilldroid;
import android.content.Context;
import android.database.Cursor;
+import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
@@ -27,11 +28,12 @@ class DBDrugs extends SQLiteOpenHelper {
private static final String TABLE_NAME = "drugs";
private static final String DRUG_CIS = "cis";
private static final String DRUG_CIP13 = "cip13";
+ private static final String DRUG_CIP7 = "cip7";
private static final String DRUG_ADMIN = "administration_mode";
private static final String DRUG_NAME = "name";
private static final String DRUG_PRES = "presentation";
- private static final String[] COLUMNS_NAMES = {DRUG_CIS, DRUG_CIP13, DRUG_ADMIN, DRUG_NAME, DRUG_PRES};
+ private static final String[] COLUMNS_NAMES = {DRUG_CIS, DRUG_CIP13, DRUG_CIP7, DRUG_ADMIN, DRUG_NAME, DRUG_PRES};
private static final String TAG = DBDrugs.class.getName();
@@ -141,9 +143,9 @@ class DBDrugs extends SQLiteOpenHelper {
// drug.setId(Integer.parseInt(cursor.getString(0)));
drug.setCis(cursor.getString(0));
drug.setCip13(cursor.getString(1));
- drug.setAdministration_mode(cursor.getString(2));
- drug.setName(cursor.getString(3));
- drug.setPresentation(cursor.getString(4));
+ drug.setAdministration_mode(cursor.getString(3));
+ drug.setName(cursor.getString(4));
+ drug.setPresentation(cursor.getString(5));
// Set default values
drug.setStock(0);
@@ -161,4 +163,72 @@ class DBDrugs extends SQLiteOpenHelper {
} else
return null;
}
+
+ String getCIP13FromCIP7(String cip7) {
+
+ String cip13 = null;
+
+ try {
+ Cursor c = this.getReadableDatabase().rawQuery("SELECT cip13 FROM "+ TABLE_NAME + " where cip7 = "+cip7, null);
+
+ Log.d(TAG, "Cursor == " + DatabaseUtils.dumpCursorToString(c));
+
+ c.moveToFirst();
+
+ if(c.getCount()>0)
+ {
+ cip13 = c.getString(0);
+ }
+ c.close();
+ } catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ return cip13;
+ }
+
+ Drug getDrugByCIP7(String cip7) {
+ Log.d(TAG, "CIP7 - " + cip7);
+
+ SQLiteDatabase db = this.getReadableDatabase();
+
+ // Build query
+ Cursor cursor = db.query(TABLE_NAME, // Which table
+ COLUMNS_NAMES, // column names
+ " cip7 =?", // selections
+ new String[]{cip7}, // selections args
+ null, // group by
+ null, // having
+ null, // order by
+ null); // limits
+ //Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NAME + " where cip13 = " + cip13, null);
+ if (cursor.getCount() != 0) {
+
+ cursor.moveToFirst();
+
+ // Build drug object
+ Drug drug = new Drug();
+ // drug.setId(Integer.parseInt(cursor.getString(0)));
+ drug.setCis(cursor.getString(0));
+ drug.setCip13(cursor.getString(1));
+ drug.setAdministration_mode(cursor.getString(3));
+ drug.setName(cursor.getString(4));
+ drug.setPresentation(cursor.getString(5));
+
+ // Set default values
+ drug.setStock(0);
+ drug.setTake(0);
+ drug.setWarnThreshold(14);
+ drug.setAlertThreshold(7);
+
+ // Log
+ Log.d(TAG, "getDrug(" + cip7 + ")" + drug.toString());
+
+ // Return drug
+
+ cursor.close();
+ return drug;
+ } else
+ return null;
+ }
}
diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java
index a0ae8f6..343fa98 100644
--- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java
+++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java
@@ -274,10 +274,20 @@ public class DrugListActivity extends AppCompatActivity {
Log.d(TAG, "formatName = " + result.getFormatName());
- if (result.getFormatName().equals("CODE_128") || (result.getFormatName().equals("EAN_13"))) { //CODE_128 || EAN 13
- cip13 = result.getContents();
- } else {
- cip13 = result.getContents().substring(4, 17);
+ switch (result.getFormatName()) {
+ case "CODE_128":
+ case "EAN_13": //CODE_128 || EAN 13
+ cip13 = result.getContents();
+ break;
+ case "CODE_39":
+ cip13 = dbDrug.getCIP13FromCIP7(result.getContents());
+ break;
+ case "DATA_MATRIX":
+ cip13 = result.getContents().substring(4, 17);
+ break;
+ default:
+ scanNotOK();
+ return;
}
// Get Drug from database
@@ -362,6 +372,21 @@ public class DrugListActivity extends AppCompatActivity {
dlg.show();
}
+ /**
+ * Tell user that the barre code cannot be interpreted
+ */
+ private void scanNotOK()
+ {
+ AlertDialog.Builder dlg = new AlertDialog.Builder(this);
+ dlg.setTitle(getString(R.string.app_name));
+
+ dlg.setMessage(R.string.notInterpreted);
+ dlg.setPositiveButton("OK", (dialog, which) -> {
+ // Nothing to do just dismiss dialog
+ });
+ dlg.show();
+ }
+
/**
* Add New drug to the user database
* @param aDrug Drug - drug to be added
@@ -378,7 +403,6 @@ public class DrugListActivity extends AppCompatActivity {
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
}
-
/**
* setupRecyclerView (list of drugs
* @param recyclerView RecyclerView
@@ -389,7 +413,6 @@ public class DrugListActivity extends AppCompatActivity {
recyclerView.setAdapter(mAdapter);
}
- // TODO: remove in release
private String getAppName() {
PackageManager packageManager = getApplicationContext().getPackageManager();
ApplicationInfo applicationInfo = null;
diff --git a/app/src/main/res/values-fr-rFR/strings.xml b/app/src/main/res/values-fr-rFR/strings.xml
index 1a0278c..80fb7dd6 100644
--- a/app/src/main/res/values-fr-rFR/strings.xml
+++ b/app/src/main/res/values-fr-rFR/strings.xml
@@ -63,4 +63,5 @@
Valeur
Libellé
Attributs d\'un médicament
+ Le code barre ne peut pas être interprété
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9f45b27..63b85e2 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -65,4 +65,5 @@
Value
Label
Drug\'s attributes
+ Barre code cannot be intrepreted