mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:15:50 +00:00
Allergy and Medication Field Added
This commit is contained in:
parent
bcc66bd187
commit
c8f4706582
6 changed files with 59 additions and 14 deletions
|
@ -63,6 +63,12 @@ public class Kid extends NamedEntity {
|
|||
@ManyToOne
|
||||
@JoinColumn(name = "parent_id")
|
||||
private Parent parent;
|
||||
|
||||
@Column(name = "allergies")
|
||||
private String allergies;
|
||||
|
||||
@Column(name = "medications")
|
||||
private String medications;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "kidId", fetch = FetchType.EAGER)
|
||||
private Set<Visit> visits = new LinkedHashSet<>();
|
||||
|
@ -90,6 +96,22 @@ public class Kid extends NamedEntity {
|
|||
protected void setParent(Parent parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public String getAllergies(){
|
||||
return this.allergies;
|
||||
}
|
||||
|
||||
public void setAllergies(String allergies){
|
||||
this.allergies = allergies;
|
||||
}
|
||||
|
||||
public String getMedications(){
|
||||
return this.medications;
|
||||
}
|
||||
|
||||
public void setMedications(String medications){
|
||||
this.medications = medications;
|
||||
}
|
||||
|
||||
protected Set<Visit> getVisitsInternal() {
|
||||
if (this.visits == null) {
|
||||
|
|
|
@ -36,10 +36,21 @@ public class KidValidator implements Validator {
|
|||
public void validate(Object obj, Errors errors) {
|
||||
Kid kid = (Kid) obj;
|
||||
String name = kid.getName();
|
||||
String medications = kid.getMedications();
|
||||
String allergies = kid.getAllergies();
|
||||
|
||||
// name validation
|
||||
if (!StringUtils.hasLength(name)) {
|
||||
errors.rejectValue("name", REQUIRED, REQUIRED);
|
||||
}
|
||||
|
||||
if (!StringUtils.hasLength(allergies)) {
|
||||
errors.rejectValue("allergies", REQUIRED, REQUIRED);
|
||||
}
|
||||
|
||||
if (!StringUtils.hasLength(medications)) {
|
||||
errors.rejectValue("medications", REQUIRED, REQUIRED);
|
||||
}
|
||||
|
||||
// gender validation
|
||||
if (kid.isNew() && kid.getGender() == null) {
|
||||
|
|
|
@ -30,19 +30,19 @@ INSERT INTO parents VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison',
|
|||
INSERT INTO parents VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435');
|
||||
INSERT INTO parents VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487');
|
||||
|
||||
INSERT INTO kids VALUES (1, 'Alyssa', '2000-09-07', 2, 1);
|
||||
INSERT INTO kids VALUES (2, 'Joe', '2002-08-06', 1, 2);
|
||||
INSERT INTO kids VALUES (3, 'Lauren', '2001-04-17', 2, 3);
|
||||
INSERT INTO kids VALUES (4, 'Nicole', '2000-03-07', 2, 3);
|
||||
INSERT INTO kids VALUES (5, 'Thomas', '2000-11-30', 1, 4);
|
||||
INSERT INTO kids VALUES (6, 'Samantha', '2000-01-20', 2, 5);
|
||||
INSERT INTO kids VALUES (7, 'George', '1995-09-04', 1, 6);
|
||||
INSERT INTO kids VALUES (8, 'Max', '1995-09-04', 1, 6);
|
||||
INSERT INTO kids VALUES (9, 'Brendan', '1999-08-06', 1, 7);
|
||||
INSERT INTO kids VALUES (10, 'Elizabeth', '1997-02-24', 2, 8);
|
||||
INSERT INTO kids VALUES (11, 'Lucy', '2000-03-09', 2, 9);
|
||||
INSERT INTO kids VALUES (12, 'Sunny', '2000-06-24', 2, 10);
|
||||
INSERT INTO kids VALUES (13, 'Conner', '2002-06-08', 1, 10);
|
||||
INSERT INTO kids VALUES (1, 'Alyssa', '2000-09-07', 2, 1, 'Claritin', 'None');
|
||||
INSERT INTO kids VALUES (2, 'Joe', '2002-08-06', 1, 2, 'None', 'Lipitor');
|
||||
INSERT INTO kids VALUES (3, 'Lauren', '2001-04-17', 2, 3, 'None', 'None');
|
||||
INSERT INTO kids VALUES (4, 'Nicole', '2000-03-07', 2, 3, 'Penicilin', 'None');
|
||||
INSERT INTO kids VALUES (5, 'Thomas', '2000-11-30', 1, 4, 'None', 'Plavix');
|
||||
INSERT INTO kids VALUES (6, 'Samantha', '2000-01-20', 2, 5, 'Latex', 'Advair Diskus');
|
||||
INSERT INTO kids VALUES (7, 'George', '1995-09-04', 1, 6, 'Insulin', 'None');
|
||||
INSERT INTO kids VALUES (8, 'Max', '1995-09-04', 1, 6, 'None', 'Singulair');
|
||||
INSERT INTO kids VALUES (9, 'Brendan', '1999-08-06', 1, 7, 'None', 'Actos');
|
||||
INSERT INTO kids VALUES (10, 'Elizabeth', '1997-02-24', 2, 8, 'None', 'None');
|
||||
INSERT INTO kids VALUES (11, 'Lucy', '2000-03-09', 2, 9, 'Iodine', 'None');
|
||||
INSERT INTO kids VALUES (12, 'Sunny', '2000-06-24', 2, 10, 'None', 'None');
|
||||
INSERT INTO kids VALUES (13, 'Conner', '2002-06-08', 1, 10, 'None', 'Epogen');
|
||||
|
||||
INSERT INTO visits VALUES (1, 7, '2013-01-01', 'rabies shot');
|
||||
INSERT INTO visits VALUES (2, 8, '2013-01-02', 'rabies shot');
|
||||
|
|
|
@ -48,7 +48,9 @@ CREATE TABLE kids (
|
|||
name VARCHAR(30),
|
||||
birth_date DATE,
|
||||
gender_id INTEGER NOT NULL,
|
||||
parent_id INTEGER NOT NULL
|
||||
parent_id INTEGER NOT NULL,
|
||||
allergies VARCHAR(255),
|
||||
medications VARCHAR(255)
|
||||
);
|
||||
ALTER TABLE kids ADD CONSTRAINT fk_kids_parents FOREIGN KEY (parent_id) REFERENCES parents (id);
|
||||
ALTER TABLE kids ADD CONSTRAINT fk_kids_gender FOREIGN KEY (gender_id) REFERENCES gender (id);
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
th:replace="~{fragments/inputField :: input ('Birth Date', 'birthDate')}" />
|
||||
<input
|
||||
th:replace="~{fragments/selectField :: select ('Gender', 'gender', ${gender})}" />
|
||||
<input
|
||||
th:replace="~{fragments/inputField :: input ('Allergies', 'allergies')}" />
|
||||
<input
|
||||
th:replace="~{fragments/inputField :: input ('Medications', 'medications')}" />
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
|
|
|
@ -50,6 +50,11 @@
|
|||
th:text="${#calendars.format(kid.birthDate, 'yyyy-MM-dd')}" /></dd>
|
||||
<dt>Gender</dt>
|
||||
<dd th:text="${kid.gender}" /></dd>
|
||||
<dt>Allergies</dt>
|
||||
<dd th:text="${kid.allergies}" /></dd>
|
||||
<dt>Medications</dt>
|
||||
<dd th:text="${kid.medications}" /></dd>
|
||||
|
||||
</dl>
|
||||
</td>
|
||||
<td valign="top">
|
||||
|
|
Loading…
Reference in a new issue