From a40dd5fe20d51b5a84c4ee7916c135e30bbdfc11 Mon Sep 17 00:00:00 2001 From: jacques Date: Wed, 16 Mar 2022 17:08:38 +0100 Subject: [PATCH] Add Medicine Room access --- .../foucry/pilldroid/dao/MedicinesDAO.java | 20 +++++ .../pilldroid/databases/MedicineDatabase.java | 19 ++++ .../net/foucry/pilldroid/models/Medicine.java | 88 +++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 app/src/main/java/net/foucry/pilldroid/dao/MedicinesDAO.java create mode 100644 app/src/main/java/net/foucry/pilldroid/databases/MedicineDatabase.java create mode 100644 app/src/main/java/net/foucry/pilldroid/models/Medicine.java diff --git a/app/src/main/java/net/foucry/pilldroid/dao/MedicinesDAO.java b/app/src/main/java/net/foucry/pilldroid/dao/MedicinesDAO.java new file mode 100644 index 0000000..7bd987e --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/dao/MedicinesDAO.java @@ -0,0 +1,20 @@ +package net.foucry.pilldroid.dao; + +import androidx.room.Dao; +import androidx.room.Query; + +import net.foucry.pilldroid.models.Medicine; + +import java.util.List; + +@Dao +public interface MedicinesDAO { + @Query("SELECT * FROM medicines") + List getAllMedicines(); + + @Query("SELECT * FROM medicines WHERE cip13 = :cip13") + Medicine getMedicineByCIP13(String cip13); + + @Query("SELECT count(*) FROM medicines") + int getMedicineCount(); +} diff --git a/app/src/main/java/net/foucry/pilldroid/databases/MedicineDatabase.java b/app/src/main/java/net/foucry/pilldroid/databases/MedicineDatabase.java new file mode 100644 index 0000000..e6b463b --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/databases/MedicineDatabase.java @@ -0,0 +1,19 @@ +package net.foucry.pilldroid.databases; + +import androidx.room.AutoMigration; +import androidx.room.Database; +import androidx.room.RoomDatabase; + +import net.foucry.pilldroid.dao.MedicinesDAO; +import net.foucry.pilldroid.dao.PrescriptionsDAO; +import net.foucry.pilldroid.models.Medicine; +import net.foucry.pilldroid.models.Prescription; + +@Database( + version = 1, + entities = {Medicine.class} +) + +public abstract class MedicineDatabase extends RoomDatabase { + public abstract MedicinesDAO getMedicinesDAO(); +} \ No newline at end of file diff --git a/app/src/main/java/net/foucry/pilldroid/models/Medicine.java b/app/src/main/java/net/foucry/pilldroid/models/Medicine.java new file mode 100644 index 0000000..d5ea4e6 --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/models/Medicine.java @@ -0,0 +1,88 @@ +package net.foucry.pilldroid.models; + +import androidx.annotation.NonNull; +import androidx.room.Entity; +import androidx.room.PrimaryKey; + +@Entity(tableName = "medicines") +public class Medicine { + @PrimaryKey + @NonNull + private String cis; + private String cip13; + private String cip7; + private String administration_mode; + private String name; + private String presentation; + private String label_group; + private Integer generic_type; + + public Medicine(@NonNull String cis) { + this.cis = cis; + } + + @NonNull + public String getCis() { + return cis; + } + + public void setCis(@NonNull String cis) { + this.cis = cis; + } + + public String getCip13() { + return cip13; + } + + public void setCip13(String cip13) { + this.cip13 = cip13; + } + + public String getCip7() { + return cip7; + } + + public void setCip7(String cip7) { + this.cip7 = cip7; + } + + public String getAdministration_mode() { + return administration_mode; + } + + public void setAdministration_mode(String administration_mode) { + this.administration_mode = administration_mode; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPresentation() { + return presentation; + } + + public void setPresentation(String presentation) { + this.presentation = presentation; + } + + public String getLabel_group() { + return label_group; + } + + public void setLabel_group(String label_group) { + this.label_group = label_group; + } + + public Integer getGeneric_type() { + return generic_type; + } + + public void setGeneric_type(Integer generic_type) { + this.generic_type = generic_type; + } +}