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-749 | To extend laboratory filter panel with search by patient #2104

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
1 change: 1 addition & 0 deletions bundle/language_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ angal.lab.exam
angal.lab.film.txt = Film
angal.lab.in = In
angal.lab.insertvalidage.msg = Insert a valid age.
angal.lab.insertvalidpatientid.msg = Insert a valid patient code.
angal.lab.laboratorybrowser.title = Laboratory Browser
angal.lab.material = Material
angal.lab.multipleresults.txt = Multiple results
Expand Down
102 changes: 92 additions & 10 deletions src/main/java/org/isf/lab/gui/LabBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -38,6 +40,7 @@
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
Expand All @@ -51,6 +54,7 @@
import org.isf.lab.gui.LabEditExtended.LabEditExtendedListener;
import org.isf.lab.gui.LabNew.LabListener;
import org.isf.lab.manager.LabManager;
import org.isf.patient.manager.PatientBrowserManager;
import org.isf.lab.model.Laboratory;
import org.isf.lab.model.LaboratoryForPrint;
import org.isf.menu.gui.MainMenu;
Expand Down Expand Up @@ -95,6 +99,7 @@ public void labUpdated() {
private JPanel jSelectionPanel;
private JTable jTable;
private JComboBox comboExams;
private JTextField patientCodeField;
private int pfrmHeight = 100;
private List<Laboratory> pLabs;
private String[] pColumns = {
Expand All @@ -108,6 +113,7 @@ public void labUpdated() {
private int[] maxWidth = {150, 200, 200, 200};
private boolean[] columnsVisible = { true, GeneralData.LABEXTENDED, true, true};
private LabManager labManager = Context.getApplicationContext().getBean(LabManager.class);
private PatientBrowserManager patManager = Context.getApplicationContext().getBean(PatientBrowserManager.class);
private PrintManager printManager = Context.getApplicationContext().getBean(PrintManager.class);
private ExamBrowsingManager examBrowsingManager = Context.getApplicationContext().getBean(ExamBrowsingManager.class);
private LabBrowsingModel model;
Expand Down Expand Up @@ -358,6 +364,8 @@ private JPanel getJSelectionPanel() {
if (jSelectionPanel == null) {
jSelectionPanel = new JPanel();
jSelectionPanel.setPreferredSize(new Dimension(225, pfrmHeight));
jSelectionPanel.add(new JLabel(MessageBundle.getMessage("angal.lab.selectapatient")));
jSelectionPanel.add(getPatientCodeField());
jSelectionPanel.add(new JLabel(MessageBundle.getMessage("angal.lab.selectanexam")));
jSelectionPanel.add(getComboExams());
jSelectionPanel.add(getDateFilterPanel());
Expand Down Expand Up @@ -392,6 +400,39 @@ private JTable getJTable() {
return jTable;
}

/**
* This method initializes the patient code search text field.
*
* @return patientCodeField (JTextField)
*/
private JTextField getPatientCodeField() {
if (patientCodeField == null) {
patientCodeField = new JTextField();
patientCodeField.setPreferredSize(new Dimension(215, 30));
patientCodeField.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_ENTER) {
model = new LabBrowsingModel(patientCodeField.getText());
model.fireTableDataChanged();
jTable.updateUI();
}
}

@Override
public void keyReleased(KeyEvent e) {
}

@Override
public void keyTyped(KeyEvent e) {
}
});
}
return patientCodeField;
}


/**
* This method initializes comboExams, that allows to choose which Exam the
* user want to display on the Table
Expand Down Expand Up @@ -453,9 +494,9 @@ private JButton getFilterButton() {
filterButton.addActionListener(actionEvent -> {
typeSelected = comboExams.getSelectedItem().toString();
if (typeSelected.equalsIgnoreCase(MessageBundle.getMessage("angal.common.all.txt"))) {
typeSelected = null;
typeSelected = "";
}
model = new LabBrowsingModel(typeSelected, dateFrom.getDate(), dateTo.getDate());
model = new LabBrowsingModel(typeSelected, dateFrom.getDate(), dateTo.getDate(), patientCodeField.getText());
model.fireTableDataChanged();
jTable.updateUI();
});
Expand All @@ -473,14 +514,55 @@ class LabBrowsingModel extends DefaultTableModel {

private static final long serialVersionUID = 1L;

public LabBrowsingModel(String exam, LocalDate dateFrom, LocalDate dateTo) {
try {
pLabs = labManager.getLaboratory(exam, dateFrom.atStartOfDay(), dateTo.atStartOfDay());
} catch (OHServiceException e) {
pLabs = new ArrayList<>();
OHServiceExceptionUtil.showMessages(e);
}
}
public LabBrowsingModel(String exam, LocalDate dateFrom, LocalDate dateTo, String patid) {
boolean exists = true;
try {
Patient pat;
if (patid.isEmpty()) {
pat = null;
} else {
try {
pat = patManager.getPatientById(Integer.parseInt(patid));
exists = pat == null ? false : true;
mwithi marked this conversation as resolved.
Show resolved Hide resolved
} catch (NumberFormatException e) {
MessageDialog.error(null, "angal.lab.insertvalidpatientid.msg");
pat = null;
}
}
if (exists) {
pLabs = labManager.getLaboratory(exam, dateFrom.atStartOfDay(), dateTo.atStartOfDay(), pat);
} else {
pLabs = new ArrayList<>();
}
} catch (OHServiceException e) {
pLabs = new ArrayList<>();
OHServiceExceptionUtil.showMessages(e);
}
}

public LabBrowsingModel(String patid) {
try {
Patient pat;
if (patid.isEmpty()) {
pat = null;
} else {
try {
pat = patManager.getPatientById(Integer.parseInt(patid));
} catch (NumberFormatException e) {
MessageDialog.error(null, "angal.lab.insertvalidpatientid.msg");
pat = null;
}
}
if (pat == null) {
pLabs = new ArrayList<>();
} else {
pLabs = labManager.getLaboratory(pat);
}
} catch (OHServiceException e) {
pLabs = new ArrayList<>();
OHServiceExceptionUtil.showMessages(e);
}
}

public LabBrowsingModel() {
try {
Expand Down