Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-162 Result Set Pagination Prototype with Decorator #856

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Checkout core
run: git clone --depth=50 --branch=develop https://github.com/informatici/openhospital-core.git openhospital-core
run: git clone --depth=50 --branch=OP-162_ResultSet_Pagination_prototype https://github.com/informatici/openhospital-core.git openhospital-core
mwithi marked this conversation as resolved.
Show resolved Hide resolved
- name: Install core
run: cd openhospital-core && mvn install -DskipTests=true && cd ..
- name: Set up JDK 1.8
Expand Down
3 changes: 3 additions & 0 deletions bundle/language_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ angal.common.new.btn
angal.common.new.btn.key = N
angal.common.newpatient.btn = New Patient
angal.common.newpatient.btn.key = N
angal.common.nextpage = Next Page
mwithi marked this conversation as resolved.
Show resolved Hide resolved
angal.common.notapplicable.txt = N/A
angal.common.notdefined.txt = N/D
angal.common.note.title = Note
Expand All @@ -303,6 +304,7 @@ angal.common.pleaseinsertacode.msg
angal.common.pleaseinsertavaliddescription.msg = Please insert a valid description.
angal.common.pleaseselectapatient.msg = Please select a patient.
angal.common.pleaseselectarow.msg = Please select a row.
angal.common.previouspage = Previous Page
angal.common.print.btn = Print
angal.common.print.btn.key = P
angal.common.qty.txt = Qty
Expand Down Expand Up @@ -1079,6 +1081,7 @@ angal.opd.opdnumberalreadyexist.msg
angal.opd.opdnumbermustbeanumber.msg = OPD No. must be a number.
angal.opd.opdoutpatientdepartment.title = OPD Out Patient Department
angal.opd.operation = Operation
angal.opd.pagenumber = Page Number
angal.opd.patientcode.fmt.msg = Patient (code: {0})
angal.opd.patientid.col = PAT. ID
angal.opd.patientstatus.col = Status
Expand Down
129 changes: 80 additions & 49 deletions src/main/java/org/isf/opd/gui/OpdBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;

import javax.swing.AbstractButton;
Expand All @@ -50,13 +51,11 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
Expand All @@ -76,8 +75,11 @@
import org.isf.utils.exception.OHServiceException;
import org.isf.utils.jobjects.MessageDialog;
import org.isf.utils.jobjects.ModalJFrame;
import org.isf.utils.jobjects.PageableTableModel;
import org.isf.utils.jobjects.PaginatedTableDecoratorFull;
import org.isf.utils.jobjects.PaginatedTableDecoratorSimple;
mwithi marked this conversation as resolved.
Show resolved Hide resolved
import org.isf.utils.jobjects.PaginationDataProvider;
import org.isf.utils.jobjects.VoLimitedTextField;
import org.isf.utils.time.TimeTools;

/**
* ------------------------------------------
Expand All @@ -101,18 +103,21 @@
* - version is now 1.2.2
* ------------------------------------------
*/
public class OpdBrowser extends ModalJFrame implements OpdEdit.SurgeryListener, OpdEditExtended.SurgeryListener {
public class OpdBrowser extends ModalJFrame implements OpdEdit.SurgeryListener, OpdEditExtended.SurgeryListener, PaginationDataProvider<Opd> {

private static final long serialVersionUID = 2372745781159245861L;

private static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");

private final int defaultPageSize = 100;
mwithi marked this conversation as resolved.
Show resolved Hide resolved

private JPanel jButtonPanel = null;
private JPanel jContainPanel = null;
private int pfrmHeight;
private JButton jNewButton = null;
private JButton jEditButton = null;
private JButton jCloseButton = null;
private JButton jPreviousPageButton = null;
private JButton jNextPageButton = null;
mwithi marked this conversation as resolved.
Show resolved Hide resolved
private JButton jDeleteButton = null;
private JPanel jSelectionPanel = null;
private JPanel dateFromPanel = null;
Expand Down Expand Up @@ -150,7 +155,8 @@ public class OpdBrowser extends ModalJFrame implements OpdEdit.SurgeryListener,
MessageBundle.getMessage("angal.opd.diseasetype.col").toUpperCase(),
MessageBundle.getMessage("angal.opd.patientstatus.col").toUpperCase()
};
private ArrayList<Opd> pSur;
private List<Opd> pSur;
private int pSurSize;
private JTable jTable = null;
private OpdBrowsingModel model;
private int[] pColumnWidth = {50, 50, 70, 70, 150, 30, 30, 195, 195, 50 };
Expand All @@ -171,6 +177,16 @@ public class OpdBrowser extends ModalJFrame implements OpdEdit.SurgeryListener,
private DiseaseBrowserManager diseaseManager = Context.getApplicationContext().getBean(DiseaseBrowserManager.class);
private ArrayList<Disease> diseases = null;
protected AbstractButton searchButton;

private String disease;
private String diseasetype;
private char sex;
private char newPatient;
private GregorianCalendar dateFrom;
private GregorianCalendar dateTo;
private int currentPageNumber;
mwithi marked this conversation as resolved.
Show resolved Hide resolved

private PaginatedTableDecoratorFull<Opd> paginatedDecorator;

public JTable getJTable() {
if (jTable == null) {
Expand Down Expand Up @@ -280,7 +296,10 @@ private JPanel getJContainPanel() {
jContainPanel.setLayout(new BorderLayout());
jContainPanel.add(getJButtonPanel(), java.awt.BorderLayout.SOUTH);
jContainPanel.add(getJSelectionPanel(), java.awt.BorderLayout.WEST);
jContainPanel.add(new JScrollPane(getJTable()), java.awt.BorderLayout.CENTER);
paginatedDecorator = PaginatedTableDecoratorFull.decorate(getJTable(),
OpdBrowser.this, new int[]{5, 10, 20, 50, 75, 100}, defaultPageSize);
jContainPanel.add(paginatedDecorator.getContentPanel());
//jContainPanel.add(new JScrollPane(getJTable()), java.awt.BorderLayout.CENTER);
validate();
}
return jContainPanel;
Expand Down Expand Up @@ -356,7 +375,9 @@ private JButton getJCloseButton() {
}
return jCloseButton;
}



/**
* This method initializes jDeleteButton
*
Expand Down Expand Up @@ -956,16 +977,19 @@ private JPanel getJAgePanel() {
return jAgePanel;
}

class OpdBrowsingModel extends DefaultTableModel {
class OpdBrowsingModel extends PageableTableModel<Opd> {

private static final long serialVersionUID = -9129145534999353730L;

public OpdBrowsingModel(String diseaseTypeCode, String diseaseCode, GregorianCalendar dateFrom, GregorianCalendar dateTo, int ageFrom, int ageTo,
char sex, char newPatient) {
char sex, char newPatient, int pageNumber, int pageSize) {
pSur = manager.getOpdPaginated(diseaseTypeCode, diseaseCode, dateFrom, dateTo, ageFrom, ageTo, sex, newPatient,
pageNumber,
pageSize == 0 ? defaultPageSize : pageSize);
try {
pSur = manager.getOpd(diseaseTypeCode, diseaseCode, dateFrom, dateTo, ageFrom, ageTo, sex, newPatient);
} catch (OHServiceException ohServiceException) {
MessageDialog.showExceptions(ohServiceException);
pSurSize = manager.getOpd(diseasetype, disease, dateFrom, dateTo, ageFrom, ageTo, sex, newPatient).size();
} catch (OHServiceException e) {
e.printStackTrace();
}
}

Expand Down Expand Up @@ -995,8 +1019,8 @@ public int getColumnCount() {
}

@Override
public Object getValueAt(int r, int c) {
Opd opd = pSur.get(pSur.size() - r - 1);
public Object getValueAt(Opd opd, int c) {
//Opd opd = pSur.get(r);
Patient pat = opd.getPatient();
if (c == -1) {
return opd;
Expand Down Expand Up @@ -1040,6 +1064,13 @@ public Object getValueAt(int r, int c) {
public boolean isCellEditable(int arg0, int arg1) {
return false;
}

@Override
public String getFieldName(int column) {
// TODO Auto-generated method stub
return null;
}

}

@Override
Expand Down Expand Up @@ -1073,34 +1104,21 @@ private JButton getFilterButton() {
MessageDialog.error(OpdBrowser.this, "angal.opd.pleaseselectadisease.msg");
return;
}
String disease = ((Disease)selectedItem).getCode();
String diseasetype = ((DiseaseType)jDiseaseTypeBox.getSelectedItem()).getCode();
disease=((Disease)selectedItem).getCode();
diseasetype=((DiseaseType)jDiseaseTypeBox.getSelectedItem()).getCode();


char sex;
if (radioa.isSelected()) {
sex='A';
} else {
if (radiom.isSelected()) {
sex='M';
} else {
sex='F';
}
}

char newPatient;
if (radioAll.isSelected()) {
newPatient='A';
} else {
if (radioNew.isSelected()) {
newPatient='N';
} else {
newPatient='R';
}
}

GregorianCalendar dateFrom = getDateFrom();
GregorianCalendar dateTo = getDateTo();
if (radioa.isSelected()) sex='A';
else if (radiom.isSelected()) sex='M';
else sex='F';

if(radioAll.isSelected()) newPatient='A';
else if(radioNew.isSelected()) newPatient='N';
else newPatient='R';

dateFrom = getDateFrom();
dateTo = getDateTo();

if (dateFrom.after(dateTo)){
MessageDialog.error(OpdBrowser.this, "angal.opd.datefrommustbebefordateto.msg");
return;
Expand All @@ -1112,23 +1130,36 @@ private JButton getFilterButton() {
ageFrom=ageTo;
return;
}

//TODO: to retrieve resultset size instead of assuming 1 year as limit for the warning
if (TimeTools.getDaysBetweenDates(dateFrom, dateTo, true) >= 360) {
int ok = JOptionPane.showConfirmDialog(OpdBrowser.this,

try {
pSurSize = manager.getOpd(diseasetype, disease, dateFrom, dateTo, ageFrom, ageTo, sex, newPatient).size();
} catch (OHServiceException e1) {
e1.printStackTrace();
}
if (getTotalRowCount() > 200) {
int ok = JOptionPane.showConfirmDialog(OpdBrowser.this,
MessageBundle.getMessage("angal.common.thiscouldretrievealargeamountofdataproceed.msg"),
MessageBundle.getMessage("angal.messagedialog.question.title"),
JOptionPane.OK_CANCEL_OPTION);
if (ok != JOptionPane.OK_OPTION) return;
}
rowCounter.setText(rowCounterText + getTotalRowCount());
paginatedDecorator.paginate();

model = new OpdBrowsingModel(diseasetype,disease,getDateFrom(), getDateTo(),ageFrom,ageTo,sex,newPatient);
model.fireTableDataChanged();
jTable.updateUI();
rowCounter.setText(rowCounterText + pSur.size());
});
}
return filterButton;
}


@Override
public int getTotalRowCount() {
return pSurSize;
}

@Override
public List<Opd> getRows(int pageNumber, int pageSize) {
model = new OpdBrowsingModel(diseasetype, disease, getDateFrom(), getDateTo(), ageFrom, ageTo, sex, newPatient, pageNumber, pageSize);
return pSur;
}

}
43 changes: 43 additions & 0 deletions src/main/java/org/isf/utils/jobjects/PageableTableModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.isf.utils.jobjects;
mwithi marked this conversation as resolved.
Show resolved Hide resolved
import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
import java.util.List;

public abstract class PageableTableModel<T> extends AbstractTableModel {
private List<T> objectRows = new ArrayList<>();

public List<T> getObjectRows() {
return objectRows;
}

public void setObjectRows(List<T> objectRows) {
this.objectRows = objectRows;
}

@Override
public int getRowCount() {
return objectRows.size();
}

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
T t = objectRows.get(rowIndex);
return getValueAt(t, columnIndex);
}

@Override
public Class<?> getColumnClass(int columnIndex) {
if (objectRows.isEmpty()) {
return Object.class;
}
Object valueAt = getValueAt(0, columnIndex);
return valueAt!=null? valueAt.getClass(): Object.class;
}

public abstract Object getValueAt(T t, int columnIndex);

@Override
public abstract String getColumnName(int column);

public abstract String getFieldName(int column);
}
Loading