This commit is contained in:
Roberto Orden Erena
2019-12-15 20:53:51 +01:00
parent 91f6bc396b
commit fbe7b34a32
6 changed files with 113 additions and 259 deletions

View File

@@ -57,9 +57,9 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
if (SessionUtils.getUserType() == UserType.PATIENT) {
LoggedUserTO user = SessionUtils.getloggedOnUser();
// 0. Conseguir el paciente en sesión
PatientTO patient = this.commonServices.findPatientById(Integer.parseInt(user.getId()));
PatientJPA patient = entman.find(PatientJPA.class, user.getId());
// 1. Buscar el médico de familia con ese professionalNumber
FamilyDoctorTO fdoctor = this.commonServices.findFamilyDoctorById(professionalNumber);
FamilyDoctorJPA fdoctor = entman.find(FamilyDoctorJPA.class, professionalNumber);
// 2. Crear un objeto de Question para ese médico desde el paciente en sesión
QuestionJPA question = new QuestionJPA(0, title, message, QuestionStatus.PENDING, patient, fdoctor, null);
// 3. Guardar

View File

@@ -1,69 +0,0 @@
package jpa;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import TO.PatientTO;
import TO.SpecialistDoctorTO;
/**
*
* @author Marcos García Núñez (mgarcianun@uoc.edu)
*
*/
@Entity
@Table(name = "MyHealth.Question")
public class ImageJPA implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String response;
@ManyToOne
@JoinColumn (name="QuestionId")
private PatientTO question;
public ImageJPA() {
}
public ImageJPA(int id, String response, PatientTO question) {
this.id = id;
this.response = response;
this.question = question;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
public PatientTO getQuestion() {
return question;
}
public void setQuestion(PatientTO question) {
this.question = question;
}
}

View File

@@ -3,6 +3,7 @@ package jpa;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@@ -11,16 +12,19 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import TO.PatientTO;
import TO.SpecialistDoctorTO;
/**
* Los nombres de los decortadores relacionados con la BBDD pueden estar
* en camelCase, snakeCase o como se quiera, puesto que en persistence.xml
* se tiene dicho que se convierta a minúsculas.
*
* @author Marcos García Núñez (mgarcianun@uoc.edu)
* Lo uso en minúsculas para mejorar la trazabilidad de los campos.
*
* @author Roberto Orden Erena <rorden@uoc.edu>
*
*/
@Entity
@Table(name = "MyHealth.MedicalTest")
@Table(name = "myhealth.medicaltest")
public class MedicalTestJPA implements Serializable {
private static final long serialVersionUID = 1L;
@@ -32,22 +36,23 @@ public class MedicalTestJPA implements Serializable {
private long time;
private String observations;
private String highresimage;
@Column(name = "type") // Con esto podríamos cambiar los nombres de las propiedades de la clase y mantener la relación con la BBDD a través de JPA
private int type;
@ManyToOne
@JoinColumn (name="PatientId")
private PatientTO patient;
@JoinColumn (name="patientid")
private PatientJPA patient;
@ManyToOne
@JoinColumn (name="SpecialistDoctorId")
private SpecialistDoctorTO specialistDoctor;
@JoinColumn (name="specialistdoctorid")
private SpecialistDoctorJPA specialistDoctor;
public MedicalTestJPA() {
super();
}
public MedicalTestJPA(int id, Date date, long time, String observations, String highresimage, int type,
PatientTO patient, SpecialistDoctorTO specialistDoctor) {
PatientJPA patient, SpecialistDoctorJPA specialistDoctor) {
this.id = id;
this.date = date;
this.time = time;
@@ -106,19 +111,19 @@ public class MedicalTestJPA implements Serializable {
this.type = type;
}
public PatientTO getPatient() {
public PatientJPA getPatient() {
return patient;
}
public void setPatient(PatientTO patient) {
public void setPatient(PatientJPA patient) {
this.patient = patient;
}
public SpecialistDoctorTO getSpecialistDoctor() {
public SpecialistDoctorJPA getSpecialistDoctor() {
return specialistDoctor;
}
public void setSpecialistDoctor(SpecialistDoctorTO specialistDoctor) {
public void setSpecialistDoctor(SpecialistDoctorJPA specialistDoctor) {
this.specialistDoctor = specialistDoctor;
}

View File

@@ -10,13 +10,12 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import TO.FamilyDoctorTO;
import TO.PatientTO;
import common.QuestionStatus;
/**
*
* @author Marcos García Núñez (mgarcianun@uoc.edu)
* @author Roberto Orden Erena <rorden@uoc.edu>
*
*/
@Entity
@@ -34,23 +33,24 @@ public class QuestionJPA implements Serializable {
private String response;
@ManyToOne
@JoinColumn(name = "PatientId")
private PatientTO patient;
@JoinColumn(name = "patientid")
private PatientJPA patient;
@ManyToOne
@JoinColumn(name = "FamilyDoctorId")
private FamilyDoctorTO doctor;
@JoinColumn(name = "familydoctorid")
private FamilyDoctorJPA familydoctor;
public QuestionJPA() {
}
public QuestionJPA(int id, String title, String message, QuestionStatus status, PatientTO patient,
FamilyDoctorTO doctor, String response) {
public QuestionJPA(int id, String title, String message, QuestionStatus status, PatientJPA patient,
FamilyDoctorJPA familydoctor, String response) {
this.id = id;
this.title = title;
this.message = message;
this.status = status;
this.patient = patient;
this.doctor = doctor;
this.familydoctor = familydoctor;
this.response = response;
}
@@ -78,11 +78,11 @@ public class QuestionJPA implements Serializable {
this.message = message;
}
public PatientTO getPatient() {
public PatientJPA getPatient() {
return patient;
}
public void setPatient(PatientTO patient) {
public void setPatient(PatientJPA patient) {
this.patient = patient;
}
@@ -94,12 +94,12 @@ public class QuestionJPA implements Serializable {
this.status = status;
}
public FamilyDoctorTO getDoctor() {
return doctor;
public FamilyDoctorJPA getDoctor() {
return familydoctor;
}
public void setDoctor(FamilyDoctorTO doctor) {
this.doctor = doctor;
public void setDoctor(FamilyDoctorJPA familydoctor) {
this.familydoctor = familydoctor;
}
public String getResponse() {

View File

@@ -1,69 +0,0 @@
package jpa;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import TO.PatientTO;
import TO.SpecialistDoctorTO;
/**
*
* @author Marcos García Núñez (mgarcianun@uoc.edu)
*
*/
@Entity
@Table(name = "MyHealth.Question")
public class ResponseJPA implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String response;
@ManyToOne
@JoinColumn (name="QuestionId")
private PatientTO question;
public ResponseJPA() {
}
public ResponseJPA(int id, String response, PatientTO question) {
this.id = id;
this.response = response;
this.question = question;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
public PatientTO getQuestion() {
return question;
}
public void setQuestion(PatientTO question) {
this.question = question;
}
}

View File

@@ -20,32 +20,33 @@ GRANT ALL ON SCHEMA myhealth TO usrmyhealth;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='administrator') THEN
drop table myhealth.administrator;
end if;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='familydoctor') THEN
drop table myhealth.familydoctor;
end if;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='medicalspecialty') THEN
drop table myhealth.medicalspecialty;
end if;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='medicaltest') THEN
drop table myhealth.medicaltest;
end if;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='patient') THEN
drop table myhealth.patient;
end if;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='primaryhealthcarecenter') THEN
drop table myhealth.primaryhealthcarecenter;
end if;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='question') THEN
drop table myhealth.question;
end if;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='response') THEN
drop table myhealth.response;
end if;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='visit') THEN
drop table myhealth.visit;
end if;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='patient') THEN
drop table myhealth.patient;
end if;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='familydoctor') THEN
drop table myhealth.familydoctor;
end if;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='primaryhealthcarecenter') THEN
drop table myhealth.primaryhealthcarecenter;
end if;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='specialistdoctor') THEN
drop table myhealth.specialistdoctor;
end if;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='visit') THEN
drop table myhealth.visit;
if exists (SELECT 1 FROM pg_tables WHERE schemaname='myhealth' and tablename='medicalspecialty') THEN
drop table myhealth.medicalspecialty;
end if;
/*
@@ -94,6 +95,22 @@ TABLESPACE pg_default;
ALTER TABLE myhealth.administrator
OWNER to "USER";
-- Table: myhealth.primaryhealthcarecenter
-- DROP TABLE myhealth.primaryhealthcarecenter;
CREATE TABLE myhealth.primaryhealthcarecenter
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
name VARCHAR(150) COLLATE pg_catalog."default" NOT NULL,
location VARCHAR(512) COLLATE pg_catalog."default",
CONSTRAINT primaryhealthcarecenter_pkey PRIMARY KEY (id)
)
TABLESPACE pg_default;
ALTER TABLE myhealth.primaryhealthcarecenter
OWNER to "USER";
-- Table: myhealth.familydoctor
-- DROP TABLE myhealth.familydoctor;
@@ -107,7 +124,7 @@ CREATE TABLE myhealth.familydoctor
name VARCHAR(100) NOT NULL COLLATE pg_catalog."default",
surname VARCHAR(100) NOT NULL COLLATE pg_catalog."default",
email VARCHAR(120) COLLATE pg_catalog."default",
primaryhealthcarecenterid integer,
primaryhealthcarecenterid integer REFERENCES myhealth.primaryhealthcarecenter(id) ,
CONSTRAINT familydoctor_pkey PRIMARY KEY (id)
)
TABLESPACE pg_default;
@@ -134,27 +151,6 @@ TABLESPACE pg_default;
ALTER TABLE myhealth.medicalspecialty
OWNER to "USER";
-- Table: myhealth.medicaltest
-- DROP TABLE myhealth.medicaltest;
CREATE TABLE myhealth.medicaltest
(
id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
date date,
"time" abstime,
observations TEXT COLLATE pg_catalog."default",
highresimage bytea,
type INTEGER,
patientid INTEGER NOT NULL,
specialistdoctorid INTEGER NOT NULL,
CONSTRAINT medicaltest_pkey PRIMARY KEY (id)
)
TABLESPACE pg_default;
ALTER TABLE myhealth.medicaltest
OWNER to "USER";
-- Table: myhealth.patient
-- DROP TABLE myhealth.patient;
@@ -168,7 +164,7 @@ CREATE TABLE myhealth.patient
name VARCHAR(100) NOT NULL COLLATE pg_catalog."default",
surname VARCHAR(100) NOT NULL COLLATE pg_catalog."default",
email VARCHAR(120) COLLATE pg_catalog."default",
familydoctorid INTEGER,
familydoctorid INTEGER REFERENCES myhealth.familydoctor(id),
CONSTRAINT patient_pkey PRIMARY KEY (id)
)
TABLESPACE pg_default;
@@ -179,56 +175,6 @@ CREATE UNIQUE INDEX patient_pic_index
ALTER TABLE myhealth.patient
OWNER to "USER";
-- Table: myhealth.primaryhealthcarecenter
-- DROP TABLE myhealth.primaryhealthcarecenter;
CREATE TABLE myhealth.primaryhealthcarecenter
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
name VARCHAR(150) COLLATE pg_catalog."default" NOT NULL,
location VARCHAR(512) COLLATE pg_catalog."default",
CONSTRAINT primaryhealthcarecenter_pkey PRIMARY KEY (id)
)
TABLESPACE pg_default;
ALTER TABLE myhealth.primaryhealthcarecenter
OWNER to "USER";
-- Table: myhealth.question
-- DROP TABLE myhealth.question;
CREATE TABLE myhealth.question
(
id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
title VARCHAR(512) COLLATE pg_catalog."default" NOT NULL,
message TEXT COLLATE pg_catalog."default" NOT NULL,
status INTEGER,
patientid INTEGER NOT NULL,
CONSTRAINT question_pkey PRIMARY KEY (id)
)
TABLESPACE pg_default;
ALTER TABLE myhealth.question
OWNER to "USER";
-- Table: myhealth.response
-- DROP TABLE myhealth.response;
CREATE TABLE myhealth.response
(
id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
response TEXT COLLATE pg_catalog."default",
questionid INTEGER NOT NULL,
CONSTRAINT response_pkey PRIMARY KEY (id)
)
TABLESPACE pg_default;
ALTER TABLE myhealth.response
OWNER to "USER";
-- Table: myhealth.specialistdoctor
-- DROP TABLE myhealth.specialistdoctor;
@@ -242,7 +188,7 @@ CREATE TABLE myhealth.specialistdoctor
name VARCHAR(100) NOT NULL COLLATE pg_catalog."default",
surname VARCHAR(100) NOT NULL COLLATE pg_catalog."default",
email VARCHAR(120) COLLATE pg_catalog."default",
medicalspecialtyid INTEGER,
medicalspecialtyid INTEGER REFERENCES myhealth.medicalspecialty(id),
CONSTRAINT specialistdoctor_pkey PRIMARY KEY (id)
)
TABLESPACE pg_default;
@@ -264,8 +210,8 @@ CREATE TABLE myhealth.visit
"time" abstime NOT NULL,
observations TEXT COLLATE pg_catalog."default",
result TEXT COLLATE pg_catalog."default",
patientid INTEGER NOT NULL,
familydoctorid INTEGER NOT NULL,
patientid INTEGER REFERENCES myhealth.patient(id),
familydoctorid INTEGER REFERENCES myhealth.familydoctor(id),
CONSTRAINT visit_pkey PRIMARY KEY (id)
)
TABLESPACE pg_default;
@@ -273,5 +219,46 @@ TABLESPACE pg_default;
ALTER TABLE myhealth.visit
OWNER to "USER";
-- Table: myhealth.question
-- DROP TABLE myhealth.question;
CREATE TABLE myhealth.question
(
id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
title VARCHAR(512) COLLATE pg_catalog."default" NOT NULL,
message TEXT COLLATE pg_catalog."default" NOT NULL,
status INTEGER,
response TEXT COLLATE pg_catalog."default",
patientid INTEGER REFERENCES myhealth.patient(id),
familydoctorid INTEGER REFERENCES myhealth.familydoctor(id),
CONSTRAINT question_pkey PRIMARY KEY (id)
)
TABLESPACE pg_default;
ALTER TABLE myhealth.question
OWNER to "USER";
-- Table: myhealth.medicaltest
-- DROP TABLE myhealth.medicaltest;
CREATE TABLE myhealth.medicaltest
(
id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
date date,
"time" abstime,
observations TEXT COLLATE pg_catalog."default",
highresimage bytea,
type INTEGER,
patientid INTEGER REFERENCES myhealth.patient(id),
specialistdoctorid INTEGER REFERENCES myhealth.specialistdoctor(id),
CONSTRAINT medicaltest_pkey PRIMARY KEY (id)
)
TABLESPACE pg_default;
ALTER TABLE myhealth.medicaltest
OWNER to "USER";
END;
$$