From 9d1b0f7381e6ea29f9f7c3767140a6636e6b6835 Mon Sep 17 00:00:00 2001 From: jnsereko Date: Wed, 22 Apr 2020 14:15:03 +0300 Subject: [PATCH] SYNCT-58: Added PersonObject class. I wasn to create an implementation for Person Object pull and push --- .../module/sync2/person/PersonObject.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 api/src/main/java/org/openmrs/module/sync2/person/PersonObject.java diff --git a/api/src/main/java/org/openmrs/module/sync2/person/PersonObject.java b/api/src/main/java/org/openmrs/module/sync2/person/PersonObject.java new file mode 100644 index 00000000..69180e0d --- /dev/null +++ b/api/src/main/java/org/openmrs/module/sync2/person/PersonObject.java @@ -0,0 +1,87 @@ +package org.openmrs.module.sync2.person; + +import java.util.Calendar; +import java.util.Date; + + +public class PersonObject { + + private String uuid; + + private Date birthDate; + + private String gender; + + private Integer age; + + private String display; + + public PersonObject() { + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String grtUuid() { + return this.uuid; + } + + public void setBirthDate(Date birthDate) { + this.birthDate = birthDate; + } + + public Date getDate() { + return this.birthDate; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getGender() { + return this.gender; + } + + public Integer getAge(Date onDate) { + if (birthDate == null) { + return null; + } + + // Use default end date as today. + Calendar today = Calendar.getInstance(); + // But if given, use the given date. + if (onDate != null) { + today.setTime(onDate); + } + + Calendar bday = Calendar.getInstance(); + bday.setTime(birthDate); + + this.age = today.get(Calendar.YEAR) - bday.get(Calendar.YEAR); + + // Adjust age when today's date is before the person's birthday + int todaysMonth = today.get(Calendar.MONTH); + int bdayMonth = bday.get(Calendar.MONTH); + int todaysDay = today.get(Calendar.DAY_OF_MONTH); + int bdayDay = bday.get(Calendar.DAY_OF_MONTH); + + if (todaysMonth < bdayMonth) { + this.age--; + } else if (todaysMonth == bdayMonth && todaysDay < bdayDay) { + // we're only comparing on month and day, not minutes, etc + this.age--; + } + + return this.age; + } + + public void SetDisplay(String display) { + this.display = display; + } + + public String getDisplay(String display) { + return this.display; + } + +} \ No newline at end of file