Add Medicine Room access

This commit is contained in:
jacques 2022-03-16 17:08:38 +01:00
parent dcff425d9e
commit a40dd5fe20
3 changed files with 127 additions and 0 deletions

View file

@ -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<Medicine> getAllMedicines();
@Query("SELECT * FROM medicines WHERE cip13 = :cip13")
Medicine getMedicineByCIP13(String cip13);
@Query("SELECT count(*) FROM medicines")
int getMedicineCount();
}

View file

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

View file

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