mirror of
https://github.com/tiennm99/BSK-All-in-One-Clinic-Management-System.git
synced 2026-10-14 20:16:47 +00:00
[update] Refactor CheckUpPage to separate regular medications and supplements in invoice generation. Update Medicine entity to include supplement flag and adjust database queries accordingly. Enhance error handling for medicine data validation.
This commit is contained in:
1 parent
c4fe96929e
commit
7acda1f4ab
3 files changed
+27
-16
No files matched your search
@@ -1779,14 +1779,31 @@ public class CheckUpPage extends JPanel {
|
||||
(servicePrescription == null || servicePrescription.length == 0)) {
|
||||
return; // Just return silently if there's nothing to print
|
||||
}
|
||||
// Separate regular medications and supplements
|
||||
List<String[]> regularMeds = new ArrayList<>();
|
||||
List<String[]> supplements = new ArrayList<>();
|
||||
|
||||
if (medicinePrescription != null) {
|
||||
for (String[] med : medicinePrescription) {
|
||||
// Check if this is a supplement (index 8 is the supplement flag)
|
||||
if (med.length > 8 && "1".equals(med[8])) {
|
||||
supplements.add(med);
|
||||
} else {
|
||||
regularMeds.add(med);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MedicineInvoice medicineInvoice = new MedicineInvoice(checkupIdField.getText(),
|
||||
customerLastNameField.getText() + " " + customerFirstNameField.getText(),
|
||||
dobPicker.getJFormattedTextField().getText(), customerPhoneField.getText(),
|
||||
genderComboBox.getSelectedItem().toString(),
|
||||
customerAddressField.getText() + ", " + (wardComboBox.getSelectedItem() != null ? wardComboBox.getSelectedItem().toString() : "") + ", " + (districtComboBox.getSelectedItem() != null ? districtComboBox.getSelectedItem().toString() : "") + ", " + (provinceComboBox.getSelectedItem() != null ? provinceComboBox.getSelectedItem().toString() : ""),
|
||||
doctorComboBox.getSelectedItem().toString(), diagnosisField.getText(),
|
||||
conclusionField.getText(), medicinePrescription, servicePrescription,
|
||||
new String[][]{} // No supplements for now
|
||||
conclusionField.getText(),
|
||||
regularMeds.toArray(new String[0][]),
|
||||
servicePrescription,
|
||||
supplements.toArray(new String[0][]) // Pass supplements
|
||||
);
|
||||
// First, show the print preview to the user
|
||||
medicineInvoice.showDirectJasperViewer();
|
||||
@@ -4888,15 +4905,6 @@ public class CheckUpPage extends JPanel {
|
||||
});
|
||||
}
|
||||
|
||||
private int findRowByCheckupId(String checkupId) {
|
||||
DefaultTableModel model = (DefaultTableModel) table.getModel();
|
||||
for (int i = 0; i < model.getRowCount(); i++) {
|
||||
if (model.getValueAt(i, 0).equals(checkupId)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1; // Not found
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,14 +19,15 @@ public class Medicine {
|
||||
private String unit;
|
||||
private String sellingPrice;
|
||||
private String preferenceNote;
|
||||
private String supplement; // 0: no, 1: yes
|
||||
|
||||
/**
|
||||
* Constructor to create Medicine from array data
|
||||
* @param data Array of medicine data from backend
|
||||
*/
|
||||
public Medicine(String[] data) {
|
||||
if (data.length < 8) {
|
||||
throw new IllegalArgumentException("Medicine data array must contain at least 8 elements");
|
||||
if (data.length < 9) {
|
||||
throw new IllegalArgumentException("Medicine data array must contain at least 9 elements");
|
||||
}
|
||||
this.id = data[0];
|
||||
this.name = data[1];
|
||||
@@ -36,6 +37,7 @@ public class Medicine {
|
||||
this.unit = data[5];
|
||||
this.sellingPrice = data[6];
|
||||
this.preferenceNote = data[7];
|
||||
this.supplement = data[8];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,6 +45,6 @@ public class Medicine {
|
||||
* @return String array representation of Medicine
|
||||
*/
|
||||
public String[] toStringArray() {
|
||||
return new String[]{id, name, company, description, quantity, unit, sellingPrice, preferenceNote};
|
||||
return new String[]{id, name, company, description, quantity, unit, sellingPrice, preferenceNote, supplement};
|
||||
}
|
||||
}
|
||||
@@ -374,7 +374,7 @@ public class ServerHandler extends SimpleChannelInboundHandler<TextWebSocketFram
|
||||
log.debug("Received GetMedInfoRequest");
|
||||
try {
|
||||
ResultSet rs = statement.executeQuery(
|
||||
"select med_id, med_name, med_company, med_description, quantity, med_unit, med_selling_price, preference_note\n" +
|
||||
"select med_id, med_name, med_company, med_description, quantity, med_unit, med_selling_price, preference_note, supplement\n" +
|
||||
" from Medicine"
|
||||
);
|
||||
|
||||
@@ -391,10 +391,11 @@ public class ServerHandler extends SimpleChannelInboundHandler<TextWebSocketFram
|
||||
String medUnit = rs.getString("med_unit");
|
||||
String medSellingPrice = rs.getString("med_selling_price");
|
||||
String preferenceNote = rs.getString("preference_note");
|
||||
String supplement = rs.getString("supplement");
|
||||
|
||||
|
||||
String result = String.join("|",medId, medName, medCompany, medDescription, quantity, medUnit,
|
||||
medSellingPrice, preferenceNote != null ? preferenceNote : "");
|
||||
medSellingPrice, preferenceNote != null ? preferenceNote : "", supplement != null ? supplement : "0");
|
||||
resultList.add(result);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user