dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21348
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10071: lwuit person registration
------------------------------------------------------------
revno: 10071
committer: Homg Em <em.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-03-08 16:38:34 +0700
message:
lwuit person registration
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java
dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java
dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java
dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java
dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java 2013-03-08 09:38:34 +0000
@@ -41,538 +41,458 @@
* @author Abyot Asalefew Gizaw
* @version $Id$
*/
-public class Patient
- implements Serializable
-{
- /**
- * Determines if a de-serialized file is compatible with this class.
- */
- private static final long serialVersionUID = 884114994005945275L;
-
- public static final String MALE = "M";
- public static final String FEMALE = "F";
- public static final String TRANSGENDER = "M";
-
- public static final char DOB_TYPE_VERIFIED = 'V';
- public static final char DOB_TYPE_DECLARED = 'D';
- public static final char DOB_TYPE_APPROXIATED = 'A';
-
- public static final char AGE_TYPE_YEAR = 'Y';
- public static final char AGE_TYPE_MONTH = 'M';
- public static final char AGE_TYPE_DAY = 'D';
-
- public static String PREFIX_IDENTIFIER_TYPE = "iden";
- public static String PREFIX_FIXED_ATTRIBUTE = "fixedAttr";
- public static String PREFIX_PATIENT_ATTRIBUTE = "attr";
- public static String PREFIX_PROGRAM = "prg";
- public static String PREFIX_PROGRAM_EVENT_BY_STATUS = "stat";
- public static String PREFIX_PROGRAM_STAGE = "prgst";
- public static String FIXED_ATTR_BIRTH_DATE = "birthDate";
- public static String FIXED_ATTR_AGE = "age";
-
- private Integer id;
-
- private String firstName;
-
- private String middleName;
-
- private String lastName;
-
- private String gender;
-
- private Date birthDate;
-
- private String phoneNumber;
-
- private Date deathDate;
-
- private Date registrationDate;
-
- private boolean isDead = false;
-
- private Set<PatientIdentifier> identifiers = new HashSet<PatientIdentifier>();
-
- private Set<Program> programs = new HashSet<Program>();
-
- private OrganisationUnit organisationUnit;
-
- private Set<PatientAttribute> attributes = new HashSet<PatientAttribute>();
-
- private Patient representative;
-
- private boolean underAge;
-
- private Character dobType;
-
- private User healthWorker;
-
- // -------------------------------------------------------------------------
- // Constructors
- // -------------------------------------------------------------------------
-
- public Patient()
- {
- }
-
- // -------------------------------------------------------------------------
- // hashCode and equals
- // -------------------------------------------------------------------------
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
-
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- result = prime * result + ((birthDate == null) ? 0 : birthDate.hashCode());
- result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
- result = prime * result + ((gender == null) ? 0 : gender.hashCode());
- result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
- result = prime * result + ((middleName == null) ? 0 : middleName.hashCode());
-
- return result;
- }
-
- @Override
- public boolean equals( Object obj )
- {
- if ( this == obj )
- {
- return true;
- }
-
- if ( obj == null )
- {
- return false;
- }
-
- if ( getClass() != obj.getClass() )
- {
- return false;
- }
-
- final Patient other = (Patient) obj;
-
- if ( birthDate == null )
- {
- if ( other.birthDate != null )
- {
- return false;
- }
- }
- else if ( !birthDate.equals( other.birthDate ) )
- {
- return false;
- }
-
- if ( firstName == null )
- {
- if ( other.firstName != null )
- {
- return false;
- }
- }
- else if ( !firstName.equals( other.firstName ) )
- {
- return false;
- }
-
- if ( gender == null )
- {
- if ( other.gender != null )
- return false;
- }
- else if ( !gender.equals( other.gender ) )
- {
- return false;
- }
-
- if ( lastName == null )
- {
- if ( other.lastName != null )
- {
- return false;
- }
- }
- else if ( !lastName.equals( other.lastName ) )
- {
- return false;
- }
-
- if ( middleName == null )
- {
- if ( other.middleName != null )
- {
- return false;
- }
- }
- else if ( !middleName.equals( other.middleName ) )
- {
- return false;
- }
-
- return true;
- }
-
- // -------------------------------------------------------------------------
- // Getters and setters
- // -------------------------------------------------------------------------
-
- public Integer getId()
- {
- return id;
- }
-
- public Set<PatientAttribute> getAttributes()
- {
- return attributes;
- }
-
- public OrganisationUnit getOrganisationUnit()
- {
- return organisationUnit;
- }
-
- public void setOrganisationUnit( OrganisationUnit organisationUnit )
- {
- this.organisationUnit = organisationUnit;
- }
-
- public void setAttributes( Set<PatientAttribute> attributes )
- {
- this.attributes = attributes;
- }
-
- public void setId( Integer id )
- {
- this.id = id;
- }
-
- public String getFirstName()
- {
- return firstName;
- }
-
- public void setFirstName( String firstName )
- {
- this.firstName = firstName;
- }
-
- public String getMiddleName()
- {
- return middleName;
- }
-
- public void setMiddleName( String middleName )
- {
- this.middleName = middleName;
- }
-
- public String getLastName()
- {
- return lastName;
- }
-
- public void setLastName( String lastName )
- {
- this.lastName = lastName;
- }
-
- public String getGender()
- {
- return gender;
- }
-
- public void setGender( String gender )
- {
- this.gender = gender;
- }
-
- public Date getBirthDate()
- {
- return birthDate;
- }
-
- public void setBirthDate( Date birthDate )
- {
- this.birthDate = birthDate;
- }
-
- public Date getDeathDate()
- {
- return deathDate;
- }
-
- public void setDeathDate( Date deathDate )
- {
- this.deathDate = deathDate;
- }
-
- public Boolean getIsDead()
- {
- return isDead;
- }
-
- public void setIsDead( Boolean isDead )
- {
- this.isDead = isDead;
- }
-
- public Set<PatientIdentifier> getIdentifiers()
- {
- return identifiers;
- }
-
- public void setIdentifiers( Set<PatientIdentifier> identifiers )
- {
- this.identifiers = identifiers;
- }
-
- public Set<Program> getPrograms()
- {
- return programs;
- }
-
- public void setPrograms( Set<Program> programs )
- {
- this.programs = programs;
- }
-
- public User getHealthWorker()
- {
- return healthWorker;
- }
-
- public void setHealthWorker( User healthWorker )
- {
- this.healthWorker = healthWorker;
- }
-
- public void setRegistrationDate( Date registrationDate )
- {
- this.registrationDate = registrationDate;
- }
-
- public Date getRegistrationDate()
- {
- return registrationDate;
- }
-
- public void setRepresentative( Patient representative )
- {
- this.representative = representative;
- }
-
- public Patient getRepresentative()
- {
- return representative;
- }
-
- // -------------------------------------------------------------------------
- // Convenience method
- // -------------------------------------------------------------------------
-
- public String getAge()
- {
- if ( birthDate == null )
- {
- return "0";
- }
-
- Calendar birthCalendar = Calendar.getInstance();
- birthCalendar.setTime( birthDate );
-
- Calendar todayCalendar = Calendar.getInstance();
-
- int age = todayCalendar.get( Calendar.YEAR ) - birthCalendar.get( Calendar.YEAR );
-
- if ( todayCalendar.get( Calendar.MONTH ) < birthCalendar.get( Calendar.MONTH ) )
- {
- age--;
- }
- else if ( todayCalendar.get( Calendar.MONTH ) == birthCalendar.get( Calendar.MONTH )
- && todayCalendar.get( Calendar.DAY_OF_MONTH ) < birthCalendar.get( Calendar.DAY_OF_MONTH ) )
- {
- age--;
- }
-
- if ( age < 1 )
- {
- return "< 1 yr";
- }
- else
- {
- return age + " yr";
- }
- }
-
- public int getIntegerValueOfAge()
- {
- if ( birthDate == null )
- {
- return 0;
- }
-
- Calendar birthCalendar = Calendar.getInstance();
- birthCalendar.setTime( birthDate );
-
- Calendar todayCalendar = Calendar.getInstance();
-
- int age = todayCalendar.get( Calendar.YEAR ) - birthCalendar.get( Calendar.YEAR );
-
- if ( todayCalendar.get( Calendar.MONTH ) < birthCalendar.get( Calendar.MONTH ) )
- {
- age--;
- }
- else if ( todayCalendar.get( Calendar.MONTH ) == birthCalendar.get( Calendar.MONTH )
- && todayCalendar.get( Calendar.DAY_OF_MONTH ) < birthCalendar.get( Calendar.DAY_OF_MONTH ) )
- {
- age--;
- }
-
- return age;
- }
-
- public void setBirthDateFromAge( int age, char ageType )
- {
- Calendar todayCalendar = Calendar.getInstance();
- todayCalendar.clear( Calendar.MILLISECOND );
- todayCalendar.clear( Calendar.SECOND );
- todayCalendar.clear( Calendar.MINUTE );
- todayCalendar.set( Calendar.HOUR_OF_DAY, 0 );
-
- // Assumed relative to the 1st of January
- // todayCalendar.set( Calendar.DATE, 1 );
- // todayCalendar.set( Calendar.MONTH, Calendar.JANUARY );
-
- if ( ageType == AGE_TYPE_YEAR )
- {
- todayCalendar.add( Calendar.YEAR, -1 * age );
- }
- else if ( ageType == AGE_TYPE_MONTH )
- {
- todayCalendar.add( Calendar.MONTH, -1 * age );
- }
- else if ( ageType == AGE_TYPE_DAY )
- {
- todayCalendar.add( Calendar.DATE, -1 * age );
- }
-
- setBirthDate( todayCalendar.getTime() );
- }
-
- public char getAgeType()
- {
- Calendar todayCalendar = Calendar.getInstance();
- todayCalendar.clear( Calendar.MILLISECOND );
- todayCalendar.clear( Calendar.SECOND );
- todayCalendar.clear( Calendar.MINUTE );
- todayCalendar.set( Calendar.HOUR_OF_DAY, 0 );
-
- Calendar birthCalendar = Calendar.getInstance();
- birthCalendar.setTime( birthDate );
-
- int age = todayCalendar.get( Calendar.YEAR ) - birthCalendar.get( Calendar.YEAR );
-
- if ( age > 0 )
- {
- return AGE_TYPE_YEAR;
- }
-
- age = todayCalendar.get( Calendar.MONTH ) - birthCalendar.get( Calendar.MONTH );
- if ( age > 0 )
- {
- return AGE_TYPE_MONTH;
- }
-
- return AGE_TYPE_DAY;
- }
-
- // -------------------------------------------------------------------------
- // Getter && Setter
- // -------------------------------------------------------------------------
-
- public String getFullName()
- {
- boolean space = false;
- String name = "";
-
- if ( firstName != null && firstName.length() != 0 )
- {
- name = firstName;
- space = true;
- }
-
- if ( middleName != null && middleName.length() != 0 )
- {
- if ( space )
- {
- name += " ";
- }
-
- name += middleName;
- space = true;
- }
-
- if ( lastName != null && lastName.length() != 0 )
- {
- if ( space )
- {
- name += " ";
- }
-
- name += lastName;
- }
-
- return name;
- }
-
- public String getPhoneNumber()
- {
- return phoneNumber;
- }
-
- public void setPhoneNumber( String phoneNumber )
- {
- this.phoneNumber = phoneNumber;
- }
-
- public boolean isUnderAge()
- {
- return underAge;
- }
-
- public void setUnderAge( boolean underAge )
- {
- this.underAge = underAge;
- }
-
- public String getTextGender()
- {
- return gender.equalsIgnoreCase( MALE ) ? "male" : "female";
- }
-
- public Character getDobType()
- {
- return dobType;
- }
-
- public void setDobType( Character dobType )
- {
- this.dobType = dobType;
- }
-
- public String getTextDoBType()
- {
- switch ( dobType )
- {
- case DOB_TYPE_VERIFIED:
- return "Verified";
- case DOB_TYPE_DECLARED:
- return "Declared";
- default:
- return "Approxiated";
- }
- }
+public class Patient implements Serializable {
+ /**
+ * Determines if a de-serialized file is compatible with this class.
+ */
+ private static final long serialVersionUID = 884114994005945275L;
+
+ public static final String MALE = "M";
+ public static final String FEMALE = "F";
+ public static final String TRANSGENDER = "M";
+
+ public static final char DOB_TYPE_VERIFIED = 'V';
+ public static final char DOB_TYPE_DECLARED = 'D';
+ public static final char DOB_TYPE_APPROXIATED = 'A';
+
+ public static final char AGE_TYPE_YEAR = 'Y';
+ public static final char AGE_TYPE_MONTH = 'M';
+ public static final char AGE_TYPE_DAY = 'D';
+
+ public static String PREFIX_IDENTIFIER_TYPE = "iden";
+ public static String PREFIX_FIXED_ATTRIBUTE = "fixedAttr";
+ public static String PREFIX_PATIENT_ATTRIBUTE = "attr";
+ public static String PREFIX_PROGRAM = "prg";
+ public static String PREFIX_PROGRAM_EVENT_BY_STATUS = "stat";
+ public static String PREFIX_PROGRAM_STAGE = "prgst";
+ public static String FIXED_ATTR_BIRTH_DATE = "birthDate";
+ public static String FIXED_ATTR_AGE = "age";
+
+ private Integer id;
+
+ private String firstName;
+
+ private String middleName;
+
+ private String lastName;
+
+ private String gender;
+
+ private Date birthDate;
+
+ private String phoneNumber;
+
+ private Date deathDate;
+
+ private Date registrationDate;
+
+ private boolean isDead = false;
+
+ private Set<PatientIdentifier> identifiers = new HashSet<PatientIdentifier>();
+
+ private Set<Program> programs = new HashSet<Program>();
+
+ private OrganisationUnit organisationUnit;
+
+ private Set<PatientAttribute> attributes = new HashSet<PatientAttribute>();
+
+ private Patient representative;
+
+ private boolean underAge;
+
+ private Character dobType;
+
+ private User healthWorker;
+
+ // -------------------------------------------------------------------------
+ // Constructors
+ // -------------------------------------------------------------------------
+
+ public Patient() {
+ }
+
+ // -------------------------------------------------------------------------
+ // hashCode and equals
+ // -------------------------------------------------------------------------
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result
+ + ((birthDate == null) ? 0 : birthDate.hashCode());
+ result = prime * result
+ + ((firstName == null) ? 0 : firstName.hashCode());
+ result = prime * result + ((gender == null) ? 0 : gender.hashCode());
+ result = prime * result
+ + ((lastName == null) ? 0 : lastName.hashCode());
+ result = prime * result
+ + ((middleName == null) ? 0 : middleName.hashCode());
+
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ final Patient other = (Patient) obj;
+
+ if (birthDate == null) {
+ if (other.birthDate != null) {
+ return false;
+ }
+ } else if (!birthDate.equals(other.birthDate)) {
+ return false;
+ }
+
+ if (firstName == null) {
+ if (other.firstName != null) {
+ return false;
+ }
+ } else if (!firstName.equals(other.firstName)) {
+ return false;
+ }
+
+ if (gender == null) {
+ if (other.gender != null)
+ return false;
+ } else if (!gender.equals(other.gender)) {
+ return false;
+ }
+
+ if (lastName == null) {
+ if (other.lastName != null) {
+ return false;
+ }
+ } else if (!lastName.equals(other.lastName)) {
+ return false;
+ }
+
+ if (middleName == null) {
+ if (other.middleName != null) {
+ return false;
+ }
+ } else if (!middleName.equals(other.middleName)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ // -------------------------------------------------------------------------
+ // Getters and setters
+ // -------------------------------------------------------------------------
+
+ public Integer getId() {
+ return id;
+ }
+
+ public Set<PatientAttribute> getAttributes() {
+ return attributes;
+ }
+
+ public OrganisationUnit getOrganisationUnit() {
+ return organisationUnit;
+ }
+
+ public void setOrganisationUnit(OrganisationUnit organisationUnit) {
+ this.organisationUnit = organisationUnit;
+ }
+
+ public void setAttributes(Set<PatientAttribute> attributes) {
+ this.attributes = attributes;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getMiddleName() {
+ return middleName;
+ }
+
+ public void setMiddleName(String middleName) {
+ this.middleName = middleName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getGender() {
+ return gender;
+ }
+
+ public void setGender(String gender) {
+ this.gender = gender;
+ }
+
+ public Date getBirthDate() {
+ return birthDate;
+ }
+
+ public void setBirthDate(Date birthDate) {
+ this.birthDate = birthDate;
+ }
+
+ public Date getDeathDate() {
+ return deathDate;
+ }
+
+ public void setDeathDate(Date deathDate) {
+ this.deathDate = deathDate;
+ }
+
+ public Boolean getIsDead() {
+ return isDead;
+ }
+
+ public void setIsDead(Boolean isDead) {
+ this.isDead = isDead;
+ }
+
+ public Set<PatientIdentifier> getIdentifiers() {
+ return identifiers;
+ }
+
+ public void setIdentifiers(Set<PatientIdentifier> identifiers) {
+ this.identifiers = identifiers;
+ }
+
+ public Set<Program> getPrograms() {
+ return programs;
+ }
+
+ public void setPrograms(Set<Program> programs) {
+ this.programs = programs;
+ }
+
+ public User getHealthWorker() {
+ return healthWorker;
+ }
+
+ public void setHealthWorker(User healthWorker) {
+ this.healthWorker = healthWorker;
+ }
+
+ public void setRegistrationDate(Date registrationDate) {
+ this.registrationDate = registrationDate;
+ }
+
+ public Date getRegistrationDate() {
+ return registrationDate;
+ }
+
+ public void setRepresentative(Patient representative) {
+ this.representative = representative;
+ }
+
+ public Patient getRepresentative() {
+ return representative;
+ }
+
+ // -------------------------------------------------------------------------
+ // Convenience method
+ // -------------------------------------------------------------------------
+
+ public String getAge() {
+ if (birthDate == null) {
+ return "0";
+ }
+
+ Calendar birthCalendar = Calendar.getInstance();
+ birthCalendar.setTime(birthDate);
+
+ Calendar todayCalendar = Calendar.getInstance();
+
+ int age = todayCalendar.get(Calendar.YEAR)
+ - birthCalendar.get(Calendar.YEAR);
+
+ if (todayCalendar.get(Calendar.MONTH) < birthCalendar
+ .get(Calendar.MONTH)) {
+ age--;
+ } else if (todayCalendar.get(Calendar.MONTH) == birthCalendar
+ .get(Calendar.MONTH)
+ && todayCalendar.get(Calendar.DAY_OF_MONTH) < birthCalendar
+ .get(Calendar.DAY_OF_MONTH)) {
+ age--;
+ }
+
+ if (age < 1) {
+ return "< 1 yr";
+ } else {
+ return age + " yr";
+ }
+ }
+
+ public int getIntegerValueOfAge() {
+ if (birthDate == null) {
+ return 0;
+ }
+
+ Calendar birthCalendar = Calendar.getInstance();
+ birthCalendar.setTime(birthDate);
+
+ Calendar todayCalendar = Calendar.getInstance();
+
+ int age = todayCalendar.get(Calendar.YEAR)
+ - birthCalendar.get(Calendar.YEAR);
+
+ if (todayCalendar.get(Calendar.MONTH) < birthCalendar
+ .get(Calendar.MONTH)) {
+ age--;
+ } else if (todayCalendar.get(Calendar.MONTH) == birthCalendar
+ .get(Calendar.MONTH)
+ && todayCalendar.get(Calendar.DAY_OF_MONTH) < birthCalendar
+ .get(Calendar.DAY_OF_MONTH)) {
+ age--;
+ }
+
+ return age;
+ }
+
+ public void setBirthDateFromAge(int age, char ageType) {
+ Calendar todayCalendar = Calendar.getInstance();
+ todayCalendar.clear(Calendar.MILLISECOND);
+ todayCalendar.clear(Calendar.SECOND);
+ todayCalendar.clear(Calendar.MINUTE);
+ todayCalendar.set(Calendar.HOUR_OF_DAY, 0);
+
+ // Assumed relative to the 1st of January
+ // todayCalendar.set( Calendar.DATE, 1 );
+ // todayCalendar.set( Calendar.MONTH, Calendar.JANUARY );
+
+ if (ageType == AGE_TYPE_YEAR) {
+ todayCalendar.add(Calendar.YEAR, -1 * age);
+ } else if (ageType == AGE_TYPE_MONTH) {
+ todayCalendar.add(Calendar.MONTH, -1 * age);
+ } else if (ageType == AGE_TYPE_DAY) {
+ todayCalendar.add(Calendar.DATE, -1 * age);
+ }
+
+ setBirthDate(todayCalendar.getTime());
+ }
+
+ public char getAgeType() {
+ Calendar todayCalendar = Calendar.getInstance();
+ todayCalendar.clear(Calendar.MILLISECOND);
+ todayCalendar.clear(Calendar.SECOND);
+ todayCalendar.clear(Calendar.MINUTE);
+ todayCalendar.set(Calendar.HOUR_OF_DAY, 0);
+
+ Calendar birthCalendar = Calendar.getInstance();
+ birthCalendar.setTime(birthDate);
+
+ int age = todayCalendar.get(Calendar.YEAR)
+ - birthCalendar.get(Calendar.YEAR);
+
+ if (age > 0) {
+ return AGE_TYPE_YEAR;
+ }
+
+ age = todayCalendar.get(Calendar.MONTH)
+ - birthCalendar.get(Calendar.MONTH);
+ if (age > 0) {
+ return AGE_TYPE_MONTH;
+ }
+
+ return AGE_TYPE_DAY;
+ }
+
+ // -------------------------------------------------------------------------
+ // Getter && Setter
+ // -------------------------------------------------------------------------
+
+ public String getFullName() {
+ boolean space = false;
+ String name = "";
+
+ if (firstName != null && firstName.length() != 0) {
+ name = firstName;
+ space = true;
+ }
+
+ if (middleName != null && middleName.length() != 0) {
+ if (space) {
+ name += " ";
+ }
+
+ name += middleName;
+ space = true;
+ }
+
+ if (lastName != null && lastName.length() != 0) {
+ if (space) {
+ name += " ";
+ }
+
+ name += lastName;
+ }
+
+ return name;
+ }
+
+ public String getPhoneNumber() {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber(String phoneNumber) {
+ this.phoneNumber = phoneNumber;
+ }
+
+ public boolean isUnderAge() {
+ return underAge;
+ }
+
+ public void setUnderAge(boolean underAge) {
+ this.underAge = underAge;
+ }
+
+ public String getTextGender() {
+ return gender.equalsIgnoreCase(MALE) ? "male" : "female";
+ }
+
+ public Character getDobType() {
+ return dobType;
+ }
+
+ public void setDobType(Character dobType) {
+ this.dobType = dobType;
+ }
+
+ public String getTextDoBType() {
+ switch (dobType) {
+ case DOB_TYPE_VERIFIED:
+ return "Verified";
+ case DOB_TYPE_DECLARED:
+ return "Declared";
+ default:
+ return "Approxiated";
+ }
+ }
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java 2013-03-06 08:07:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java 2013-03-08 09:38:34 +0000
@@ -42,180 +42,203 @@
* @author Abyot Asalefew Gizaw
* @version $Id$
*/
-public interface PatientService
-{
- String ID = PatientService.class.getName();
-
- int savePatient( Patient patient );
-
- void deletePatient( Patient patient );
-
- void updatePatient( Patient patient );
-
- Patient getPatient( int id );
-
- Collection<Patient> getAllPatients();
-
- /**
- * Search Patient base on firstname/middlename/lastname/birthDate/gender
- *
- * @param firstName
- * @param middleName
- * @param lastName
- * @param birthdate
- * @param gender
- * @return Patient List
- */
- Collection<Patient> getPatients( String firstName, String middleName, String lastName, Date birthdate, String gender );
-
- /**
- * Search Patient base on gender
- *
- * @param gender
- * @return Patient List
- */
- Collection<Patient> getPatiensByGender( String gender );
-
- /**
- * Search Patient base on birthDate
- *
- * @param birthdate
- * @return Patient List
- */
- Collection<Patient> getPatientsByBirthDate( Date birthDate );
-
- /**
- * Search Patient base on fullName
- *
- * @param name fullName
- * @return Patient List
- */
- Collection<Patient> getPatientsByNames( String name, Integer min, Integer max );
-
- /**
- * Search Patient base on full-name or identifier value
- *
- * @param searchText value
- * @return Patient List
- */
- Collection<Patient> getPatients( String searchText, Integer min, Integer max );
-
- /**
- * Search Patient for mobile base on identifier value
- *
- * @param searchText value
- * @param orgUnitId
- * @return Patient List
- */
- Collection<Patient> getPatientsForMobile( String searchText, int orgUnitId );
-
- /**
- * Search Patient base on organization unit with result limited
- *
- * @param organisationUnit organisationUnit
- * @return Patient List
- */
- Collection<Patient> getPatients( OrganisationUnit organisationUnit, Integer min, Integer max );
-
- /**
- * Search Patient base on organization unit and sort the result by PatientAttribute
- *
- * @param organisationUnit organisationUnit
- * @param patientAttribute
- * @param min
- * @param max
- * @return Patient List
- */
- Collection<Patient> getPatients( OrganisationUnit organisationUnit, PatientAttribute patientAttribute, Integer min, Integer max );
-
- /**
- * Search Patient base on organisationUnit and identifier value
- * name
- *
- * @param organisationUnit
- * @param searchText identifier value
- * @param min
- * @param max
- * @return
- */
- Collection<Patient> getPatients( OrganisationUnit organisationUnit, String searchText, Integer min, Integer max );
-
- /**
- * Search Patient base on PatientIdentifierType or Attribute or Patient's
- * name
- *
- * @param identifierTypeId
- * @param attributeId
- * @param value
- * @return
- */
- Collection<Patient> getPatient( Integer identifierTypeId, Integer attributeId, String value );
-
- /**
- * Search Patient base on OrganisationUnit and Program with result limited
- * name
- *
- * @param organisationUnit
- * @param program
- * @param min
- * @param max
- * @return
- */
- Collection<Patient> getPatients( OrganisationUnit organisationUnit, Program program, Integer min, Integer max );
-
- /**
- * Sort the result by PatientAttribute
- *
- * @param patients
- * @param patientAttribute
- * @return Patient List
- */
- Collection<Patient> sortPatientsByAttribute( Collection<Patient> patients, PatientAttribute patientAttribute );
-
-
- Collection<Patient> getRepresentatives( Patient patient );
- /**
- * Search Patient base on identifier value and get number of result
- *
- * @param searchText
- * @return number of patients
- */
- int countGetPatients( String searchText );
-
- /**
- * Search Patient base on firstname/middlename/lastname and get number of result
- *
- * @param name
- * @return number of patients
- */
- int countGetPatientsByName( String name );
-
- int createPatient( Patient patient,Integer representativeId,
- Integer relationshipTypeId, List<PatientAttributeValue> patientAttributeValues );
-
- void updatePatient( Patient patient, Integer representativeId,
- Integer relationshipTypeId, List<PatientAttributeValue> valuesForSave,
- List<PatientAttributeValue> valuesForUpdate, Collection<PatientAttributeValue> valuesForDelete );
-
- int countGetPatientsByOrgUnit( OrganisationUnit organisationUnit );
-
- int countGetPatientsByOrgUnitProgram( OrganisationUnit organisationUnit, Program program );
-
- Object getObjectValue( String property, String value, I18nFormat format );
-
- void removeErollmentPrograms( Program program );
-
- Collection<Patient> searchPatients( List<String> searchKeys, OrganisationUnit orgunit, Integer min, Integer max );
-
- int countSearchPatients( List<String> searchKeys, OrganisationUnit orgunit );
-
- Collection<String> getPatientPhoneNumbers( List<String> searchKeys, OrganisationUnit orgunit, Integer min, Integer max );
-
- List<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit, Integer min, Integer max );
-
- Grid getScheduledEventsReport( List<String> searchKeys, OrganisationUnit orgunit, I18n i18n );
-
- Collection<Patient> getPatientsByPhone( String phoneNumber, Integer min, Integer max );
-
- Collection<Patient> getPatientByFullname( String fullName, Integer orgunitId );
+
+public interface PatientService {
+ String ID = PatientService.class.getName();
+
+ int savePatient(Patient patient);
+
+ void deletePatient(Patient patient);
+
+ void updatePatient(Patient patient);
+
+ Patient getPatient(int id);
+
+ Collection<Patient> getAllPatients();
+
+ /**
+ * Search Patient base on firstname/middlename/lastname/birthDate/gender
+ *
+ * @param firstName
+ * @param middleName
+ * @param lastName
+ * @param birthdate
+ * @param gender
+ * @return Patient List
+ */
+ Collection<Patient> getPatients(String firstName, String middleName,
+ String lastName, Date birthdate, String gender);
+
+ /**
+ * Search Patient base on gender
+ *
+ * @param gender
+ * @return Patient List
+ */
+ Collection<Patient> getPatiensByGender(String gender);
+
+ /**
+ * Search Patient base on birthDate
+ *
+ * @param birthdate
+ * @return Patient List
+ */
+ Collection<Patient> getPatientsByBirthDate(Date birthDate);
+
+ /**
+ * Search Patient base on fullName
+ *
+ * @param name
+ * fullName
+ * @return Patient List
+ */
+ Collection<Patient> getPatientsByNames(String name, Integer min, Integer max);
+
+ /**
+ * Search Patient base on full-name or identifier value
+ *
+ * @param searchText
+ * value
+ * @return Patient List
+ */
+ Collection<Patient> getPatients(String searchText, Integer min, Integer max);
+
+ /**
+ * Search Patient for mobile base on identifier value
+ *
+ * @param searchText
+ * value
+ * @param orgUnitId
+ * @return Patient List
+ */
+ Collection<Patient> getPatientsForMobile(String searchText, int orgUnitId);
+
+ /**
+ * Search Patient base on organization unit with result limited
+ *
+ * @param organisationUnit
+ * organisationUnit
+ * @return Patient List
+ */
+ Collection<Patient> getPatients(OrganisationUnit organisationUnit,
+ Integer min, Integer max);
+
+ /**
+ * Search Patient base on organization unit and sort the result by
+ * PatientAttribute
+ *
+ * @param organisationUnit
+ * organisationUnit
+ * @param patientAttribute
+ * @param min
+ * @param max
+ * @return Patient List
+ */
+ Collection<Patient> getPatients(OrganisationUnit organisationUnit,
+ PatientAttribute patientAttribute, Integer min, Integer max);
+
+ /**
+ * Search Patient base on organisationUnit and identifier value name
+ *
+ * @param organisationUnit
+ * @param searchText
+ * identifier value
+ * @param min
+ * @param max
+ * @return
+ */
+ Collection<Patient> getPatients(OrganisationUnit organisationUnit,
+ String searchText, Integer min, Integer max);
+
+ /**
+ * Search Patient base on PatientIdentifierType or Attribute or Patient's
+ * name
+ *
+ * @param identifierTypeId
+ * @param attributeId
+ * @param value
+ * @return
+ */
+ Collection<Patient> getPatient(Integer identifierTypeId,
+ Integer attributeId, String value);
+
+ /**
+ * Search Patient base on OrganisationUnit and Program with result limited
+ * name
+ *
+ * @param organisationUnit
+ * @param program
+ * @param min
+ * @param max
+ * @return
+ */
+ Collection<Patient> getPatients(OrganisationUnit organisationUnit,
+ Program program, Integer min, Integer max);
+
+ /**
+ * Sort the result by PatientAttribute
+ *
+ * @param patients
+ * @param patientAttribute
+ * @return Patient List
+ */
+ Collection<Patient> sortPatientsByAttribute(Collection<Patient> patients,
+ PatientAttribute patientAttribute);
+
+ Collection<Patient> getRepresentatives(Patient patient);
+
+ /**
+ * Search Patient base on identifier value and get number of result
+ *
+ * @param searchText
+ * @return number of patients
+ */
+ int countGetPatients(String searchText);
+
+ /**
+ * Search Patient base on firstname/middlename/lastname and get number of
+ * result
+ *
+ * @param name
+ * @return number of patients
+ */
+ int countGetPatientsByName(String name);
+
+ int createPatient(Patient patient, Integer representativeId,
+ Integer relationshipTypeId,
+ List<PatientAttributeValue> patientAttributeValues);
+
+ void updatePatient(Patient patient, Integer representativeId,
+ Integer relationshipTypeId,
+ List<PatientAttributeValue> valuesForSave,
+ List<PatientAttributeValue> valuesForUpdate,
+ Collection<PatientAttributeValue> valuesForDelete);
+
+ int countGetPatientsByOrgUnit(OrganisationUnit organisationUnit);
+
+ int countGetPatientsByOrgUnitProgram(OrganisationUnit organisationUnit,
+ Program program);
+
+ Object getObjectValue(String property, String value, I18nFormat format);
+
+ void removeErollmentPrograms(Program program);
+
+ Collection<Patient> searchPatients(List<String> searchKeys,
+ OrganisationUnit orgunit, Integer min, Integer max);
+
+ int countSearchPatients(List<String> searchKeys, OrganisationUnit orgunit);
+
+ Collection<String> getPatientPhoneNumbers(List<String> searchKeys,
+ OrganisationUnit orgunit, Integer min, Integer max);
+
+ List<Integer> getProgramStageInstances(List<String> searchKeys,
+ OrganisationUnit orgunit, Integer min, Integer max);
+
+ Grid getScheduledEventsReport(List<String> searchKeys,
+ OrganisationUnit orgunit, I18n i18n);
+
+ Collection<Patient> getPatientsByPhone(String phoneNumber, Integer min,
+ Integer max);
+
+ Collection<Patient> getPatientByFullname(String fullName, Integer orgunitId);
}
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java 2013-03-06 04:25:38 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java 2013-03-08 09:38:34 +0000
@@ -38,531 +38,467 @@
import org.hisp.dhis.api.mobile.model.DataStreamSerializable;
import org.hisp.dhis.api.mobile.model.PatientAttribute;
import org.hisp.dhis.api.mobile.model.PatientIdentifier;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
/**
* @author Nguyen Kim Lai
*
* @version $ Patient.java Jan 22, 2013 $
*/
-public class Patient
- implements DataStreamSerializable
-{
-
- private String clientVersion;
-
- private int id;
-
- private String firstName;
-
- private String middleName;
-
- private String lastName;
-
- private int age;
-
- private List<PatientAttribute> patientAttValues;
-
- private PatientAttribute groupAttribute;
-
- private List<PatientIdentifier> identifiers;
-
- private String gender;
-
- private Date birthDate;
-
- private Date registrationDate;
-
- private Character dobType;
-
- private List<Program> programs;
-
- private List<Relationship> relationships;
-
- private List<Program> enrollmentPrograms;
-
- public List<PatientIdentifier> getIdentifiers()
- {
- return identifiers;
- }
-
- public void setIdentifiers( List<PatientIdentifier> identifiers )
- {
- this.identifiers = identifiers;
- }
-
- public List<Program> getPrograms()
- {
- return programs;
- }
-
- public void setPrograms( List<Program> programs )
- {
- this.programs = programs;
- }
-
- public List<Relationship> getRelationships()
- {
- return relationships;
- }
-
- public void setRelationships( List<Relationship> relationships )
- {
- this.relationships = relationships;
- }
-
- public List<Program> getEnrollmentPrograms()
- {
- return enrollmentPrograms;
- }
-
- public void setEnrollmentPrograms( List<Program> enrollmentPrograms )
- {
- this.enrollmentPrograms = enrollmentPrograms;
- }
-
- public String getFullName()
- {
- boolean space = false;
- String name = "";
-
- if ( firstName != null && firstName.length() != 0 )
- {
- name = firstName;
- space = true;
- }
- if ( middleName != null && middleName.length() != 0 )
- {
- if ( space )
- name += " ";
- name += middleName;
- space = true;
- }
- if ( lastName != null && lastName.length() != 0 )
- {
- if ( space )
- name += " ";
- name += lastName;
- }
- return name;
- }
-
- public int getAge()
- {
- return age;
- }
-
- public String getGender()
- {
- return gender;
- }
-
- public void setGender( String gender )
- {
- this.gender = gender;
- }
-
- public Date getBirthDate()
- {
- return birthDate;
- }
-
- public void setBirthDate( Date birthDate )
- {
- this.birthDate = birthDate;
- }
-
- public Date getRegistrationDate()
- {
- return registrationDate;
- }
-
- public void setRegistrationDate( Date registrationDate )
- {
- this.registrationDate = registrationDate;
- }
-
- public Character getDobType()
- {
- return dobType;
- }
-
- public void setDobType( Character dobType )
- {
- this.dobType = dobType;
- }
-
- public void setAge( int age )
- {
- this.age = age;
- }
-
- public PatientAttribute getGroupAttribute()
- {
- return groupAttribute;
- }
-
- public void setGroupAttribute( PatientAttribute groupAttribute )
- {
- this.groupAttribute = groupAttribute;
- }
-
- public List<PatientAttribute> getPatientAttValues()
- {
- return patientAttValues;
- }
-
- public void setPatientAttValues( List<PatientAttribute> patientAttValues )
- {
- this.patientAttValues = patientAttValues;
- }
-
- public int getId()
- {
- return id;
- }
-
- public void setId( int id )
- {
- this.id = id;
- }
-
- public String getFirstName()
- {
- return firstName;
- }
-
- public void setFirstName( String firstName )
- {
- this.firstName = firstName;
- }
-
- public String getMiddleName()
- {
- return middleName;
- }
-
- public void setMiddleName( String middleName )
- {
- this.middleName = middleName;
- }
-
- public String getLastName()
- {
- return lastName;
- }
-
- public void setLastName( String lastName )
- {
- this.lastName = lastName;
- }
-
- public String getClientVersion()
- {
- return clientVersion;
- }
-
- public void setClientVersion( String clientVersion )
- {
- this.clientVersion = clientVersion;
- }
-
- @Override
- public void serialize( DataOutputStream out )
- throws IOException
- {
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- DataOutputStream dout = new DataOutputStream( bout );
-
- dout.writeInt( this.getId() );
- dout.writeUTF( this.getFirstName() );
- dout.writeUTF( this.getMiddleName() );
- dout.writeUTF( this.getLastName() );
- dout.writeInt( this.getAge() );
-
- if ( gender != null )
- {
- dout.writeBoolean( true );
- dout.writeUTF( gender );
- }
- else
- {
- dout.writeBoolean( false );
- }
-
- if ( dobType != null )
- {
- dout.writeBoolean( true );
- dout.writeChar( dobType );
- }
- else
- {
- dout.writeBoolean( false );
- }
-
- if ( birthDate != null )
- {
- dout.writeBoolean( true );
- dout.writeLong( birthDate.getTime() );
- }
- else
- {
- dout.writeBoolean( false );
- }
- // doesn't transfer blood group to client
- dout.writeBoolean( false );
-
- if ( registrationDate != null )
- {
- dout.writeBoolean( true );
- dout.writeLong( registrationDate.getTime() );
- }
- else
- {
- dout.writeBoolean( false );
- }
-
- /*
- * Write attribute which is used as group factor of beneficiary - false:
- * no group factor, true: with group factor
- */
- if ( this.getGroupAttribute() != null )
- {
- dout.writeBoolean( true );
- this.getGroupAttribute().serialize( dout );
- }
- else
- {
- dout.writeBoolean( false );
- }
-
- List<PatientAttribute> atts = this.getPatientAttValues();
- dout.writeInt( atts.size() );
- for ( PatientAttribute att : atts )
- {
- dout.writeUTF( att.getName() + ":" + att.getValue() );
- }
-
- // Write PatientIdentifier
- dout.writeInt( identifiers.size() );
- for ( PatientIdentifier each : identifiers )
- {
- each.serialize( dout );
- }
-
- // Write Enrolled Programs
-
- dout.writeInt( programs.size() );
- for ( Program each : programs )
- {
- each.serialize( dout );
- }
-
- // Write Relationships
- dout.writeInt( relationships.size() );
- for ( Relationship each : relationships )
- {
- each.serialize( dout );
- }
-
- // Write Available Program To Enroll
- dout.writeInt( enrollmentPrograms.size() );
- for ( Program each : enrollmentPrograms )
- {
- each.serialize( dout );
- }
-
- bout.flush();
- bout.writeTo( out );
- }
-
- @Override
- public void deSerialize( DataInputStream dataInputStream )
- throws IOException
- {
-
- }
-
- @Override
- public boolean equals( Object otherObject )
- {
- Beneficiary otherBeneficiary = (Beneficiary) otherObject;
- return this.getId() == otherBeneficiary.getId();
- }
-
- @Override
- public void serializeVersion2_8( DataOutputStream out )
- throws IOException
- {
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- DataOutputStream dout = new DataOutputStream( bout );
-
- dout.writeInt( this.getId() );
- dout.writeUTF( this.getFirstName() );
- dout.writeUTF( this.getMiddleName() );
- dout.writeUTF( this.getLastName() );
- dout.writeInt( this.getAge() );
-
- if ( gender != null )
- {
- dout.writeBoolean( true );
- dout.writeUTF( gender );
- }
- else
- {
- dout.writeBoolean( false );
- }
-
- if ( dobType != null )
- {
- dout.writeBoolean( true );
- dout.writeChar( dobType );
- }
- else
- {
- dout.writeBoolean( false );
- }
-
- if ( birthDate != null )
- {
- dout.writeBoolean( true );
- dout.writeLong( birthDate.getTime() );
- }
- else
- {
- dout.writeBoolean( false );
- }
- // doesn't transfer blood group to client
- dout.writeBoolean( false );
-
- if ( registrationDate != null )
- {
- dout.writeBoolean( true );
- dout.writeLong( registrationDate.getTime() );
- }
- else
- {
- dout.writeBoolean( false );
- }
-
- /*
- * Write attribute which is used as group factor of beneficiary - false:
- * no group factor, true: with group factor
- */
- if ( this.getGroupAttribute() != null )
- {
- dout.writeBoolean( true );
- this.getGroupAttribute().serialize( dout );
- }
- else
- {
- dout.writeBoolean( false );
- }
-
- List<PatientAttribute> atts = this.getPatientAttValues();
- dout.writeInt( atts.size() );
- for ( PatientAttribute att : atts )
- {
- dout.writeUTF( att.getName() + ":" + att.getValue() );
- }
-
- // Write PatientIdentifier
- dout.writeInt( identifiers.size() );
- for ( PatientIdentifier each : identifiers )
- {
- each.serializeVersion2_8( dout );
- }
-
- bout.flush();
- bout.writeTo( out );
- }
-
- @Override
- public void serializeVersion2_9( DataOutputStream dout )
- throws IOException
- {
- dout.writeInt( this.getId() );
- dout.writeUTF( this.getFirstName() );
- dout.writeUTF( this.getMiddleName() );
- dout.writeUTF( this.getLastName() );
- dout.writeInt( this.getAge() );
-
- if ( gender != null )
- {
- dout.writeBoolean( true );
- dout.writeUTF( gender );
- }
- else
- {
- dout.writeBoolean( false );
- }
-
- if ( dobType != null )
- {
- dout.writeBoolean( true );
- dout.writeChar( dobType );
- }
- else
- {
- dout.writeBoolean( false );
- }
-
- if ( birthDate != null )
- {
- dout.writeBoolean( true );
- dout.writeLong( birthDate.getTime() );
- }
- else
- {
- dout.writeBoolean( false );
- }
- // doesn't transfer blood group to client
- dout.writeBoolean( false );
-
- if ( registrationDate != null )
- {
- dout.writeBoolean( true );
- dout.writeLong( registrationDate.getTime() );
- }
- else
- {
- dout.writeBoolean( false );
- }
-
- /*
- * Write attribute which is used as group factor of beneficiary - false:
- * no group factor, true: with group factor
- */
- if ( this.getGroupAttribute() != null )
- {
- dout.writeBoolean( true );
- this.getGroupAttribute().serialize( dout );
- }
- else
- {
- dout.writeBoolean( false );
- }
-
- List<PatientAttribute> atts = this.getPatientAttValues();
- dout.writeInt( atts.size() );
- for ( PatientAttribute att : atts )
- {
- dout.writeUTF( att.getName() + ":" + att.getValue() );
- }
-
- // Write PatientIdentifier
- dout.writeInt( identifiers.size() );
- for ( PatientIdentifier each : identifiers )
- {
- each.serializeVersion2_9( dout );
- }
- }
-
- @Override
- public void serializeVersion2_10( DataOutputStream dataOutputStream )
- throws IOException
- {
- // TODO Auto-generated method stub
-
- }
+
+public class Patient implements DataStreamSerializable {
+
+ private String clientVersion;
+
+ private int id;
+
+ private String firstName;
+
+ private String middleName;
+
+ private String lastName;
+
+ private int age;
+
+ private List<PatientAttribute> patientAttValues;
+
+ private PatientAttribute groupAttribute;
+
+ private List<PatientIdentifier> identifiers;
+
+ private String gender;
+
+ private Date birthDate;
+
+ private Date registrationDate;
+
+ private Character dobType;
+
+ private List<Program> programs;
+
+ private List<Relationship> relationships;
+
+ private String phoneNumber;
+
+ private OrganisationUnit organisationUnit;
+
+ public List<PatientIdentifier> getIdentifiers() {
+ return identifiers;
+ }
+
+ public void setIdentifiers(List<PatientIdentifier> identifiers) {
+ this.identifiers = identifiers;
+ }
+
+ public List<Program> getPrograms() {
+ return programs;
+ }
+
+ public void setPrograms(List<Program> programs) {
+ this.programs = programs;
+ }
+
+ public List<Relationship> getRelationships() {
+ return relationships;
+ }
+
+ public void setRelationships(List<Relationship> relationships) {
+ this.relationships = relationships;
+ }
+
+ public String getFullName() {
+ boolean space = false;
+ String name = "";
+
+ if (firstName != null && firstName.length() != 0) {
+ name = firstName;
+ space = true;
+ }
+ if (middleName != null && middleName.length() != 0) {
+ if (space)
+ name += " ";
+ name += middleName;
+ space = true;
+ }
+ if (lastName != null && lastName.length() != 0) {
+ if (space)
+ name += " ";
+ name += lastName;
+ }
+ return name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public String getGender() {
+ return gender;
+ }
+
+ public void setGender(String gender) {
+ this.gender = gender;
+ }
+
+ public Date getBirthDate() {
+ return birthDate;
+ }
+
+ public void setBirthDate(Date birthDate) {
+ this.birthDate = birthDate;
+ }
+
+ public Date getRegistrationDate() {
+ return registrationDate;
+ }
+
+ public void setRegistrationDate(Date registrationDate) {
+ this.registrationDate = registrationDate;
+ }
+
+ public Character getDobType() {
+ return dobType;
+ }
+
+ public void setDobType(Character dobType) {
+ this.dobType = dobType;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public PatientAttribute getGroupAttribute() {
+ return groupAttribute;
+ }
+
+ public void setGroupAttribute(PatientAttribute groupAttribute) {
+ this.groupAttribute = groupAttribute;
+ }
+
+ public List<PatientAttribute> getPatientAttValues() {
+ return patientAttValues;
+ }
+
+ public void setPatientAttValues(List<PatientAttribute> patientAttValues) {
+ this.patientAttValues = patientAttValues;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getMiddleName() {
+ return middleName;
+ }
+
+ public void setMiddleName(String middleName) {
+ this.middleName = middleName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getClientVersion() {
+ return clientVersion;
+ }
+
+ public void setClientVersion(String clientVersion) {
+ this.clientVersion = clientVersion;
+ }
+
+ public String getPhoneNumber() {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber(String phoneNumber) {
+ this.phoneNumber = phoneNumber;
+ }
+
+ public OrganisationUnit getOrganisationUnit() {
+ return organisationUnit;
+ }
+
+ public void setOrganisationUnit(OrganisationUnit organisationUnit) {
+ this.organisationUnit = organisationUnit;
+ }
+
+ @Override
+ public void serialize(DataOutputStream out) throws IOException {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ DataOutputStream dout = new DataOutputStream(bout);
+
+ dout.writeInt(this.getId());
+ dout.writeUTF(this.getFirstName());
+ dout.writeUTF(this.getMiddleName());
+ dout.writeUTF(this.getLastName());
+ dout.writeInt(this.getAge());
+ dout.writeUTF(this.getPhoneNumber());
+ dout.writeUTF(this.getGender());
+
+ if (gender != null) {
+ dout.writeBoolean(true);
+ dout.writeUTF(gender);
+ } else {
+ dout.writeBoolean(false);
+ }
+
+ if (dobType != null) {
+ dout.writeBoolean(true);
+ dout.writeChar(dobType);
+ } else {
+ dout.writeBoolean(false);
+ }
+
+ if (birthDate != null) {
+ dout.writeBoolean(true);
+ dout.writeLong(birthDate.getTime());
+ } else {
+ dout.writeBoolean(false);
+ }
+ // doesn't transfer blood group to client
+ dout.writeBoolean(false);
+
+ if (registrationDate != null) {
+ dout.writeBoolean(true);
+ dout.writeLong(registrationDate.getTime());
+ } else {
+ dout.writeBoolean(false);
+ }
+
+ if (phoneNumber != null) {
+ dout.writeBoolean(true);
+ dout.writeUTF(phoneNumber);
+ } else {
+ dout.writeBoolean(false);
+ }
+
+ /*
+ * Write attribute which is used as group factor of beneficiary - false:
+ * no group factor, true: with group factor
+ */
+ if (this.getGroupAttribute() != null) {
+ dout.writeBoolean(true);
+ this.getGroupAttribute().serialize(dout);
+ } else {
+ dout.writeBoolean(false);
+ }
+
+ List<PatientAttribute> atts = this.getPatientAttValues();
+ dout.writeInt(atts.size());
+ for (PatientAttribute att : atts) {
+ dout.writeUTF(att.getName() + ":" + att.getValue());
+ }
+
+ // Write PatientIdentifier
+ dout.writeInt(identifiers.size());
+ for (PatientIdentifier each : identifiers) {
+ each.serialize(dout);
+ }
+
+ // Write Enrolled Programs
+
+ dout.writeInt(programs.size());
+ for (Program each : programs) {
+ each.serialize(dout);
+ }
+
+ // Write Relationships
+ dout.writeInt(relationships.size());
+ for (Relationship each : relationships) {
+ each.serialize(dout);
+ }
+
+ bout.flush();
+ bout.writeTo(out);
+ }
+
+ @Override
+ public void deSerialize(DataInputStream din) throws IOException {
+ this.setId(din.readInt());
+ this.setFirstName(din.readUTF());
+ this.setGender(din.readUTF());
+ this.setPhoneNumber(din.readUTF());
+
+ if (din.readBoolean()) {
+ char dobTypeDeserialized = din.readChar();
+ this.setDobType(new Character(dobTypeDeserialized));
+ } else {
+ this.setDobType(null);
+ }
+
+ if (din.readBoolean()) {
+ this.setBirthDate(new Date(din.readLong()));
+ } else {
+ this.setBirthDate(null);
+ }
+
+ if (din.readBoolean()) {
+ this.setRegistrationDate(new Date(din.readLong()));
+ } else {
+ this.setRegistrationDate(null);
+ }
+
+ }
+
+ @Override
+ public boolean equals(Object otherObject) {
+ Beneficiary otherBeneficiary = (Beneficiary) otherObject;
+ return this.getId() == otherBeneficiary.getId();
+ }
+
+ @Override
+ public void serializeVersion2_8(DataOutputStream out) throws IOException {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ DataOutputStream dout = new DataOutputStream(bout);
+
+ dout.writeInt(this.getId());
+ dout.writeUTF(this.getFirstName());
+ dout.writeUTF(this.getMiddleName());
+ dout.writeUTF(this.getLastName());
+ dout.writeInt(this.getAge());
+
+ if (gender != null) {
+ dout.writeBoolean(true);
+ dout.writeUTF(gender);
+ } else {
+ dout.writeBoolean(false);
+ }
+
+ if (dobType != null) {
+ dout.writeBoolean(true);
+ dout.writeChar(dobType);
+ } else {
+ dout.writeBoolean(false);
+ }
+
+ if (birthDate != null) {
+ dout.writeBoolean(true);
+ dout.writeLong(birthDate.getTime());
+ } else {
+ dout.writeBoolean(false);
+ }
+ // doesn't transfer blood group to client
+ dout.writeBoolean(false);
+
+ if (registrationDate != null) {
+ dout.writeBoolean(true);
+ dout.writeLong(registrationDate.getTime());
+ } else {
+ dout.writeBoolean(false);
+ }
+
+ /*
+ * Write attribute which is used as group factor of beneficiary - false:
+ * no group factor, true: with group factor
+ */
+ if (this.getGroupAttribute() != null) {
+ dout.writeBoolean(true);
+ this.getGroupAttribute().serialize(dout);
+ } else {
+ dout.writeBoolean(false);
+ }
+
+ List<PatientAttribute> atts = this.getPatientAttValues();
+ dout.writeInt(atts.size());
+ for (PatientAttribute att : atts) {
+ dout.writeUTF(att.getName() + ":" + att.getValue());
+ }
+
+ // Write PatientIdentifier
+ dout.writeInt(identifiers.size());
+ for (PatientIdentifier each : identifiers) {
+ each.serializeVersion2_8(dout);
+ }
+
+ bout.flush();
+ bout.writeTo(out);
+ }
+
+ @Override
+ public void serializeVersion2_9(DataOutputStream dout) throws IOException {
+ dout.writeInt(this.getId());
+ dout.writeUTF(this.getFirstName());
+ dout.writeUTF(this.getMiddleName());
+ dout.writeUTF(this.getLastName());
+ dout.writeInt(this.getAge());
+
+ if (gender != null) {
+ dout.writeBoolean(true);
+ dout.writeUTF(gender);
+ } else {
+ dout.writeBoolean(false);
+ }
+
+ if (dobType != null) {
+ dout.writeBoolean(true);
+ dout.writeChar(dobType);
+ } else {
+ dout.writeBoolean(false);
+ }
+
+ if (birthDate != null) {
+ dout.writeBoolean(true);
+ dout.writeLong(birthDate.getTime());
+ } else {
+ dout.writeBoolean(false);
+ }
+ // doesn't transfer blood group to client
+ dout.writeBoolean(false);
+
+ if (registrationDate != null) {
+ dout.writeBoolean(true);
+ dout.writeLong(registrationDate.getTime());
+ } else {
+ dout.writeBoolean(false);
+ }
+
+ /*
+ * Write attribute which is used as group factor of beneficiary - false:
+ * no group factor, true: with group factor
+ */
+ if (this.getGroupAttribute() != null) {
+ dout.writeBoolean(true);
+ this.getGroupAttribute().serialize(dout);
+ } else {
+ dout.writeBoolean(false);
+ }
+
+ List<PatientAttribute> atts = this.getPatientAttValues();
+ dout.writeInt(atts.size());
+ for (PatientAttribute att : atts) {
+ dout.writeUTF(att.getName() + ":" + att.getValue());
+ }
+
+ // Write PatientIdentifier
+ dout.writeInt(identifiers.size());
+ for (PatientIdentifier each : identifiers) {
+ each.serializeVersion2_9(dout);
+ }
+ }
+
+ @Override
+ public void serializeVersion2_10(DataOutputStream dataOutputStream)
+ throws IOException {
+ // TODO Auto-generated method stub
+
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java 2013-03-06 04:25:38 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java 2013-03-08 09:38:34 +0000
@@ -65,12 +65,17 @@
private String updateContactUrl;
private String findPatientUrl;
+
+
+ private String registerPersonUrl;
+
private String uploadProgramStageUrl;
private String enrollProgramUrl;
+
@XmlAttribute
public int getId()
{
@@ -203,6 +208,18 @@
this.findPatientUrl = findPatientUrl;
}
+
+
+
+ public String getRegisterPerson() {
+ return registerPersonUrl;
+ }
+
+ public void setRegisterPerson(String registerPersonUrl) {
+ this.registerPersonUrl = registerPersonUrl;
+ }
+
+
public String getUploadProgramStageUrl()
{
return uploadProgramStageUrl;
@@ -225,6 +242,7 @@
public void serialize( DataOutputStream dataOutputStream )
+
throws IOException
{
dataOutputStream.writeInt( this.id );
@@ -239,6 +257,7 @@
dataOutputStream.writeUTF( this.updateNewVersionUrl );
dataOutputStream.writeUTF( this.updateContactUrl );
dataOutputStream.writeUTF( this.findPatientUrl );
+ dataOutputStream.writeUTF(this.registerPersonUrl);
dataOutputStream.writeUTF( this.uploadProgramStageUrl );
dataOutputStream.writeUTF( this.enrollProgramUrl );
}
@@ -258,10 +277,15 @@
this.updateNewVersionUrl = dataInputStream.readUTF();
this.updateContactUrl = dataInputStream.readUTF();
this.findPatientUrl = dataInputStream.readUTF();
+ this.uploadProgramStageUrl = dataInputStream.readUTF();
+ this.registerPersonUrl = dataInputStream.readUTF();
this.uploadProgramStageUrl = dataInputStream.readUTF();
this.enrollProgramUrl = dataInputStream.readUTF();
}
+
+
+
@Override
public void serializeVersion2_8( DataOutputStream dataOutputStream )
throws IOException
@@ -311,7 +335,10 @@
dataOutputStream.writeUTF( this.updateContactUrl );
dataOutputStream.writeUTF( this.findPatientUrl );
dataOutputStream.writeUTF( this.uploadProgramStageUrl );
+ dataOutputStream.writeUTF(this.registerPersonUrl);
dataOutputStream.writeUTF( this.enrollProgramUrl );
}
+
+
}
=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java 2013-03-07 07:59:41 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java 2013-03-08 09:38:34 +0000
@@ -115,6 +115,7 @@
orgUnit.setSearchUrl( getUrl( request, unit.getId(), "search" ) );
orgUnit.setUpdateContactUrl( getUrl( request, unit.getId(), "updateContactForMobile" ) );
orgUnit.setFindPatientUrl( getUrl( request, unit.getId(), "findPatient" ) );
+ orgUnit.setRegisterPerson(getUrl(request, unit.getId(), "registerPerson"));
orgUnit.setUploadProgramStageUrl( getUrl( request, unit.getId(), "uploadProgramStage" ) );
orgUnit.setEnrollProgramUrl( getUrl( request, unit.getId(), "enrollProgram" ) );
=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java 2013-03-06 04:25:38 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java 2013-03-08 09:38:34 +0000
@@ -5,6 +5,7 @@
import java.util.Date;
import java.util.List;
import java.util.Locale;
+
import org.hisp.dhis.api.mobile.ActivityReportingService;
import org.hisp.dhis.api.mobile.FacilityReportingService;
import org.hisp.dhis.api.mobile.IProgramService;
@@ -17,15 +18,18 @@
import org.hisp.dhis.api.mobile.model.DataStreamSerializable;
import org.hisp.dhis.api.mobile.model.MobileModel;
import org.hisp.dhis.api.mobile.model.ModelList;
+import org.hisp.dhis.api.mobile.model.PatientAttribute;
+import org.hisp.dhis.api.mobile.model.SMSCode;
+import org.hisp.dhis.api.mobile.model.SMSCommand;
import org.hisp.dhis.api.mobile.model.LWUITmodel.Patient;
import org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage;
-import org.hisp.dhis.api.mobile.model.SMSCode;
-import org.hisp.dhis.api.mobile.model.SMSCommand;
import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.patient.PatientAttributeService;
+import org.hisp.dhis.patient.PatientIdentifierType;
+import org.hisp.dhis.patient.PatientIdentifierTypeService;
import org.hisp.dhis.patient.PatientService;
-import org.hisp.dhis.sms.parse.ParserType;
import org.hisp.dhis.smscommand.SMSCommandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@@ -37,262 +41,330 @@
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
-@RequestMapping( value = "/mobile" )
-public class MobileOrganisationUnitController
- extends AbstractMobileController
-{
- private static final String ACTIVITY_REPORT_UPLOADED = "activity_report_uploaded";
-
- private static final String DATASET_REPORT_UPLOADED = "dataset_report_uploaded";
-
- private static final String PROGRAM_STAGE_UPLOADED = "program_stage_uploaded";
-
- @Autowired
- private ActivityReportingService activityReportingService;
-
- @Autowired
- private IProgramService programService;
-
- @Autowired
- private FacilityReportingService facilityReportingService;
-
- @Autowired
- private OrganisationUnitService organisationUnitService;
-
- @Autowired
- private I18nService i18nService;
-
- @Autowired
- private PatientService patientService;
-
- @Autowired
- private SMSCommandService smsCommandService;
-
- // For client version 2.8 and lower
- @RequestMapping( method = RequestMethod.GET, value = "orgUnits/{id}/all" )
- @ResponseBody
- public MobileModel getAllDataForOrgUnit2_8( @PathVariable int id, @RequestHeader( "accept-language" ) String locale )
- {
- MobileModel mobileModel = new MobileModel();
- mobileModel.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT );
- OrganisationUnit unit = getUnit( id );
- mobileModel.setActivityPlan( activityReportingService.getCurrentActivityPlan( unit, locale ) );
- mobileModel.setPrograms( programService.getPrograms( unit, locale ) );
- mobileModel.setDatasets( facilityReportingService.getMobileDataSetsForUnit( unit, locale ) );
- mobileModel.setServerCurrentDate( new Date() );
- mobileModel.setLocales( getLocalStrings( i18nService.getAvailableLocales() ) );
- return mobileModel;
- }
-
- @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/updateDataSets" )
- @ResponseBody
- public DataSetList checkUpdatedDataSet2_8( @PathVariable int id, @RequestBody DataSetList dataSetList,
- @RequestHeader( "accept-language" ) String locale )
- {
- DataSetList returnList = facilityReportingService.getUpdatedDataSet( dataSetList, getUnit( id ), locale );
- returnList.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT );
- return returnList;
- }
-
- /**
- * Save a facility report for unit
- *
- * @param dataSetValue - the report to save
- * @throws NotAllowedException if the {@link DataSetValue} is invalid
- */
- @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/dataSets" )
- @ResponseBody
- public String saveDataSetValues2_8( @PathVariable int id, @RequestBody DataSetValue dataSetValue )
- throws NotAllowedException
- {
- facilityReportingService.saveDataSetValues( getUnit( id ), dataSetValue );
- return DATASET_REPORT_UPLOADED;
- }
-
- /**
- * Save activity report for unit
- *
- * @param activityValue - the report to save
- * @throws NotAllowedException if the {@link ActivityValue activity value}
- * is invalid
- */
- @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/activities" )
- @ResponseBody
- public String saveActivityReport2_8( @PathVariable int id, @RequestBody ActivityValue activityValue )
- throws NotAllowedException
- {
- // FIXME set the last argument to 0 to fix compilation error
- activityReportingService.saveActivityReport( getUnit( id ), activityValue, 0 );
- return ACTIVITY_REPORT_UPLOADED;
- }
-
- @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/activitiyplan" )
- @ResponseBody
- public MobileModel updatePrograms2_8( @PathVariable int id, @RequestHeader( "accept-language" ) String locale,
- @RequestBody ModelList programsFromClient )
- {
- MobileModel model = new MobileModel();
- model.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT );
- model.setPrograms( programService.updateProgram( programsFromClient, locale, getUnit( id ) ) );
- model.setActivityPlan( activityReportingService.getCurrentActivityPlan( getUnit( id ), locale ) );
- model.setServerCurrentDate( new Date() );
- return model;
- }
-
- @RequestMapping( method = RequestMethod.GET, value = "orgUnits/{id}/search" )
- @ResponseBody
- public ActivityPlan search2_8( @PathVariable int id, @RequestHeader( "identifier" ) String identifier )
- throws NotAllowedException
- {
- ActivityPlan activityPlan = activityReportingService.getActivitiesByIdentifier( identifier );
- ;
- activityPlan.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT );
- return activityPlan;
- }
-
- @RequestMapping( method = RequestMethod.GET, value = "orgUnits/{id}/changeLanguageDataSet" )
- @ResponseBody
- public DataSetList changeLanguageDataSet2_8( @PathVariable int id, @RequestHeader( "accept-language" ) String locale )
- {
- return facilityReportingService.getDataSetsForLocale( getUnit( id ), locale );
- }
-
- // For client version 2.9 and higher
-
- @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/all" )
- @ResponseBody
- public MobileModel getAllDataForOrgUnit( @PathVariable String clientVersion, @PathVariable int id,
- @RequestHeader( "accept-language" ) String locale )
- {
- MobileModel mobileModel = new MobileModel();
- mobileModel.setClientVersion( clientVersion );
- OrganisationUnit unit = getUnit( id );
- mobileModel.setActivityPlan( activityReportingService.getCurrentActivityPlan( unit, locale ) );
- mobileModel.setPrograms( programService.getPrograms( unit, locale ) );
- mobileModel.setDatasets( facilityReportingService.getMobileDataSetsForUnit( unit, locale ) );
- mobileModel.setServerCurrentDate( new Date() );
- mobileModel.setLocales( getLocalStrings( i18nService.getAvailableLocales() ) );
- mobileModel.setSmsCommands( this.getMobileSMSCommands( smsCommandService.getSMSCommands() ) );
- return mobileModel;
- }
-
- @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/updateDataSets" )
- @ResponseBody
- public DataSetList checkUpdatedDataSet( @PathVariable String clientVersion, @PathVariable int id,
- @RequestBody DataSetList dataSetList, @RequestHeader( "accept-language" ) String locale )
- {
- DataSetList returnList = facilityReportingService.getUpdatedDataSet( dataSetList, getUnit( id ), locale );
- returnList.setClientVersion( clientVersion );
- return returnList;
- }
-
- /**
- * Save a facility report for unit
- *
- * @param dataSetValue - the report to save
- * @throws NotAllowedException if the {@link DataSetValue} is invalid
- */
-
- @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/dataSets" )
- @ResponseBody
- public String saveDataSetValues( @PathVariable int id, @RequestBody DataSetValue dataSetValue )
- throws NotAllowedException
- {
- facilityReportingService.saveDataSetValues( getUnit( id ), dataSetValue );
- return DATASET_REPORT_UPLOADED;
- }
-
- @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/activitiyplan" )
- @ResponseBody
- public MobileModel updatePrograms( @PathVariable String clientVersion, @PathVariable int id,
- @RequestHeader( "accept-language" ) String locale, @RequestBody ModelList programsFromClient )
- {
- MobileModel model = new MobileModel();
- model.setClientVersion( clientVersion );
- model.setPrograms( programService.updateProgram( programsFromClient, locale, getUnit( id ) ) );
- model.setActivityPlan( activityReportingService.getCurrentActivityPlan( getUnit( id ), locale ) );
- model.setServerCurrentDate( new Date() );
- return model;
- }
-
- @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/search" )
- @ResponseBody
- public ActivityPlan search( @PathVariable String clientVersion, @PathVariable int id,
- @RequestHeader( "identifier" ) String identifier )
- throws NotAllowedException
- {
- ActivityPlan activityPlan = activityReportingService.getActivitiesByIdentifier( identifier );
- activityPlan.setClientVersion( clientVersion );
- return activityPlan;
- }
-
- /**
- * Save a facility report for unit
- *
- * @param dataSetValue - the report to save
- * @throws NotAllowedException if the {@link DataSetValue} is invalid
- */
-
- // @RequestMapping( method = RequestMethod.POST, value =
- // "{clientVersion}/orgUnits/{id}/dataSets" )
- // @ResponseBody
- // public String saveDataSetValues( @PathVariable int id, @RequestBody
- // DataSetValue dataSetValue )
- // throws NotAllowedException
- // {
- // facilityReportingService.saveDataSetValues( getUnit( id ), dataSetValue
- // );
- // return DATASET_REPORT_UPLOADED;
- // }
-
- /**
- * Save activity report for unit
- *
- * @param activityValue - the report to save
- * @throws NotAllowedException if the {@link ActivityValue activity value}
- * is invalid
- */
- @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/activities" )
- @ResponseBody
- public String saveActivityReport( @PathVariable int id, @RequestBody ActivityValue activityValue )
- throws NotAllowedException
- {
- // FIXME set the last argument to 0 to fix compilation error
- activityReportingService.saveActivityReport( getUnit( id ), activityValue, 0 );
- return ACTIVITY_REPORT_UPLOADED;
- }
-
- @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/changeLanguageDataSet" )
- @ResponseBody
- public DataSetList changeLanguageDataSet( @PathVariable int id, @RequestHeader( "accept-language" ) String locale )
- {
- return facilityReportingService.getDataSetsForLocale( getUnit( id ), locale );
- }
-
- @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/updateContactForMobile" )
- @ResponseBody
- public Contact updateContactForMobile()
- {
- return facilityReportingService.updateContactForMobile();
- }
-
- @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/findPatient" )
- @ResponseBody
- public Patient findPatientByName( @PathVariable int id, @RequestHeader( "name" ) String fullName )
- throws NotAllowedException
- {
- return activityReportingService.findPatient( fullName, id );
- }
-
- @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/uploadProgramStage" )
+@RequestMapping(value = "/mobile")
+public class MobileOrganisationUnitController extends AbstractMobileController {
+ private static final String ACTIVITY_REPORT_UPLOADED = "activity_report_uploaded";
+
+ private static final String DATASET_REPORT_UPLOADED = "dataset_report_uploaded";
+
+ private static final String PROGRAM_STAGE_UPLOADED = "program_stage_uploaded";
+
+ private static final String PATIENT_REGISTERED = "patient_registered";
+
+ @Autowired
+ private ActivityReportingService activityReportingService;
+
+ @Autowired
+ private IProgramService programService;
+
+ @Autowired
+ private FacilityReportingService facilityReportingService;
+
+ @Autowired
+ private OrganisationUnitService organisationUnitService;
+
+ @Autowired
+ private I18nService i18nService;
+
+ @Autowired
+ private PatientService patientService;
+
+ @Autowired
+ private SMSCommandService smsCommandService;
+
+ private PatientIdentifierTypeService patientIdentifierTypeService;
+
+ public PatientIdentifierTypeService getPatientIdentifierTypeService() {
+ return patientIdentifierTypeService;
+ }
+
+ public void setPatientIdentifierTypeService(
+ PatientIdentifierTypeService patientIdentifierTypeService) {
+ this.patientIdentifierTypeService = patientIdentifierTypeService;
+ }
+
+ private Collection<PatientIdentifierType> patientIdentifierTypes;
+
+ public Collection<PatientIdentifierType> getPatientIdentifierTypes() {
+ return patientIdentifierTypes;
+ }
+
+ public void setPatientIdentifierTypes(
+ Collection<PatientIdentifierType> patientIdentifierTypes) {
+ this.patientIdentifierTypes = patientIdentifierTypes;
+ }
+
+ private Collection<PatientAttribute> patientAttributes;
+
+ public Collection<PatientAttribute> getPatientAttributes() {
+ return patientAttributes;
+ }
+
+ public void setPatientAttributes(
+ Collection<PatientAttribute> patientAttributes) {
+ this.patientAttributes = patientAttributes;
+ }
+
+ private PatientAttributeService patientAttributeService;
+
+ public PatientAttributeService getPatientAttributeService() {
+ return patientAttributeService;
+ }
+
+ public void setPatientAttributeService(
+ PatientAttributeService patientAttributeService) {
+ this.patientAttributeService = patientAttributeService;
+ }
+
+ // For client version 2.8 and lower
+ @RequestMapping(method = RequestMethod.GET, value = "orgUnits/{id}/all")
+ @ResponseBody
+ public MobileModel getAllDataForOrgUnit2_8(@PathVariable int id,
+ @RequestHeader("accept-language") String locale) {
+ MobileModel mobileModel = new MobileModel();
+ mobileModel.setClientVersion(DataStreamSerializable.TWO_POINT_EIGHT);
+ OrganisationUnit unit = getUnit(id);
+ mobileModel.setActivityPlan(activityReportingService
+ .getCurrentActivityPlan(unit, locale));
+ mobileModel.setPrograms(programService.getPrograms(unit, locale));
+ mobileModel.setDatasets(facilityReportingService
+ .getMobileDataSetsForUnit(unit, locale));
+ mobileModel.setServerCurrentDate(new Date());
+ mobileModel.setLocales(getLocalStrings(i18nService
+ .getAvailableLocales()));
+ return mobileModel;
+ }
+
+ @RequestMapping(method = RequestMethod.POST, value = "orgUnits/{id}/updateDataSets")
+ @ResponseBody
+ public DataSetList checkUpdatedDataSet2_8(@PathVariable int id,
+ @RequestBody DataSetList dataSetList,
+ @RequestHeader("accept-language") String locale) {
+ DataSetList returnList = facilityReportingService.getUpdatedDataSet(
+ dataSetList, getUnit(id), locale);
+ returnList.setClientVersion(DataStreamSerializable.TWO_POINT_EIGHT);
+ return returnList;
+ }
+
+ /**
+ * Save a facility report for unit
+ *
+ * @param dataSetValue
+ * - the report to save
+ * @throws NotAllowedException
+ * if the {@link DataSetValue} is invalid
+ */
+ @RequestMapping(method = RequestMethod.POST, value = "orgUnits/{id}/dataSets")
+ @ResponseBody
+ public String saveDataSetValues2_8(@PathVariable int id,
+ @RequestBody DataSetValue dataSetValue) throws NotAllowedException {
+ facilityReportingService.saveDataSetValues(getUnit(id), dataSetValue);
+ return DATASET_REPORT_UPLOADED;
+ }
+
+ /**
+ * Save activity report for unit
+ *
+ * @param activityValue
+ * - the report to save
+ * @throws NotAllowedException
+ * if the {@link ActivityValue activity value} is invalid
+ */
+ @RequestMapping(method = RequestMethod.POST, value = "orgUnits/{id}/activities")
+ @ResponseBody
+ public String saveActivityReport2_8(@PathVariable int id,
+ @RequestBody ActivityValue activityValue)
+ throws NotAllowedException {
+ // FIXME set the last argument to 0 to fix compilation error
+ activityReportingService.saveActivityReport(getUnit(id), activityValue,
+ 0);
+ return ACTIVITY_REPORT_UPLOADED;
+ }
+
+ @RequestMapping(method = RequestMethod.POST, value = "orgUnits/{id}/activitiyplan")
+ @ResponseBody
+ public MobileModel updatePrograms2_8(@PathVariable int id,
+ @RequestHeader("accept-language") String locale,
+ @RequestBody ModelList programsFromClient) {
+ MobileModel model = new MobileModel();
+ model.setClientVersion(DataStreamSerializable.TWO_POINT_EIGHT);
+ model.setPrograms(programService.updateProgram(programsFromClient,
+ locale, getUnit(id)));
+ model.setActivityPlan(activityReportingService.getCurrentActivityPlan(
+ getUnit(id), locale));
+ model.setServerCurrentDate(new Date());
+ return model;
+ }
+
+ @RequestMapping(method = RequestMethod.GET, value = "orgUnits/{id}/search")
+ @ResponseBody
+ public ActivityPlan search2_8(@PathVariable int id,
+ @RequestHeader("identifier") String identifier)
+ throws NotAllowedException {
+ ActivityPlan activityPlan = activityReportingService
+ .getActivitiesByIdentifier(identifier);
+ ;
+ activityPlan.setClientVersion(DataStreamSerializable.TWO_POINT_EIGHT);
+ return activityPlan;
+ }
+
+ @RequestMapping(method = RequestMethod.GET, value = "orgUnits/{id}/changeLanguageDataSet")
+ @ResponseBody
+ public DataSetList changeLanguageDataSet2_8(@PathVariable int id,
+ @RequestHeader("accept-language") String locale) {
+ return facilityReportingService.getDataSetsForLocale(getUnit(id),
+ locale);
+ }
+
+ // For client version 2.9 and higher
+
+ @RequestMapping(method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/all")
+ @ResponseBody
+ public MobileModel getAllDataForOrgUnit(@PathVariable String clientVersion,
+ @PathVariable int id,
+ @RequestHeader("accept-language") String locale) {
+ MobileModel mobileModel = new MobileModel();
+ mobileModel.setClientVersion(clientVersion);
+ OrganisationUnit unit = getUnit(id);
+ mobileModel.setActivityPlan(activityReportingService
+ .getCurrentActivityPlan(unit, locale));
+ mobileModel.setPrograms(programService.getPrograms(unit, locale));
+ mobileModel.setDatasets(facilityReportingService
+ .getMobileDataSetsForUnit(unit, locale));
+ mobileModel.setServerCurrentDate(new Date());
+ mobileModel.setLocales(getLocalStrings(i18nService
+ .getAvailableLocales()));
+ mobileModel.setSmsCommands(this.getMobileSMSCommands(smsCommandService
+ .getSMSCommands()));
+ return mobileModel;
+ }
+
+ @RequestMapping(method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/updateDataSets")
+ @ResponseBody
+ public DataSetList checkUpdatedDataSet(@PathVariable String clientVersion,
+ @PathVariable int id, @RequestBody DataSetList dataSetList,
+ @RequestHeader("accept-language") String locale) {
+ DataSetList returnList = facilityReportingService.getUpdatedDataSet(
+ dataSetList, getUnit(id), locale);
+ returnList.setClientVersion(clientVersion);
+ return returnList;
+ }
+
+ /**
+ * Save a facility report for unit
+ *
+ * @param dataSetValue
+ * - the report to save
+ * @throws NotAllowedException
+ * if the {@link DataSetValue} is invalid
+ */
+
+ @RequestMapping(method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/dataSets")
+ @ResponseBody
+ public String saveDataSetValues(@PathVariable int id,
+ @RequestBody DataSetValue dataSetValue) throws NotAllowedException {
+ facilityReportingService.saveDataSetValues(getUnit(id), dataSetValue);
+ return DATASET_REPORT_UPLOADED;
+ }
+
+ @RequestMapping(method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/activitiyplan")
+ @ResponseBody
+ public MobileModel updatePrograms(@PathVariable String clientVersion,
+ @PathVariable int id,
+ @RequestHeader("accept-language") String locale,
+ @RequestBody ModelList programsFromClient) {
+ MobileModel model = new MobileModel();
+ model.setClientVersion(clientVersion);
+ model.setPrograms(programService.updateProgram(programsFromClient,
+ locale, getUnit(id)));
+ model.setActivityPlan(activityReportingService.getCurrentActivityPlan(
+ getUnit(id), locale));
+ model.setServerCurrentDate(new Date());
+ return model;
+ }
+
+ @RequestMapping(method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/search")
+ @ResponseBody
+ public ActivityPlan search(@PathVariable String clientVersion,
+ @PathVariable int id, @RequestHeader("identifier") String identifier)
+ throws NotAllowedException {
+ ActivityPlan activityPlan = activityReportingService
+ .getActivitiesByIdentifier(identifier);
+ activityPlan.setClientVersion(clientVersion);
+ return activityPlan;
+ }
+
+ /**
+ * Save a facility report for unit
+ *
+ * @param dataSetValue
+ * - the report to save
+ * @throws NotAllowedException
+ * if the {@link DataSetValue} is invalid
+ */
+
+ // @RequestMapping( method = RequestMethod.POST, value =
+ // "{clientVersion}/orgUnits/{id}/dataSets" )
+ // @ResponseBody
+ // public String saveDataSetValues( @PathVariable int id, @RequestBody
+ // DataSetValue dataSetValue )
+ // throws NotAllowedException
+ // {
+ // facilityReportingService.saveDataSetValues( getUnit( id ),
+ // dataSetValue
+ // );
+ // return DATASET_REPORT_UPLOADED;
+ // }
+
+ /**
+ * Save activity report for unit
+ *
+ * @param activityValue
+ * - the report to save
+ * @throws NotAllowedException
+ * if the {@link ActivityValue activity value} is invalid
+ */
+ @RequestMapping(method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/activities")
+ @ResponseBody
+ public String saveActivityReport(@PathVariable int id,
+ @RequestBody ActivityValue activityValue)
+ throws NotAllowedException {
+ // FIXME set the last argument to 0 to fix compilation error
+ activityReportingService.saveActivityReport(getUnit(id), activityValue,
+ 0);
+ return ACTIVITY_REPORT_UPLOADED;
+ }
+
+ @RequestMapping(method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/changeLanguageDataSet")
+ @ResponseBody
+ public DataSetList changeLanguageDataSet(@PathVariable int id,
+ @RequestHeader("accept-language") String locale) {
+ return facilityReportingService.getDataSetsForLocale(getUnit(id),
+ locale);
+ }
+
+ @RequestMapping(method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/updateContactForMobile")
+ @ResponseBody
+ public Contact updateContactForMobile() {
+ return facilityReportingService.updateContactForMobile();
+ }
+
+ @RequestMapping(method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/findPatient")
+ @ResponseBody
+ public Patient findPatientByName(@PathVariable int id,
+ @RequestHeader("name") String fullName) throws NotAllowedException {
+ return activityReportingService.findPatient(fullName);
+ }
+
+ @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/uploadProgramStage" )
@ResponseBody
public String saveProgramStage( @PathVariable int id, @RequestBody ProgramStage programStage )
throws NotAllowedException
{
return activityReportingService.saveProgramStage( programStage );
}
-
- @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/enrollProgram" )
+
+ @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/enrollProgram" )
@ResponseBody
public Patient enrollProgram( @PathVariable int id, @RequestHeader( "enrollInfo" ) String enrollInfo )
throws NotAllowedException
@@ -300,53 +372,92 @@
return activityReportingService.enrollProgram( enrollInfo, id );
}
- // Supportive methods
-
- private Collection<String> getLocalStrings( Collection<Locale> locales )
- {
- if ( locales == null || locales.isEmpty() )
- {
- return null;
- }
- Collection<String> localeStrings = new ArrayList<String>();
-
- for ( Locale locale : locales )
- {
- localeStrings.add( locale.getLanguage() + "-" + locale.getCountry() );
- }
- return localeStrings;
- }
-
- private List<SMSCommand> getMobileSMSCommands( Collection<org.hisp.dhis.smscommand.SMSCommand> normalSMSCommands )
- {
- List<SMSCommand> smsCommands = new ArrayList<SMSCommand>();
- for ( org.hisp.dhis.smscommand.SMSCommand normalSMSCommand : normalSMSCommands )
- {
- SMSCommand mobileSMSCommand = new SMSCommand();
- List<SMSCode> smsCodes = new ArrayList<SMSCode>();
-
- mobileSMSCommand.setParserType( normalSMSCommand.getParserType().name() );
- mobileSMSCommand.setCodeSeparator( normalSMSCommand.getCodeSeparator() );
- mobileSMSCommand.setDataSetId( normalSMSCommand.getDataset().getId() );
- mobileSMSCommand.setSeparator( normalSMSCommand.getSeparator() );
-
- for ( org.hisp.dhis.smscommand.SMSCode normalSMSCode : normalSMSCommand.getCodes() )
- {
- SMSCode smsCode = new SMSCode();
-
- smsCode.setCode( normalSMSCode.getCode() );
- smsCode.setDataElementId( normalSMSCode.getDataElement().getId() );
- smsCode.setOptionId( normalSMSCode.getOptionId());
- smsCodes.add( smsCode );
- }
- mobileSMSCommand.setSmsCodes( smsCodes );
- smsCommands.add( mobileSMSCommand );
- }
- return smsCommands;
- }
-
- private OrganisationUnit getUnit( int id )
- {
- return organisationUnitService.getOrganisationUnit( id );
- }
+ // Supportive methods
+
+ private Collection<String> getLocalStrings(Collection<Locale> locales) {
+ if (locales == null || locales.isEmpty()) {
+ return null;
+ }
+ Collection<String> localeStrings = new ArrayList<String>();
+
+ for (Locale locale : locales) {
+ localeStrings.add(locale.getLanguage() + "-" + locale.getCountry());
+ }
+ return localeStrings;
+ }
+
+ private List<SMSCommand> getMobileSMSCommands(
+ Collection<org.hisp.dhis.smscommand.SMSCommand> normalSMSCommands) {
+ List<SMSCommand> smsCommands = new ArrayList<SMSCommand>();
+ for (org.hisp.dhis.smscommand.SMSCommand normalSMSCommand : normalSMSCommands) {
+ SMSCommand mobileSMSCommand = new SMSCommand();
+ List<SMSCode> smsCodes = new ArrayList<SMSCode>();
+
+ mobileSMSCommand.setParserType(normalSMSCommand.getParserType()
+ .name());
+ mobileSMSCommand.setCodeSeparator(normalSMSCommand
+ .getCodeSeparator());
+ mobileSMSCommand
+ .setDataSetId(normalSMSCommand.getDataset().getId());
+ mobileSMSCommand.setSeparator(normalSMSCommand.getSeparator());
+
+ for (org.hisp.dhis.smscommand.SMSCode normalSMSCode : normalSMSCommand
+ .getCodes()) {
+ SMSCode smsCode = new SMSCode();
+
+ smsCode.setCode(normalSMSCode.getCode());
+ smsCode.setDataElementId(normalSMSCode.getDataElement().getId());
+ smsCode.setOptionId(normalSMSCode.getId());
+ smsCodes.add(smsCode);
+ }
+ smsCommands.add(mobileSMSCommand);
+ }
+ return smsCommands;
+ }
+
+ private OrganisationUnit getUnit(int id) {
+ return organisationUnitService.getOrganisationUnit(id);
+ }
+
+ @RequestMapping(method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/registerPerson")
+ @ResponseBody
+ public String savePatient(@PathVariable int id, @RequestBody Patient patient) {
+
+ org.hisp.dhis.patient.Patient patientWeb = new org.hisp.dhis.patient.Patient();
+
+ int startIndex = patient.getFirstName().indexOf(' ');
+ int endIndex = patient.getFirstName().lastIndexOf(' ');
+
+ String firstName = patient.getFirstName().toString();
+ String middleName = "";
+ String lastName = "";
+
+ if (patient.getFirstName().indexOf(' ') != -1) {
+ firstName = patient.getFirstName().substring(0, startIndex);
+ if (startIndex == endIndex) {
+ middleName = "";
+ lastName = patient.getFirstName().substring(startIndex + 1,
+ patient.getFirstName().length());
+ } else {
+ middleName = patient.getFirstName().substring(startIndex + 1,
+ endIndex);
+ lastName = patient.getFirstName().substring(endIndex + 1,
+ patient.getFirstName().length());
+ }
+ }
+
+ patientWeb.setFirstName(firstName);
+ patientWeb.setMiddleName(middleName);
+ patientWeb.setLastName(lastName);
+ patientWeb.setGender(patient.getGender());
+ patientWeb.setDobType(patient.getDobType());
+ patientWeb.setPhoneNumber(patient.getPhoneNumber());
+ patientWeb.setOrganisationUnit(organisationUnitService
+ .getOrganisationUnit(id));
+
+ patientService.savePatient(patientWeb);
+
+ return PATIENT_REGISTERED;
+
+ }
}