Skip to content

Commit

Permalink
OP-1219 Add Ward comparator to sort in combobox (#1328)
Browse files Browse the repository at this point in the history
* OP-1219 Add Ward comparator to sort in combobox

* Remove unnecessary comparator (so far) and using Apache Commons compare
  • Loading branch information
mwithi committed May 10, 2024
1 parent 69229df commit 48b5819
Showing 1 changed file with 55 additions and 45 deletions.
100 changes: 55 additions & 45 deletions src/main/java/org/isf/ward/model/Ward.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
package org.isf.ward.model;

import java.util.Comparator;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -31,11 +33,12 @@
import javax.persistence.Version;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.StringUtils;
import org.isf.utils.db.Auditable;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Entity
@Table(name="OH_WARD")
@Table(name = "OH_WARD")
@EntityListeners(AuditingEntityListener.class)
@AttributeOverride(name = "createdBy", column = @Column(name = "WRD_CREATED_BY", updatable = false))
@AttributeOverride(name = "createdDate", column = @Column(name = "WRD_CREATED_DATE", updatable = false))
Expand All @@ -45,66 +48,67 @@
public class Ward extends Auditable<String> {

@Id
@Column(name="WRD_ID_A")
@Column(name = "WRD_ID_A")
private String code;

@NotNull
@Column(name="WRD_NAME")
@Column(name = "WRD_NAME")
private String description;
@Column(name="WRD_TELE")

@Column(name = "WRD_TELE")
private String telephone;
@Column(name="WRD_FAX")

@Column(name = "WRD_FAX")
private String fax;
@Column(name="WRD_EMAIL")

@Column(name = "WRD_EMAIL")
private String email;

@NotNull
@Column(name="WRD_NBEDS")
@Column(name = "WRD_NBEDS")
private Integer beds;

@NotNull
@Column(name="WRD_NQUA_NURS")
@Column(name = "WRD_NQUA_NURS")
private Integer nurs;

@NotNull
@Column(name="WRD_NDOC")
@Column(name = "WRD_NDOC")
private Integer docs;
@Column(name="WRD_IS_OPD")

@Column(name = "WRD_IS_OPD")
private boolean isOpd;

@NotNull
@Column(name="WRD_IS_PHARMACY")
@Column(name = "WRD_IS_PHARMACY")
private boolean isPharmacy;

@NotNull
@Column(name="WRD_IS_MALE")
@Column(name = "WRD_IS_MALE")
private boolean isMale;

@NotNull
@Column(name="WRD_IS_FEMALE")
@Column(name = "WRD_IS_FEMALE")
private boolean isFemale;

@NotNull
@Column(name="WRD_VISIT_DURATION")
@Column(name = "WRD_VISIT_DURATION")
private int visitDuration;

@Version
@Column(name="WRD_LOCK")
@Column(name = "WRD_LOCK")
private Integer lock;

@Transient
private volatile int hashCode;

public Ward() {
super();
}

public Ward(String code, String description, String telephone, String fax, String email, Integer beds, Integer nurs, Integer docs, boolean isOpd, boolean isPharmacy,
boolean isMale, boolean isFemale) {
public Ward(String code, String description, String telephone, String fax, String email, Integer beds, Integer nurs, Integer docs, boolean isOpd,
boolean isPharmacy,
boolean isMale, boolean isFemale) {
this(code, description, telephone, fax, email, beds, nurs, docs, isOpd, isPharmacy, isMale, isFemale, 30);
}

Expand All @@ -122,8 +126,9 @@ public Ward(String code, String description, String telephone, String fax, Strin
* @param isFemale
* @param visitDuration
*/
public Ward(String code, String description, String telephone, String fax, String email, Integer beds, Integer nurs, Integer docs, boolean isOpd, boolean isPharmacy,
boolean isMale, boolean isFemale, int visitDuration) {
public Ward(String code, String description, String telephone, String fax, String email, Integer beds, Integer nurs, Integer docs, boolean isOpd,
boolean isPharmacy,
boolean isMale, boolean isFemale, int visitDuration) {
super();
this.code = code;
this.description = description;
Expand All @@ -140,14 +145,14 @@ public Ward(String code, String description, String telephone, String fax, Strin
this.visitDuration = visitDuration;
}

//TODO: to reduce number of constructors
// TODO: to reduce number of constructors
public Ward(String code, String description, String telephone, String fax, String email, Integer beds, Integer nurs, Integer docs, boolean isMale,
boolean isFemale) {
boolean isFemale) {
this(code, description, telephone, fax, email, beds, nurs, docs, isMale, isFemale, 30);
}

public Ward(String code, String description, String telephone, String fax, String email, Integer beds, Integer nurs, Integer docs, boolean isMale,
boolean isFemale, int visitDuration) {
boolean isFemale, int visitDuration) {
super();
this.code = code;
this.description = description;
Expand Down Expand Up @@ -235,15 +240,15 @@ public Integer getLock() {
public void setLock(Integer aLock) {
this.lock = aLock;
}

public boolean isOpd() {
return isOpd;
}

public void setOpd(boolean isOPD) {
this.isOpd = isOPD;
}

public boolean isPharmacy() {
return isPharmacy;
}
Expand Down Expand Up @@ -279,15 +284,15 @@ public void setVisitDuration(int visitDuration) {
@Override
public boolean equals(Object anObject) {
return anObject instanceof Ward
&& (getCode().equals(((Ward) anObject).getCode()))
&& getDescription().equalsIgnoreCase(((Ward) anObject).getDescription())
&& getTelephone().equalsIgnoreCase(((Ward) anObject).getTelephone())
&& (getFax().equalsIgnoreCase(((Ward) anObject).getFax()))
&& (getEmail().equalsIgnoreCase(((Ward) anObject).getEmail()))
&& (getBeds().equals(((Ward) anObject).getBeds()))
&& (getNurs().equals(((Ward) anObject).getNurs()))
&& (getDocs().equals(((Ward) anObject).getDocs()))
&& (getVisitDuration() == ((Ward) anObject).getVisitDuration());
&& (getCode().equals(((Ward) anObject).getCode()))
&& getDescription().equalsIgnoreCase(((Ward) anObject).getDescription())
&& getTelephone().equalsIgnoreCase(((Ward) anObject).getTelephone())
&& (getFax().equalsIgnoreCase(((Ward) anObject).getFax()))
&& (getEmail().equalsIgnoreCase(((Ward) anObject).getEmail()))
&& (getBeds().equals(((Ward) anObject).getBeds()))
&& (getNurs().equals(((Ward) anObject).getNurs()))
&& (getDocs().equals(((Ward) anObject).getDocs()))
&& (getVisitDuration() == ((Ward) anObject).getVisitDuration());
}

@Override
Expand All @@ -297,9 +302,9 @@ public String toString() {

public String debug() {
return "Ward [code=" + code + ", description=" + description + ", telephone=" + telephone + ", fax=" + fax
+ ", email=" + email + ", beds=" + beds + ", nurs=" + nurs + ", docs=" + docs + ", isPharmacy="
+ isPharmacy + ", isMale=" + isMale + ", isFemale=" + isFemale + ", lock=" + lock + ", hashCode="
+ hashCode + ']';
+ ", email=" + email + ", beds=" + beds + ", nurs=" + nurs + ", docs=" + docs + ", isPharmacy="
+ isPharmacy + ", isMale=" + isMale + ", isFemale=" + isFemale + ", lock=" + lock + ", hashCode="
+ hashCode + ']';
}

@Override
Expand All @@ -314,7 +319,12 @@ public int hashCode() {
}
return this.hashCode;
}



public static class WardDescriptionComparator implements Comparator<Ward> {

@Override
public int compare(Ward object1, Ward object2) {
return StringUtils.compare(object1.getDescription(), object2.getDescription());
}
}
}

0 comments on commit 48b5819

Please sign in to comment.