Skip to content

Commit

Permalink
Signed-off-by: Dr M H B Ariyaratne <[email protected]>
Browse files Browse the repository at this point in the history
  • Loading branch information
buddhika75 committed Aug 30, 2023
1 parent 6d2839e commit f6a5d87
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 9 deletions.
108 changes: 102 additions & 6 deletions src/main/java/lk/gov/health/phsp/bean/LetterController.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ public void processDailyCounts() {
});
}



public String removeUpload() {
if (removingUpload == null) {
JsfUtil.addErrorMessage("Nothing to remove");
Expand Down Expand Up @@ -852,6 +850,37 @@ public String forwardOrCopyTo() {
return toLetterView();
}

public String forwardOrCopyToForUnitLetter() {
if (webUserCopy == null) {
JsfUtil.addErrorMessage("Select a user to transfer ownership");
return "";
}
if (selected == null) {
JsfUtil.addErrorMessage("Select a file");
return "";
}
save(selected);
DocumentHistory docHx = new DocumentHistory();
docHx.setHistoryType(HistoryType.Letter_Copy_or_Forward);
docHx.setDocument(selected);
docHx.setFromUser(selected.getCurrentOwner());
docHx.setToInsOrUser(webUserCopy);
docHx.setComments(comments);
docHx.setItem(minute);
docHx.setInstitution(webUserController.getLoggedInstitution());
saveDocumentHx(docHx);

selected.setCompleted(false);
documentFacade.edit(selected);

minute = null;
webUserCopy = null;
comments = "";

JsfUtil.addSuccessMessage("Letter copied/forwarded successfully");
return "/document/unit_letter_view";
}

public String forwardOrCopyToAndNew() {
if (webUserCopy == null) {
JsfUtil.addErrorMessage("Select a user to transfer ownership");
Expand Down Expand Up @@ -884,6 +913,38 @@ public String forwardOrCopyToAndNew() {
return menuController.toLetterAddNewReceivedLetter();
}

public String forwardOrCopyToAndNewUnitLetter() {
if (webUserCopy == null) {
JsfUtil.addErrorMessage("Select a user to transfer ownership");
return "";
}
if (selected == null) {
JsfUtil.addErrorMessage("Select a file");
return "";
}

DocumentHistory docHx = new DocumentHistory();
docHx.setHistoryType(HistoryType.Letter_Copy_or_Forward);
docHx.setDocument(selected);
docHx.setFromUser(selected.getCurrentOwner());
docHx.setToInsOrUser(webUserCopy);
docHx.setComments(comments);
docHx.setItem(minute);
docHx.setInstitution(webUserController.getLoggedInstitution());

saveDocumentHx(docHx);

selected.setCompleted(false);
documentFacade.edit(selected);

minute = null;
webUserCopy = null;
comments = "";

JsfUtil.addSuccessMessage("Letter copied/forwarded successfully");
return menuController.toUnitLetterAdd();
}

public String recordActionTaken() {
if (comments == null || comments.trim().equals("")) {
JsfUtil.addErrorMessage("Enter details of the action.");
Expand Down Expand Up @@ -951,7 +1012,7 @@ public String unitLetterAddSaveAndView() {

return "/document/unit_letter_view";
}

public String unitLetterEditSaveAndView() {
if (selected == null) {
JsfUtil.addErrorMessage("Not selected");
Expand Down Expand Up @@ -1153,7 +1214,7 @@ public String unitLetterEditSaveAndNew() {

return menuController.toUnitLetterAdd();
}

public String unitLetterAddSaveAndNew() {
if (selected == null) {
JsfUtil.addErrorMessage("Nothing to save");
Expand Down Expand Up @@ -1693,6 +1754,41 @@ public String toInstitutionReceivedLetterView() {
selectedUploads = uploadFacade.findByJpql(j, m);
return "/document/letter_view";
}


public String toInstitutionReceivedUnitLetterView() {
System.out.println("toInstitutionReceivedLetterView");
String j = "select h "
+ " from DocumentHistory h "
+ " where h.retired=false "
+ " and h.document=:doc "
+ " and (h.institution=:ins or h.fromInstitution=:ins or h.toInstitution=:ins) "
+ " order by h.id desc";
Map m = new HashMap();
m.put("doc", selected);
m.put("ins", webUserController.getLoggedInstitution());
System.out.println("m = " + m);
System.out.println("j = " + j);
selectedDocumentHistories = documentHxFacade.findByJpql(j, m);
System.out.println("selectedDocumentHistories = " + selectedDocumentHistories.size());

j = "select h "
+ " from Upload h "
+ " where h.retired=false "
+ " and h.document=:doc "
+ " order by h.id";
m = new HashMap();
m.put("doc", selected);
// m.put("ins", webUserController.getLoggedInstitution());
//TODO: Need to allow only original upload
// if (selected.getFromInstitution() != null) {
// m.put("fins", selected.getFromInstitution());
// } else {
// m.put("fins", webUserController.getLoggedInstitution());
// }
selectedUploads = uploadFacade.findByJpql(j, m);
return "/document/unit_letter_view";
}

public String toMailDepartmentReceivedLetterView() {
System.out.println("toMailDepartmentReceivedLetterView");
Expand Down Expand Up @@ -1784,9 +1880,9 @@ public String toLetterView() {
return toMailDepartmentReceivedLetterView();
case Other:
case Received_by_institution:
return toInstitutionReceivedLetterView();
return toInstitutionReceivedUnitLetterView();
}
return toInstitutionReceivedLetterView();
return toInstitutionReceivedUnitLetterView();
}

public String toLetterViewFromDocumentHistory() {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/lk/gov/health/phsp/bean/MenuController.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public String toSearch() {
}

public String toAdministrationIndex() {
System.out.println("toAdministrationIndex");
boolean privileged = false;
for (UserPrivilege up : webUserController.getLoggedUserPrivileges()) {
if (up.getPrivilege() == Privilege.Institution_Administration) {
Expand All @@ -244,10 +245,12 @@ public String toAdministrationIndex() {
privileged = true;
}
}
System.out.println("privileged = " + privileged);
if (!privileged) {
JsfUtil.addErrorMessage("You are NOT autherized");
return "";
}
System.out.println("webUserController.getLoggedUser().getWebUserRoleLevel() = " + webUserController.getLoggedUser().getWebUserRoleLevel());
switch (webUserController.getLoggedUser().getWebUserRoleLevel()) {
case National:
return "/national/admin/index";
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/lk/gov/health/phsp/bean/WebUserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@ List<Privilege> getInitialPrivileges(WebUserRole role) {
}
switch (role) {
case Institutional_Administrator:
wups.add(Privilege.Institution_Administration);
wups.add(Privilege.Manage_Institution_Users);
wups.add(Privilege.Manage_Authorised_Institutions);
case Institutional_Super_User:
Expand All @@ -1037,6 +1038,13 @@ List<Privilege> getInitialPrivileges(WebUserRole role) {
wups.add(Privilege.User);
wups.add(Privilege.Search_File);
wups.add(Privilege.Retire_File);
wups.add(Privilege.Add_Actions_To_Letter);
wups.add(Privilege.Add_Letter);
wups.add(Privilege.Assign_Letter);
wups.add(Privilege.Edit_Letter);
wups.add(Privilege.Institutional_Mail_Management);
wups.add(Privilege.Receive_File);
wups.add(Privilege.Retire_Letter);
break;
case System_Administrator:
case Super_User:
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/lk/gov/health/phsp/entity/WebUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public WebUserRole getWebUserRole() {
public void setWebUserRole(WebUserRole webUserRole) {
this.webUserRole = webUserRole;
}

@Override
public Boolean getInstitute() {
return false;
Expand Down Expand Up @@ -492,6 +492,11 @@ public WebUserRoleLevel getWebUserRoleLevel() {
case Institutional_User:
webUserRoleLevel = WebUserRoleLevel.Institutional;
break;
case Postal_Branch_Administrator:
case Postal_Branch_Super_User:
case Postal_Branch_User:
webUserRoleLevel = WebUserRoleLevel.Institutional;
break;
}
}
return webUserRoleLevel;
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/document/unit_letter_view.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
value="#{letterController.comments}" ></h:inputTextarea>

<h:commandButton class="form-control btn btn-warning" value="Send &amp; New"
action="#{letterController.forwardOrCopyToAndNew()}" ></h:commandButton>
action="#{letterController.forwardOrCopyToAndNewUnitLetter()}" ></h:commandButton>
<h:commandButton class="form-control btn btn-primary" value="Send"
action="#{letterController.forwardOrCopyTo()}" ></h:commandButton>
</p:panelGrid>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/institution/admin/index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<div class="card border border-light">
<div class="card-header bg-white fw-bold text-secondary fs-5 my-2">
<h:outputLabel value="System Administration"></h:outputLabel>
<h:outputLabel value="Institution Administration"></h:outputLabel>
</div>
<div class="card-body container-fluid">
<div class="row">
Expand Down

0 comments on commit f6a5d87

Please sign in to comment.