Skip to content

Commit

Permalink
Issue #41: Fix add provider type
Browse files Browse the repository at this point in the history
Issue #41: Fix or remove provider type creation/deletion
  • Loading branch information
Frank Duncan committed Jul 23, 2018
1 parent 48dbb33 commit bb798f9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public String create(ProviderType providerType) throws PortalServiceException {
}

try {
if (providerType.getCode() == null) {
if (Util.isBlank(providerType.getCode())) {
providerType.setCode(generateCode(getLookupService().findAllLookups(ProviderType.class)));
}
getEm().persist(providerType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,23 @@
Functions
</div>
<h1>Functions</h1>

<c:if test="${not empty requestScope['flash_error']}">
<div class="clear"></div>
<div class="errorInfo formErrorMarker" style="display: block;">
<h3>Please correct the following errors:</h3>
<p class="bindingError"><c:out value="${requestScope['flash_error']}"></c:out></p>
<div class="tl"></div>
<div class="tr"></div>
<div class="bl"></div>
<div class="br"></div>
</div>
<div class="clear"></div>
</c:if>
<div class="tabSection">
<%@include file="/WEB-INF/pages/provider/enrollment/steps/errors.jsp" %>
</div>
<div class="tabSection functionTab" id="enrollmentSection">
<c:set var="functionsServiceActiveMenuProviderTypes" value="1"/>
<h:handlebars template="admin/includes/functions_service_nav" context="${pageContext}" />


<div class="tabContent" id="tabProviderTypes">
<form:form id="providerTypeForm" modelAttribute="providerType" action="${ctx}/admin/createProviderType" method="post">
<div id="addProviderPanel">
<div class="sideBorder"><h3>Add Provider Type</h3></div>
<%@ include file="/WEB-INF/pages/admin/includes/service_admin_create_edit_provider_type_common.jsp" %>
</div>
</form:form>
<!--/ #addProviderPanel -->
<div class="sideBorder"><h3>Add Provider Type</h3></div>
<c:set var="editCreateProviderTypeFormAction" value="${ctx}/admin/createProviderType" />
<%@ include file="/WEB-INF/pages/admin/includes/service_admin_create_edit_provider_type_common.jsp" %>
</div>
</div>
</div>
</div>
<!-- /#mainContent -->

</div>
<h:handlebars template="includes/footer" context="${pageContext}"/>
</div>
<!-- /#wrapper -->
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package gov.medicaid.controllers.admin;

import gov.medicaid.controllers.ControllerHelper;
import gov.medicaid.entities.AgreementDocument;
import gov.medicaid.entities.AgreementDocumentSearchCriteria;
import gov.medicaid.entities.AgreementDocumentType;
import gov.medicaid.entities.LicenseType;
import gov.medicaid.entities.ProviderType;
import gov.medicaid.entities.ProviderTypeSearchCriteria;
Expand Down Expand Up @@ -178,25 +176,10 @@ public ModelAndView get(@RequestParam("providerTypeId") String providerTypeId) t
*/
@RequestMapping(value = "/admin/beginCreateProviderType", method = RequestMethod.GET)
public ModelAndView beginCreate() throws PortalServiceException {
// Retrieve agreements
AgreementDocumentSearchCriteria criteria = new AgreementDocumentSearchCriteria();
criteria.setPageNumber(1);
criteria.setPageSize(-1);
criteria.setType(AgreementDocumentType.AGREEMENT);

List<AgreementDocument> agreements = agreementDocumentService.search(criteria).getItems();
// Retrieve addendums
criteria = new AgreementDocumentSearchCriteria();
criteria.setPageNumber(1);
criteria.setPageSize(-1);
criteria.setType(AgreementDocumentType.ADDENDUM);

List<AgreementDocument> addendums = agreementDocumentService.search(criteria).getItems();
ModelAndView model = new ModelAndView("admin/service_admin_create_provider_type");
model.addObject("agreements", agreements);
model.addObject("addendums", addendums);
model.addObject("providerType", new ProviderType());
return model;
return addCommonElements(
new ModelAndView("admin/service_admin_create_provider_type"),
new ProviderType()
);
}

/**
Expand All @@ -213,7 +196,9 @@ public ModelAndView beginCreate() throws PortalServiceException {
public ModelAndView beginEdit(@RequestParam("providerTypeId") String providerTypeId) throws PortalServiceException {
ProviderType providerType = providerTypeService.get(providerTypeId);

return edit(providerType);
return addCommonElements(
new ModelAndView("admin/service_admin_edit_provider_type"),
providerType);
}

/**
Expand All @@ -232,23 +217,36 @@ public ModelAndView create(@ModelAttribute("providerType") ProviderType provider
throws PortalServiceException {
boolean blank = Util.isBlank(providerType.getDescription());
boolean exists = getLookupService().findLookupByDescription(ProviderType.class, providerType.getDescription()) != null;

long[] agreementIds = ServletRequestUtils.getLongParameters(request, "providerAgreements");
String[] licenseIds = ServletRequestUtils.getStringParameters(request, "providerLicenses");

if (!blank && !exists) {
providerTypeService.create(providerType);

// Retrieve
providerType = providerTypeService.get(providerType.getCode());

providerTypeService.updateProviderTypeAgreementSettings(providerType, agreementIds);
providerTypeService.updateProviderTypeLicenseSettings(providerType, licenseIds);

return view(providerType);
} else {
FormError error = new FormError();
error.setFieldId("placeholder");

ModelAndView mv = beginCreate();
if (blank) {
ControllerHelper.addError("Please specify a provider type.");
error.setMessage("Please specify a provider type.");
} else if (exists) {
ControllerHelper.addError("Specified provider type already exists.");
error.setMessage("Specified provider type already exists.");
}
mv.addObject("providerType", providerType);
return mv;

return addCommonElements(
new ModelAndView("admin/service_admin_create_provider_type"),
providerType,
agreementIds,
licenseIds,
Collections.singletonList(error));
}
}

Expand Down Expand Up @@ -280,7 +278,8 @@ public ModelAndView edit(@ModelAttribute("providerType") ProviderType providerTy
error.setFieldId("placeholder");
error.setMessage("Cannot have a duplicate description: " + providerType.getDescription());

return edit(
return addCommonElements(
new ModelAndView("admin/service_admin_edit_provider_type"),
providerType,
agreementIds,
licenseIds,
Expand Down Expand Up @@ -379,22 +378,28 @@ private ModelAndView view(ProviderType providerType) {
return model;
}

private ModelAndView edit(ProviderType providerType) throws PortalServiceException {
return edit(
private ModelAndView addCommonElements(ModelAndView mv, ProviderType providerType) throws PortalServiceException {
return addCommonElements(
mv,
providerType,
providerType.getAgreementDocuments()
.stream()
.mapToLong(AgreementDocument::getId)
.toArray(),
providerType.getLicenseTypes()
.stream()
.map(LicenseType::getCode)
.toArray(String[]::new),
providerType.getAgreementDocuments() == null ?
new long[0] :
providerType.getAgreementDocuments()
.stream()
.mapToLong(AgreementDocument::getId)
.toArray(),
providerType.getLicenseTypes() == null ?
new String[0] :
providerType.getLicenseTypes()
.stream()
.map(LicenseType::getCode)
.toArray(String[]::new),
null
);
}

private ModelAndView edit(
private ModelAndView addCommonElements(
ModelAndView mv,
ProviderType providerType,
long[] selectedAgreementIds,
String[] selectedLicenseCodes,
Expand All @@ -417,16 +422,15 @@ private ModelAndView edit(
}
}
}
ModelAndView model = new ModelAndView("admin/service_admin_edit_provider_type");
model.addObject("providerType", providerType);
model.addObject("selectedAgreements", selectedAgreements);
model.addObject("remainingAgreements", remainingAgreements);
mv.addObject("providerType", providerType);
mv.addObject("selectedAgreements", selectedAgreements);
mv.addObject("remainingAgreements", remainingAgreements);

List<LicenseType> allLicenseTypes = lookupService.findAllLookups(LicenseType.class);

model.addObject("selectedLicenseCodes", selectedLicenseCodes);
model.addObject("allLicenseTypes", allLicenseTypes);
model.addObject("errors", errors);
return model;
mv.addObject("selectedLicenseCodes", selectedLicenseCodes);
mv.addObject("allLicenseTypes", allLicenseTypes);
mv.addObject("errors", errors);
return mv;
}
}

0 comments on commit bb798f9

Please sign in to comment.