From a98601c8b08dd716ee3481d8a5f678cd6a2149be Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Mon, 7 Mar 2022 18:19:35 +0100 Subject: [PATCH] Add Room prescription database amangement --- .../net/foucry/pilldroid/MedicDatabase.java | 13 ++++++++ .../net/foucry/pilldroid/dao/MedicDAO.java | 32 +++++++++++++++++++ .../net/foucry/pilldroid/models/Medic.java | 22 +++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 app/src/main/java/net/foucry/pilldroid/MedicDatabase.java create mode 100644 app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java create mode 100644 app/src/main/java/net/foucry/pilldroid/models/Medic.java diff --git a/app/src/main/java/net/foucry/pilldroid/MedicDatabase.java b/app/src/main/java/net/foucry/pilldroid/MedicDatabase.java new file mode 100644 index 0000000..2aaf85c --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/MedicDatabase.java @@ -0,0 +1,13 @@ +package net.foucry.pilldroid; + +import android.arch.persistence.root.Database; +import android.arch.persistence.root.RoomDatabase; + +import net.foucry.pilldroid.dao.MedicDAO; +import net.foucry.pilldroid.model.Medic; + +@Database(entities = {Medic.class}, version = 1) + +public abstract class PilldroidDatabase extends RoomDatabase { + public abstract MedicDAO getMedicDAO(); +} diff --git a/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java new file mode 100644 index 0000000..56b2df5 --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/dao/MedicDAO.java @@ -0,0 +1,32 @@ +package net.foucry.pilldroid.dao; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Delete; +import android.arch.persistence.room.Insert; +import android.arch.persistence.room.Update; +import net.foucry.pilldroid.models.Medic; + +import android.arch.persistence.room.Query; +import java.util.list; + +@Dao +public interface MedicDAO { + @Insert + public void insert(Medic... medics); + @Upfdate + public void update(Medic... medics); + @Delete + public void delete(Medic medic); +} + +@Query("SELECT * FROM medics") +public List getMedics(); + +@Query("SELECT * FROM medics WHERE id = :id") +public Medic getMedicBy(Long id); + +@Query("SELECT * FROM medics WHERE cip13 = :cip13") +public Medic getMedicByCIP13(String cip13); + +@Query("SELECT count(*) FROM medics") +public int getMedicCount(); diff --git a/app/src/main/java/net/foucry/pilldroid/models/Medic.java b/app/src/main/java/net/foucry/pilldroid/models/Medic.java new file mode 100644 index 0000000..3c050fb --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/models/Medic.java @@ -0,0 +1,22 @@ +package net.foucry.pilldroid.models; + +import android.arch.persitence.room.Entity; +import android.arch.persitence.room.PrimaryKey; +import android.support.annotation.NonNull; + +@Entity(tableName = "medics") +public class medic { + @PrimaryKey + @NonNull private Long id; + private String cis; + private String cip13; + private String name; + private String administration_mode; + private String presentation; + private Long stock; + private Long take; + private Int warning; + private Int alert; + private Long last_update; +} +