diff --git a/sql-scripts/Ward-Admission-LocalSurgery-Card-Templates.sql b/sql-scripts/Ward-Admission-LocalSurgery-Card-Templates.sql
new file mode 100644
index 00000000000..941745fac7f
--- /dev/null
+++ b/sql-scripts/Ward-Admission-LocalSurgery-Card-Templates.sql
@@ -0,0 +1,285 @@
+-- Ward Admission Card and Local Surgery Card Document Templates
+-- This script creates the default document templates for ward admission and local surgery cards
+
+-- Insert Ward Admission Card Template Type
+INSERT INTO document_template_type (id, code, name, created_date, created_user, modified_date, modified_user, retired, retired_date, retired_user, description)
+VALUES (
+ UUID(),
+ 'WARD_ADMISSION_CARD',
+ 'Ward Admission Card',
+ NOW(),
+ 'system',
+ NOW(),
+ 'system',
+ false,
+ NULL,
+ NULL,
+ 'Document template for ward admission records with patient, clinical, and discharge information'
+);
+
+-- Insert Local Surgery Card Template Type
+INSERT INTO document_template_type (id, code, name, created_date, created_user, modified_date, modified_user, retired, retired_date, retired_user, description)
+VALUES (
+ UUID(),
+ 'LOCAL_SURGERY_CARD',
+ 'Local Surgery Card',
+ NOW(),
+ 'system',
+ NOW(),
+ 'system',
+ false,
+ NULL,
+ NULL,
+ 'Document template for surgical procedure records with surgical team and operative details'
+);
+
+-- Insert Default Ward Admission Card Template
+INSERT INTO document_template (
+ id,
+ name,
+ code,
+ template_type_id,
+ contents,
+ is_default,
+ is_retired,
+ created_date,
+ created_user,
+ modified_date,
+ modified_user,
+ description,
+ department_id,
+ institution_id
+)
+SELECT
+ UUID(),
+ 'Standard Ward Admission Card',
+ 'WARD_ADMISSION_STANDARD',
+ dtt.id,
+ CONCAT(
+ '
',
+ '
WARD ADMISSION CARD
',
+ '
',
+ '',
+ '
Patient Information
',
+ '
',
+ ' ',
+ ' | Name: | ',
+ ' {{name}} | ',
+ ' Age: | ',
+ ' {{age}} | ',
+ '
',
+ ' ',
+ ' | Gender: | ',
+ ' {{sex}} | ',
+ ' Phone: | ',
+ ' {{phone}} | ',
+ '
',
+ ' ',
+ ' | Address: | ',
+ ' {{address}} | ',
+ '
',
+ '
',
+ '',
+ '
Hospital Record
',
+ '
',
+ ' ',
+ ' | BHT No: | ',
+ ' {{bht}} | ',
+ ' Room/Bed: | ',
+ ' {{room}} | ',
+ '
',
+ ' ',
+ ' | Date of Admission: | ',
+ ' {{doa}} | ',
+ ' Date of Discharge: | ',
+ ' {{dod}} | ',
+ '
',
+ ' ',
+ ' | Height: | ',
+ ' {{height}} cm | ',
+ ' Weight: | ',
+ ' {{weight}} kg | ',
+ '
',
+ ' ',
+ ' | BMI: | ',
+ ' {{bmi}} | ',
+ ' BP: | ',
+ ' {{bp}} | ',
+ '
',
+ '
',
+ '',
+ '
Diagnosis & Medical History
',
+ '
',
+ ' Current Diagnosis:
{{dx}}',
+ '
',
+ '
',
+ ' Past Medical History:
{{past-dx}}',
+ '
',
+ '
',
+ ' Known Allergies:
{{allergies}}',
+ '
',
+ '',
+ '
Treatment During Ward Stay
',
+ '
',
+ ' Routine Medications & Treatment:
{{rx}}',
+ '
',
+ '
',
+ ' Procedures Performed:
{{procedures}}',
+ '
',
+ '',
+ '
Discharge Instructions
',
+ '
',
+ ' Discharge Medications:
{{drx}}',
+ '
',
+ '
',
+ ' Follow-up Investigations:
{{ix}}',
+ '
',
+ '',
+ '
Clinical Notes
',
+ '
',
+ ' {{comments}}',
+ '
',
+ '',
+ '
',
+ '
Generated by HMIS - Hospital Management Information System
',
+ '
'
+ ),
+ true,
+ false,
+ NOW(),
+ 'system',
+ NOW(),
+ 'system',
+ 'Default ward admission card with patient info, diagnosis, treatment, and discharge instructions',
+ NULL,
+ NULL
+FROM document_template_type dtt
+WHERE dtt.code = 'WARD_ADMISSION_CARD'
+LIMIT 1;
+
+-- Insert Default Local Surgery Card Template
+INSERT INTO document_template (
+ id,
+ name,
+ code,
+ template_type_id,
+ contents,
+ is_default,
+ is_retired,
+ created_date,
+ created_user,
+ modified_date,
+ modified_user,
+ description,
+ department_id,
+ institution_id
+)
+SELECT
+ UUID(),
+ 'Standard Local Surgery Card',
+ 'LOCAL_SURGERY_STANDARD',
+ dtt.id,
+ CONCAT(
+ '',
+ '
SURGICAL PROCEDURE RECORD
',
+ '
',
+ '',
+ '
Patient Details
',
+ '
',
+ ' ',
+ ' | Name: | ',
+ ' {{name}} | ',
+ ' Age: | ',
+ ' {{age}} | ',
+ '
',
+ ' ',
+ ' | Gender: | ',
+ ' {{sex}} | ',
+ ' Phone: | ',
+ ' {{phone}} | ',
+ '
',
+ ' ',
+ ' | BHT No: | ',
+ ' {{bht}} | ',
+ ' Room/Bed: | ',
+ ' {{room}} | ',
+ '
',
+ '
',
+ '',
+ '
Pre-Operative Assessment
',
+ '
',
+ ' Pre-Operative Diagnosis:
{{dx}}',
+ '
',
+ '
',
+ ' Height: {{height}} cm | Weight: {{weight}} kg | BMI: {{bmi}}',
+ '
',
+ '',
+ '
Surgical Procedure
',
+ '
',
+ ' Surgery Type & Details:
{{procedures}}',
+ '
',
+ '
',
+ ' Date of Surgery:
{{surgery-date}}',
+ '
',
+ '',
+ '
Surgical Team
',
+ '
',
+ ' ',
+ ' | Surgeon (Performed By): | ',
+ ' {{surgery-performed-by}} | ',
+ '
',
+ ' ',
+ ' | Anesthesiologist (Anesthesia By): | ',
+ ' {{anesthesia-by}} | ',
+ '
',
+ ' ',
+ ' | Surgical Assistant (Assistant By): | ',
+ ' {{assistant-by}} | ',
+ '
',
+ '
',
+ '',
+ '
Intra-Operative Details
',
+ '
',
+ ' Operative Findings & Procedure Notes:
{{comments}}',
+ '
',
+ '
',
+ ' Implants/Materials/Supplies Used:
{{implants-used}}',
+ '
',
+ '',
+ '
Intra-Operative Complications
',
+ '
',
+ ' {{complications}}',
+ '
',
+ '',
+ '
Post-Operative Instructions
',
+ '
',
+ ' Post-Operative Medications:
{{drx}}',
+ '
',
+ '
',
+ ' Follow-up Investigations:
{{ix}}',
+ '
',
+ '
',
+ ' Post-Operative Notes & Care Instructions:
{{post-op-notes}}',
+ '
',
+ '',
+ '
',
+ '
Generated by HMIS - Hospital Management Information System
',
+ '
'
+ ),
+ true,
+ false,
+ NOW(),
+ 'system',
+ NOW(),
+ 'system',
+ 'Default local surgery card with surgical team, procedure details, and post-operative instructions',
+ NULL,
+ NULL
+FROM document_template_type dtt
+WHERE dtt.code = 'LOCAL_SURGERY_CARD'
+LIMIT 1;
+
+-- Verify Inserts
+SELECT 'Verification Results:' as status;
+SELECT COUNT(*) as ward_admission_templates FROM document_template WHERE code LIKE 'WARD_ADMISSION_%';
+SELECT COUNT(*) as local_surgery_templates FROM document_template WHERE code LIKE 'LOCAL_SURGERY_%';
diff --git a/src/main/java/com/divudi/bean/inward/BhtSummeryController.java b/src/main/java/com/divudi/bean/inward/BhtSummeryController.java
index 905dc083ef4..ff6afbb610d 100644
--- a/src/main/java/com/divudi/bean/inward/BhtSummeryController.java
+++ b/src/main/java/com/divudi/bean/inward/BhtSummeryController.java
@@ -32,6 +32,7 @@
import com.divudi.core.entity.BillFee;
import com.divudi.core.entity.BillItem;
import com.divudi.core.entity.BilledBill;
+import com.divudi.core.entity.CancelledBill;
import com.divudi.core.entity.Item;
import com.divudi.core.entity.PatientEncounter;
import com.divudi.core.entity.PatientItem;
@@ -219,7 +220,10 @@ public String navigateToAddServiceFromSurgeriesFromAdmissionProfile() {
}
public List getPatientRooms() {
- if (patientRooms == null) {
+ if (patientRooms == null && patientEncounter != null) {
+ if (childPatientEncouters == null || childPatientEncouters.isEmpty()) {
+ childPatientEncouters = getInwardBean().fetchChildPatientEncounter(getPatientEncounter());
+ }
patientRooms = createPatientRooms();
}
return patientRooms;
@@ -230,9 +234,11 @@ public void setPatientRooms(List patientRooms) {
}
public List getDoctorAndNurseFee() {
- if (doctorAndNurseFee == null) {
- List cpts = getInwardBean().fetchChildPatientEncounter(getPatientEncounter());
- doctorAndNurseFee = getInwardBean().createDoctorAndNurseFee(getPatientEncounter(), cpts);
+ if (doctorAndNurseFee == null && patientEncounter != null) {
+ if (childPatientEncouters == null || childPatientEncouters.isEmpty()) {
+ childPatientEncouters = getInwardBean().fetchChildPatientEncounter(getPatientEncounter());
+ }
+ doctorAndNurseFee = getInwardBean().createDoctorAndNurseFee(getPatientEncounter(), childPatientEncouters);
}
return doctorAndNurseFee;
}
@@ -1854,6 +1860,11 @@ private void saveTempBill() {
getTempBill().setCreatedAt(new Date());
getTempBill().setCreater(getSessionController().getLoggedUser());
+ // Calculate and save VAT for temp bill to avoid recalculation in preview
+ double vatAmount = calculateSelectiveVatAmount(getTempBill().getBillItems());
+ getTempBill().setVat(vatAmount);
+ getTempBill().setVatPlusNetTotal(getTempBill().getNetTotal() + vatAmount);
+
}
private void saveOriginalBill() {
@@ -1883,6 +1894,11 @@ private void saveOriginalBill() {
getOriginalBill().setCreatedAt(new Date());
getOriginalBill().setCreater(getSessionController().getLoggedUser());
+ // Calculate and save VAT for original bill to avoid recalculation in preview
+ double vatAmount = calculateSelectiveVatAmount(getOriginalBill().getBillItems());
+ getOriginalBill().setVat(vatAmount);
+ getOriginalBill().setVatPlusNetTotal(getOriginalBill().getNetTotal() + vatAmount);
+
if (getOriginalBill().getId() == null) {
getBillFacade().create(getOriginalBill());
} else {
@@ -2251,7 +2267,10 @@ private List createPatientItems() {
}
public List getPatientItems() {
- if (patientItems == null) {
+ if (patientItems == null && patientEncounter != null) {
+ if (childPatientEncouters == null || childPatientEncouters.isEmpty()) {
+ childPatientEncouters = getInwardBean().fetchChildPatientEncounter(getPatientEncounter());
+ }
patientItems = createPatientItems();
}
@@ -2440,6 +2459,34 @@ private void setPatientRoomData() {
if (p.getAdmittedAt() == null) {
p.setAdmittedAt(new Date());
}
+
+ // Initialize current charges from room facility if not already set
+ if (p.getRoomFacilityCharge() != null) {
+ if (p.getCurrentRoomCharge() == 0) {
+ p.setCurrentRoomCharge(p.getRoomFacilityCharge().getRoomCharge());
+ }
+ if (p.getCurrentMaintananceCharge() == 0) {
+ p.setCurrentMaintananceCharge(p.getRoomFacilityCharge().getMaintananceCharge());
+ }
+ if (p.getCurrentLinenCharge() == 0) {
+ p.setCurrentLinenCharge(p.getRoomFacilityCharge().getLinenCharge());
+ }
+ if (!(p instanceof GuardianRoom)) {
+ if (p.getCurrentNursingCharge() == 0) {
+ p.setCurrentNursingCharge(p.getRoomFacilityCharge().getNursingCharge());
+ }
+ if (p.getCurrentMoCharge() == 0) {
+ p.setCurrentMoCharge(p.getRoomFacilityCharge().getMoCharge());
+ }
+ if (p.getCurrentAdministrationCharge() == 0) {
+ p.setCurrentAdministrationCharge(p.getRoomFacilityCharge().getAdminstrationCharge());
+ }
+ if (p.getCurrentMedicalCareCharge() == 0) {
+ p.setCurrentMedicalCareCharge(p.getRoomFacilityCharge().getMedicalCareCharge());
+ }
+ }
+ }
+
calculateRoomCharge(p);
calculateMaintananceCharge(p);
calculateLinenCharge(p);
@@ -2638,7 +2685,10 @@ public void setServiceFacade(ServiceFacade serviceFacade) {
}
public List getProfesionallFee() {
- if (profesionallFee == null) {
+ if (profesionallFee == null && patientEncounter != null) {
+ if (childPatientEncouters == null || childPatientEncouters.isEmpty()) {
+ childPatientEncouters = getInwardBean().fetchChildPatientEncounter(getPatientEncounter());
+ }
profesionallFee = getInwardBean().createProfesionallFee(getPatientEncounter(), childPatientEncouters);
}
return profesionallFee;
@@ -2649,7 +2699,10 @@ public void setProfesionallFee(List profesionallFee) {
}
public List getPaymentBill() {
- if (paymentBill == null) {
+ if (paymentBill == null && patientEncounter != null) {
+ if (childPatientEncouters == null || childPatientEncouters.isEmpty()) {
+ childPatientEncouters = getInwardBean().fetchChildPatientEncounter(getPatientEncounter());
+ }
paymentBill = getInwardBean().fetchPaymentBill(getPatientEncounter(), childPatientEncouters);
}
return paymentBill;
@@ -2751,8 +2804,13 @@ private List filterMedicineOnlyIssues(List pharmacyIssues) {
List filtered = new ArrayList<>();
for (Bill bill : pharmacyIssues) {
- // Check if bill's bill type atomic is an inward/regular medicine type
- if (isInwardMedicineType(bill.getBillTypeAtomic())) {
+ // For RefundBill and CancelledBill, check the original bill's category
+ if ((bill instanceof RefundBill || bill instanceof CancelledBill) && bill.getBilledBill() != null) {
+ if (isInwardMedicineType(bill.getBilledBill().getBillTypeAtomic())) {
+ filtered.add(bill);
+ }
+ } else if (isInwardMedicineType(bill.getBillTypeAtomic())) {
+ // For PreBill, check the bill itself
filtered.add(bill);
}
}
@@ -2773,8 +2831,13 @@ private List filterMedicinesAndSurgicalSupplies(List pharmacyIssues)
}
for (Bill bill : pharmacyIssues) {
- // Check if bill's bill type atomic is a theatre/surgical supplies medicine type
- if (isTheatreMedicineType(bill.getBillTypeAtomic())) {
+ // For RefundBill and CancelledBill, check the original bill's category
+ if ((bill instanceof RefundBill || bill instanceof CancelledBill) && bill.getBilledBill() != null) {
+ if (isTheatreMedicineType(bill.getBilledBill().getBillTypeAtomic())) {
+ filtered.add(bill);
+ }
+ } else if (isTheatreMedicineType(bill.getBillTypeAtomic())) {
+ // For PreBill, check the bill itself
filtered.add(bill);
}
}
@@ -3128,7 +3191,10 @@ public void setPatientEncounterFacade(PatientEncounterFacade patientEncounterFac
}
public List getAdditionalChargeBill() {
- if (additionalChargeBill == null) {
+ if (additionalChargeBill == null && patientEncounter != null) {
+ if (childPatientEncouters == null || childPatientEncouters.isEmpty()) {
+ childPatientEncouters = getInwardBean().fetchChildPatientEncounter(getPatientEncounter());
+ }
additionalChargeBill = getInwardBean().fetchOutSideBill(getPatientEncounter(), childPatientEncouters);
}
return additionalChargeBill;
@@ -3155,7 +3221,10 @@ public void setToTime(Date toTime) {
}
public List getDepartmentBillItems() {
- if (departmentBillItems == null) {
+ if (departmentBillItems == null && patientEncounter != null) {
+ if (childPatientEncouters == null || childPatientEncouters.isEmpty()) {
+ childPatientEncouters = getInwardBean().fetchChildPatientEncounter(getPatientEncounter());
+ }
departmentBillItems = getInwardBean().createDepartmentBillItems(patientEncounter, null, childPatientEncouters);
}
return departmentBillItems;
@@ -3351,6 +3420,189 @@ public void setChildPatientEncouters(List childPatientEncouter
this.childPatientEncouters = childPatientEncouters;
}
+ /**
+ * Check if VAT is enabled via application option
+ * Default: false (VAT disabled)
+ */
+ public boolean isVatEnabled() {
+ return configOptionApplicationController.getBooleanValueByKey("Enable VAT in Bills", false);
+ }
+
+ /**
+ * Get VAT percentage from application option
+ * Default: 18
+ */
+ public double getVatPercentage() {
+ try {
+ Double vatPercent = configOptionApplicationController.getDoubleValueByKey("VAT Percentage", 18.0);
+ return vatPercent != null ? vatPercent : 18.0;
+ } catch (Exception e) {
+ return 18.0;
+ }
+ }
+
+ /**
+ * Get VAT percentage for a specific charge type
+ * Application option format: "VAT Percentage For [ChargeTypeName]"
+ * Falls back to global VAT Percentage if not found
+ */
+ public double getVatPercentageForChargeType(InwardChargeType chargeType) {
+ if (chargeType == null) {
+ return getVatPercentage();
+ }
+
+ try {
+ String optionKey = "VAT Percentage For " + chargeType.name();
+ Double vatPercent = configOptionApplicationController.getDoubleValueByKey(optionKey, null);
+
+ // If charge-type-specific percentage exists, use it
+ if (vatPercent != null && vatPercent > 0) {
+ return vatPercent;
+ }
+
+ // Otherwise fall back to global VAT percentage
+ return getVatPercentage();
+ } catch (Exception e) {
+ return getVatPercentage();
+ }
+ }
+
+ /**
+ * Calculate VAT amount based on vatable charge types in bill items
+ * Only includes charges marked as vatable
+ */
+ public double calculateVatAmount(List billItems) {
+ return calculateSelectiveVatAmount(billItems);
+ }
+
+ /**
+ * Calculate total with VAT (Net Total + Selective VAT)
+ * VAT is only applied to vatable charge types
+ */
+ public double calculateVatPlusNetTotal(double netTotal, List billItems) {
+ if (!isVatEnabled()) {
+ return netTotal;
+ }
+ return netTotal + calculateSelectiveVatAmount(billItems);
+ }
+
+ /**
+ * Get VAT label from application option
+ * Default: "VAT"
+ */
+ public String getVatLabel() {
+ String label = configOptionApplicationController.getLongTextValueByKey("VAT Label", "VAT");
+ return label != null ? label : "VAT";
+ }
+
+ /**
+ * Check if a specific InwardChargeType should have VAT applied
+ * Application option format: "VAT Enabled For [ChargeTypeName]"
+ * Default: false (VAT disabled for specific charge type)
+ */
+ public boolean isChargeTypeVatable(InwardChargeType chargeType) {
+ if (chargeType == null || !isVatEnabled()) {
+ return false;
+ }
+ String optionKey = "VAT Enabled For " + chargeType.name();
+ return configOptionApplicationController.getBooleanValueByKey(optionKey, false);
+ }
+
+ /**
+ * Calculate VAT amount for a specific charge type
+ * Only applies VAT if that charge type is marked as vatable
+ * Uses charge-type-specific VAT percentage if configured
+ */
+ public double calculateVatAmountForChargeType(double amount, InwardChargeType chargeType) {
+ if (!isChargeTypeVatable(chargeType) || amount <= 0) {
+ return 0.0;
+ }
+ double vatPercent = getVatPercentageForChargeType(chargeType);
+ return amount * (vatPercent / 100.0);
+ }
+
+ /**
+ * Calculate VAT amount only for specified charge types from bill items
+ * Sums VAT for items whose charge type is marked as vatable
+ */
+ public double calculateSelectiveVatAmount(List billItems) {
+ if (!isVatEnabled() || billItems == null || billItems.isEmpty()) {
+ return 0.0;
+ }
+ double totalVat = 0.0;
+ for (BillItem item : billItems) {
+ if (item.getAdjustedValue() != 0 && item.getInwardChargeType() != null) {
+ if (isChargeTypeVatable(item.getInwardChargeType())) {
+ totalVat += calculateVatAmountForChargeType(item.getAdjustedValue(), item.getInwardChargeType());
+ }
+ }
+ }
+ return totalVat;
+ }
+
+ /**
+ * Get the name/label for a specific charge type (supports customization via application option)
+ * Format: "Inward Charge Type - Name For [ChargeTypeName]"
+ * Default: charge type's label
+ */
+ public String getChargeTypeLabel(InwardChargeType chargeType) {
+ if (chargeType == null) {
+ return "";
+ }
+ try {
+ String label = configOptionApplicationController.getLongTextValueByKey(
+ "Inward Charge Type - Name For " + chargeType.name(),
+ chargeType.getLabel()
+ );
+ return label != null ? label : chargeType.getLabel();
+ } catch (Exception e) {
+ return chargeType.getLabel();
+ }
+ }
+
+ /**
+ * Calculate VAT amount - public method that can be called from templates
+ * Returns 0 if VAT is not enabled or no items to calculate
+ */
+ public double getVatAmount() {
+ try {
+ // If not enabled, return 0
+ if (!isVatEnabled()) {
+ return 0.0;
+ }
+
+ // If no patient encounter, return 0
+ if (patientEncounter == null) {
+ return 0.0;
+ }
+
+ // Calculate VAT from charge item totals (more reliable for interim bills)
+ double totalVat = 0.0;
+ if (chargeItemTotals != null && !chargeItemTotals.isEmpty()) {
+ for (ChargeItemTotal cit : chargeItemTotals) {
+ if (cit.getInwardChargeType() != null && isChargeTypeVatable(cit.getInwardChargeType())) {
+ totalVat += calculateVatAmountForChargeType(cit.getAdjustedTotal(), cit.getInwardChargeType());
+ }
+ }
+ }
+
+ return totalVat;
+ } catch (Exception e) {
+ return 0.0;
+ }
+ }
+
+ /**
+ * Get all bill items for the current patient encounter
+ * Used for VAT calculation in interim and final bills
+ */
+ public List getAllBillItemsForEncounter() {
+ if (patientEncounter == null) {
+ return new ArrayList<>();
+ }
+ return new ArrayList<>();
+ }
+
/**
* Calculate total of bed charges (Linen, MO, Nursing, Maintain, Medical Care, Administration)
* @param billItems List of bill items to calculate from
@@ -3360,10 +3612,10 @@ public double getBedChargesTotal(List billItems) {
if (billItems == null) {
return 0.0;
}
-
+
double total = 0.0;
for (BillItem item : billItems) {
- if (item.getAdjustedValue() != 0 &&
+ if (item.getAdjustedValue() != 0 &&
(item.getInwardChargeType() == InwardChargeType.LinenCharges ||
item.getInwardChargeType() == InwardChargeType.MOCharges ||
item.getInwardChargeType() == InwardChargeType.NursingCharges ||
diff --git a/src/main/java/com/divudi/bean/inward/InpatientClinicalDataController.java b/src/main/java/com/divudi/bean/inward/InpatientClinicalDataController.java
index 51edf87b59c..96b7a1639a1 100644
--- a/src/main/java/com/divudi/bean/inward/InpatientClinicalDataController.java
+++ b/src/main/java/com/divudi/bean/inward/InpatientClinicalDataController.java
@@ -10,14 +10,16 @@
import com.divudi.bean.clinical.*;
import com.divudi.bean.common.BillController;
+import com.divudi.bean.common.ConfigOptionApplicationController;
import com.divudi.bean.common.SearchController;
import com.divudi.bean.common.SessionController;
-
+import com.divudi.bean.inward.AdmissionController;
import com.divudi.bean.pharmacy.PharmacySaleController;
import com.divudi.core.data.BillType;
import com.divudi.core.data.SymanticType;
import com.divudi.core.data.clinical.ClinicalFindingValueType;
import com.divudi.core.data.clinical.PrescriptionTemplateType;
+import com.divudi.core.data.inward.PatientEncounterComponentType;
import com.divudi.core.data.inward.PatientEncounterType;
import com.divudi.core.data.lab.InvestigationResultForGraph;
import com.divudi.core.entity.Bill;
@@ -35,6 +37,7 @@
import com.divudi.core.entity.clinical.ItemUsage;
import com.divudi.core.entity.clinical.Prescription;
import com.divudi.core.entity.clinical.PrescriptionTemplate;
+import com.divudi.core.entity.inward.EncounterComponent;
import com.divudi.core.entity.lab.Investigation;
import com.divudi.core.entity.lab.InvestigationItem;
import com.divudi.core.entity.lab.PatientInvestigation;
@@ -44,6 +47,8 @@
import com.divudi.core.facade.BillFacade;
import com.divudi.core.facade.ClinicalEntityFacade;
import com.divudi.core.facade.ClinicalFindingValueFacade;
+import com.divudi.core.facade.DocumentTemplateFacade;
+import com.divudi.core.facade.EncounterComponentFacade;
import com.divudi.core.facade.ItemUsageFacade;
import com.divudi.core.facade.PatientEncounterFacade;
import com.divudi.core.facade.PatientFacade;
@@ -114,6 +119,10 @@ public class InpatientClinicalDataController implements Serializable {
private ItemUsageFacade itemUsageFacade;
@EJB
private PrescriptionFacade prescriptionFacade;
+ @EJB
+ private DocumentTemplateFacade documentTemplateFacade;
+ @EJB
+ private EncounterComponentFacade encounterComponentFacade;
/**
* Controllers
*/
@@ -127,6 +136,10 @@ public class InpatientClinicalDataController implements Serializable {
DocumentTemplateController documentTemplateController;
@Inject
SearchController searchController;
+ @Inject
+ AdmissionController admissionController;
+ @Inject
+ ConfigOptionApplicationController configOptionApplicationController;
/**
* Properties
@@ -228,6 +241,12 @@ public class InpatientClinicalDataController implements Serializable {
private Upload selectedDiagnosisCardTemplate;
private Upload selectedDiagnosisCard;
+ // Diagnosis card types - Ward Admission and Local Surgery
+ private String wardAdmissionDiagnosisCardHtml;
+ private String localSurgeryDiagnosisCardHtml;
+ private String diagnosisCardHtml;
+ private String selectedDiagnosisCardTypeHtml;
+
@Deprecated
public void calculateBmi() {
if (current == null) {
@@ -271,59 +290,89 @@ public StreamedContent downloadSampleWordFile() {
public Map createReplacementsMap(PatientEncounter encounter) {
Map replacements = new HashMap<>();
- // Extracting information from the encounter
- String name = encounter.getPatient().getPerson().getNameWithTitle();
- String age = encounter.getPatient().getPerson().getAgeAsString() != null ? encounter.getPatient().getPerson().getAgeAsString() : "";
- String sex = encounter.getPatient().getPerson().getSex() != null ? encounter.getPatient().getPerson().getSex().name() : "";
- String address = encounter.getPatient().getPerson().getAddress() != null ? encounter.getPatient().getPerson().getAddress() : "";
- String phone = encounter.getPatient().getPerson().getPhone() != null ? encounter.getPatient().getPerson().getPhone() : "";
- String visitDate = CommonFunctions.formatDate(encounter.getCreatedAt(), sessionController.getApplicationPreference().getLongDateFormat());
- String doa = CommonFunctions.formatDate(encounter.getDateOfAdmission(), sessionController.getApplicationPreference().getLongDateFormat());
- String dod;
- if (encounter.getDateOfDischarge() == null) {
- dod = CommonFunctions.formatDate(new Date(), sessionController.getApplicationPreference().getLongDateFormat());
- } else {
- dod = CommonFunctions.formatDate(encounter.getDateOfDischarge(), sessionController.getApplicationPreference().getLongDateFormat());
+
+ // Extracting information from the encounter with null safety
+ String name = "";
+ String age = "";
+ String sex = "";
+ String address = "";
+ String phone = "";
+ String nic = "";
+ String phn = "";
+
+ if (encounter != null && encounter.getPatient() != null && encounter.getPatient().getPerson() != null) {
+ Person person = encounter.getPatient().getPerson();
+ name = person.getNameWithTitle() != null ? person.getNameWithTitle() : "";
+ age = person.getAgeAsString() != null ? person.getAgeAsString() : "";
+ sex = person.getSex() != null ? person.getSex().name() : "";
+ address = person.getAddress() != null ? person.getAddress() : "";
+ phone = person.getPhone() != null ? person.getPhone() : "";
+ nic = person.getNic() != null ? person.getNic() : "";
+ }
+
+ if (encounter != null && encounter.getPatient() != null) {
+ phn = encounter.getPatient().getPhn() != null ? encounter.getPatient().getPhn() : "";
+ }
+
+ String visitDate = "";
+ String doa = "";
+ String dod = "";
+
+ if (encounter != null) {
+ visitDate = CommonFunctions.formatDate(encounter.getCreatedAt(), sessionController.getApplicationPreference().getLongDateFormat());
+ doa = CommonFunctions.formatDate(encounter.getDateOfAdmission(), sessionController.getApplicationPreference().getLongDateFormat());
+ if (encounter.getDateOfDischarge() == null) {
+ dod = CommonFunctions.formatDate(new Date(), sessionController.getApplicationPreference().getLongDateFormat());
+ } else {
+ dod = CommonFunctions.formatDate(encounter.getDateOfDischarge(), sessionController.getApplicationPreference().getLongDateFormat());
+ }
}
- String bht = encounter.getBhtNo();
+
+ String bht = encounter != null ? (encounter.getBhtNo() != null ? encounter.getBhtNo() : "") : "";
String room = "";
- if (encounter.getCurrentPatientRoom() != null) {
- encounter.getCurrentPatientRoom().getName();
- }
- String weight = CommonFunctions.formatNumber(encounter.getWeight(), "0.0") + " kg";
- String height = CommonFunctions.formatNumber(encounter.getHeight(), "0") + " cm";
- String bmi = encounter.getBmiFormatted();
- String rr = encounter.getRespiratoryRate()+" bpm";
- String bp = encounter.getBp();
+ if (encounter != null && encounter.getCurrentPatientRoom() != null) {
+ room = encounter.getCurrentPatientRoom().getName() != null ? encounter.getCurrentPatientRoom().getName() : "";
+ }
+ String weight = encounter != null && encounter.getWeight() != null ? CommonFunctions.formatNumber(encounter.getWeight(), "0.0") + " kg" : "0.0 kg";
+ String height = encounter != null && encounter.getHeight() != null ? CommonFunctions.formatNumber(encounter.getHeight(), "0") + " cm" : "0 cm";
+ String bmi = encounter != null ? (encounter.getBmiFormatted() != null ? encounter.getBmiFormatted() : "") : "";
+ String rr = encounter != null && encounter.getRespiratoryRate() != null ? encounter.getRespiratoryRate()+" bpm" : "";
+ String bp = encounter != null ? (encounter.getBp() != null ? encounter.getBp() : "") : "";
String comments = encounter.getComments() != null ? encounter.getComments() : "";
if (comments == null) {
comments = "";
}
StringBuilder diagnosisTextBuilder = new StringBuilder();
- for (ClinicalFindingValue dx : getEncounterDiagnoses()) {
- if (dx != null && dx.getItemValue() != null) {
- diagnosisTextBuilder.append(dx.getItemValue().getName());
- if (dx.getLobValue() != null) {
- diagnosisTextBuilder.append(" ").append(dx.getLobValue());
+ List diagnoses = getEncounterDiagnoses();
+ if (diagnoses != null) {
+ for (ClinicalFindingValue dx : diagnoses) {
+ if (dx != null && dx.getItemValue() != null) {
+ diagnosisTextBuilder.append(dx.getItemValue().getName());
+ if (dx.getLobValue() != null) {
+ diagnosisTextBuilder.append(" ").append(dx.getLobValue());
+ }
+ diagnosisTextBuilder.append("
"); // Using
for new line in HTML
}
- diagnosisTextBuilder.append("
"); // Using
for new line in HTML
}
}
String diagnosisText = diagnosisTextBuilder.toString();
String inpatientRxStrat = "Rx" + "
";
String inpatientRx = inpatientRxStrat;
- for (ClinicalFindingValue cf : getEncounterMedicines()) {
- if (cf != null && cf.getPrescription() != null) {
- if (!cf.getPrescription().isIndoor()) {
- String rxName = cf.getPrescription().getItem() != null ? cf.getPrescription().getItem().getName() : "";
- String dose = cf.getPrescription().getDose() != null ? String.format("%.0f", cf.getPrescription().getDose()) : "";
- String doseUnit = cf.getPrescription().getDoseUnit() != null ? cf.getPrescription().getDoseUnit().getName() : "";
- String frequencyUnit = cf.getPrescription().getFrequencyUnit() != null ? cf.getPrescription().getFrequencyUnit().getName() : "";
- String duration = cf.getPrescription().getDuration() != null ? String.format("%.0f", cf.getPrescription().getDuration()) : "";
- String durationUnit = cf.getPrescription().getDurationUnit() != null ? cf.getPrescription().getDurationUnit().getName() : "";
- inpatientRx += rxName + " " + dose + " " + doseUnit + " " + frequencyUnit + " " + duration + " " + durationUnit + "
";
+ List medicines = getEncounterMedicines();
+ if (medicines != null) {
+ for (ClinicalFindingValue cf : medicines) {
+ if (cf != null && cf.getPrescription() != null) {
+ if (!cf.getPrescription().isIndoor()) {
+ String rxName = cf.getPrescription().getItem() != null ? cf.getPrescription().getItem().getName() : "";
+ String dose = cf.getPrescription().getDose() != null ? String.format("%.0f", cf.getPrescription().getDose()) : "";
+ String doseUnit = cf.getPrescription().getDoseUnit() != null ? cf.getPrescription().getDoseUnit().getName() : "";
+ String frequencyUnit = cf.getPrescription().getFrequencyUnit() != null ? cf.getPrescription().getFrequencyUnit().getName() : "";
+ String duration = cf.getPrescription().getDuration() != null ? String.format("%.0f", cf.getPrescription().getDuration()) : "";
+ String durationUnit = cf.getPrescription().getDurationUnit() != null ? cf.getPrescription().getDurationUnit().getName() : "";
+ inpatientRx += rxName + " " + dose + " " + doseUnit + " " + frequencyUnit + " " + duration + " " + durationUnit + "
";
+ }
}
}
}
@@ -333,17 +382,18 @@ public Map createReplacementsMap(PatientEncounter encounter) {
String drxStart = "Rx" + "
";
String drxAsString = drxStart;
- for (ClinicalFindingValue cf : getDischargeMedicines()) {
- if (cf != null && cf.getPrescription() != null) {
-
- String rxName = cf.getPrescription().getItem() != null ? cf.getPrescription().getItem().getName() : "";
- String dose = cf.getPrescription().getDose() != null ? String.format("%.0f", cf.getPrescription().getDose()) : "";
- String doseUnit = cf.getPrescription().getDoseUnit() != null ? cf.getPrescription().getDoseUnit().getName() : "";
- String frequencyUnit = cf.getPrescription().getFrequencyUnit() != null ? cf.getPrescription().getFrequencyUnit().getName() : "";
- String duration = cf.getPrescription().getDuration() != null ? String.format("%.0f", cf.getPrescription().getDuration()) : "";
- String durationUnit = cf.getPrescription().getDurationUnit() != null ? cf.getPrescription().getDurationUnit().getName() : "";
- drxAsString += rxName + " " + dose + " " + doseUnit + " " + frequencyUnit + " " + duration + " " + durationUnit + "
";
-
+ List dischargeMedicines = getDischargeMedicines();
+ if (dischargeMedicines != null) {
+ for (ClinicalFindingValue cf : dischargeMedicines) {
+ if (cf != null && cf.getPrescription() != null) {
+ String rxName = cf.getPrescription().getItem() != null ? cf.getPrescription().getItem().getName() : "";
+ String dose = cf.getPrescription().getDose() != null ? String.format("%.0f", cf.getPrescription().getDose()) : "";
+ String doseUnit = cf.getPrescription().getDoseUnit() != null ? cf.getPrescription().getDoseUnit().getName() : "";
+ String frequencyUnit = cf.getPrescription().getFrequencyUnit() != null ? cf.getPrescription().getFrequencyUnit().getName() : "";
+ String duration = cf.getPrescription().getDuration() != null ? String.format("%.0f", cf.getPrescription().getDuration()) : "";
+ String durationUnit = cf.getPrescription().getDurationUnit() != null ? cf.getPrescription().getDurationUnit().getName() : "";
+ drxAsString += rxName + " " + dose + " " + doseUnit + " " + frequencyUnit + " " + duration + " " + durationUnit + "
";
+ }
}
}
if (drxAsString.equals(drxStart)) {
@@ -352,8 +402,13 @@ public Map createReplacementsMap(PatientEncounter encounter) {
String ixStart = " " + "
";
String ixAsString = ixStart;
- for (ClinicalFindingValue ix : getEncounterInvestigations()) {
- ixAsString += ix.getItemValue().getName() + ixStart;
+ List investigations = getEncounterInvestigations();
+ if (investigations != null) {
+ for (ClinicalFindingValue ix : investigations) {
+ if (ix != null && ix.getItemValue() != null && ix.getItemValue().getName() != null) {
+ ixAsString += ix.getItemValue().getName() + ixStart;
+ }
+ }
}
if (ixAsString.equals(ixStart)) {
ixAsString = "No investigations peformed";
@@ -361,11 +416,14 @@ public Map createReplacementsMap(PatientEncounter encounter) {
String allergyStart = "Allergies " + "
";
String allergiesAsString = allergyStart;
- for (ClinicalFindingValue cf : getPatientAllergies()) {
- if (cf != null) {
- String allergyName = cf.getItemValue() != null && cf.getItemValue().getName() != null ? cf.getItemValue().getName() : "";
- String details = cf.getStringValue() != null ? cf.getStringValue() : "";
- allergiesAsString += allergyName + (details.isEmpty() ? "" : " - " + details) + "
";
+ List allergies = getPatientAllergies();
+ if (allergies != null) {
+ for (ClinicalFindingValue cf : allergies) {
+ if (cf != null) {
+ String allergyName = cf.getItemValue() != null && cf.getItemValue().getName() != null ? cf.getItemValue().getName() : "";
+ String details = cf.getStringValue() != null ? cf.getStringValue() : "";
+ allergiesAsString += allergyName + (details.isEmpty() ? "" : " - " + details) + "
";
+ }
}
}
if (allergiesAsString.equals(allergyStart)) {
@@ -374,29 +432,35 @@ public Map createReplacementsMap(PatientEncounter encounter) {
String routeineMedicineStart = "Routeine Medicines " + "
";
String routineMedicinesAsString = "";
- for (ClinicalFindingValue rx : getPatientMedicines()) {
- if (rx != null && rx.getPrescription() != null) {
- String medicineName = rx.getPrescription().getItem() != null ? rx.getPrescription().getItem().getName() : "";
- String dose = rx.getPrescription().getDose() != null ? String.valueOf(rx.getPrescription().getDose()) : "";
- String doseUnit = rx.getPrescription().getDoseUnit() != null ? rx.getPrescription().getDoseUnit().getName() : "";
- String frequency = rx.getPrescription().getFrequencyUnit() != null ? rx.getPrescription().getFrequencyUnit().getName() : "";
- String duration = rx.getPrescription().getDuration() != null ? String.valueOf(rx.getPrescription().getDuration()) : "";
- String durationUnit = rx.getPrescription().getDurationUnit() != null ? rx.getPrescription().getDurationUnit().getName() : "";
-
- routineMedicinesAsString += medicineName + " " + dose + " " + doseUnit + " - " + frequency + " - " + duration + " " + durationUnit + "
";
+ List patientMeds = getPatientMedicines();
+ if (patientMeds != null) {
+ for (ClinicalFindingValue rx : patientMeds) {
+ if (rx != null && rx.getPrescription() != null) {
+ String medicineName = rx.getPrescription().getItem() != null ? rx.getPrescription().getItem().getName() : "";
+ String dose = rx.getPrescription().getDose() != null ? String.valueOf(rx.getPrescription().getDose()) : "";
+ String doseUnit = rx.getPrescription().getDoseUnit() != null ? rx.getPrescription().getDoseUnit().getName() : "";
+ String frequency = rx.getPrescription().getFrequencyUnit() != null ? rx.getPrescription().getFrequencyUnit().getName() : "";
+ String duration = rx.getPrescription().getDuration() != null ? String.valueOf(rx.getPrescription().getDuration()) : "";
+ String durationUnit = rx.getPrescription().getDurationUnit() != null ? rx.getPrescription().getDurationUnit().getName() : "";
+
+ routineMedicinesAsString += medicineName + " " + dose + " " + doseUnit + " - " + frequency + " - " + duration + " " + durationUnit + "
";
+ }
}
}
- if (routineMedicinesAsString.equals(routeineMedicineStart)) {
+ if (routineMedicinesAsString.isEmpty() || routineMedicinesAsString.equals(routeineMedicineStart)) {
routineMedicinesAsString = "Not on any routeine medicines";
}
String pastDxStart = "Past History " + "
";
String pastDxAsString = pastDxStart;
- for (ClinicalFindingValue dx : getPatientDiagnoses()) {
- if (dx != null) {
- String diagnosisName = dx.getItemValue() != null && dx.getItemValue().getName() != null ? dx.getItemValue().getName() : "";
- String details = dx.getStringValue() != null ? dx.getStringValue() : "";
- pastDxAsString += diagnosisName + (details.isEmpty() ? "" : " - " + details) + "
";
+ List patientDxs = getPatientDiagnoses();
+ if (patientDxs != null) {
+ for (ClinicalFindingValue dx : patientDxs) {
+ if (dx != null) {
+ String diagnosisName = dx.getItemValue() != null && dx.getItemValue().getName() != null ? dx.getItemValue().getName() : "";
+ String details = dx.getStringValue() != null ? dx.getStringValue() : "";
+ pastDxAsString += diagnosisName + (details.isEmpty() ? "" : " - " + details) + "
";
+ }
}
}
if (pastDxAsString.equals(pastDxStart)) {
@@ -406,8 +470,13 @@ public Map createReplacementsMap(PatientEncounter encounter) {
//Procedures - {procedures}
String prStart = " " + "
";
String prAsString = prStart;
- for (ClinicalFindingValue pr : getEncounterProcedures()) {
- prAsString += pr.getItemValue().getName();
+ List procedures = getEncounterProcedures();
+ if (procedures != null) {
+ for (ClinicalFindingValue pr : procedures) {
+ if (pr != null && pr.getItemValue() != null && pr.getItemValue().getName() != null) {
+ prAsString += pr.getItemValue().getName();
+ }
+ }
}
if (prAsString.equals(prStart)) {
prAsString = "No Procedures peformed";
@@ -416,20 +485,38 @@ public Map createReplacementsMap(PatientEncounter encounter) {
// Add more replacement keys and values as needed
replacements.put("{name}", name);
- replacements.put("{age}", age); // Duplicate removed
- replacements.put("{sex}", sex); // Duplicate removed
- replacements.put("{address}", address); // Duplicate removed
- replacements.put("{phone}", phone); // Duplicate removed
- replacements.put("{visit-date}", visitDate); // Duplicate removed
+ replacements.put("{patient_name}", name); // Alias
+ replacements.put("{age}", age);
+ replacements.put("{patient_age}", age); // Alias
+ replacements.put("{sex}", sex);
+ replacements.put("{address}", address);
+ replacements.put("{phone}", phone);
+ replacements.put("{nic}", nic);
+ replacements.put("{patient_nic}", nic); // Alias
+ replacements.put("{patient_nic_number}", nic); // Alias
+ replacements.put("{phn}", phn);
+ replacements.put("{patient_phn}", phn); // Alias
+ replacements.put("{patient_phn_number}", phn); // Alias
+ replacements.put("{visit-date}", visitDate);
+
+ // Admission Details
+ replacements.put("{bht}", bht);
+ replacements.put("{bht-number}", bht); // Alias
+ replacements.put("{admission-number}", bht); // Alias
replacements.put("{doa}", doa);
+ replacements.put("{admission-date}", doa); // Alias
+ replacements.put("{date-of-admission}", doa); // Alias
replacements.put("{dod}", dod);
+ replacements.put("{discharge-date}", dod); // Alias
+ replacements.put("{date-of-discharge}", dod); // Alias
replacements.put("{room}", room);
- replacements.put("{bht}", bht);
- replacements.put("{height}", height); // Duplicate removed
- replacements.put("{weight}", weight); // Duplicate removed
- replacements.put("{bmi}", bmi); // Duplicate removed
- replacements.put("{bp}", bp); // Duplicate removed
- replacements.put("{comments}", comments); // Duplicate removed
+ replacements.put("{room-number}", room); // Alias
+
+ replacements.put("{height}", height);
+ replacements.put("{weight}", weight);
+ replacements.put("{bmi}", bmi);
+ replacements.put("{bp}", bp);
+ replacements.put("{comments}", comments);
replacements.put("{rx}", inpatientRx);
replacements.put("{drx}", drxAsString);
replacements.put("{ix}", ixAsString);
@@ -438,6 +525,50 @@ public Map createReplacementsMap(PatientEncounter encounter) {
replacements.put("{routine-medicines}", routineMedicinesAsString);
replacements.put("{allergies}", allergiesAsString);
replacements.put("{dx}", diagnosisText);
+
+ // Surgery Details
+ String surgeryName = "";
+ String surgeryProcedure = "";
+ String surgeryPerformedBy = "";
+ String surgeryAssistant = "";
+ String anesthesia = "";
+ String anesthesiologist = "";
+ String surgeryDate = "";
+ String surgeryTime = "";
+
+ // Fetch surgery details from EncounterComponent records
+ try {
+ Map surgeryData = fetchSurgeryDetails(encounter);
+ if (surgeryData != null) {
+ surgeryName = surgeryData.getOrDefault("procedure", "");
+ surgeryProcedure = surgeryData.getOrDefault("procedure", "");
+ surgeryPerformedBy = surgeryData.getOrDefault("surgeon", "");
+ surgeryAssistant = surgeryData.getOrDefault("assistant", "");
+ anesthesiologist = surgeryData.getOrDefault("anesthesiologist", "");
+ // For anesthesia type, we use the same anesthesiologist info (can be extended if more data exists)
+ anesthesia = anesthesiologist.isEmpty() ? "" : "General Anesthesia";
+ surgeryDate = surgeryData.getOrDefault("date", "");
+ surgeryTime = surgeryData.getOrDefault("time", "");
+ }
+ } catch (Exception e) {
+ // Silently handle if surgery details are not available
+ System.out.println("Error loading surgery details: " + e.getMessage());
+ }
+
+ replacements.put("{surgery-name}", surgeryName);
+ replacements.put("{procedure}", surgeryName); // Alias
+ replacements.put("{surgery-procedure}", surgeryProcedure);
+ replacements.put("{performed-by}", surgeryPerformedBy);
+ replacements.put("{surgeon}", surgeryPerformedBy); // Alias
+ replacements.put("{surgery-surgeon}", surgeryPerformedBy); // Alias
+ replacements.put("{assistant}", surgeryAssistant);
+ replacements.put("{surgery-assistant}", surgeryAssistant); // Alias
+ replacements.put("{anesthesia}", anesthesia);
+ replacements.put("{anesthesia-type}", anesthesia); // Alias
+ replacements.put("{anesthesiologist}", anesthesiologist);
+ replacements.put("{surgery-anesthesiologist}", anesthesiologist); // Alias
+ replacements.put("{surgery-date}", surgeryDate);
+ replacements.put("{surgery-time}", surgeryTime);
return replacements;
}
@@ -481,6 +612,183 @@ public Upload findAndReplaceText(Upload upload, Map replacements
return upload;
}
+ /**
+ * Initialize controller for Ward Admission Card generation
+ * Should be called from admission_profile.xhtml before opening the dialog
+ */
+ public void initializeWardAdmissionCard() {
+ // current should be set from the calling page context
+ // If not set, try to get it from the session
+ if (current == null) {
+ JsfUtil.addErrorMessage("Patient encounter not loaded. Please try again.");
+ return;
+ }
+
+ // Load available templates
+ availableWardTemplates = null;
+ getAvailableWardTemplates();
+
+ // Reset selected template and card HTML
+ selectedWardTemplate = "";
+ wardAdmissionDiagnosisCardHtml = null;
+ }
+
+ /**
+ * Initialize controller for Local Surgery Card generation
+ * Should be called from admission_profile.xhtml before opening the dialog
+ */
+ public void initializeSurgeryCard() {
+ // current should be set from the calling page context
+ // If not set, try to get it from the session
+ if (current == null) {
+ JsfUtil.addErrorMessage("Patient encounter not loaded. Please try again.");
+ return;
+ }
+
+ // Load available templates
+ availableSurgeryTemplates = null;
+ getAvailableSurgeryTemplates();
+
+ // Reset selected template and card HTML
+ selectedSurgeryTemplate = "";
+ localSurgeryDiagnosisCardHtml = null;
+ }
+
+ /**
+ * Load and display Ward Admission Diagnosis Card with variable replacement
+ */
+ public void loadWardAdmissionDiagnosisCard() {
+ // If current is not set, try to get it from admissionController
+ if (current == null && admissionController != null) {
+ current = admissionController.getCurrent();
+ }
+
+ if (current == null) {
+ JsfUtil.addErrorMessage("No patient encounter selected");
+ return;
+ }
+
+ String templateHtml = null;
+
+ // Debug: Check what template ID was selected
+ System.out.println("Selected Ward Template ID: " + selectedWardTemplate);
+
+ // Try to load from selected template in dropdown first
+ if (selectedWardTemplate != null && !selectedWardTemplate.isEmpty() && !selectedWardTemplate.equals("")) {
+ try {
+ Long templateId = Long.parseLong(selectedWardTemplate);
+ System.out.println("Parsing template ID: " + templateId);
+
+ DocumentTemplate template = documentTemplateFacade.find(templateId);
+ System.out.println("Template found: " + (template != null ? template.getName() : "NULL"));
+
+ if (template != null && !template.isRetired()) {
+ templateHtml = template.getContents();
+ System.out.println("Template contents length: " + (templateHtml != null ? templateHtml.length() : "NULL"));
+ }
+ } catch (NumberFormatException nfe) {
+ System.out.println("Error parsing template ID: " + nfe.getMessage());
+ JsfUtil.addErrorMessage("Invalid template ID selected: " + selectedWardTemplate);
+ } catch (Exception e) {
+ System.out.println("Error loading template: " + e.getMessage());
+ e.printStackTrace();
+ // Fall through to config option if selected template fails
+ }
+ }
+
+ // Fallback to config option if no template selected or not found
+ if (templateHtml == null || templateHtml.isEmpty()) {
+ System.out.println("Falling back to config option");
+ templateHtml = configOptionApplicationController.getLongTextValueByKey("Ward Admission Diagnosis Card Template", "");
+ }
+
+ if (templateHtml == null || templateHtml.isEmpty()) {
+ JsfUtil.addErrorMessage("Ward Admission Diagnosis Card template not configured. Please select a template or configure a default.");
+ return;
+ }
+
+ System.out.println("Creating replacements map");
+ Map replacements = createReplacementsMap(current);
+ System.out.println("Applying replacements to template");
+ wardAdmissionDiagnosisCardHtml = replaceVariablesInHtml(templateHtml, replacements);
+ System.out.println("Ward card HTML generated, length: " + (wardAdmissionDiagnosisCardHtml != null ? wardAdmissionDiagnosisCardHtml.length() : "NULL"));
+ selectedDiagnosisCardTypeHtml = wardAdmissionDiagnosisCardHtml;
+ }
+
+ /**
+ * Load and display Local Surgery Diagnosis Card with variable replacement
+ */
+ public void loadLocalSurgeryDiagnosisCard() {
+ // If current is not set, try to get it from admissionController
+ if (current == null && admissionController != null) {
+ current = admissionController.getCurrent();
+ }
+
+ if (current == null) {
+ JsfUtil.addErrorMessage("No patient encounter selected");
+ return;
+ }
+
+ String templateHtml = null;
+
+ // Debug: Check what template ID was selected
+ System.out.println("Selected Surgery Template ID: " + selectedSurgeryTemplate);
+
+ // Try to load from selected template in dropdown first
+ if (selectedSurgeryTemplate != null && !selectedSurgeryTemplate.isEmpty() && !selectedSurgeryTemplate.equals("")) {
+ try {
+ Long templateId = Long.parseLong(selectedSurgeryTemplate);
+ System.out.println("Parsing template ID: " + templateId);
+
+ DocumentTemplate template = documentTemplateFacade.find(templateId);
+ System.out.println("Template found: " + (template != null ? template.getName() : "NULL"));
+
+ if (template != null && !template.isRetired()) {
+ templateHtml = template.getContents();
+ System.out.println("Template contents length: " + (templateHtml != null ? templateHtml.length() : "NULL"));
+ }
+ } catch (NumberFormatException nfe) {
+ System.out.println("Error parsing template ID: " + nfe.getMessage());
+ JsfUtil.addErrorMessage("Invalid template ID selected: " + selectedSurgeryTemplate);
+ } catch (Exception e) {
+ System.out.println("Error loading template: " + e.getMessage());
+ e.printStackTrace();
+ // Fall through to config option if selected template fails
+ }
+ }
+
+ // Fallback to config option if no template selected or not found
+ if (templateHtml == null || templateHtml.isEmpty()) {
+ System.out.println("Falling back to config option");
+ templateHtml = configOptionApplicationController.getLongTextValueByKey("Local Surgery Diagnosis Card Template", "");
+ }
+
+ if (templateHtml == null || templateHtml.isEmpty()) {
+ JsfUtil.addErrorMessage("Local Surgery Diagnosis Card template not configured. Please select a template or configure a default.");
+ return;
+ }
+
+ System.out.println("Creating replacements map");
+ Map replacements = createReplacementsMap(current);
+ System.out.println("Applying replacements to template");
+ localSurgeryDiagnosisCardHtml = replaceVariablesInHtml(templateHtml, replacements);
+ System.out.println("Surgery card HTML generated, length: " + (localSurgeryDiagnosisCardHtml != null ? localSurgeryDiagnosisCardHtml.length() : "NULL"));
+ selectedDiagnosisCardTypeHtml = localSurgeryDiagnosisCardHtml;
+ }
+
+ /**
+ * Replace variables in HTML with actual values using the replacements map
+ */
+ public String replaceVariablesInHtml(String htmlTemplate, Map replacements) {
+ String result = htmlTemplate;
+ for (Map.Entry replacement : replacements.entrySet()) {
+ if (replacement.getValue() != null) {
+ result = result.replace("{{" + replacement.getKey().substring(1, replacement.getKey().length() - 1) + "}}", replacement.getValue());
+ }
+ }
+ return result;
+ }
+
public String generateDocumentFromTemplate(DocumentTemplate t, PatientEncounter e) {
if (t == null) {
@@ -1463,6 +1771,86 @@ public List loadCurrentEncounterFindingValues(PatientEncou
return vs;
}
+ /**
+ * Fetch surgery details from EncounterComponent records
+ * @param encounter PatientEncounter to fetch surgery details for
+ * @return Map with surgery details (surgeon, assistant, anesthesiologist)
+ */
+ private Map fetchSurgeryDetails(PatientEncounter encounter) {
+ Map surgeryDetails = new HashMap<>();
+ surgeryDetails.put("surgeon", "");
+ surgeryDetails.put("assistant", "");
+ surgeryDetails.put("anesthesiologist", "");
+ surgeryDetails.put("procedure", "");
+ surgeryDetails.put("date", "");
+ surgeryDetails.put("time", "");
+
+ try {
+ if (encounter == null || encounter.getEncounterId() == null) {
+ return surgeryDetails;
+ }
+
+ // Query EncounterComponent records for this encounter
+ String jpql = "SELECT ec FROM EncounterComponent ec WHERE ec.patientEncounter = :encounter AND ec.retired = false ORDER BY ec.createdAt DESC";
+ List components = encounterComponentFacade.findByJpql(jpql,
+ new java.util.HashMap() {
+ {
+ put("encounter", encounter);
+ }
+ });
+
+ if (components != null) {
+ for (EncounterComponent component : components) {
+ if (component == null || component.getPatientEncounterComponentType() == null) {
+ continue;
+ }
+
+ PatientEncounterComponentType componentType = component.getPatientEncounterComponentType();
+
+ // Extract surgeon (Performed_By)
+ if (componentType == PatientEncounterComponentType.Performed_By) {
+ if (component.getStaff() != null && component.getStaff().getPerson() != null) {
+ surgeryDetails.put("surgeon", component.getStaff().getPerson().getNameWithTitle());
+ } else if (component.getName() != null) {
+ surgeryDetails.put("surgeon", component.getName());
+ }
+ }
+ // Extract assistant (Assisted_by)
+ else if (componentType == PatientEncounterComponentType.Assisted_by) {
+ if (component.getStaff() != null && component.getStaff().getPerson() != null) {
+ surgeryDetails.put("assistant", component.getStaff().getPerson().getNameWithTitle());
+ } else if (component.getName() != null) {
+ surgeryDetails.put("assistant", component.getName());
+ }
+ }
+ // Extract anesthesiologist (Ananesthesia_by - note: typo in enum)
+ else if (componentType == PatientEncounterComponentType.Ananesthesia_by) {
+ if (component.getStaff() != null && component.getStaff().getPerson() != null) {
+ surgeryDetails.put("anesthesiologist", component.getStaff().getPerson().getNameWithTitle());
+ } else if (component.getName() != null) {
+ surgeryDetails.put("anesthesiologist", component.getName());
+ }
+ }
+ // Extract procedure (Item)
+ else if (componentType == PatientEncounterComponentType.Item) {
+ if (component.getItem() != null && component.getItem().getName() != null) {
+ surgeryDetails.put("procedure", component.getItem().getName());
+ } else if (component.getName() != null) {
+ surgeryDetails.put("procedure", component.getName());
+ }
+ }
+ }
+ }
+
+ // If no surgery data found, use empty strings (already set above)
+ } catch (Exception e) {
+ // Log error but don't throw - surgery details are optional
+ System.out.println("Error fetching surgery details: " + e.getMessage());
+ }
+
+ return surgeryDetails;
+ }
+
public String navigateToOldOpdVisitFromSearch() {
if (current == null) {
JsfUtil.addErrorMessage("Nothing");
@@ -3201,6 +3589,574 @@ public void setDiagnosisCardText(String diagnosisCardText) {
this.diagnosisCardText = diagnosisCardText;
}
+ public String getDiagnosisCardHtml() {
+ return diagnosisCardHtml;
+ }
+
+ public void setDiagnosisCardHtml(String diagnosisCardHtml) {
+ this.diagnosisCardHtml = diagnosisCardHtml;
+ }
+
+ // Template Selection Properties
+ private String selectedWardTemplate;
+ private String selectedSurgeryTemplate;
+ private String selectedDiagnosisTemplate;
+ private List availableWardTemplates;
+ private List availableSurgeryTemplates;
+ private List availableDiagnosisTemplates;
+
+ /**
+ * Get available Ward Admission templates from database
+ */
+ public List getAvailableWardTemplates() {
+ if (availableWardTemplates == null || availableWardTemplates.isEmpty()) {
+ try {
+ String jpql = "SELECT d FROM DocumentTemplate d WHERE d.type = com.divudi.core.data.clinical.DocumentTemplateType.WardAdmissionCard AND d.retired = false ORDER BY d.name";
+ availableWardTemplates = (List) documentTemplateFacade.executeQuery(DocumentTemplate.class, jpql);
+ if (availableWardTemplates == null) {
+ availableWardTemplates = new ArrayList<>();
+ }
+ } catch (Exception e) {
+ availableWardTemplates = new ArrayList<>();
+ JsfUtil.addErrorMessage("Error loading Ward templates: " + e.getMessage());
+ }
+ }
+ return availableWardTemplates;
+ }
+
+ public void setAvailableWardTemplates(List availableWardTemplates) {
+ this.availableWardTemplates = availableWardTemplates;
+ }
+
+ /**
+ * Get available Local Surgery templates from database
+ */
+ /**
+ * Get available Local Surgery templates from database
+ */
+ public List getAvailableSurgeryTemplates() {
+ if (availableSurgeryTemplates == null || availableSurgeryTemplates.isEmpty()) {
+ try {
+ String jpql = "SELECT d FROM DocumentTemplate d WHERE d.type = com.divudi.core.data.clinical.DocumentTemplateType.LocalSurgeryCard AND d.retired = false ORDER BY d.name";
+ availableSurgeryTemplates = (List) documentTemplateFacade.executeQuery(DocumentTemplate.class, jpql);
+ if (availableSurgeryTemplates == null) {
+ availableSurgeryTemplates = new ArrayList<>();
+ }
+ } catch (Exception e) {
+ availableSurgeryTemplates = new ArrayList<>();
+ JsfUtil.addErrorMessage("Error loading Surgery templates: " + e.getMessage());
+ }
+ }
+ return availableSurgeryTemplates;
+ }
+
+ public void setAvailableSurgeryTemplates(List availableSurgeryTemplates) {
+ this.availableSurgeryTemplates = availableSurgeryTemplates;
+ }
+
+ /**
+ * Get available Diagnosis templates from database
+ */
+ public List getAvailableDiagnosisTemplates() {
+ if (availableDiagnosisTemplates == null || availableDiagnosisTemplates.isEmpty()) {
+ try {
+ String jpql = "SELECT d FROM DocumentTemplate d WHERE d.type = com.divudi.core.data.clinical.DocumentTemplateType.DiagnosisCard AND d.retired = false ORDER BY d.name";
+ availableDiagnosisTemplates = (List) documentTemplateFacade.executeQuery(DocumentTemplate.class, jpql);
+ if (availableDiagnosisTemplates == null) {
+ availableDiagnosisTemplates = new ArrayList<>();
+ }
+ } catch (Exception e) {
+ availableDiagnosisTemplates = new ArrayList<>();
+ JsfUtil.addErrorMessage("Error loading Diagnosis templates: " + e.getMessage());
+ }
+ }
+ return availableDiagnosisTemplates;
+ }
+
+ public void setAvailableDiagnosisTemplates(List availableDiagnosisTemplates) {
+ this.availableDiagnosisTemplates = availableDiagnosisTemplates;
+ }
+
+ /**
+ * Get selected Ward template ID
+ */
+ public String getSelectedWardTemplate() {
+ return selectedWardTemplate;
+ }
+
+ public void setSelectedWardTemplate(String selectedWardTemplate) {
+ this.selectedWardTemplate = selectedWardTemplate;
+ }
+
+ /**
+ * Get selected Surgery template ID
+ */
+ public String getSelectedSurgeryTemplate() {
+ return selectedSurgeryTemplate;
+ }
+
+ public void setSelectedSurgeryTemplate(String selectedSurgeryTemplate) {
+ this.selectedSurgeryTemplate = selectedSurgeryTemplate;
+ }
+
+ /**
+ * Handle Ward template selection change
+ */
+ public void onWardTemplateChange() {
+ if (selectedWardTemplate != null && !selectedWardTemplate.isEmpty()) {
+ loadWardAdmissionDiagnosisCard();
+ }
+ }
+
+ /**
+ * Handle Surgery template selection change
+ */
+ public void onSurgeryTemplateChange() {
+ if (selectedSurgeryTemplate != null && !selectedSurgeryTemplate.isEmpty()) {
+ loadLocalSurgeryDiagnosisCard();
+ }
+ }
+
+ /**
+ * Get selected Diagnosis template ID
+ */
+ public String getSelectedDiagnosisTemplate() {
+ return selectedDiagnosisTemplate;
+ }
+
+ public void setSelectedDiagnosisTemplate(String selectedDiagnosisTemplate) {
+ this.selectedDiagnosisTemplate = selectedDiagnosisTemplate;
+ }
+
+ /**
+ * Load and display Diagnosis Card with variable replacement
+ */
+ public void loadDiagnosisCard() {
+ // If current is not set, try to get it from admissionController
+ if (current == null && admissionController != null) {
+ current = admissionController.getCurrent();
+ }
+
+ if (current == null) {
+ JsfUtil.addErrorMessage("No patient encounter selected");
+ return;
+ }
+
+ String templateHtml = null;
+
+ // Debug: Check what template ID was selected
+ System.out.println("Selected Diagnosis Template ID: " + selectedDiagnosisTemplate);
+
+ // Try to load from selected template in dropdown first
+ if (selectedDiagnosisTemplate != null && !selectedDiagnosisTemplate.isEmpty() && !selectedDiagnosisTemplate.equals("")) {
+ try {
+ Long templateId = Long.parseLong(selectedDiagnosisTemplate);
+ System.out.println("Parsing template ID: " + templateId);
+
+ DocumentTemplate template = documentTemplateFacade.find(templateId);
+ System.out.println("Template found: " + (template != null ? template.getName() : "NULL"));
+
+ if (template != null && !template.isRetired()) {
+ templateHtml = template.getContents();
+ System.out.println("Template contents length: " + (templateHtml != null ? templateHtml.length() : "NULL"));
+ }
+ } catch (NumberFormatException nfe) {
+ System.out.println("Error parsing template ID: " + nfe.getMessage());
+ JsfUtil.addErrorMessage("Invalid template ID selected: " + selectedDiagnosisTemplate);
+ } catch (Exception e) {
+ System.out.println("Error loading template: " + e.getMessage());
+ e.printStackTrace();
+ // Fall through to config option if selected template fails
+ }
+ }
+
+ // Fallback to config option if no template selected or not found
+ if (templateHtml == null || templateHtml.isEmpty()) {
+ System.out.println("Falling back to config option");
+ templateHtml = configOptionApplicationController.getLongTextValueByKey("Diagnosis Card Template", "");
+ }
+
+ if (templateHtml == null || templateHtml.isEmpty()) {
+ JsfUtil.addErrorMessage("Diagnosis Card template not configured. Please select a template or configure a default.");
+ return;
+ }
+
+ System.out.println("Creating replacements map");
+ Map replacements = createReplacementsMap(current);
+ System.out.println("Applying replacements to template");
+ diagnosisCardHtml = replaceVariablesInHtml(templateHtml, replacements);
+ System.out.println("Diagnosis card HTML generated, length: " + (diagnosisCardHtml != null ? diagnosisCardHtml.length() : "NULL"));
+ }
+
+ /**
+ * Handle Diagnosis template selection change
+ */
+ public void onDiagnosisTemplateChange() {
+ if (selectedDiagnosisTemplate != null && !selectedDiagnosisTemplate.isEmpty()) {
+ loadDiagnosisCard();
+ }
+ }
+
+ // Diagnostic Card Data Holder
+ private DiagnosticCardData diagnosticCardData;
+ private ClinicalEntity diagnosisCaptureItem;
+ private String diagnosisCaptureDetails;
+ private List capturedDiagnoses = new ArrayList<>();
+
+ private InvestigationItem investigationCaptureItem;
+ private String investigationCaptureDetails;
+ private List capturedInvestigations = new ArrayList<>();
+
+ // Ward Admission Card Data Holder
+ private WardAdmissionCardData wardAdmissionCardData;
+ private ClinicalEntity wardDiagnosisCaptureItem;
+
+ public DiagnosticCardData getDiagnosticCardData() {
+ if (diagnosticCardData == null) {
+ diagnosticCardData = new DiagnosticCardData();
+ }
+ return diagnosticCardData;
+ }
+
+ public void setDiagnosticCardData(DiagnosticCardData diagnosticCardData) {
+ this.diagnosticCardData = diagnosticCardData;
+ }
+
+ public ClinicalEntity getDiagnosisCaptureItem() {
+ return diagnosisCaptureItem;
+ }
+
+ public void setDiagnosisCaptureItem(ClinicalEntity diagnosisCaptureItem) {
+ this.diagnosisCaptureItem = diagnosisCaptureItem;
+ }
+
+ public String getDiagnosisCaptureDetails() {
+ return diagnosisCaptureDetails;
+ }
+
+ public void setDiagnosisCaptureDetails(String diagnosisCaptureDetails) {
+ this.diagnosisCaptureDetails = diagnosisCaptureDetails;
+ }
+
+ public List getCapturedDiagnoses() {
+ return capturedDiagnoses;
+ }
+
+ public void setCapturedDiagnoses(List capturedDiagnoses) {
+ this.capturedDiagnoses = capturedDiagnoses;
+ }
+
+ public InvestigationItem getInvestigationCaptureItem() {
+ return investigationCaptureItem;
+ }
+
+ public void setInvestigationCaptureItem(InvestigationItem investigationCaptureItem) {
+ this.investigationCaptureItem = investigationCaptureItem;
+ }
+
+ public String getInvestigationCaptureDetails() {
+ return investigationCaptureDetails;
+ }
+
+ public void setInvestigationCaptureDetails(String investigationCaptureDetails) {
+ this.investigationCaptureDetails = investigationCaptureDetails;
+ }
+
+ public List getCapturedInvestigations() {
+ return capturedInvestigations;
+ }
+
+ public void setCapturedInvestigations(List capturedInvestigations) {
+ this.capturedInvestigations = capturedInvestigations;
+ }
+
+ public WardAdmissionCardData getWardAdmissionCardData() {
+ if (wardAdmissionCardData == null) {
+ wardAdmissionCardData = new WardAdmissionCardData();
+ }
+ return wardAdmissionCardData;
+ }
+
+ public void setWardAdmissionCardData(WardAdmissionCardData wardAdmissionCardData) {
+ this.wardAdmissionCardData = wardAdmissionCardData;
+ }
+
+ public ClinicalEntity getWardDiagnosisCaptureItem() {
+ return wardDiagnosisCaptureItem;
+ }
+
+ public void setWardDiagnosisCaptureItem(ClinicalEntity wardDiagnosisCaptureItem) {
+ this.wardDiagnosisCaptureItem = wardDiagnosisCaptureItem;
+ }
+
+ /**
+ * Save Diagnostic Card Data
+ */
+ public void saveDiagnosticCardData() {
+ if (diagnosticCardData == null) {
+ JsfUtil.addErrorMessage("No diagnostic card data to save");
+ return;
+ }
+ try {
+ // Logic to save diagnosticCardData to database
+ JsfUtil.addSuccessMessage("Diagnostic card data saved successfully");
+ } catch (Exception e) {
+ JsfUtil.addErrorMessage("Error saving diagnostic card data: " + e.getMessage());
+ }
+ }
+
+ /**
+ * Cancel Diagnostic Card Capture
+ */
+ public void cancelDiagnosticCardCapture() {
+ diagnosticCardData = null;
+ capturedDiagnoses.clear();
+ capturedInvestigations.clear();
+ diagnosisCaptureItem = null;
+ investigationCaptureItem = null;
+ }
+
+ /**
+ * Add Diagnosis to Captured List
+ */
+ public void addDiagnosisToCapture() {
+ if (diagnosisCaptureItem != null) {
+ capturedDiagnoses.add(diagnosisCaptureItem);
+ diagnosisCaptureItem = null;
+ diagnosisCaptureDetails = null;
+ }
+ }
+
+ /**
+ * Remove Captured Diagnosis
+ */
+ public void removeCapturedDiagnosis(ClinicalEntity dx) {
+ capturedDiagnoses.remove(dx);
+ }
+
+ /**
+ * Add Investigation to Captured List
+ */
+ public void addInvestigationToCapture() {
+ if (investigationCaptureItem != null) {
+ capturedInvestigations.add(investigationCaptureItem);
+ investigationCaptureItem = null;
+ investigationCaptureDetails = null;
+ }
+ }
+
+ /**
+ * Remove Captured Investigation
+ */
+ public void removeCapturedInvestigation(InvestigationItem ix) {
+ capturedInvestigations.remove(ix);
+ }
+
+ /**
+ * Save Ward Admission Card Data
+ */
+ public void saveWardAdmissionCardData() {
+ if (wardAdmissionCardData == null) {
+ JsfUtil.addErrorMessage("No ward admission card data to save");
+ return;
+ }
+ try {
+ // Logic to save wardAdmissionCardData to database
+ JsfUtil.addSuccessMessage("Ward admission card data saved successfully");
+ } catch (Exception e) {
+ JsfUtil.addErrorMessage("Error saving ward admission card data: " + e.getMessage());
+ }
+ }
+
+ /**
+ * Cancel Ward Admission Card Capture
+ */
+ public void cancelWardAdmissionCapture() {
+ wardAdmissionCardData = null;
+ wardDiagnosisCaptureItem = null;
+ }
+
+ /**
+ * Inner class to hold Diagnostic Card data
+ */
+ public static class DiagnosticCardData implements Serializable {
+ private String chiefComplaint;
+ private String historyOfPresentIllness;
+ private String physicalExamination;
+ private String vitalSigns;
+ private String treatmentPlan;
+ private String medications;
+ private String followUpNotes;
+ private String differentialDiagnosis;
+ private String prognosis;
+ private String specialInstructions;
+
+ public String getChiefComplaint() { return chiefComplaint; }
+ public void setChiefComplaint(String chiefComplaint) { this.chiefComplaint = chiefComplaint; }
+
+ public String getHistoryOfPresentIllness() { return historyOfPresentIllness; }
+ public void setHistoryOfPresentIllness(String historyOfPresentIllness) { this.historyOfPresentIllness = historyOfPresentIllness; }
+
+ public String getPhysicalExamination() { return physicalExamination; }
+ public void setPhysicalExamination(String physicalExamination) { this.physicalExamination = physicalExamination; }
+
+ public String getVitalSigns() { return vitalSigns; }
+ public void setVitalSigns(String vitalSigns) { this.vitalSigns = vitalSigns; }
+
+ public String getTreatmentPlan() { return treatmentPlan; }
+ public void setTreatmentPlan(String treatmentPlan) { this.treatmentPlan = treatmentPlan; }
+
+ public String getMedications() { return medications; }
+ public void setMedications(String medications) { this.medications = medications; }
+
+ public String getFollowUpNotes() { return followUpNotes; }
+ public void setFollowUpNotes(String followUpNotes) { this.followUpNotes = followUpNotes; }
+
+ public String getDifferentialDiagnosis() { return differentialDiagnosis; }
+ public void setDifferentialDiagnosis(String differentialDiagnosis) { this.differentialDiagnosis = differentialDiagnosis; }
+
+ public String getPrognosis() { return prognosis; }
+ public void setPrognosis(String prognosis) { this.prognosis = prognosis; }
+
+ public String getSpecialInstructions() { return specialInstructions; }
+ public void setSpecialInstructions(String specialInstructions) { this.specialInstructions = specialInstructions; }
+ }
+
+ /**
+ * Inner class to hold Ward Admission Card data
+ */
+ public static class WardAdmissionCardData implements Serializable {
+ private String bhtNumber;
+ private String admissionType;
+ private String ward;
+ private String bedNumber;
+ private Date dateOfAdmission;
+ private String timeOfAdmission;
+ private String chiefComplaint;
+ private String historyOfPresentIllness;
+ private String pastMedicalHistory;
+ private String medicationsOnAdmission;
+ private Double temperature;
+ private String bloodPressure;
+ private Integer pulseRate;
+ private Integer respiratoryRate;
+ private Double weight;
+ private Double height;
+ private Double bmi;
+ private String generalExamination;
+ private String primaryDiagnosis;
+ private String treatmentPlan;
+ private String medicationsPrescribed;
+ private String laboratoryTests;
+ private String imaging;
+ private String physicianName;
+ private String physicianContact;
+ private String physicianSignature;
+ private String nurseName;
+ private String nurseContact;
+ private String nurseSignature;
+ private String allergies;
+ private String precautions;
+ private String additionalNotes;
+
+ // Getters and Setters
+ public String getBhtNumber() { return bhtNumber; }
+ public void setBhtNumber(String bhtNumber) { this.bhtNumber = bhtNumber; }
+
+ public String getAdmissionType() { return admissionType; }
+ public void setAdmissionType(String admissionType) { this.admissionType = admissionType; }
+
+ public String getWard() { return ward; }
+ public void setWard(String ward) { this.ward = ward; }
+
+ public String getBedNumber() { return bedNumber; }
+ public void setBedNumber(String bedNumber) { this.bedNumber = bedNumber; }
+
+ public Date getDateOfAdmission() { return dateOfAdmission; }
+ public void setDateOfAdmission(Date dateOfAdmission) { this.dateOfAdmission = dateOfAdmission; }
+
+ public String getTimeOfAdmission() { return timeOfAdmission; }
+ public void setTimeOfAdmission(String timeOfAdmission) { this.timeOfAdmission = timeOfAdmission; }
+
+ public String getChiefComplaint() { return chiefComplaint; }
+ public void setChiefComplaint(String chiefComplaint) { this.chiefComplaint = chiefComplaint; }
+
+ public String getHistoryOfPresentIllness() { return historyOfPresentIllness; }
+ public void setHistoryOfPresentIllness(String historyOfPresentIllness) { this.historyOfPresentIllness = historyOfPresentIllness; }
+
+ public String getPastMedicalHistory() { return pastMedicalHistory; }
+ public void setPastMedicalHistory(String pastMedicalHistory) { this.pastMedicalHistory = pastMedicalHistory; }
+
+ public String getMedicationsOnAdmission() { return medicationsOnAdmission; }
+ public void setMedicationsOnAdmission(String medicationsOnAdmission) { this.medicationsOnAdmission = medicationsOnAdmission; }
+
+ public Double getTemperature() { return temperature; }
+ public void setTemperature(Double temperature) { this.temperature = temperature; }
+
+ public String getBloodPressure() { return bloodPressure; }
+ public void setBloodPressure(String bloodPressure) { this.bloodPressure = bloodPressure; }
+
+ public Integer getPulseRate() { return pulseRate; }
+ public void setPulseRate(Integer pulseRate) { this.pulseRate = pulseRate; }
+
+ public Integer getRespiratoryRate() { return respiratoryRate; }
+ public void setRespiratoryRate(Integer respiratoryRate) { this.respiratoryRate = respiratoryRate; }
+
+ public Double getWeight() { return weight; }
+ public void setWeight(Double weight) { this.weight = weight; }
+
+ public Double getHeight() { return height; }
+ public void setHeight(Double height) { this.height = height; }
+
+ public Double getBmi() { return bmi; }
+ public void setBmi(Double bmi) { this.bmi = bmi; }
+
+ public String getGeneralExamination() { return generalExamination; }
+ public void setGeneralExamination(String generalExamination) { this.generalExamination = generalExamination; }
+
+ public String getPrimaryDiagnosis() { return primaryDiagnosis; }
+ public void setPrimaryDiagnosis(String primaryDiagnosis) { this.primaryDiagnosis = primaryDiagnosis; }
+
+ public String getTreatmentPlan() { return treatmentPlan; }
+ public void setTreatmentPlan(String treatmentPlan) { this.treatmentPlan = treatmentPlan; }
+
+ public String getMedicationsPrescribed() { return medicationsPrescribed; }
+ public void setMedicationsPrescribed(String medicationsPrescribed) { this.medicationsPrescribed = medicationsPrescribed; }
+
+ public String getLaboratoryTests() { return laboratoryTests; }
+ public void setLaboratoryTests(String laboratoryTests) { this.laboratoryTests = laboratoryTests; }
+
+ public String getImaging() { return imaging; }
+ public void setImaging(String imaging) { this.imaging = imaging; }
+
+ public String getPhysicianName() { return physicianName; }
+ public void setPhysicianName(String physicianName) { this.physicianName = physicianName; }
+
+ public String getPhysicianContact() { return physicianContact; }
+ public void setPhysicianContact(String physicianContact) { this.physicianContact = physicianContact; }
+
+ public String getPhysicianSignature() { return physicianSignature; }
+ public void setPhysicianSignature(String physicianSignature) { this.physicianSignature = physicianSignature; }
+
+ public String getNurseName() { return nurseName; }
+ public void setNurseName(String nurseName) { this.nurseName = nurseName; }
+
+ public String getNurseContact() { return nurseContact; }
+ public void setNurseContact(String nurseContact) { this.nurseContact = nurseContact; }
+
+ public String getNurseSignature() { return nurseSignature; }
+ public void setNurseSignature(String nurseSignature) { this.nurseSignature = nurseSignature; }
+
+ public String getAllergies() { return allergies; }
+ public void setAllergies(String allergies) { this.allergies = allergies; }
+
+ public String getPrecautions() { return precautions; }
+ public void setPrecautions(String precautions) { this.precautions = precautions; }
+
+ public String getAdditionalNotes() { return additionalNotes; }
+ public void setAdditionalNotes(String additionalNotes) { this.additionalNotes = additionalNotes; }
+ }
+
}
enum ClinicalField {
diff --git a/src/main/java/com/divudi/bean/inward/InwardBeanController.java b/src/main/java/com/divudi/bean/inward/InwardBeanController.java
index 1c4f8f6fe13..ebf5f2b7a7d 100644
--- a/src/main/java/com/divudi/bean/inward/InwardBeanController.java
+++ b/src/main/java/com/divudi/bean/inward/InwardBeanController.java
@@ -6,6 +6,7 @@
package com.divudi.bean.inward;
import com.divudi.bean.common.BillBeanController;
+import com.divudi.bean.common.ConfigOptionApplicationController;
import com.divudi.bean.common.SessionController;
import com.divudi.core.data.BillType;
import com.divudi.core.data.BillTypeAtomic;
@@ -111,6 +112,8 @@ public class InwardBeanController implements Serializable {
InwardReportControllerBht inwardReportControllerBht;
@Inject
SessionController sessionController;
+ @Inject
+ private ConfigOptionApplicationController configOptionApplicationController;
public String inwardDepositBillText(Bill b) {
String template = sessionController.getDepartmentPreference().getInwardDepositBillTemplate();
@@ -377,8 +380,7 @@ public double calCostOfIssue(PatientEncounter patientEncounter, BillType billTyp
public double calCostOfIssueByBill(PatientEncounter patientEncounter, List btas, List cpts) {
String sql;
HashMap hm;
- sql = "SELECT sum(b.netTotal)"
- + " FROM Bill b "
+ sql = "SELECT b FROM Bill b "
+ " WHERE b.retired=false "
+ " and b.billTypeAtomic IN :btp "
+ " and b.patientEncounter IN :pe";
@@ -390,7 +392,21 @@ public double calCostOfIssueByBill(PatientEncounter patientEncounter, List bills = getBillItemFacade().findByJpql(sql, hm);
+ double total = 0;
+
+ // Calculate total with sign inversion for cancelled and refund bills
+ for (Bill bill : bills) {
+ // For RefundBill and CancelledBill, invert the value (deduct instead of add)
+ if (bill instanceof RefundBill || bill instanceof CancelledBill) {
+ total -= bill.getNetTotal();
+ } else {
+ total += bill.getNetTotal();
+ }
+ }
+
+ return total;
}
@@ -967,6 +983,12 @@ public double getProfessionalCharge(PatientEncounter patientEncounter, List pts = new ArrayList<>();
pts.add(patientEncounter);
diff --git a/src/main/java/com/divudi/bean/inward/InwardReportControllerBht.java b/src/main/java/com/divudi/bean/inward/InwardReportControllerBht.java
index 49a004f7e24..7b0db75250b 100644
--- a/src/main/java/com/divudi/bean/inward/InwardReportControllerBht.java
+++ b/src/main/java/com/divudi/bean/inward/InwardReportControllerBht.java
@@ -625,6 +625,14 @@ public void createTimedService() {
public void updateBillItemAndBill(Bill bill) {
bill.setNetTotal(bill.getTotal() - bill.getDiscount());
+
+ // Recalculate VAT when bill totals change
+ if (bill.getBillItems() != null && !bill.getBillItems().isEmpty()) {
+ double vatAmount = calculateSelectiveVatAmount(bill.getBillItems());
+ bill.setVat(vatAmount);
+ bill.setVatPlusNetTotal(bill.getNetTotal() + vatAmount);
+ }
+
billFacade.edit(bill);
if (bill.getSingleBillItem() != null) {
@@ -1801,4 +1809,22 @@ public double getPharmacyIssueDtosToPatientEncounterNetTotal() {
public void setPharmacyIssueDtosToPatientEncounterNetTotal(double pharmacyIssueDtosToPatientEncounterNetTotal) {
this.pharmacyIssueDtosToPatientEncounterNetTotal = pharmacyIssueDtosToPatientEncounterNetTotal;
}
+
+ /**
+ * Calculate selective VAT amount from bill items
+ * VAT is calculated based on specific charge types configured for VAT
+ */
+ private double calculateSelectiveVatAmount(List billItems) {
+ if (billItems == null || billItems.isEmpty()) {
+ return 0.0;
+ }
+
+ double vat = 0.0;
+ for (BillItem billItem : billItems) {
+ if (billItem != null && billItem.getVat() > 0) {
+ vat += billItem.getVat();
+ }
+ }
+ return vat;
+ }
}
diff --git a/src/main/java/com/divudi/bean/inward/InwardStaffPaymentBillController.java b/src/main/java/com/divudi/bean/inward/InwardStaffPaymentBillController.java
index 5c3456538ac..8e6de58dfd6 100644
--- a/src/main/java/com/divudi/bean/inward/InwardStaffPaymentBillController.java
+++ b/src/main/java/com/divudi/bean/inward/InwardStaffPaymentBillController.java
@@ -2073,4 +2073,26 @@ public void setBundle(IncomeBundle bundle) {
this.bundle = bundle;
}
+ /**
+ * Check if any bill fees are marked as collected by doctor
+ * Used to display "FEE COLLECTED DIRECTLY BY DOCTOR" message on bill
+ */
+ public boolean hasFeeCollectedByDoctor() {
+ if (current == null) {
+ return false;
+ }
+
+ List billFees = current.getBillFees();
+ if (billFees == null || billFees.isEmpty()) {
+ return false;
+ }
+
+ for (BillFee bf : billFees) {
+ if (bf.isFeeCollectedByDoctor()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
}
diff --git a/src/main/java/com/divudi/bean/inward/SurgeryBillController.java b/src/main/java/com/divudi/bean/inward/SurgeryBillController.java
index b6cf5c00f65..d58ea683755 100644
--- a/src/main/java/com/divudi/bean/inward/SurgeryBillController.java
+++ b/src/main/java/com/divudi/bean/inward/SurgeryBillController.java
@@ -20,6 +20,7 @@
import com.divudi.core.entity.BillFee;
import com.divudi.core.entity.BillItem;
import com.divudi.core.entity.BilledBill;
+import com.divudi.core.entity.CancelledBill;
import com.divudi.core.entity.PatientEncounter;
import com.divudi.core.entity.PatientItem;
import com.divudi.core.entity.PreBill;
@@ -92,6 +93,8 @@ public class SurgeryBillController implements Serializable {
private InwardBeanController inwardBean;
@Inject
BhtSummeryController bhtSummeryController;
+ @Inject
+ private com.divudi.bean.common.ConfigOptionApplicationController configOptionApplicationController;
public InwardTimedItemController getInwardTimedItemController() {
return inwardTimedItemController;
@@ -488,6 +491,20 @@ public Bill getSurgeryBill() {
return surgeryBill;
}
+ private List getBillsByForwardRef(Bill b) {
+ String sql = "Select bf from Bill bf where bf.cancelled=false and "
+ + " bf.retired=false and bf.forwardReferenceBill=:bill";
+ HashMap hm = new HashMap();
+ hm.put("bill", b);
+ List list = getBillFacade().findByJpql(sql, hm);
+
+ if (list == null) {
+ return new ArrayList<>();
+ }
+
+ return list;
+ }
+
// private List getBillsByForwardRef(Bill b) {
// String sql = "Select bf from Bill bf where bf.cancelled=false and "
// + " bf.retired=false and bf.forwardReferenceBill=:bill";
@@ -531,6 +548,13 @@ public Bill getSurgeryBill() {
List storeIssues;
public List getStoreIssues() {
+ if (storeIssues == null && getSurgeryBill() != null) {
+ // Lazy-load store issues from database
+ storeIssues = createIssueTable(BillType.StoreBhtPre);
+ }
+ if (storeIssues == null) {
+ storeIssues = new ArrayList<>();
+ }
return storeIssues;
}
@@ -567,19 +591,42 @@ private List createIssueTable(BillType billType) {
+ " and b.bill.billType=:btp"
+ " and b.bill.forwardReferenceBill=:bil "
+ " and type(b.bill.billedBill)=:billedClass "
- + " and (type(b.bill)=:class)"
+ + " and (type(b.bill)=:refundClass)"
+ " order by b.item.name ";
hm = new HashMap();
hm.put("btp", billType);
- hm.put("class", RefundBill.class);
+ hm.put("refundClass", RefundBill.class);
hm.put("billedClass", PreBill.class);
hm.put("bil", getSurgeryBill());
-// hm.put("pe", getBatchBill().getPatientEncounter());
List billItems1 = getBillItemFacade().findByJpql(sql, hm);
billItems.addAll(billItems1);
+ // Also fetch CancelledBill items if feature is enabled (for cancelled medicines/surgical supplies)
+ boolean includeCancelledBills = configOptionApplicationController.getBooleanValueByKey(
+ "Separate Medicines and Surgical Supplies Tab", false);
+
+ if (includeCancelledBills) {
+ hm.clear();
+ sql = "SELECT b FROM BillItem b "
+ + " WHERE b.retired=false "
+ + " and b.bill.billType=:btp"
+ + " and b.bill.forwardReferenceBill=:bil "
+ + " and type(b.bill.billedBill)=:billedClass "
+ + " and (type(b.bill)=:cancelledClass)"
+ + " order by b.item.name ";
+ hm = new HashMap();
+ hm.put("btp", billType);
+ hm.put("cancelledClass", CancelledBill.class);
+ hm.put("billedClass", PreBill.class);
+ hm.put("bil", getSurgeryBill());
+
+ List billItems2 = getBillItemFacade().findByJpql(sql, hm);
+
+ billItems1.addAll(billItems2);
+ }
+
return billItems;
}
@@ -653,6 +700,25 @@ public void addProfessionalFee() {
}
public List getProEncounterComponents() {
+ if (proEncounterComponents == null && getSurgeryBill() != null) {
+ // Lazy-load professional fee components from database
+ Bill professionalBill = getBillsByForwardRef(getSurgeryBill()).stream()
+ .filter(b -> b.getSurgeryBillType() == SurgeryBillType.ProfessionalFee)
+ .findFirst()
+ .orElse(null);
+
+ if (professionalBill != null) {
+ setProfessionalBill(professionalBill);
+ List enc = getBillBean().getEncounterComponents(professionalBill);
+ if (enc != null && !enc.isEmpty()) {
+ proEncounterComponents = enc;
+ } else {
+ proEncounterComponents = new ArrayList<>();
+ }
+ } else {
+ proEncounterComponents = new ArrayList<>();
+ }
+ }
if (proEncounterComponents == null) {
proEncounterComponents = new ArrayList<>();
}
@@ -720,6 +786,24 @@ public void setBillNumberBean(BillNumberGenerator billNumberBean) {
}
public List getTimedEncounterComponents() {
+ if (timedEncounterComponents == null && getSurgeryBill() != null) {
+ // Lazy-load timed service components from database
+ Bill timedBill = getBillsByForwardRef(getSurgeryBill()).stream()
+ .filter(b -> b.getSurgeryBillType() == SurgeryBillType.TimedService)
+ .findFirst()
+ .orElse(null);
+
+ if (timedBill != null) {
+ List enc = getBillBean().getEncounterComponents(timedBill);
+ if (enc != null && !enc.isEmpty()) {
+ timedEncounterComponents = enc;
+ } else {
+ timedEncounterComponents = new ArrayList<>();
+ }
+ } else {
+ timedEncounterComponents = new ArrayList<>();
+ }
+ }
if (timedEncounterComponents == null) {
timedEncounterComponents = new ArrayList<>();
}
@@ -783,6 +867,13 @@ public void setDepartmentBillItems(List departmentBillItems
}
public List getPharmacyIssues() {
+ if (pharmacyIssues == null && getSurgeryBill() != null) {
+ // Lazy-load pharmacy issues from database
+ pharmacyIssues = createIssueTable(BillType.PharmacyBhtPre);
+ }
+ if (pharmacyIssues == null) {
+ pharmacyIssues = new ArrayList<>();
+ }
return pharmacyIssues;
}
diff --git a/src/main/java/com/divudi/core/data/clinical/DocumentTemplateType.java b/src/main/java/com/divudi/core/data/clinical/DocumentTemplateType.java
index 27157d1384e..944aed78c50 100644
--- a/src/main/java/com/divudi/core/data/clinical/DocumentTemplateType.java
+++ b/src/main/java/com/divudi/core/data/clinical/DocumentTemplateType.java
@@ -14,4 +14,6 @@ public enum DocumentTemplateType {
MedicalCertificate,
FitnessCertificate,
Referral,
+ WardAdmissionCard,
+ LocalSurgeryCard,
}
diff --git a/src/main/java/com/divudi/core/data/inward/PatientEncounterComponentType.java b/src/main/java/com/divudi/core/data/inward/PatientEncounterComponentType.java
index 367c323511a..7f9b884bd9f 100644
--- a/src/main/java/com/divudi/core/data/inward/PatientEncounterComponentType.java
+++ b/src/main/java/com/divudi/core/data/inward/PatientEncounterComponentType.java
@@ -16,6 +16,7 @@ public enum PatientEncounterComponentType {
Ananesthesia_by,
Item,
Category,
+ OTHER
}
diff --git a/src/main/webapp/emr/settings/document_template.xhtml b/src/main/webapp/emr/settings/document_template.xhtml
index 7b7c485da40..1d7e18caa72 100644
--- a/src/main/webapp/emr/settings/document_template.xhtml
+++ b/src/main/webapp/emr/settings/document_template.xhtml
@@ -127,8 +127,12 @@
{sex} - Patient gender
{address} - Patient address
{phone} - Patient phone
- {patient_phn_number} - Patient PHN
- {patient_nic} - Patient NIC
+ {nic} - Patient NIC
+ {patient_nic} - Patient NIC (alias)
+ {patient_nic_number} - Patient NIC (full alias)
+ {phn} - Patient PHN
+ {patient_phn} - Patient PHN (alias)
+ {patient_phn_number} - Patient PHN (full alias)
@@ -149,18 +153,39 @@
-
Clinical Data
+
Admission Details
- {visit-dx} - Visit diagnosis
- {past-dx} - Past diagnosis
- {medicines} - All medicines
- {indoor} - Indoor medicines
- {outdoor} - Outdoor medicines
- {routine-medicines} - Routine medicines
- {ix} - Investigations (multiline)
- {ix-same-line} - Investigations (single line)
- {pa} - Plan of action
- {allergies} - Patient allergies
+ {bht} - BHT number
+ {bht-number} - BHT number (alias)
+ {admission-number} - Admission number (alias)
+ {doa} - Date of admission
+ {admission-date} - Date of admission (alias)
+ {date-of-admission} - Date of admission (full alias)
+ {dod} - Date of discharge
+ {discharge-date} - Date of discharge (alias)
+ {date-of-discharge} - Date of discharge (full alias)
+ {room} - Room number
+ {room-number} - Room number (alias)
+
+
+
+
+
Surgery Details
+
+ {surgery-name} - Surgery name
+ {procedure} - Procedure (alias)
+ {surgery-procedure} - Surgery procedure
+ {performed-by} - Surgeon name
+ {surgeon} - Surgeon (alias)
+ {surgery-surgeon} - Surgery surgeon (full)
+ {assistant} - Assistant name
+ {surgery-assistant} - Surgery assistant (full)
+ {anesthesia} - Anesthesia type
+ {anesthesia-type} - Anesthesia type (alias)
+ {anesthesiologist} - Anesthesiologist name
+ {surgery-anesthesiologist} - Surgery anesthesiologist (full)
+ {surgery-date} - Surgery date
+ {surgery-time} - Surgery time
diff --git a/src/main/webapp/inward/admission_profile.xhtml b/src/main/webapp/inward/admission_profile.xhtml
index 6cac7790549..dd60e3a7e53 100644
--- a/src/main/webapp/inward/admission_profile.xhtml
+++ b/src/main/webapp/inward/admission_profile.xhtml
@@ -351,6 +351,23 @@
icon="fa fa-diagnoses"
class="w-100">
+
+
+
+
+
@@ -525,13 +542,6 @@
-
-
-
-
-
-
-
diff --git a/src/main/webapp/inward/clinical_data_diagnosis_card.xhtml b/src/main/webapp/inward/clinical_data_diagnosis_card.xhtml
index ff3fad4ecf2..c08da9b812d 100644
--- a/src/main/webapp/inward/clinical_data_diagnosis_card.xhtml
+++ b/src/main/webapp/inward/clinical_data_diagnosis_card.xhtml
@@ -693,6 +693,124 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/inward/inward_bill_intrim.xhtml b/src/main/webapp/inward/inward_bill_intrim.xhtml
index d9e3af3f976..32ade9c10da 100644
--- a/src/main/webapp/inward/inward_bill_intrim.xhtml
+++ b/src/main/webapp/inward/inward_bill_intrim.xhtml
@@ -539,7 +539,9 @@
rowStyleClass="#{((iss.billClass eq 'class com.divudi.core.entity.PreBill')
or
(iss.billedBill ne null
- and iss.billClass eq 'class com.divudi.core.entity.RefundBill'))? '':'noDisplayRow'}">
+ and iss.billClass eq 'class com.divudi.core.entity.RefundBill'
+ or (configOptionApplicationController.getBooleanValueByKey('Separate Medicines and Surgical Supplies Tab', false)
+ and iss.billClass eq 'class com.divudi.core.entity.CancelledBill')))? '':'noDisplayRow'}">
@@ -629,7 +631,9 @@
rowStyleClass="#{((iss.billClass eq 'class com.divudi.core.entity.PreBill')
or
(iss.billedBill ne null
- and iss.billClass eq 'class com.divudi.core.entity.RefundBill'))? '':'noDisplayRow'}">
+ and iss.billClass eq 'class com.divudi.core.entity.RefundBill'
+ or (configOptionApplicationController.getBooleanValueByKey('Separate Medicines and Surgical Supplies Tab', false)
+ and iss.billClass eq 'class com.divudi.core.entity.CancelledBill')))? '':'noDisplayRow'}">
#{iss.deptId}
@@ -711,7 +715,9 @@
rowStyleClass="#{((iss.billClass eq 'class com.divudi.core.entity.PreBill')
or
(iss.billedBill ne null
- and iss.billClass eq 'class com.divudi.core.entity.RefundBill'))? '':'noDisplayRow'}">
+ and iss.billClass eq 'class com.divudi.core.entity.RefundBill'
+ or (configOptionApplicationController.getBooleanValueByKey('Separate Medicines and Surgical Supplies Tab', false)
+ and iss.billClass eq 'class com.divudi.core.entity.CancelledBill')))? '':'noDisplayRow'}">
@@ -730,7 +736,7 @@
-
+
diff --git a/src/main/webapp/inward/inward_bill_professional_payment.xhtml b/src/main/webapp/inward/inward_bill_professional_payment.xhtml
index de8d55828b4..846dad374af 100644
--- a/src/main/webapp/inward/inward_bill_professional_payment.xhtml
+++ b/src/main/webapp/inward/inward_bill_professional_payment.xhtml
@@ -280,7 +280,7 @@
-
+
diff --git a/src/main/webapp/inward/inward_bill_surgery_payment.xhtml b/src/main/webapp/inward/inward_bill_surgery_payment.xhtml
index bc30f25a3d7..f909ae4fc0e 100644
--- a/src/main/webapp/inward/inward_bill_surgery_payment.xhtml
+++ b/src/main/webapp/inward/inward_bill_surgery_payment.xhtml
@@ -49,9 +49,9 @@
value="#{inwardSurgeryPaymentBillController.surgery}"
inputStyleClass="w-100" class="m-1 w-100"
id="scSurgery"
- completeMethod="#{inwardSurgeryPaymentBillController.completeSurgery}"
+ completeMethod="#{procedureController.completeProcedures}"
var="mys"
- itemLabel="#{mys.item.name}"
+ itemLabel="#{mys.name}"
itemValue="#{mys}"
>
@@ -287,7 +287,7 @@
-
+
diff --git a/src/main/webapp/inward/local_surgery_diagnosis_card.xhtml b/src/main/webapp/inward/local_surgery_diagnosis_card.xhtml
new file mode 100644
index 00000000000..e1f8c4a62ff
--- /dev/null
+++ b/src/main/webapp/inward/local_surgery_diagnosis_card.xhtml
@@ -0,0 +1,342 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/inward/ward_admission_diagnosis_card.xhtml b/src/main/webapp/inward/ward_admission_diagnosis_card.xhtml
new file mode 100644
index 00000000000..be131f73543
--- /dev/null
+++ b/src/main/webapp/inward/ward_admission_diagnosis_card.xhtml
@@ -0,0 +1,1135 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/resources/inward/bill/finalBill.xhtml b/src/main/webapp/resources/inward/bill/finalBill.xhtml
index 49b6a90ea38..62782eec8cd 100644
--- a/src/main/webapp/resources/inward/bill/finalBill.xhtml
+++ b/src/main/webapp/resources/inward/bill/finalBill.xhtml
@@ -423,116 +423,96 @@
-
-
-
-
-
-
- |
-
- |
-
- |
-
-
-
-
- |
-
-
-
-
-
-
-
-
- |
-
- |
-
- |
-
-
-
-
- |
-
-
-
+
+
+
+
+
+ |
+
+ |
+
+ |
+
+
+
+
+ |
+
+
+
-
-
-
-
- |
-
- |
-
- |
-
-
-
-
- |
-
-
-
+
+
+
+
+ |
+
+ |
+
+ |
+
+
+
+
+ |
+
+
+
-
-
-
-
- |
-
- |
-
- |
-
-
-
-
- |
-
-
-
+
+
+
+
+ |
+
+ |
+
+ |
+
+
+
+
+ |
+
+
+
-
-
-
-
- |
-
- |
-
- |
-
-
-
-
- |
-
-
-
-
+
+
+
+
+ |
+
+ |
+
+ |
+
+
+
+
+ |
+
+
+
-
-
-
+
+
+
|
-
+
|
|
-
+
|
-
+
@@ -840,6 +820,36 @@
+
+
+
+ |
+
+ |
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+ |
+
+ |
+ |
+
+
+
+
+ |
+
+
+
| |
|
diff --git a/src/main/webapp/resources/inward/bill/intrimBill.xhtml b/src/main/webapp/resources/inward/bill/intrimBill.xhtml
index 9a33a3cbe5f..9e751d06576 100644
--- a/src/main/webapp/resources/inward/bill/intrimBill.xhtml
+++ b/src/main/webapp/resources/inward/bill/intrimBill.xhtml
@@ -167,53 +167,20 @@
-
-
-
-
- |
-
- |
-
-
-
-
- |
-
-
-
-
-
-
-
-
-
- |
-
- |
-
-
-
-
- |
-
-
-
-
-
-
+
+
|
-
+
|
-
+
-
+
|
-
+
@@ -232,6 +199,34 @@
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+
+
+
diff --git a/src/main/webapp/sections/clinical_cards_with_template_selection.xhtml b/src/main/webapp/sections/clinical_cards_with_template_selection.xhtml
new file mode 100644
index 00000000000..bd66b268095
--- /dev/null
+++ b/src/main/webapp/sections/clinical_cards_with_template_selection.xhtml
@@ -0,0 +1,111 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+]]>
\ No newline at end of file
diff --git a/src/main/webapp/theater/inward_bill_surgery_professional.xhtml b/src/main/webapp/theater/inward_bill_surgery_professional.xhtml
index 11b7514ae54..3c9c983a20c 100644
--- a/src/main/webapp/theater/inward_bill_surgery_professional.xhtml
+++ b/src/main/webapp/theater/inward_bill_surgery_professional.xhtml
@@ -173,7 +173,7 @@
completeMethod="#{specialityController.completeSpeciality}" var="sp"
itemLabel="#{sp.name}"
itemValue="#{sp}" size="70" style="width: 400px;" class="mx-4 my-1">
-
+
@@ -183,7 +183,6 @@
completeMethod="#{inwardProfessionalBillController.completeItems}" var="st"
itemLabel="#{st.person.nameWithTitle}" itemValue="#{st}" size="70"
style="width: 400px;" class="mx-4 my-1">
-