Skip to content

Commit

Permalink
Merge pull request #6411 from hmislk/Issue#6404
Browse files Browse the repository at this point in the history
Issue#6404 Closes #6404
  • Loading branch information
Irani96 authored Jul 19, 2024
2 parents 9df9c78 + 4a456f8 commit 3152531
Show file tree
Hide file tree
Showing 9 changed files with 461 additions and 71 deletions.
13 changes: 4 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.divudi</groupId>

<artifactId>digasiri</artifactId>
<artifactId>demo1</artifactId>
<version>3.0.0</version>
<packaging>war</packaging>
<name>digasiri</name>


<name>demo1</name>

<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -309,11 +308,7 @@
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>9.0.83</version> <!-- or the version compatible with your setup -->
</dependency>


</dependencies>

Expand Down
46 changes: 38 additions & 8 deletions src/main/java/com/divudi/bean/common/DepartmentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Department findAndSaveDepartmentByName(String name) {
+ " and i.retired=:ret";
Department i = getFacade().findFirstByJpql(sql, m);
if (i == null) {
i = new Department();
i = new Department();
i.setName(name);
getFacade().create(i);
} else {
Expand All @@ -79,7 +79,7 @@ public Department findAndSaveDepartmentByName(String name) {
}
return i;
}

public Department findAndSaveDepartmentByName(String name, Institution ins) {
if (name == null || name.trim().equals("")) {
return null;
Expand All @@ -94,7 +94,7 @@ public Department findAndSaveDepartmentByName(String name, Institution ins) {
+ " and i.retired=:ret";
Department i = getFacade().findFirstByJpql(sql, m);
if (i == null) {
i = new Department();
i = new Department();
i.setName(name);
i.setInstitution(ins);
getFacade().create(i);
Expand All @@ -104,7 +104,7 @@ public Department findAndSaveDepartmentByName(String name, Institution ins) {
}
return i;
}

public Department findExistingDepartmentByName(String name, Institution ins) {
if (name == null || name.trim().equals("")) {
return null;
Expand All @@ -120,13 +120,45 @@ public Department findExistingDepartmentByName(String name, Institution ins) {
Department i = getFacade().findFirstByJpql(sql, m);
return i;
}


public DepartmentType findDepartmentType(String deptType) {
if (deptType == null || deptType.trim().isEmpty()) {
return DepartmentType.Other; // Default to 'Other' if the input is null or empty
}

String cleanedDeptType = deptType.trim().toLowerCase();

// First, try to match with enum name
for (DepartmentType type : DepartmentType.values()) {
if (type.name().equalsIgnoreCase(cleanedDeptType)) {
return type;
}
}

// Next, try to match with labels
for (DepartmentType type : DepartmentType.values()) {
if (type.getLabel().equalsIgnoreCase(cleanedDeptType)) {
return type;
}
}

// Finally, attempt partial match with labels
for (DepartmentType type : DepartmentType.values()) {
if (type.getLabel().toLowerCase().contains(cleanedDeptType)) {
return type;
}
}

// If no match found, default to 'Other'
return DepartmentType.Other;
}

public void fillItems() {
String j;
j = "select i from Department i where i.retired=false order by i.name";
items = getFacade().findByJpql(j);
}

public List<Department> getInstitutionDepatrments(Institution ins) {
List<Department> deps;
if (ins == null) {
Expand Down Expand Up @@ -287,8 +319,6 @@ public List<Department> listAllDepatrments() {
return departments;
}



public Department getDefaultDepatrment(Institution ins) {
Department dep;
if (ins == null) {
Expand Down
162 changes: 162 additions & 0 deletions src/main/java/com/divudi/bean/emr/DataUploadController.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import com.divudi.entity.Doctor;
import com.divudi.entity.inward.InwardService;
import com.divudi.java.CommonFunctions;
import com.mysql.cj.jdbc.interceptors.SessionAssociationInterceptor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import javax.inject.Named;
Expand Down Expand Up @@ -198,6 +199,7 @@ public class DataUploadController implements Serializable {
private List<Item> items;
private List<ItemFee> itemFees;
private List<Institution> collectingCentres;
private List<Department> departments;
private List<Area> areas;
private StreamedContent templateForItemWithFeeUpload;
private StreamedContent templateForCollectingCentreUpload;
Expand Down Expand Up @@ -233,6 +235,11 @@ public String navigateToCollectingCenterUpload() {
return "/admin/institutions/collecting_centre_upload?faces-redirect=true";
}

public String navigateToDepartmentUpload() {
uploadComplete = false;
return "/admin/institutions/department_upload?faces-redirect=true";
}

public void uploadPatientAreas() {
areas = new ArrayList<>();
if (file != null) {
Expand Down Expand Up @@ -878,6 +885,14 @@ public void saveStaff() {
staffToSave = new ArrayList<>();
}

public void saveDepartments() {
for (Department stf : departments) {
departmentController.save(stf);
}
JsfUtil.addSuccessMessage("Saved");
departments = new ArrayList<>();
}

private List<Item> readOpdItemsAndFeesFromExcel(InputStream inputStream) throws IOException {
Workbook workbook = new XSSFWorkbook(inputStream);
Sheet sheet = workbook.getSheetAt(0);
Expand Down Expand Up @@ -2308,6 +2323,21 @@ public void uploadCollectingCentres() {
JsfUtil.addSuccessMessage("Successfully Uploaded");
}

public void uploadDepartments() {
departments = new ArrayList<>();
if (file != null) {
try ( InputStream inputStream = file.getInputStream()) {
departments = readDepartmentFromExcel(inputStream);
} catch (IOException e) {
e.printStackTrace();
uploadComplete = false;
JsfUtil.addErrorMessage("Error in Uploading. " + e.getMessage());
}
}
uploadComplete = true;
JsfUtil.addSuccessMessage("Uploaded. Please click the save button to save.");
}

public void uploadCreditCOmpanies() {
creditCompanies = new ArrayList<>();
if (file != null) {
Expand Down Expand Up @@ -2555,6 +2585,130 @@ private List<Institution> readCollectingCentresFromExcel(InputStream inputStream
return collectingCentresList;
}

private List<Department> readDepartmentFromExcel(InputStream inputStream) throws IOException {
Workbook workbook = new XSSFWorkbook(inputStream);
Sheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.rowIterator();

List<Department> departmentList = new ArrayList<>();

// Assuming the first row contains headers, skip it
if (rowIterator.hasNext()) {
rowIterator.next();
}

while (rowIterator.hasNext()) {
Row row = rowIterator.next();

Department department;
String departmentCode = null;
String departmentName = null;
String billPrefix = null;
String departmentType = null;
String phone = null;
String email = null;
String address = null;
String institutionName = null;
Boolean active = null;

// Column A: Department Code (Required)
Cell departmentCodeCell = row.getCell(0);
if (departmentCodeCell != null && departmentCodeCell.getCellType() == CellType.STRING) {
departmentCode = departmentCodeCell.getStringCellValue();
}
if (departmentCode == null || departmentCode.trim().isEmpty()) {
continue;
}

// Column B: Department Name (Required)
Cell departmentNameCell = row.getCell(1);
if (departmentNameCell != null && departmentNameCell.getCellType() == CellType.STRING) {
departmentName = departmentNameCell.getStringCellValue();
}
if (departmentName == null || departmentName.trim().isEmpty()) {
continue;
}

// Column C: Bill Prefix (Optional)
Cell billPrefixCell = row.getCell(2);
if (billPrefixCell != null && billPrefixCell.getCellType() == CellType.STRING) {
billPrefix = billPrefixCell.getStringCellValue();
}

// Column D: Department Type (Optional)
Cell departmentTypeCell = row.getCell(3);
if (departmentTypeCell != null && departmentTypeCell.getCellType() == CellType.STRING) {
departmentType = departmentTypeCell.getStringCellValue();
}
if (departmentType == null || departmentType.trim().isEmpty()) {
departmentType = "Other";
}

// Column E: Phone (Optional)
Cell phoneCell = row.getCell(4);
if (phoneCell != null) {
if (phoneCell.getCellType() == CellType.NUMERIC) {
DecimalFormat decimalFormat = new DecimalFormat("#");
phone = decimalFormat.format(phoneCell.getNumericCellValue());
} else if (phoneCell.getCellType() == CellType.STRING) {
phone = phoneCell.getStringCellValue();
}
}

// Column F: Email (Optional)
Cell emailCell = row.getCell(5);
if (emailCell != null && emailCell.getCellType() == CellType.STRING) {
email = emailCell.getStringCellValue();
}

// Column G: Address (Optional)
Cell addressCell = row.getCell(6);
if (addressCell != null && addressCell.getCellType() == CellType.STRING) {
address = addressCell.getStringCellValue();
}

// Column H: Institution (Optional)
Cell institutionCell = row.getCell(7);
if (institutionCell != null && institutionCell.getCellType() == CellType.STRING) {
institutionName = institutionCell.getStringCellValue();
}
Institution parentInstitution = institutionController.findExistingInstitutionByName(institutionName);
if (parentInstitution == null) {
parentInstitution = sessionController.getInstitution();
}

// Column I: Active (True/False)
Cell activeCell = row.getCell(8);
if (activeCell != null && activeCell.getCellType() == CellType.BOOLEAN) {
active = activeCell.getBooleanCellValue();
}
if (active == null) {
active = false;
}

department = departmentController.findExistingDepartmentByName(departmentName, parentInstitution);
if (department == null) {
department = new Department();
department.setName(departmentName);
department.setCode(departmentCode);
department.setDepartmentCode(billPrefix);
department.setDepartmentType(departmentController.findDepartmentType(departmentType));
department.setTelephone1(phone);
department.setTelephone2(phone);
department.setEmail(email);
department.setAddress(address);
department.setInstitution(parentInstitution);
department.setActive(active);
department.setCreatedAt(new Date());
department.setCreater(sessionController.getLoggedUser());
}

departmentList.add(department);
}

return departmentList;
}

private List<Institution> readCreditCOmpanyFromExcel(InputStream inputStream) throws IOException {
Workbook workbook = new XSSFWorkbook(inputStream);
Sheet sheet = workbook.getSheetAt(0);
Expand Down Expand Up @@ -4531,4 +4685,12 @@ public void setDepartment(Department department) {
this.department = department;
}

public List<Department> getDepartments() {
return departments;
}

public void setDepartments(List<Department> departments) {
this.departments = departments;
}

}
40 changes: 26 additions & 14 deletions src/main/java/com/divudi/data/DepartmentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,36 @@
package com.divudi.data;

/**
* @author Buddhika
* Author: Buddhika
*/
public enum DepartmentType {
Clinical("Clinical"),
NonClinical("Non-Clinical"),
Pharmacy("Pharmacy"),
Lab("Lab"),
Channelling("Channelling"),
Opd("Out Patient Department (OPD)"),
Inward("Inward"),
Theatre("Theatre"),
Etu("Emergency Treatment Unit (ETU)"),
CollectingCentre("Collecting Centre"),
Store("Store"),
Inventry("Inventory"),
Kitchen("Kitchen"),
Optician("Optician"),
Counter("Counter"),
Cashier("Cashier"),
Office("Office"),
Ict("Information and Communication Technology (ICT)"),
Other("Other");

Pharmacy,
Lab,
Channelling,
Store,
Theatre,
Kitchen,
Opd,
Inventry,
Counter,
Inward,
Optician,
Other;
private final String label;

DepartmentType(String label) {
this.label = label;
}

public String getLabel() {
return this.toString();
return label;
}
}
Loading

0 comments on commit 3152531

Please sign in to comment.