From b5e8f287504b2aff32e1ab539586833cb84903e2 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 11:19:21 +0800 Subject: [PATCH 01/59] Refracted and abstracted Patient attributes from Person class to Patient class --- .../seedu/address/model/patient/Patient.java | 34 +++++++++++++++++++ .../model/{person => patient}/Status.java | 2 +- .../model/{person => patient}/Teeth.java | 2 +- .../model/{person => patient}/Tooth.java | 2 +- .../seedu/address/model/person/Person.java | 23 ++++++++----- 5 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 src/main/java/seedu/address/model/patient/Patient.java rename src/main/java/seedu/address/model/{person => patient}/Status.java (93%) rename src/main/java/seedu/address/model/{person => patient}/Teeth.java (94%) rename src/main/java/seedu/address/model/{person => patient}/Tooth.java (95%) diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java new file mode 100644 index 000000000000..359324226cd4 --- /dev/null +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -0,0 +1,34 @@ +package seedu.address.model.patient; + +import java.util.Set; + +import seedu.address.model.person.Address; +import seedu.address.model.person.Email; +import seedu.address.model.person.Name; +import seedu.address.model.person.Person; +import seedu.address.model.person.Phone; +import seedu.address.model.tag.Tag; + +/** + * Represents a patient which is extend from the Person class. + * Guarantees: details are present and not null, field values are validated, immutable. + */ +public class Patient extends Person { + private Teeth teeth; + + /** + * Every field must be present and not null. + */ + public Patient(Name name, Phone phone, Email email, Address address, Set tags) { + super(name, phone, email, address, tags); + } + + public Patient(Name name, Phone phone, Email email, Address address, Set tags, + Person personToCopy, int copyCount) { + super(name, phone, email, address, tags, personToCopy, copyCount); + } + + public Teeth getTeeth() { + return teeth; + } +} diff --git a/src/main/java/seedu/address/model/person/Status.java b/src/main/java/seedu/address/model/patient/Status.java similarity index 93% rename from src/main/java/seedu/address/model/person/Status.java rename to src/main/java/seedu/address/model/patient/Status.java index 17eb89b9de89..8ab74e820b0f 100644 --- a/src/main/java/seedu/address/model/person/Status.java +++ b/src/main/java/seedu/address/model/patient/Status.java @@ -1,4 +1,4 @@ -package seedu.address.model.person; +package seedu.address.model.patient; import java.util.Date; diff --git a/src/main/java/seedu/address/model/person/Teeth.java b/src/main/java/seedu/address/model/patient/Teeth.java similarity index 94% rename from src/main/java/seedu/address/model/person/Teeth.java rename to src/main/java/seedu/address/model/patient/Teeth.java index 9e939f5ddfeb..38c70c2ca1b1 100644 --- a/src/main/java/seedu/address/model/person/Teeth.java +++ b/src/main/java/seedu/address/model/patient/Teeth.java @@ -1,4 +1,4 @@ -package seedu.address.model.person; +package seedu.address.model.patient; import java.util.ArrayList; diff --git a/src/main/java/seedu/address/model/person/Tooth.java b/src/main/java/seedu/address/model/patient/Tooth.java similarity index 95% rename from src/main/java/seedu/address/model/person/Tooth.java rename to src/main/java/seedu/address/model/patient/Tooth.java index b7b7190cded8..1288888bc072 100644 --- a/src/main/java/seedu/address/model/person/Tooth.java +++ b/src/main/java/seedu/address/model/patient/Tooth.java @@ -1,4 +1,4 @@ -package seedu.address.model.person; +package seedu.address.model.patient; /** * Represents a tooth of a Person. diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 831c2ed7f2c9..9eec3e665bb8 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -21,9 +21,6 @@ public class Person { private final Phone phone; private final Email email; - // Mutable fields - private Teeth teeth; - // Data fields private final Address address; private final Set tags = new HashSet<>(); @@ -73,9 +70,13 @@ public Address getAddress() { return address; } - public int getCopyCount() { return copyCount; } + public int getCopyCount() { + return copyCount; + } - public boolean hasCopy() { return copyCount > 0; } + public boolean hasCopy() { + return copyCount > 0; + } /** * @@ -90,11 +91,17 @@ private boolean copyInTag() { return false; } - public boolean isCopy() { return copyInfo != null || copyInTag(); } + public boolean isCopy() { + return copyInfo != null || copyInTag(); + } - public void editCopy() { copyInfo.getOriginalPerson().edittedCopy(); } + public void editCopy() { + copyInfo.getOriginalPerson().edittedCopy(); + } - private void edittedCopy() { copyCount -= 1; } + private void edittedCopy() { + copyCount -= 1; + } /** * @return another instance of the same person From 649e857cdf98355b85b0d3c9a91a016a7c554928 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 12:34:33 +0800 Subject: [PATCH 02/59] Implemented teeth initialisation methods --- .../seedu/address/model/patient/Patient.java | 37 ++++++++++++++++++- .../exceptions/TeethLayoutException.java | 10 +++++ .../seedu/address/model/record/Record.java | 1 - 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/main/java/seedu/address/model/patient/exceptions/TeethLayoutException.java diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java index 359324226cd4..170f5a57d9c9 100644 --- a/src/main/java/seedu/address/model/patient/Patient.java +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -2,6 +2,7 @@ import java.util.Set; +import seedu.address.model.patient.exceptions.TeethLayoutException; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; @@ -14,7 +15,9 @@ * Guarantees: details are present and not null, field values are validated, immutable. */ public class Patient extends Person { - private Teeth teeth; + private static final String CHILD = "child"; + private static final String ADULT = "adult"; + private Teeth teeth = null; /** * Every field must be present and not null. @@ -24,10 +27,40 @@ public Patient(Name name, Phone phone, Email email, Address address, Set ta } public Patient(Name name, Phone phone, Email email, Address address, Set tags, - Person personToCopy, int copyCount) { + Person personToCopy, int copyCount) { super(name, phone, email, address, tags, personToCopy, copyCount); } + /** + * Builds a default child teeth layout. + */ + public void specifyChild() { + specifyBuild(CHILD); + } + + /** + * Builds a default adult teeth layout. + */ + public void specifyAdult() { + specifyBuild(ADULT); + } + + /** + * Build a default child/adult teeth layout, according to the parameters. + */ + private void specifyBuild(String teethLayout) { + switch (teethLayout) { + case CHILD: + teeth = null; + break; + case ADULT: + teeth = null; + break; + default: + throw new TeethLayoutException(); + } + } + public Teeth getTeeth() { return teeth; } diff --git a/src/main/java/seedu/address/model/patient/exceptions/TeethLayoutException.java b/src/main/java/seedu/address/model/patient/exceptions/TeethLayoutException.java new file mode 100644 index 000000000000..64da2ea31fb5 --- /dev/null +++ b/src/main/java/seedu/address/model/patient/exceptions/TeethLayoutException.java @@ -0,0 +1,10 @@ +package seedu.address.model.patient.exceptions; + +/** + * Signals the operation that the chosen teeth layout is not recognised, and that no operations is done. + */ +public class TeethLayoutException extends RuntimeException { + public TeethLayoutException() { + super("Invalid teeth layout is selected. No teeth is built."); + } +} diff --git a/src/main/java/seedu/address/model/record/Record.java b/src/main/java/seedu/address/model/record/Record.java index 316d8ca41034..501da065db9d 100644 --- a/src/main/java/seedu/address/model/record/Record.java +++ b/src/main/java/seedu/address/model/record/Record.java @@ -37,7 +37,6 @@ public Record(Person person, Procedure procedure, Date date, Time time, Name doc this.description = desc; } - //getter methods public Person getPerson() { return person; } From 64ae109bf9b0a9c3ec4e4dc3e8655d4ac86eeb6f Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 12:55:56 +0800 Subject: [PATCH 03/59] Implemented new ways to infer patients' teeth builds --- .../seedu/address/model/patient/Patient.java | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java index 170f5a57d9c9..fd6562fc9d24 100644 --- a/src/main/java/seedu/address/model/patient/Patient.java +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -15,9 +15,11 @@ * Guarantees: details are present and not null, field values are validated, immutable. */ public class Patient extends Person { + private static final String NONE = "none"; private static final String CHILD = "child"; private static final String ADULT = "adult"; private Teeth teeth = null; + private boolean buildSpecified = false; /** * Every field must be present and not null. @@ -31,8 +33,31 @@ public Patient(Name name, Phone phone, Email email, Address address, Set ta super(name, phone, email, address, tags, personToCopy, copyCount); } + /** + * Takes in the age of the patient and infers the teeth build he/she has. + * @param age the age of the patient. + */ + private void inferTeethBuild(int age) { + if (age < 2) { + specifyBuild(NONE); + } else if (age < 13) { + specifyBuild(CHILD); + } else { + specifyBuild(ADULT); + } + } + + /** + * Builds a default no teeth layout. + * Which represents a baby with no teeth. + */ + public void specifyNone() { + specifyBuild(NONE); + } + /** * Builds a default child teeth layout. + * Which represents a child with child teeth. */ public void specifyChild() { specifyBuild(CHILD); @@ -40,21 +65,28 @@ public void specifyChild() { /** * Builds a default adult teeth layout. + * Which represents a teenager/adult with permanent teeth. */ public void specifyAdult() { specifyBuild(ADULT); } /** - * Build a default child/adult teeth layout, according to the parameters. + * Build a default none/child/adult teeth layout, according to the parameters. */ private void specifyBuild(String teethLayout) { switch (teethLayout) { + case NONE: + teeth = null; // Stub + buildSpecified = true; + break; case CHILD: - teeth = null; + teeth = null; // Stub + buildSpecified = true; break; case ADULT: - teeth = null; + teeth = null; // Stub + buildSpecified = true; break; default: throw new TeethLayoutException(); @@ -64,4 +96,8 @@ private void specifyBuild(String teethLayout) { public Teeth getTeeth() { return teeth; } + + public boolean isBuildSpecified() { + return buildSpecified; + } } From 94a1241b96ba355ff141458e261dc392b3b91093 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 13:24:21 +0800 Subject: [PATCH 04/59] Added new attributes and essential methods to Patient class --- .../seedu/address/model/patient/Patient.java | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java index fd6562fc9d24..983cfdf6d8f5 100644 --- a/src/main/java/seedu/address/model/patient/Patient.java +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -1,13 +1,20 @@ package seedu.address.model.patient; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.Set; import seedu.address.model.patient.exceptions.TeethLayoutException; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; +import seedu.address.model.person.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.record.Record; import seedu.address.model.tag.Tag; /** @@ -18,26 +25,35 @@ public class Patient extends Person { private static final String NONE = "none"; private static final String CHILD = "child"; private static final String ADULT = "adult"; + private Nric nric; + private Date dateOfBirth; private Teeth teeth = null; private boolean buildSpecified = false; + private ArrayList records = new ArrayList<>(); /** * Every field must be present and not null. */ - public Patient(Name name, Phone phone, Email email, Address address, Set tags) { + public Patient(Name name, Phone phone, Email email, Address address, Set tags, Nric nric, Date dateOfBirth) { super(name, phone, email, address, tags); + requireAllNonNull(nric, dateOfBirth); + this.nric = nric; + this.dateOfBirth = dateOfBirth; } public Patient(Name name, Phone phone, Email email, Address address, Set tags, - Person personToCopy, int copyCount) { + Person personToCopy, int copyCount, Nric nric, Date dateOfBirth) { super(name, phone, email, address, tags, personToCopy, copyCount); + requireAllNonNull(nric, dateOfBirth); + this.nric = nric; + this.dateOfBirth = dateOfBirth; } /** * Takes in the age of the patient and infers the teeth build he/she has. - * @param age the age of the patient. */ - private void inferTeethBuild(int age) { + private void inferTeethBuild() { + int age = getPatientAge(); if (age < 2) { specifyBuild(NONE); } else if (age < 13) { @@ -93,10 +109,28 @@ private void specifyBuild(String teethLayout) { } } + private int getPatientAge() { + Date today = new Date(); + Calendar cal = Calendar.getInstance(); + cal.setTime(today); + int currentYear = cal.get(Calendar.DAY_OF_YEAR); + cal.setTime(dateOfBirth); + int birthYear = cal.get(Calendar.DAY_OF_YEAR); + return currentYear - birthYear; + } + public Teeth getTeeth() { return teeth; } + public Nric getNric() { + return nric; + } + + public Date getDateOfBirth() { + return dateOfBirth; + } + public boolean isBuildSpecified() { return buildSpecified; } From 8ed0b59b2a2c83632916841f11514d285a773b55 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 13:56:50 +0800 Subject: [PATCH 05/59] Refracted methods to enhance class structure --- .../seedu/address/model/patient/Patient.java | 19 ++---------- .../seedu/address/model/patient/Teeth.java | 29 ++++++++++++++----- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java index 983cfdf6d8f5..4a9b50a3a044 100644 --- a/src/main/java/seedu/address/model/patient/Patient.java +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -7,7 +7,6 @@ import java.util.Date; import java.util.Set; -import seedu.address.model.patient.exceptions.TeethLayoutException; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; @@ -91,22 +90,8 @@ public void specifyAdult() { * Build a default none/child/adult teeth layout, according to the parameters. */ private void specifyBuild(String teethLayout) { - switch (teethLayout) { - case NONE: - teeth = null; // Stub - buildSpecified = true; - break; - case CHILD: - teeth = null; // Stub - buildSpecified = true; - break; - case ADULT: - teeth = null; // Stub - buildSpecified = true; - break; - default: - throw new TeethLayoutException(); - } + buildSpecified = true; + teeth = new Teeth(teethLayout); } private int getPatientAge() { diff --git a/src/main/java/seedu/address/model/patient/Teeth.java b/src/main/java/seedu/address/model/patient/Teeth.java index 38c70c2ca1b1..8c89ae3cd22e 100644 --- a/src/main/java/seedu/address/model/patient/Teeth.java +++ b/src/main/java/seedu/address/model/patient/Teeth.java @@ -2,25 +2,40 @@ import java.util.ArrayList; +import seedu.address.model.patient.exceptions.TeethLayoutException; + /** * Represents a set of teeth a Person has. */ public class Teeth { - private final int childTeethCount = 20; - private final int adultTeethCount = 32; + private static final String NONE = "none"; + private static final String CHILD = "child"; + private static final int CHILDTEETHCOUNT = 20; + private static final String ADULT = "adult"; + private static final int ADULTTEETHCOUNT = 32; - private ArrayList teeth; + private ArrayList permanentTeeth = new ArrayList<>(); + private ArrayList primaryTeeth = new ArrayList<>(); - public Teeth() { - teeth = new ArrayList<>(); + Teeth(String teethLayout) { + switch (teethLayout) { + case NONE: + break; + case CHILD: + break; + case ADULT: + break; + default: + throw new TeethLayoutException(); + } } /** * Returns a Tooth representing a patient's tooth using a tooth number. - * @param toothNum the tooth number of tooth to be retrieved. + * @param index the tooth number of tooth to be retrieved. * @return the tooth represented by provided tooth number. */ - public Tooth getTooth(int toothNum) { + public Tooth getTooth(int index) { return null; } } From 1f26cfc2ddf8963c78553fe23d86a418bb62a8a9 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 14:06:47 +0800 Subject: [PATCH 06/59] Changed access modifiers of Person class to improve inheritance --- .../seedu/address/model/patient/Patient.java | 17 ++++++++++++++++- .../java/seedu/address/model/person/Person.java | 14 +++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java index 4a9b50a3a044..2891e2073c76 100644 --- a/src/main/java/seedu/address/model/patient/Patient.java +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -38,14 +38,16 @@ public Patient(Name name, Phone phone, Email email, Address address, Set ta requireAllNonNull(nric, dateOfBirth); this.nric = nric; this.dateOfBirth = dateOfBirth; + inferTeethBuild(); } - public Patient(Name name, Phone phone, Email email, Address address, Set tags, + private Patient(Name name, Phone phone, Email email, Address address, Set tags, Person personToCopy, int copyCount, Nric nric, Date dateOfBirth) { super(name, phone, email, address, tags, personToCopy, copyCount); requireAllNonNull(nric, dateOfBirth); this.nric = nric; this.dateOfBirth = dateOfBirth; + inferTeethBuild(); } /** @@ -104,6 +106,19 @@ private int getPatientAge() { return currentYear - birthYear; } + /** + * @return another instance of the same person + * {@code Tag} Copy is added + */ + @Override + public Patient copy() { + if (isCopy()) { + super.copy(); + } + copyCount++; + return new Patient(name, phone, email, address, tags, this, copyCount, nric, dateOfBirth); + } + public Teeth getTeeth() { return teeth; } diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 9eec3e665bb8..ae87bffd04ae 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -17,15 +17,15 @@ public class Person { // Identity fields - private final Name name; - private final Phone phone; - private final Email email; + protected final Name name; + protected final Phone phone; + protected final Email email; // Data fields - private final Address address; - private final Set tags = new HashSet<>(); - private CopyTag copyInfo; - private int copyCount; + protected final Address address; + protected final Set tags = new HashSet<>(); + protected CopyTag copyInfo; + protected int copyCount; /** * Every field must be present and not null. From 19f819a8e094382f85f35f6723d44cb82311529d Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 14:09:07 +0800 Subject: [PATCH 07/59] Added javadoc to new methods --- src/main/java/seedu/address/model/patient/Patient.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java index 2891e2073c76..f42df5d91d17 100644 --- a/src/main/java/seedu/address/model/patient/Patient.java +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -96,6 +96,10 @@ private void specifyBuild(String teethLayout) { teeth = new Teeth(teethLayout); } + /** + * Using the patient's year of birth and the current year, derive his or her age. + * @return the age of the patient. + */ private int getPatientAge() { Date today = new Date(); Calendar cal = Calendar.getInstance(); From 0877972d16f1ee9546b8f5e75bd61197747ed095 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 14:43:16 +0800 Subject: [PATCH 08/59] Overwritten appropriate methods in Patient class --- .../seedu/address/model/patient/Patient.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java index f42df5d91d17..a8858b2bd70f 100644 --- a/src/main/java/seedu/address/model/patient/Patient.java +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.Objects; import java.util.Set; import seedu.address.model.person.Address; @@ -138,4 +139,19 @@ public Date getDateOfBirth() { public boolean isBuildSpecified() { return buildSpecified; } + + /** + * Returns true if both patients of the same name have at least one other identity field that is the same. + * This defines a weaker notion of equality between two patients. + */ + public boolean isSamePatient(Person otherPerson) { + return super.isSamePerson(otherPerson); + } + + @Override + public int hashCode() { + // use this method for custom fields hashing instead of implementing your own + return Objects.hash(name, phone, email, address, tags, nric, dateOfBirth, records); + } + } From d9618e58195531002ce7a5a9c23ab3fd78c7eedc Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 15:29:04 +0800 Subject: [PATCH 09/59] Added a method that adds a record to patient --- .../seedu/address/model/patient/Patient.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java index a8858b2bd70f..864410c1e51f 100644 --- a/src/main/java/seedu/address/model/patient/Patient.java +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -51,6 +51,14 @@ private Patient(Name name, Phone phone, Email email, Address address, Set t inferTeethBuild(); } + /** + * Adds a new medical record to a patient. + * @param record the medical record to be added. + */ + public void addRecord(Record record) { + this.records.add(record); + } + /** * Takes in the age of the patient and infers the teeth build he/she has. */ @@ -124,6 +132,10 @@ public Patient copy() { return new Patient(name, phone, email, address, tags, this, copyCount, nric, dateOfBirth); } + public void setRecords(ArrayList records) { + this.records = records; + } + public Teeth getTeeth() { return teeth; } @@ -140,6 +152,10 @@ public boolean isBuildSpecified() { return buildSpecified; } + public ArrayList getRecords() { + return records; + } + /** * Returns true if both patients of the same name have at least one other identity field that is the same. * This defines a weaker notion of equality between two patients. From 1ca62872dd23668c7f5512539ca1a31ee85a0947 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 19:54:15 +0800 Subject: [PATCH 10/59] Added methods to create template teeth layouts --- .../seedu/address/model/patient/Teeth.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Teeth.java b/src/main/java/seedu/address/model/patient/Teeth.java index 8c89ae3cd22e..4ce5e50c5b81 100644 --- a/src/main/java/seedu/address/model/patient/Teeth.java +++ b/src/main/java/seedu/address/model/patient/Teeth.java @@ -10,12 +10,12 @@ public class Teeth { private static final String NONE = "none"; private static final String CHILD = "child"; - private static final int CHILDTEETHCOUNT = 20; + private static final int PRIMARYTEETHCOUNT = 20; private static final String ADULT = "adult"; - private static final int ADULTTEETHCOUNT = 32; + private static final int PERMANENTTEETHCOUNT = 32; - private ArrayList permanentTeeth = new ArrayList<>(); - private ArrayList primaryTeeth = new ArrayList<>(); + private ArrayList permanentTeeth; + private ArrayList primaryTeeth; Teeth(String teethLayout) { switch (teethLayout) { @@ -30,6 +30,28 @@ public class Teeth { } } + /** + * Initialises a set of good primary teeth. + */ + private void buildPrimaryTeeth() { + ArrayList primaryTeeth = new ArrayList<>(); + for (int i = 0; i < PRIMARYTEETHCOUNT; i++) { + primaryTeeth.add(new Tooth()); + } + this.primaryTeeth = primaryTeeth; + } + + /** + * Initialises a set of good permanent teeth. + */ + private void buildPermanentTeeth() { + ArrayList permanentTeeth = new ArrayList<>(); + for (int i = 0; i < PERMANENTTEETHCOUNT; i++) { + permanentTeeth.add(new Tooth()); + } + this.permanentTeeth = permanentTeeth; + } + /** * Returns a Tooth representing a patient's tooth using a tooth number. * @param index the tooth number of tooth to be retrieved. From ee50a630d6c697d5f6d72c5c9b60ae20853c46fa Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 20:06:58 +0800 Subject: [PATCH 11/59] New Tooth constructor that takes in a boolean variable --- src/main/java/seedu/address/model/patient/Tooth.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Tooth.java b/src/main/java/seedu/address/model/patient/Tooth.java index 1288888bc072..d1ecbe0b0227 100644 --- a/src/main/java/seedu/address/model/patient/Tooth.java +++ b/src/main/java/seedu/address/model/patient/Tooth.java @@ -3,19 +3,23 @@ /** * Represents a tooth of a Person. */ -public class Tooth { +class Tooth { private boolean isPresent = true; private boolean isOnStatus = false; private Status status; - public Tooth() { } + Tooth() { } - public Tooth(Status status) { + Tooth(boolean isPresent) { + this.isPresent = isPresent; + } + + Tooth(Status status) { this.isOnStatus = true; this.status = status; } - public Tooth(boolean isPresent, boolean hasStatus) { + Tooth(boolean isPresent, boolean hasStatus) { this.isPresent = isPresent; this.isOnStatus = hasStatus; } From a0f83e73c3276fe96acbd33ac22a722f7cfb2a50 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 20:10:13 +0800 Subject: [PATCH 12/59] Removed empty constructor --- src/main/java/seedu/address/model/patient/Tooth.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Tooth.java b/src/main/java/seedu/address/model/patient/Tooth.java index d1ecbe0b0227..c9078498f747 100644 --- a/src/main/java/seedu/address/model/patient/Tooth.java +++ b/src/main/java/seedu/address/model/patient/Tooth.java @@ -8,8 +8,6 @@ class Tooth { private boolean isOnStatus = false; private Status status; - Tooth() { } - Tooth(boolean isPresent) { this.isPresent = isPresent; } From 7de42e1565cf3ca885bedb9c98f00582a441c544 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 20:14:57 +0800 Subject: [PATCH 13/59] Added appropriate getter and setter methods --- .../seedu/address/model/patient/Tooth.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Tooth.java b/src/main/java/seedu/address/model/patient/Tooth.java index c9078498f747..14a8510d91ad 100644 --- a/src/main/java/seedu/address/model/patient/Tooth.java +++ b/src/main/java/seedu/address/model/patient/Tooth.java @@ -22,19 +22,28 @@ class Tooth { this.isOnStatus = hasStatus; } - public void setStatus(Status status) { - this.status = status; + public void setPresent(boolean present) { + isPresent = present; } - public Status getStatus() { - return status; + public void setOnStatus(boolean onStatus) { + isOnStatus = onStatus; + } + + public void setStatus(Status status) { + this.status = status; } public boolean isPresent() { return isPresent; } - public boolean isStatus() { + public boolean isOnStatus() { return isOnStatus; } + + public Status getStatus() { + return status; + } + } From 45bca4a4334381979096ecf246e51c3f595cb6d7 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 20:18:49 +0800 Subject: [PATCH 14/59] Finished methods that build default teeth layouts for users --- .../seedu/address/model/patient/Teeth.java | 57 +++++++++++++++---- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Teeth.java b/src/main/java/seedu/address/model/patient/Teeth.java index 4ce5e50c5b81..d1c7576738b6 100644 --- a/src/main/java/seedu/address/model/patient/Teeth.java +++ b/src/main/java/seedu/address/model/patient/Teeth.java @@ -10,20 +10,27 @@ public class Teeth { private static final String NONE = "none"; private static final String CHILD = "child"; - private static final int PRIMARYTEETHCOUNT = 20; private static final String ADULT = "adult"; + private static final int PRIMARYTEETHCOUNT = 20; private static final int PERMANENTTEETHCOUNT = 32; private ArrayList permanentTeeth; private ArrayList primaryTeeth; + /** + * Default constructor. Builds a teeth template according to the specified teeth layout. + * @param teethLayout the teeth layout specified by the user. + */ Teeth(String teethLayout) { + buildNoTeeth(); switch (teethLayout) { case NONE: break; case CHILD: + addPrimaryTeeth(); break; case ADULT: + addPermanentTeeth(); break; default: throw new TeethLayoutException(); @@ -31,33 +38,63 @@ public class Teeth { } /** - * Initialises a set of good primary teeth. + * Initialises an empty set of primary and permanent teeth. */ - private void buildPrimaryTeeth() { + private void buildNoTeeth() { ArrayList primaryTeeth = new ArrayList<>(); + ArrayList permanentTeeth = new ArrayList<>(); + for (int i = 0; i < PRIMARYTEETHCOUNT; i++) { - primaryTeeth.add(new Tooth()); + primaryTeeth.add(new Tooth(false)); } + this.primaryTeeth = primaryTeeth; + + for (int i = 0; i < PERMANENTTEETHCOUNT; i++) { + permanentTeeth.add(new Tooth(false)); + } + + this.permanentTeeth = permanentTeeth; + } + + /** + * Initialises a set of good primary teeth. + */ + private void addPrimaryTeeth() { + for (Tooth tooth : primaryTeeth) { + tooth.setPresent(true); + } } /** * Initialises a set of good permanent teeth. */ - private void buildPermanentTeeth() { - ArrayList permanentTeeth = new ArrayList<>(); - for (int i = 0; i < PERMANENTTEETHCOUNT; i++) { - permanentTeeth.add(new Tooth()); + private void addPermanentTeeth() { + for (Tooth tooth : permanentTeeth) { + tooth.setPresent(true); } - this.permanentTeeth = permanentTeeth; } /** + * For primary tooth. + * Returns a Tooth representing a patient's tooth using a tooth alphabet. + * @param index the tooth alphabet of tooth to be retrieved. + * @return the tooth represented by provided tooth alphabet. + */ + public Tooth getTooth(char index) { + int parsedIndex = (int) index - (int) 'a'; + return primaryTeeth.get(parsedIndex); + } + + /** + * For permanent tooth. * Returns a Tooth representing a patient's tooth using a tooth number. * @param index the tooth number of tooth to be retrieved. * @return the tooth represented by provided tooth number. */ public Tooth getTooth(int index) { - return null; + int adjustedIndex = index - 1; + return permanentTeeth.get(adjustedIndex); } + } From 487df3f8b32bc700d6b52290aa22840306933ba2 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 20:35:39 +0800 Subject: [PATCH 15/59] Simplified attributes of status class --- src/main/java/seedu/address/model/patient/Status.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Status.java b/src/main/java/seedu/address/model/patient/Status.java index 8ab74e820b0f..b707e832c3e1 100644 --- a/src/main/java/seedu/address/model/patient/Status.java +++ b/src/main/java/seedu/address/model/patient/Status.java @@ -1,25 +1,17 @@ package seedu.address.model.patient; -import java.util.Date; - /** * Represents the status of a teeth. * Attributes of class is immutable to uphold information integrity. */ public class Status { private String description; - private Date dateCreated; public Status(String description) { this.description = description; - this.dateCreated = new Date(); } public String getDescription() { return description; } - - public Date getDateCreated() { - return dateCreated; - } } From 89ba81ba53c3dde618775cf2cc1afe740854e388 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 20:38:58 +0800 Subject: [PATCH 16/59] Further simplified attributes and methods of status class --- src/main/java/seedu/address/model/patient/Status.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/model/patient/Status.java b/src/main/java/seedu/address/model/patient/Status.java index b707e832c3e1..020dc9e0a042 100644 --- a/src/main/java/seedu/address/model/patient/Status.java +++ b/src/main/java/seedu/address/model/patient/Status.java @@ -7,7 +7,11 @@ public class Status { private String description; - public Status(String description) { + Status() { + this.description = null; + } + + public void setDescription(String description) { this.description = description; } From 20c4dc4a86d08a381f1dafec74349acd4f265476 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 20:52:24 +0800 Subject: [PATCH 17/59] Updated attributes in Tooth class --- .../seedu/address/model/patient/Tooth.java | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Tooth.java b/src/main/java/seedu/address/model/patient/Tooth.java index 14a8510d91ad..4610796937fd 100644 --- a/src/main/java/seedu/address/model/patient/Tooth.java +++ b/src/main/java/seedu/address/model/patient/Tooth.java @@ -4,46 +4,33 @@ * Represents a tooth of a Person. */ class Tooth { - private boolean isPresent = true; - private boolean isOnStatus = false; - private Status status; + private boolean isPresent; + private boolean onStatus; + private Status status = new Status(); Tooth(boolean isPresent) { this.isPresent = isPresent; - } - - Tooth(Status status) { - this.isOnStatus = true; - this.status = status; - } - - Tooth(boolean isPresent, boolean hasStatus) { - this.isPresent = isPresent; - this.isOnStatus = hasStatus; + this.onStatus = false; } public void setPresent(boolean present) { isPresent = present; } - public void setOnStatus(boolean onStatus) { - isOnStatus = onStatus; + public boolean isPresent() { + return isPresent; } public void setStatus(Status status) { this.status = status; } - public boolean isPresent() { - return isPresent; + public Status getStatus() { + return status; } public boolean isOnStatus() { - return isOnStatus; - } - - public Status getStatus() { - return status; + return onStatus; } } From 20cfdd2b298ab7b1e374ee2966eb611e724f9e06 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 20:59:33 +0800 Subject: [PATCH 18/59] Improved the algorithm in Teeth class --- .../seedu/address/model/patient/Teeth.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/main/java/seedu/address/model/patient/Teeth.java b/src/main/java/seedu/address/model/patient/Teeth.java index d1c7576738b6..cf04c2c16fe6 100644 --- a/src/main/java/seedu/address/model/patient/Teeth.java +++ b/src/main/java/seedu/address/model/patient/Teeth.java @@ -75,6 +75,26 @@ private void addPermanentTeeth() { } } + /** + * For permanent tooth. + * Sets a status for a tooth. + * @param index the tooth alphabet. + * @param status the status of the tooth. + */ + public void setToothStatus(char index, Status status) { + getTooth(index).setStatus(status); + } + + /** + * For primary tooth. + * Sets a status for a tooth. + * @param index the tooth number. + * @param status the status of the tooth. + */ + public void setToothStatus(int index, Status status) { + getTooth(index).setStatus(status); + } + /** * For primary tooth. * Returns a Tooth representing a patient's tooth using a tooth alphabet. @@ -97,4 +117,27 @@ public Tooth getTooth(int index) { return permanentTeeth.get(adjustedIndex); } + /** + * Exports the format of the teeth. (For permanent teeth). + * Used mainly to print the preview of the teeth layout on GUI to user. + * 0 - Absent. (Red). + * 1 - Present, on status. (Yellow). + * 2 - Present, healthy. (White). + * @return an Integer array consisting of current teeth layout information. + */ + public ArrayList exportTeeth() { + ArrayList exportFormat = new ArrayList<>(); + + for (Tooth tooth : permanentTeeth) { + if (!tooth.isPresent()) { + exportFormat.add(0); + } else if (tooth.isOnStatus()) { + exportFormat.add(1); + } else { + exportFormat.add(2); + } + } + + return exportFormat; + } } From b86009182189fe422989ec257bcd9d104065e170 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 21:00:33 +0800 Subject: [PATCH 19/59] New function that allows Patient class to create default teeth layouts --- .../seedu/address/model/patient/Patient.java | 55 +++++-------------- 1 file changed, 13 insertions(+), 42 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java index 864410c1e51f..6c59083d254e 100644 --- a/src/main/java/seedu/address/model/patient/Patient.java +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -60,48 +60,33 @@ public void addRecord(Record record) { } /** + * Age inferred teeth layout. * Takes in the age of the patient and infers the teeth build he/she has. */ private void inferTeethBuild() { int age = getPatientAge(); if (age < 2) { - specifyBuild(NONE); + buildTeeth(NONE); } else if (age < 13) { - specifyBuild(CHILD); + buildTeeth(CHILD); } else { - specifyBuild(ADULT); + buildTeeth(ADULT); } } /** - * Builds a default no teeth layout. - * Which represents a baby with no teeth. - */ - public void specifyNone() { - specifyBuild(NONE); - } - - /** - * Builds a default child teeth layout. - * Which represents a child with child teeth. - */ - public void specifyChild() { - specifyBuild(CHILD); - } - - /** - * Builds a default adult teeth layout. - * Which represents a teenager/adult with permanent teeth. + * User specified teeth layout. + * Build a default none/child/adult teeth layout, according to the parameters. */ - public void specifyAdult() { - specifyBuild(ADULT); + private void specifyBuild(String teethLayout) { + buildSpecified = true; + buildTeeth(teethLayout); } /** * Build a default none/child/adult teeth layout, according to the parameters. */ - private void specifyBuild(String teethLayout) { - buildSpecified = true; + private void buildTeeth(String teethLayout) { teeth = new Teeth(teethLayout); } @@ -119,19 +104,6 @@ private int getPatientAge() { return currentYear - birthYear; } - /** - * @return another instance of the same person - * {@code Tag} Copy is added - */ - @Override - public Patient copy() { - if (isCopy()) { - super.copy(); - } - copyCount++; - return new Patient(name, phone, email, address, tags, this, copyCount, nric, dateOfBirth); - } - public void setRecords(ArrayList records) { this.records = records; } @@ -157,11 +129,10 @@ public ArrayList getRecords() { } /** - * Returns true if both patients of the same name have at least one other identity field that is the same. - * This defines a weaker notion of equality between two patients. + * Returns true if both patients has the same NRIC. */ - public boolean isSamePatient(Person otherPerson) { - return super.isSamePerson(otherPerson); + public boolean isSamePatient(Patient otherPerson) { + return nric.equals(otherPerson.getNric()); } @Override From 3b175d268e670455f6657228e919326aad8c89be Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 21:11:11 +0800 Subject: [PATCH 20/59] Changed success message to reflect our morphed program --- src/main/java/seedu/address/logic/commands/ClearCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/logic/commands/ClearCommand.java b/src/main/java/seedu/address/logic/commands/ClearCommand.java index a22219ad76ad..3e7da4fbbfb5 100644 --- a/src/main/java/seedu/address/logic/commands/ClearCommand.java +++ b/src/main/java/seedu/address/logic/commands/ClearCommand.java @@ -12,7 +12,7 @@ public class ClearCommand extends Command { public static final String COMMAND_WORD = "clear"; - public static final String MESSAGE_SUCCESS = "Address book has been cleared!"; + public static final String MESSAGE_SUCCESS = "Dental book has been cleared!"; @Override From 8bafba499d199a78a2322a6d441090d883f2c7cd Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 21:14:18 +0800 Subject: [PATCH 21/59] Morphed add command to take in a patient rather than person --- .../seedu/address/logic/commands/AddCommand.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index d88e831ff1ce..a9544b27a996 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -10,10 +10,10 @@ import seedu.address.logic.CommandHistory; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.person.Person; +import seedu.address.model.patient.Patient; /** - * Adds a person to the address book. + * Adds a patient to the address book. */ public class AddCommand extends Command { @@ -34,17 +34,17 @@ public class AddCommand extends Command { + PREFIX_TAG + "friends " + PREFIX_TAG + "owesMoney"; - public static final String MESSAGE_SUCCESS = "New person added: %1$s"; - public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; + public static final String MESSAGE_SUCCESS = "New patient added: %1$s"; + public static final String MESSAGE_DUPLICATE_PERSON = "This patient already exists in the dental book"; - private final Person toAdd; + private final Patient toAdd; /** * Creates an AddCommand to add the specified {@code Person} */ - public AddCommand(Person person) { - requireNonNull(person); - toAdd = person; + public AddCommand(Patient patient) { + requireNonNull(patient); + toAdd = patient; } @Override From 3e9dc5632404931ef6f98d275119e1926b93c484 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Thu, 7 Mar 2019 21:23:10 +0800 Subject: [PATCH 22/59] Updated CliSyntax with NRIC and DOB user input prefixes --- src/main/java/seedu/address/logic/parser/CliSyntax.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 75b1a9bf1190..fcf77bb9d061 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -11,5 +11,7 @@ public class CliSyntax { public static final Prefix PREFIX_EMAIL = new Prefix("e/"); public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); + public static final Prefix PREFIX_NRIC = new Prefix("ic/"); + public static final Prefix PREFIX_DOB = new Prefix("dob/"); } From 2905b03faea1be6e173f7b083f799e00f7e33baa Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Fri, 8 Mar 2019 00:13:17 +0800 Subject: [PATCH 23/59] Fixed regular expression of Nric class --- src/main/java/seedu/address/model/person/Nric.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Nric.java b/src/main/java/seedu/address/model/person/Nric.java index 14df6a1a58a0..0fd47b5e8db4 100644 --- a/src/main/java/seedu/address/model/person/Nric.java +++ b/src/main/java/seedu/address/model/person/Nric.java @@ -11,7 +11,7 @@ public class Nric { public static final String MESSAGE_CONSTRAINTS = "Nric should only contain numbers, and it should be between 2 to 3 digits long"; - public static final String VALIDATION_REGEX = "^([S,T])(\\d {7})(A-Z)$"; + public static final String VALIDATION_REGEX = "^[STFG]\\d{7}[A-Z]$"; public final String value; /** @@ -21,7 +21,7 @@ public class Nric { */ public Nric(String nric) { requireNonNull(nric); - checkArgument(isValidNric(nric), MESSAGE_CONSTRAINTS); + checkArgument(isValidNric(nric), MESSAGE_CONSTRAINTS + " , provided: " + nric); value = nric; } From 5be20ce26f04be131d6eeee343e09898c6591c55 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Fri, 8 Mar 2019 00:14:18 +0800 Subject: [PATCH 24/59] Modified AddCommand for polymorphism --- src/main/java/seedu/address/logic/commands/AddCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index a9544b27a996..cc539bfce6c4 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -10,7 +10,7 @@ import seedu.address.logic.CommandHistory; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.patient.Patient; +import seedu.address.model.person.Person; /** * Adds a patient to the address book. @@ -37,12 +37,12 @@ public class AddCommand extends Command { public static final String MESSAGE_SUCCESS = "New patient added: %1$s"; public static final String MESSAGE_DUPLICATE_PERSON = "This patient already exists in the dental book"; - private final Patient toAdd; + private final Person toAdd; /** * Creates an AddCommand to add the specified {@code Person} */ - public AddCommand(Patient patient) { + public AddCommand(Person patient) { requireNonNull(patient); toAdd = patient; } From 2073051e6d59ec039c474582236d3c10937c33d3 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Fri, 8 Mar 2019 00:15:06 +0800 Subject: [PATCH 25/59] Change of attributes in Patient class --- .../seedu/address/model/patient/Patient.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java index 6c59083d254e..ec6993faca94 100644 --- a/src/main/java/seedu/address/model/patient/Patient.java +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -26,7 +26,7 @@ public class Patient extends Person { private static final String CHILD = "child"; private static final String ADULT = "adult"; private Nric nric; - private Date dateOfBirth; + private Integer yearOfBirth; private Teeth teeth = null; private boolean buildSpecified = false; private ArrayList records = new ArrayList<>(); @@ -34,20 +34,21 @@ public class Patient extends Person { /** * Every field must be present and not null. */ - public Patient(Name name, Phone phone, Email email, Address address, Set tags, Nric nric, Date dateOfBirth) { + public Patient(Name name, Phone phone, Email email, Address address, Set tags, Nric nric, + Integer yearOfBirth) { super(name, phone, email, address, tags); - requireAllNonNull(nric, dateOfBirth); + requireAllNonNull(nric, yearOfBirth); this.nric = nric; - this.dateOfBirth = dateOfBirth; + this.yearOfBirth = yearOfBirth; inferTeethBuild(); } private Patient(Name name, Phone phone, Email email, Address address, Set tags, - Person personToCopy, int copyCount, Nric nric, Date dateOfBirth) { + Person personToCopy, int copyCount, Nric nric, int yearOfBirth) { super(name, phone, email, address, tags, personToCopy, copyCount); - requireAllNonNull(nric, dateOfBirth); + requireAllNonNull(nric, yearOfBirth); this.nric = nric; - this.dateOfBirth = dateOfBirth; + this.yearOfBirth = yearOfBirth; inferTeethBuild(); } @@ -99,9 +100,7 @@ private int getPatientAge() { Calendar cal = Calendar.getInstance(); cal.setTime(today); int currentYear = cal.get(Calendar.DAY_OF_YEAR); - cal.setTime(dateOfBirth); - int birthYear = cal.get(Calendar.DAY_OF_YEAR); - return currentYear - birthYear; + return currentYear - yearOfBirth; } public void setRecords(ArrayList records) { @@ -116,8 +115,8 @@ public Nric getNric() { return nric; } - public Date getDateOfBirth() { - return dateOfBirth; + public Integer getYearOfBirth() { + return yearOfBirth; } public boolean isBuildSpecified() { @@ -132,13 +131,17 @@ public ArrayList getRecords() { * Returns true if both patients has the same NRIC. */ public boolean isSamePatient(Patient otherPerson) { - return nric.equals(otherPerson.getNric()); + if (nric != null) { + return nric.equals(otherPerson.getNric()); + } else { + return false; + } } @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, address, tags, nric, dateOfBirth, records); + return Objects.hash(name, phone, email, address, tags, nric, yearOfBirth, records); } } From ad955f78dde3efb1909b6032416a1e46f0a54649 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Fri, 8 Mar 2019 00:16:11 +0800 Subject: [PATCH 26/59] Class changes to accommodate Patient class --- .../logic/parser/AddCommandParser.java | 15 +++++++------ .../seedu/address/logic/parser/CliSyntax.java | 2 +- .../address/logic/parser/ParserUtil.java | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 3b8bfa035e83..a1b5513ab460 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -1,21 +1,18 @@ package seedu.address.logic.parser; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; -import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; -import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.*; import java.util.Set; import java.util.stream.Stream; import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.patient.Patient; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; -import seedu.address.model.person.Person; +import seedu.address.model.person.Nric; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; @@ -43,10 +40,12 @@ public AddCommand parse(String args) throws ParseException { Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); + Nric nric = ParserUtil.parseNric(argMultimap.getValue(PREFIX_NRIC).orElse("S1234567A")); + int yearOfBirth = ParserUtil.parseYear(argMultimap.getValue(PREFIX_YEAR).orElse("1995")); - Person person = new Person(name, phone, email, address, tagList); + Patient patient = new Patient(name, phone, email, address, tagList, nric, yearOfBirth); - return new AddCommand(person); + return new AddCommand(patient); } /** diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index fcf77bb9d061..3c29f1b97ddf 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -12,6 +12,6 @@ public class CliSyntax { public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); public static final Prefix PREFIX_NRIC = new Prefix("ic/"); - public static final Prefix PREFIX_DOB = new Prefix("dob/"); + public static final Prefix PREFIX_YEAR = new Prefix("year/"); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 579d4a5e29c3..67f50d4e7294 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -13,6 +13,7 @@ import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; +import seedu.address.model.person.Nric; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; @@ -96,6 +97,26 @@ public static Email parseEmail(String email) throws ParseException { return new Email(trimmedEmail); } + /** + * Parses a {@code String nric} into an {@code Nric}. + * Leading and trailing whitespaces will be trimmed. + */ + public static Nric parseNric(String nric) { + requireNonNull(nric); + String trimmedNric = nric.trim(); + return new Nric(trimmedNric); + } + + /** + * Parses a {@code String email} into an {@code Email}. + * Leading and trailing whitespaces will be trimmed. + */ + public static int parseYear(String year) { + requireNonNull(year); + String trimmedYear = year.trim(); + return Integer.parseInt(trimmedYear); + } + /** * Parses a {@code String tag} into a {@code Tag}. * Leading and trailing whitespaces will be trimmed. From f08571a5ee7fa2b02397a7f018fcfd08a8135cd5 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Fri, 8 Mar 2019 00:23:21 +0800 Subject: [PATCH 27/59] Small modifications to Nric class --- .../java/seedu/address/model/person/Nric.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Nric.java b/src/main/java/seedu/address/model/person/Nric.java index 0fd47b5e8db4..64f28a511289 100644 --- a/src/main/java/seedu/address/model/person/Nric.java +++ b/src/main/java/seedu/address/model/person/Nric.java @@ -3,6 +3,8 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; +import seedu.address.logic.parser.AddCommandParser; + /** * Represents a Person's Nric in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidNric(String)} @@ -10,7 +12,7 @@ public class Nric { public static final String MESSAGE_CONSTRAINTS = - "Nric should only contain numbers, and it should be between 2 to 3 digits long"; + "Nric should contain only \"-\" or \"XdddddddX\""; public static final String VALIDATION_REGEX = "^[STFG]\\d{7}[A-Z]$"; public final String value; @@ -26,10 +28,16 @@ public Nric(String nric) { } /** - * Returns true if a given string is a valid Nric number. + * Returns true if a given string is a valid Nric number, or intentionally left empty (-). + * @param test the string to be tested. */ - public static boolean isValidNric(String test) { - return test.matches(VALIDATION_REGEX); + private static boolean isValidNric(String test) { + requireNonNull(test); + if (test.equals(AddCommandParser.DEFAULT_NULL)) { + return true; + } else { + return test.matches(VALIDATION_REGEX); + } } @Override From b1e7867fa20c3560b249e42250c1eff58e4f1377 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Fri, 8 Mar 2019 00:23:49 +0800 Subject: [PATCH 28/59] Added default value if Nric or Year is not specified by user --- .../java/seedu/address/logic/parser/AddCommandParser.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index a1b5513ab460..37a778c78c14 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -20,6 +20,7 @@ * Parses input arguments and creates a new AddCommand object */ public class AddCommandParser implements Parser { + public static final String DEFAULT_NULL = "-"; /** * Parses the given {@code String} of arguments in the context of the AddCommand @@ -40,8 +41,8 @@ public AddCommand parse(String args) throws ParseException { Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Nric nric = ParserUtil.parseNric(argMultimap.getValue(PREFIX_NRIC).orElse("S1234567A")); - int yearOfBirth = ParserUtil.parseYear(argMultimap.getValue(PREFIX_YEAR).orElse("1995")); + Nric nric = ParserUtil.parseNric(argMultimap.getValue(PREFIX_NRIC).orElse(DEFAULT_NULL)); + int yearOfBirth = ParserUtil.parseYear(argMultimap.getValue(PREFIX_YEAR).orElse(DEFAULT_NULL)); Patient patient = new Patient(name, phone, email, address, tagList, nric, yearOfBirth); From e610953899f9554f63a9a3d0271d83cff220d41d Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Fri, 8 Mar 2019 00:42:13 +0800 Subject: [PATCH 29/59] Minor changes to AddCommandParser and Nric classes --- .../java/seedu/address/logic/parser/AddCommandParser.java | 7 ++++--- src/main/java/seedu/address/model/person/Nric.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 37a778c78c14..49eb0a57b82d 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -20,7 +20,8 @@ * Parses input arguments and creates a new AddCommand object */ public class AddCommandParser implements Parser { - public static final String DEFAULT_NULL = "-"; + public static final String DEFAULT_NRIC = "-"; + public static final String DEFAULT_YEAR = "1900"; /** * Parses the given {@code String} of arguments in the context of the AddCommand @@ -41,8 +42,8 @@ public AddCommand parse(String args) throws ParseException { Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Nric nric = ParserUtil.parseNric(argMultimap.getValue(PREFIX_NRIC).orElse(DEFAULT_NULL)); - int yearOfBirth = ParserUtil.parseYear(argMultimap.getValue(PREFIX_YEAR).orElse(DEFAULT_NULL)); + Nric nric = ParserUtil.parseNric(argMultimap.getValue(PREFIX_NRIC).orElse(DEFAULT_NRIC)); + int yearOfBirth = ParserUtil.parseYear(argMultimap.getValue(PREFIX_YEAR).orElse(DEFAULT_YEAR)); Patient patient = new Patient(name, phone, email, address, tagList, nric, yearOfBirth); diff --git a/src/main/java/seedu/address/model/person/Nric.java b/src/main/java/seedu/address/model/person/Nric.java index 64f28a511289..4f02d6c7d870 100644 --- a/src/main/java/seedu/address/model/person/Nric.java +++ b/src/main/java/seedu/address/model/person/Nric.java @@ -33,7 +33,7 @@ public Nric(String nric) { */ private static boolean isValidNric(String test) { requireNonNull(test); - if (test.equals(AddCommandParser.DEFAULT_NULL)) { + if (test.equals(AddCommandParser.DEFAULT_NRIC)) { return true; } else { return test.matches(VALIDATION_REGEX); From 614263ddc7d9b277d10c8d1731c9329bc4f91e1d Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Fri, 8 Mar 2019 00:47:50 +0800 Subject: [PATCH 30/59] Simplified add success message to show only name of person added --- src/main/java/seedu/address/logic/commands/AddCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index cc539bfce6c4..91e828b0a74e 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -57,7 +57,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command model.addPerson(toAdd); model.commitAddressBook(); - return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); + return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd.getName())); } @Override From 2c3e7a9339003249d8a741cfdb40dd7b8b8310e1 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Fri, 8 Mar 2019 10:41:10 +0800 Subject: [PATCH 31/59] New class added to store birth day of patients --- .../address/model/patient/DateOfBirth.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/seedu/address/model/patient/DateOfBirth.java diff --git a/src/main/java/seedu/address/model/patient/DateOfBirth.java b/src/main/java/seedu/address/model/patient/DateOfBirth.java new file mode 100644 index 000000000000..b11b24d0acc7 --- /dev/null +++ b/src/main/java/seedu/address/model/patient/DateOfBirth.java @@ -0,0 +1,46 @@ +package seedu.address.model.patient; + +/** + * Represents the birth day of a patient. + */ +public class DateOfBirth { + private int day; + private int month; + private int year; + + /** + * Default constructor that takes in a birth day. + * @param day the day of birth. + * @param month the month of birth. + * @param year the year of birth. + */ + public DateOfBirth(int day, int month, int year) { + this.day = day; + this.month = month; + this.year = year; + } + + /** + * Sets the birth day of a patient to a specified date. + * @param day the day of birth. + * @param month the month of birth. + * @param year the year of birth. + */ + public void setTo(int day, int month, int year) { + this.day = day; + this.month = month; + this.year = year; + } + + public int getDay() { + return day; + } + + public int getMonth() { + return month; + } + + public int getYear() { + return year; + } +} From d18fb7bc4d0d896a11d5653f3e15293552cead41 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Fri, 8 Mar 2019 13:25:29 +0800 Subject: [PATCH 32/59] New exception to indicate when a person instance is not a patient instance --- .../model/patient/exceptions/PersonIsNotPatient.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/seedu/address/model/patient/exceptions/PersonIsNotPatient.java diff --git a/src/main/java/seedu/address/model/patient/exceptions/PersonIsNotPatient.java b/src/main/java/seedu/address/model/patient/exceptions/PersonIsNotPatient.java new file mode 100644 index 000000000000..19cc9238e9b4 --- /dev/null +++ b/src/main/java/seedu/address/model/patient/exceptions/PersonIsNotPatient.java @@ -0,0 +1,10 @@ +package seedu.address.model.patient.exceptions; + +/** + * Signals the operation that a person is not a patient instance. + */ +public class PersonIsNotPatient extends RuntimeException { + public PersonIsNotPatient() { + super("Person instance is not of Patient class. This should not happen."); + } +} From 67a90d232c3c2f7c92291db16f5adca6f6d48bd0 Mon Sep 17 00:00:00 2001 From: Kyler Wong Shen Meng Date: Fri, 8 Mar 2019 14:54:15 +0800 Subject: [PATCH 33/59] Working copy --- .../address/logic/commands/AddCommand.java | 11 ++- .../logic/parser/AddCommandParser.java | 26 ++++--- .../seedu/address/logic/parser/CliSyntax.java | 2 +- .../address/logic/parser/ParserUtil.java | 24 +++++-- .../address/model/patient/DateOfBirth.java | 70 ++++++++++++++----- .../model/{person => patient}/Nric.java | 18 +++-- .../seedu/address/model/patient/Patient.java | 58 +++++++++------ .../java/seedu/address/ui/PersonCard.java | 28 +++++--- src/main/resources/view/PersonListCard.fxml | 2 + 9 files changed, 163 insertions(+), 76 deletions(-) rename src/main/java/seedu/address/model/{person => patient}/Nric.java (78%) diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 91e828b0a74e..22885fe550b0 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -4,12 +4,15 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_YEAR; import seedu.address.logic.CommandHistory; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.patient.Patient; import seedu.address.model.person.Person; /** @@ -22,12 +25,16 @@ public class AddCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. " + "Parameters: " + PREFIX_NAME + "NAME " + + PREFIX_NRIC + "NRIC " + + PREFIX_YEAR + "DOB " + PREFIX_PHONE + "PHONE " + PREFIX_EMAIL + "EMAIL " + PREFIX_ADDRESS + "ADDRESS " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "John Doe " + + PREFIX_NRIC + "S1234567A " + + PREFIX_YEAR + "30-12-1990 " + PREFIX_PHONE + "98765432 " + PREFIX_EMAIL + "johnd@example.com " + PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " @@ -37,12 +44,12 @@ public class AddCommand extends Command { public static final String MESSAGE_SUCCESS = "New patient added: %1$s"; public static final String MESSAGE_DUPLICATE_PERSON = "This patient already exists in the dental book"; - private final Person toAdd; + private final Patient toAdd; /** * Creates an AddCommand to add the specified {@code Person} */ - public AddCommand(Person patient) { + public AddCommand(Patient patient) { requireNonNull(patient); toAdd = patient; } diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 49eb0a57b82d..58857242de11 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -1,18 +1,25 @@ package seedu.address.logic.parser; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.*; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_YEAR; import java.util.Set; import java.util.stream.Stream; import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.patient.DateOfBirth; import seedu.address.model.patient.Patient; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; -import seedu.address.model.person.Nric; +import seedu.address.model.patient.Nric; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; @@ -20,8 +27,6 @@ * Parses input arguments and creates a new AddCommand object */ public class AddCommandParser implements Parser { - public static final String DEFAULT_NRIC = "-"; - public static final String DEFAULT_YEAR = "1900"; /** * Parses the given {@code String} of arguments in the context of the AddCommand @@ -30,10 +35,11 @@ public class AddCommandParser implements Parser { */ public AddCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG); + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG, + PREFIX_NRIC, PREFIX_YEAR); - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL) - || !argMultimap.getPreamble().isEmpty()) { + if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_NRIC, + PREFIX_YEAR) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } @@ -42,10 +48,10 @@ public AddCommand parse(String args) throws ParseException { Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Nric nric = ParserUtil.parseNric(argMultimap.getValue(PREFIX_NRIC).orElse(DEFAULT_NRIC)); - int yearOfBirth = ParserUtil.parseYear(argMultimap.getValue(PREFIX_YEAR).orElse(DEFAULT_YEAR)); + Nric nric = ParserUtil.parseNric(argMultimap.getValue(PREFIX_NRIC).get()); + DateOfBirth dateOfBirth = ParserUtil.parseDob(argMultimap.getValue(PREFIX_YEAR).get()); - Patient patient = new Patient(name, phone, email, address, tagList, nric, yearOfBirth); + Patient patient = new Patient(name, phone, email, address, tagList, nric, dateOfBirth); return new AddCommand(patient); } diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 3c29f1b97ddf..23ddbe351a1b 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -12,6 +12,6 @@ public class CliSyntax { public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); public static final Prefix PREFIX_NRIC = new Prefix("ic/"); - public static final Prefix PREFIX_YEAR = new Prefix("year/"); + public static final Prefix PREFIX_YEAR = new Prefix("dob/"); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 67f50d4e7294..6cca2f4b60e2 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -10,10 +10,11 @@ import seedu.address.commons.core.index.Index; import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.patient.DateOfBirth; +import seedu.address.model.patient.Nric; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; -import seedu.address.model.person.Nric; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; @@ -44,6 +45,7 @@ public static Index parseIndex(String oneBasedIndex) throws ParseException { * @throws ParseException if the given {@code name} is invalid. */ public static Name parseName(String name) throws ParseException { + System.out.println("Parsed name = " + name); requireNonNull(name); String trimmedName = name.trim(); if (!Name.isValidName(trimmedName)) { @@ -101,20 +103,28 @@ public static Email parseEmail(String email) throws ParseException { * Parses a {@code String nric} into an {@code Nric}. * Leading and trailing whitespaces will be trimmed. */ - public static Nric parseNric(String nric) { + public static Nric parseNric(String nric) throws ParseException { + System.out.println("Parsed NRIC = " + nric); requireNonNull(nric); String trimmedNric = nric.trim(); + if (!Nric.isValidNric(trimmedNric)) { + throw new ParseException(Nric.MESSAGE_CONSTRAINTS); + } return new Nric(trimmedNric); } /** - * Parses a {@code String email} into an {@code Email}. + * Parses a {@code String dob} into an {@code Dob}. * Leading and trailing whitespaces will be trimmed. */ - public static int parseYear(String year) { - requireNonNull(year); - String trimmedYear = year.trim(); - return Integer.parseInt(trimmedYear); + public static DateOfBirth parseDob(String dob) throws ParseException { + System.out.println("Parsed DOB = " + dob); + requireNonNull(dob); + String trimmedDob = dob.trim(); + if (!DateOfBirth.isValidDob(dob)) { + throw new ParseException(DateOfBirth.MESSAGE_CONSTRAINTS); + } + return new DateOfBirth(trimmedDob); } /** diff --git a/src/main/java/seedu/address/model/patient/DateOfBirth.java b/src/main/java/seedu/address/model/patient/DateOfBirth.java index b11b24d0acc7..e76566ddb4e7 100644 --- a/src/main/java/seedu/address/model/patient/DateOfBirth.java +++ b/src/main/java/seedu/address/model/patient/DateOfBirth.java @@ -1,23 +1,53 @@ package seedu.address.model.patient; +import static java.util.Objects.requireNonNull; + +import java.util.Calendar; +import java.util.Date; + /** * Represents the birth day of a patient. */ public class DateOfBirth { + public static final String MESSAGE_CONSTRAINTS = + "Date of birth is compulsory, denoted by \\dob and should be in standard format."; + private static final String[] MONTHS = {"", "January", "February", "March", "April", "May", "June", "July", + "August", "September", "October", "November", "December"}; + private int day; private int month; private int year; /** * Default constructor that takes in a birth day. - * @param day the day of birth. - * @param month the month of birth. - * @param year the year of birth. + * @param dob the dob in yyyy-mm-dd format. */ - public DateOfBirth(int day, int month, int year) { - this.day = day; - this.month = month; - this.year = year; + public DateOfBirth(String dob) { + String[] temp = dob.split("-"); + int year = Integer.parseInt(temp[0].trim()); + int month = Integer.parseInt(temp[1].trim()); + int day = Integer.parseInt(temp[2].trim()); + setTo(day, month, year); + } + + /** + * Returns true if a given string is a valid DOB. + * @param test the string to be tested. + */ + public static boolean isValidDob(String test) { + requireNonNull(test); + try { + String[] temp = test.split("-"); + String year = temp[0].trim(); + String month = temp[1].trim(); + String day = temp[2].trim(); + assert year.length() == 4 : "Year length is not 4"; + assert month.length() == 2 : "Month length is not 2"; + assert day.length() == 2 : "Day length is not 2"; + return true; + } catch (Exception e) { + return false; + } } /** @@ -26,21 +56,29 @@ public DateOfBirth(int day, int month, int year) { * @param month the month of birth. * @param year the year of birth. */ - public void setTo(int day, int month, int year) { + void setTo(int day, int month, int year) { this.day = day; this.month = month; this.year = year; } - public int getDay() { - return day; - } - - public int getMonth() { - return month; + /** + * Gets the birth day of the patient in DD MMMM YYYY format. + * @return the birth day. + */ + public String getDate() { + return day + " " + MONTHS[month] + " " + year; } - public int getYear() { - return year; + /** + * Calculates the patient's age. + * @return the patient's age. + */ + int getAge() { + Date today = new Date(); + Calendar cal = Calendar.getInstance(); + cal.setTime(today); + int currentYear = cal.get(Calendar.DAY_OF_YEAR); + return currentYear - year; } } diff --git a/src/main/java/seedu/address/model/person/Nric.java b/src/main/java/seedu/address/model/patient/Nric.java similarity index 78% rename from src/main/java/seedu/address/model/person/Nric.java rename to src/main/java/seedu/address/model/patient/Nric.java index 4f02d6c7d870..15eaf628d7de 100644 --- a/src/main/java/seedu/address/model/person/Nric.java +++ b/src/main/java/seedu/address/model/patient/Nric.java @@ -1,10 +1,8 @@ -package seedu.address.model.person; +package seedu.address.model.patient; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; -import seedu.address.logic.parser.AddCommandParser; - /** * Represents a Person's Nric in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidNric(String)} @@ -12,7 +10,7 @@ public class Nric { public static final String MESSAGE_CONSTRAINTS = - "Nric should contain only \"-\" or \"XdddddddX\""; + "Nric is compulsory, denoted by \\nric and should be in standard format."; public static final String VALIDATION_REGEX = "^[STFG]\\d{7}[A-Z]$"; public final String value; @@ -31,13 +29,13 @@ public Nric(String nric) { * Returns true if a given string is a valid Nric number, or intentionally left empty (-). * @param test the string to be tested. */ - private static boolean isValidNric(String test) { + public static boolean isValidNric(String test) { requireNonNull(test); - if (test.equals(AddCommandParser.DEFAULT_NRIC)) { - return true; - } else { - return test.matches(VALIDATION_REGEX); - } + return test.matches(VALIDATION_REGEX); + } + + public String getNric() { + return value; } @Override diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java index ec6993faca94..14bdb3dff939 100644 --- a/src/main/java/seedu/address/model/patient/Patient.java +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -3,15 +3,13 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; import java.util.Objects; import java.util.Set; +import seedu.address.model.patient.exceptions.PersonIsNotPatient; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; -import seedu.address.model.person.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; import seedu.address.model.record.Record; @@ -26,7 +24,7 @@ public class Patient extends Person { private static final String CHILD = "child"; private static final String ADULT = "adult"; private Nric nric; - private Integer yearOfBirth; + private DateOfBirth dateOfBirth; private Teeth teeth = null; private boolean buildSpecified = false; private ArrayList records = new ArrayList<>(); @@ -35,20 +33,20 @@ public class Patient extends Person { * Every field must be present and not null. */ public Patient(Name name, Phone phone, Email email, Address address, Set tags, Nric nric, - Integer yearOfBirth) { + DateOfBirth dateOfBirth) { super(name, phone, email, address, tags); - requireAllNonNull(nric, yearOfBirth); + requireAllNonNull(nric, dateOfBirth); this.nric = nric; - this.yearOfBirth = yearOfBirth; + this.dateOfBirth = dateOfBirth; inferTeethBuild(); } private Patient(Name name, Phone phone, Email email, Address address, Set tags, - Person personToCopy, int copyCount, Nric nric, int yearOfBirth) { + Person personToCopy, int copyCount, Nric nric, DateOfBirth dateOfBirth) { super(name, phone, email, address, tags, personToCopy, copyCount); - requireAllNonNull(nric, yearOfBirth); + requireAllNonNull(nric, dateOfBirth); this.nric = nric; - this.yearOfBirth = yearOfBirth; + this.dateOfBirth = dateOfBirth; inferTeethBuild(); } @@ -96,11 +94,7 @@ private void buildTeeth(String teethLayout) { * @return the age of the patient. */ private int getPatientAge() { - Date today = new Date(); - Calendar cal = Calendar.getInstance(); - cal.setTime(today); - int currentYear = cal.get(Calendar.DAY_OF_YEAR); - return currentYear - yearOfBirth; + return dateOfBirth.getAge(); } public void setRecords(ArrayList records) { @@ -115,8 +109,8 @@ public Nric getNric() { return nric; } - public Integer getYearOfBirth() { - return yearOfBirth; + public DateOfBirth getDateOfBirth() { + return dateOfBirth; } public boolean isBuildSpecified() { @@ -130,18 +124,38 @@ public ArrayList getRecords() { /** * Returns true if both patients has the same NRIC. */ - public boolean isSamePatient(Patient otherPerson) { - if (nric != null) { - return nric.equals(otherPerson.getNric()); + @Override + public boolean isSamePerson(Person otherPerson) { + if (otherPerson instanceof Patient) { + return nric.equals(((Patient) otherPerson).getNric()); } else { - return false; + System.out.println(otherPerson); + throw new PersonIsNotPatient(); } } @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, address, tags, nric, yearOfBirth, records); + return Objects.hash(name, phone, email, address, tags, nric, dateOfBirth, records); } + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append(getName()) + .append(" NRIC: ") + .append(nric.getNric()) + .append(" Date of Birth: ") + .append(dateOfBirth.getDate()) + .append(" Phone: ") + .append(getPhone()) + .append(" Email: ") + .append(getEmail()) + .append(" Address: ") + .append(getAddress()) + .append(" Tags: "); + getTags().forEach(builder::append); + return builder.toString(); + } } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index f6727ea83abd..0f52c5fed62f 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -5,6 +5,8 @@ import javafx.scene.layout.FlowPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Region; +import seedu.address.model.patient.Patient; +import seedu.address.model.patient.exceptions.PersonIsNotPatient; import seedu.address.model.person.Person; /** @@ -27,9 +29,13 @@ public class PersonCard extends UiPart { @FXML private HBox cardPane; @FXML + private Label id; + @FXML private Label name; @FXML - private Label id; + private Label nric; + @FXML + private Label dateOfBirth; @FXML private Label phone; @FXML @@ -41,13 +47,19 @@ public class PersonCard extends UiPart { public PersonCard(Person person, int displayedIndex) { super(FXML); - this.person = person; - id.setText(displayedIndex + ". "); - name.setText(person.getName().fullName); - phone.setText(person.getPhone().value); - address.setText(person.getAddress().value); - email.setText(person.getEmail().value); - person.getTags().forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); + if (person instanceof Patient) { + this.person = person; + id.setText(displayedIndex + ". "); + name.setText(person.getName().fullName); + nric.setText(((Patient) person).getNric().toString()); + dateOfBirth.setText(((Patient) person).getDateOfBirth().getDate()); + phone.setText(person.getPhone().value); + address.setText(person.getAddress().value); + email.setText(person.getEmail().value); + person.getTags().forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); + } else { + throw new PersonIsNotPatient(); + } } @Override diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index f08ea32ad558..723579000fd8 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -28,6 +28,8 @@