forked from openmrs/openmrs-core
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add delete/purge for program states in the workflow
- Loading branch information
1 parent
fe98f3a
commit c7aa668
Showing
8 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -101,6 +101,9 @@ public class PrivilegeConstants { | |
@AddOnStartup(description = "Able to get which programs that patients are in") | ||
public static final String GET_PATIENT_PROGRAMS = "Get Patient Programs"; | ||
|
||
@AddOnStartup(description = "Able to delete state from the system") | ||
This comment has been minimized.
Sorry, something went wrong. |
||
public static final String DELETE_PROGRAMWORKFLOWSTATE = "Delete ProgramWorkflowState"; | ||
This comment has been minimized.
Sorry, something went wrong.
dkayiwa
|
||
|
||
@AddOnStartup(description = "Able to get global properties on the administration screen") | ||
public static final String GET_GLOBAL_PROPERTIES = "Get Global Properties"; | ||
|
||
|
This file contains 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 |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import org.apache.commons.logging.LogFactory; | ||
import org.openmrs.ProgramWorkflow; | ||
import org.openmrs.ProgramWorkflowState; | ||
import org.openmrs.api.APIException; | ||
import org.openmrs.api.ProgramWorkflowService; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.web.WebConstants; | ||
|
@@ -35,6 +36,7 @@ | |
import org.springframework.web.servlet.ModelAndView; | ||
import org.springframework.web.servlet.mvc.SimpleFormController; | ||
import org.springframework.web.servlet.view.RedirectView; | ||
import org.springframework.dao.DataIntegrityViolationException; | ||
|
||
public class WorkflowFormController extends SimpleFormController { | ||
|
||
|
@@ -85,12 +87,46 @@ protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse | |
log.debug("about to save " + obj); | ||
|
||
HttpSession httpSession = request.getSession(); | ||
ProgramWorkflowService pwsr = Context.getProgramWorkflowService(); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
String view = getFormView(); | ||
|
||
if (Context.isAuthenticated()) { | ||
ProgramWorkflow wf = (ProgramWorkflow) obj; | ||
|
||
if (request.getParameter("delete") != null) { | ||
String detstatesStr = request.getParameter("deletedStates"); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
for (StringTokenizer st = new StringTokenizer(detstatesStr, "|"); st.hasMoreTokens();) { | ||
String str = st.nextToken(); | ||
String[] tmp = str.split(","); | ||
Integer conceptId = Integer.valueOf(tmp[0]); | ||
ProgramWorkflowState pws = null; | ||
for (ProgramWorkflowState s : wf.getStates()) { | ||
if (s.getConcept().getConceptId().equals(conceptId)) { | ||
pws = s; | ||
break; | ||
} | ||
} | ||
|
||
try { | ||
wf.removeState(pws); | ||
pwsr.deleteProgramWorkflowState(pws); | ||
httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "ProgramWorkflowState.delete.success"); | ||
} | ||
catch (DataIntegrityViolationException e) { | ||
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.object.inuse.cannot.delete"); | ||
This comment has been minimized.
Sorry, something went wrong.
dkayiwa
|
||
} | ||
catch (APIException e) { | ||
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.general: " | ||
+ e.getLocalizedMessage()); | ||
} | ||
view = getSuccessView(); | ||
return new ModelAndView(new RedirectView(view)); | ||
|
||
} | ||
|
||
} | ||
|
||
// get list of states, and update the command object | ||
String statesStr = request.getParameter("newStates"); | ||
// This is a brute-force algorithm, but n will be small. | ||
|
This file contains 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 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
Can we remove this TODO?