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-1341 Enable Medical Type for Soft Deletion #2092

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
38 changes: 37 additions & 1 deletion src/main/java/org/isf/medtype/gui/MedicalTypeBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@

import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
Expand All @@ -51,6 +53,13 @@
public class MedicalTypeBrowser extends ModalJFrame implements MedicalTypeListener {

private static final long serialVersionUID = 1L;

private static final String STR_ALL = MessageBundle.getMessage("angal.common.all.txt");
private static final String STR_ACTIVE_ONLY = MessageBundle.getMessage("angal.medicals.activeonly.txt");
private static final String STR_DISABLED_ONLY = MessageBundle.getMessage("angal.medicals.disabledonly.txt");

private String pSelection;
private String activeSelection = STR_ACTIVE_ONLY;
private List<MedicalType> pMedicalType;
private String[] pColumns = {
MessageBundle.getMessage("angal.common.code.txt").toUpperCase(),
Expand All @@ -63,6 +72,7 @@ public class MedicalTypeBrowser extends ModalJFrame implements MedicalTypeListen
private JButton jEditButton;
private JButton jCloseButton;
private JButton jDeleteButton;
private JComboBox activeComboBox;
private JTable jTable;
private MedicalTypeBrowserModel model;
private int selectedrow;
Expand Down Expand Up @@ -101,6 +111,7 @@ private JPanel getJContainPanel() {
private JPanel getJButtonPanel() {
if (jButtonPanel == null) {
jButtonPanel = new JPanel();
jButtonPanel.add(getComboBoxActive());
jButtonPanel.add(getJNewButton(), null);
jButtonPanel.add(getJEditButton(), null);
jButtonPanel.add(getJDeleteButton(), null);
Expand All @@ -123,6 +134,24 @@ private JButton getJNewButton() {
return jNewButton;
}

private JComboBox getComboBoxActive() {
if (activeComboBox == null) {
activeComboBox = new JComboBox();
activeComboBox.addItem(STR_ACTIVE_ONLY);
activeComboBox.addItem(STR_ALL);
activeComboBox.addItem(STR_DISABLED_ONLY);
activeSelection = STR_ACTIVE_ONLY;
}
activeComboBox.addActionListener(actionEvent -> {
activeSelection = activeComboBox.getSelectedItem().toString();
model = new MedicalTypeBrowserModel();
jTable.setModel(model);
model.fireTableDataChanged();
jTable.updateUI();
});
return activeComboBox;
}

/**
* This method initializes jEditButton
*
Expand Down Expand Up @@ -210,6 +239,11 @@ class MedicalTypeBrowserModel extends DefaultTableModel {
public MedicalTypeBrowserModel() {
try {
pMedicalType = medicalTypeBrowserManager.getMedicalType();
if (activeSelection.equals(STR_ACTIVE_ONLY)) {
pMedicalType = new ArrayList<>(pMedicalType.stream().filter(med -> med.getDeleted() == 'N').toList());
} else if (activeSelection.equals(STR_DISABLED_ONLY)) {
pMedicalType = new ArrayList<>(pMedicalType.stream().filter(med -> med.getDeleted() == 'Y').toList());
}
} catch (OHServiceException e) {
pMedicalType = null;
OHServiceExceptionUtil.showMessages(e);
Expand Down Expand Up @@ -257,10 +291,11 @@ public boolean isCellEditable(int arg0, int arg1) {
public void medicalTypeUpdated(AWTEvent e) {
pMedicalType.set(selectedrow, medicalType);
((MedicalTypeBrowserModel) jTable.getModel()).fireTableDataChanged();
jTable.updateUI();
if (jTable.getRowCount() > 0 && selectedrow > -1) {
jTable.setRowSelectionInterval(selectedrow, selectedrow);
}
model = new MedicalTypeBrowserModel();
jTable.updateUI();
}


Expand All @@ -271,5 +306,6 @@ public void medicalTypeInserted(AWTEvent e) {
if (jTable.getRowCount() > 0) {
jTable.setRowSelectionInterval(0, 0);
}
model = new MedicalTypeBrowserModel();
}
}
23 changes: 20 additions & 3 deletions src/main/java/org/isf/medtype/gui/MedicalTypeBrowserEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.EventListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
Expand Down Expand Up @@ -95,8 +96,10 @@ private void fireMedicalUpdated() {
private JButton cancelButton;
private JButton okButton;
private JTextField descriptionTextField;
private JCheckBox activeCheckbox;
private VoLimitedTextField codeTextField;
private String lastdescription;
private char isLastDeleted;
private MedicalType medicalType;
private boolean insert;
private JPanel jDataPanel;
Expand All @@ -110,6 +113,7 @@ public MedicalTypeBrowserEdit(JFrame owner, MedicalType old, boolean inserting)
insert = inserting;
medicalType = old; //medical type will be used for every operation
lastdescription = medicalType.getDescription();
isLastDeleted = medicalType.getDeleted();
initialize();
}

Expand All @@ -124,9 +128,11 @@ private void initialize() {
this.setTitle(MessageBundle.getMessage("angal.medtype.editmedicaltype.title"));
}
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.getActiveField();
this.pack();
this.setLocationRelativeTo(null);
}


/**
* This method initializes jContentPane
Expand Down Expand Up @@ -197,7 +203,8 @@ private JButton getOkButton() {

medicalType.setDescription(descriptionTextField.getText());
medicalType.setCode(codeTextField.getText());

medicalType.setDeleted(activeCheckbox.isSelected() ? 'N' : 'Y');

if (insert) { // inserting
try {
MedicalType insertedMedicalType = medicalTypeBrowserManager.newMedicalType(medicalType);
Expand All @@ -211,7 +218,7 @@ private JButton getOkButton() {
OHServiceExceptionUtil.showMessages(e1);
}
} else { // updating
if (descriptionTextField.getText().equals(lastdescription)) {
if (descriptionTextField.getText().equals(lastdescription) && medicalType.getDeleted() == isLastDeleted) {
dispose();
} else {
try {
Expand Down Expand Up @@ -263,6 +270,14 @@ private JTextField getCodeTextField() {
}
return codeTextField;
}

private JCheckBox getActiveField() {
if (activeCheckbox == null) {
activeCheckbox = new JCheckBox("Active");
mwithi marked this conversation as resolved.
Show resolved Hide resolved
activeCheckbox.setSelected(medicalType.getDeleted() == 'N');
}
return activeCheckbox;
}

/**
* This method initializes jDataPanel
Expand All @@ -276,7 +291,9 @@ private JPanel getJDataPanel() {
jDataPanel.add(getCodeTextField());
jDataPanel.add(new JLabel(MessageBundle.getMessage("angal.common.description.txt") + ':'));
jDataPanel.add(getDescriptionTextField());
SpringUtilities.makeCompactGrid(jDataPanel, 2, 2, 5, 5, 5, 5);
jDataPanel.add(new JLabel(MessageBundle.getMessage("Active") + ':'));
mwithi marked this conversation as resolved.
Show resolved Hide resolved
jDataPanel.add(getActiveField());
SpringUtilities.makeCompactGrid(jDataPanel, 3, 2, 5, 5, 5, 5);
}
return jDataPanel;
}
Expand Down
Loading