-
Notifications
You must be signed in to change notification settings - Fork 126
Implement three-tier discharge system: clinical, room, and hospital discharge #19658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
11cda0d
Implement three-tier discharge system: clinical, room, and hospital d…
buddhika75 90225ad
Fix compilation error: use PatientEncounterFacade for encounter updat…
buddhika75 fd9a04d
Address CodeRabbit review comments on three-tier discharge system
buddhika75 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
228 changes: 228 additions & 0 deletions
228
src/main/java/com/divudi/bean/clinical/DischargeConditionController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,228 @@ | ||
| /* | ||
| * Open Hospital Management Information System | ||
| * | ||
| * Dr M H B Ariyaratne | ||
| * Acting Consultant (Health Informatics) | ||
| */ | ||
| package com.divudi.bean.clinical; | ||
|
|
||
| import com.divudi.bean.common.SessionController; | ||
| import com.divudi.core.util.JsfUtil; | ||
| import com.divudi.core.data.SymanticType; | ||
| import com.divudi.core.entity.clinical.ClinicalEntity; | ||
| import com.divudi.core.facade.ClinicalEntityFacade; | ||
| import java.io.Serializable; | ||
| import java.util.ArrayList; | ||
| import java.util.Date; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import javax.ejb.EJB; | ||
| import javax.enterprise.context.SessionScoped; | ||
| import javax.faces.component.UIComponent; | ||
| import javax.faces.context.FacesContext; | ||
| import javax.faces.convert.Converter; | ||
| import javax.faces.convert.FacesConverter; | ||
| import javax.inject.Inject; | ||
| import javax.inject.Named; | ||
| import javax.servlet.http.HttpServletResponse; | ||
| import org.apache.poi.ss.usermodel.Row; | ||
| import org.apache.poi.ss.usermodel.Sheet; | ||
| import org.apache.poi.ss.usermodel.Workbook; | ||
| import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||
|
|
||
| /** | ||
| * Manages configurable discharge condition values (e.g. Stable, DAMA, Referred) | ||
| * used in the clinical discharge workflow. | ||
| * | ||
| * @author Dr. M. H. B. Ariyaratne | ||
| */ | ||
| @Named | ||
| @SessionScoped | ||
| public class DischargeConditionController implements Serializable { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| @Inject | ||
| SessionController sessionController; | ||
|
|
||
| @EJB | ||
| private ClinicalEntityFacade ejbFacade; | ||
|
|
||
| private ClinicalEntity current; | ||
| private List<ClinicalEntity> items = null; | ||
| private String selectText = ""; | ||
|
|
||
| public DischargeConditionController() { | ||
| } | ||
|
|
||
| public void prepareAdd() { | ||
| current = new ClinicalEntity(); | ||
| current.setSymanticType(SymanticType.Discharge_Condition); | ||
| } | ||
|
|
||
| public void saveSelected() { | ||
| current.setSymanticType(SymanticType.Discharge_Condition); | ||
| if (getCurrent().getId() != null && getCurrent().getId() > 0) { | ||
| getFacade().edit(current); | ||
| JsfUtil.addSuccessMessage("Updated"); | ||
| } else { | ||
| current.setCreatedAt(new Date()); | ||
| current.setCreater(getSessionController().getLoggedUser()); | ||
| getFacade().create(current); | ||
| JsfUtil.addSuccessMessage("Saved"); | ||
| } | ||
| recreateModel(); | ||
| getItems(); | ||
| } | ||
|
|
||
| public void delete() { | ||
| if (current != null) { | ||
| current.setRetired(true); | ||
| current.setRetiredAt(new Date()); | ||
| current.setRetirer(getSessionController().getLoggedUser()); | ||
| getFacade().edit(current); | ||
| JsfUtil.addSuccessMessage("Deleted Successfully"); | ||
| } else { | ||
| JsfUtil.addErrorMessage("Nothing to Delete"); | ||
| } | ||
| recreateModel(); | ||
| getItems(); | ||
| current = null; | ||
| getCurrent(); | ||
| } | ||
|
|
||
| public List<ClinicalEntity> getItems() { | ||
| if (items == null) { | ||
| Map m = new HashMap(); | ||
| m.put("t", SymanticType.Discharge_Condition); | ||
| String sql = "select c from ClinicalEntity c where c.retired=false and c.symanticType=:t order by c.name"; | ||
| items = getFacade().findByJpql(sql, m); | ||
| } | ||
| return items; | ||
| } | ||
|
|
||
| public List<ClinicalEntity> completeDischargeConditions(String qry) { | ||
| if (qry == null || qry.trim().isEmpty()) { | ||
| return new ArrayList<>(); | ||
| } | ||
| List<ClinicalEntity> c; | ||
| Map m = new HashMap(); | ||
| m.put("t", SymanticType.Discharge_Condition); | ||
| m.put("n", "%" + qry.toUpperCase() + "%"); | ||
| String sql = "select c from ClinicalEntity c where c.retired=false and upper(c.name) like :n and c.symanticType=:t order by c.name"; | ||
| c = getFacade().findByJpql(sql, m, 10); | ||
| if (c == null) { | ||
| c = new ArrayList<>(); | ||
| } | ||
| return c; | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public void downloadAsExcel() { | ||
| getItems(); | ||
| FacesContext context = FacesContext.getCurrentInstance(); | ||
| try (Workbook workbook = new XSSFWorkbook()) { | ||
| Sheet sheet = workbook.createSheet("Discharge Conditions"); | ||
|
|
||
| Row headerRow = sheet.createRow(0); | ||
| headerRow.createCell(0).setCellValue("No"); | ||
| headerRow.createCell(1).setCellValue("Name"); | ||
| headerRow.createCell(2).setCellValue("Code"); | ||
| headerRow.createCell(3).setCellValue("Description"); | ||
|
|
||
| int rowNum = 1; | ||
| for (ClinicalEntity item : items) { | ||
| Row row = sheet.createRow(rowNum); | ||
| row.createCell(0).setCellValue(rowNum); | ||
| row.createCell(1).setCellValue(item.getName()); | ||
| row.createCell(2).setCellValue(item.getCode()); | ||
| row.createCell(3).setCellValue(item.getDescreption()); | ||
| rowNum++; | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); | ||
| response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); | ||
| response.setHeader("Content-Disposition", "attachment; filename=\"discharge_conditions.xlsx\""); | ||
|
|
||
| workbook.write(response.getOutputStream()); | ||
| context.responseComplete(); | ||
| } catch (Exception e) { | ||
| JsfUtil.addErrorMessage("Error generating Excel file: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private void recreateModel() { | ||
| items = null; | ||
| } | ||
|
|
||
| private ClinicalEntityFacade getFacade() { | ||
| return ejbFacade; | ||
| } | ||
|
|
||
| public ClinicalEntity getCurrent() { | ||
| if (current == null) { | ||
| current = new ClinicalEntity(); | ||
| } | ||
| return current; | ||
| } | ||
|
|
||
| public void setCurrent(ClinicalEntity current) { | ||
| this.current = current; | ||
| } | ||
|
|
||
| public String getSelectText() { | ||
| return selectText; | ||
| } | ||
|
|
||
| public void setSelectText(String selectText) { | ||
| this.selectText = selectText; | ||
| } | ||
|
|
||
| public SessionController getSessionController() { | ||
| return sessionController; | ||
| } | ||
|
|
||
| public void setSessionController(SessionController sessionController) { | ||
| this.sessionController = sessionController; | ||
| } | ||
|
|
||
| public ClinicalEntityFacade getEjbFacade() { | ||
| return ejbFacade; | ||
| } | ||
|
|
||
| public void setEjbFacade(ClinicalEntityFacade ejbFacade) { | ||
| this.ejbFacade = ejbFacade; | ||
| } | ||
|
|
||
| @FacesConverter("dischargeConditionConverter") | ||
| public static class DischargeConditionConverter implements Converter { | ||
|
|
||
| @Override | ||
| public Object getAsObject(FacesContext facesContext, UIComponent component, String value) { | ||
| if (value == null || value.length() == 0) { | ||
| return null; | ||
| } | ||
| try { | ||
| DischargeConditionController controller = (DischargeConditionController) facesContext.getApplication() | ||
| .getELResolver().getValue(facesContext.getELContext(), null, "dischargeConditionController"); | ||
| return controller.getEjbFacade().find(Long.valueOf(value)); | ||
| } catch (NumberFormatException e) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getAsString(FacesContext facesContext, UIComponent component, Object object) { | ||
| if (object == null) { | ||
| return null; | ||
| } | ||
| if (object instanceof ClinicalEntity) { | ||
| ClinicalEntity o = (ClinicalEntity) object; | ||
| return String.valueOf(o.getId()); | ||
| } else { | ||
| throw new IllegalArgumentException("object " + object + " is of type " | ||
| + object.getClass().getName() + "; expected type: ClinicalEntity"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.