Skip to content

Commit

Permalink
Merge pull request #983 from SolutionGuidance/41-Fix-Provider-Types-I…
Browse files Browse the repository at this point in the history
…nterface

Fix 41: Create/Delete Provider Types
  • Loading branch information
Frank Duncan authored Aug 29, 2018
2 parents a2b28d6 + 6bdf723 commit 06698f1
Show file tree
Hide file tree
Showing 29 changed files with 912 additions and 381 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@

package gov.medicaid.services.impl;

import gov.medicaid.domain.model.ApplicantType;
import gov.medicaid.domain.model.ProviderInformationType;
import gov.medicaid.entities.AgreementDocument;
import gov.medicaid.entities.BeneficialOwnerType;
import gov.medicaid.entities.EntityStructureType;
import gov.medicaid.entities.LookupEntity;
import gov.medicaid.entities.ProviderType;
import gov.medicaid.entities.dto.ViewStatics;
import gov.medicaid.services.LookupService;
import gov.medicaid.services.util.Util;
Expand All @@ -33,14 +29,10 @@
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.EntityGraph;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* Defines the UI related services.
Expand All @@ -66,65 +58,6 @@ public class LookupServiceBean implements LookupService {
public LookupServiceBean() {
}

public List<ProviderType> getAllProviderTypes() {
return em.createQuery(
"FROM ProviderType",
ProviderType.class
).getResultList();
}

/**
* Retrieves the provider types filtered by applicant type.
*
* @param applicantType
* individual or organizations
* @return the filtered provider types
*/
public List<ProviderType> getProviderTypes(ApplicantType applicantType) {
return em.createQuery(
"FROM ProviderType WHERE applicantType = :type",
ProviderType.class
).setParameter(
"type",
applicantType
).getResultList();
}

@Override
public ProviderType getProviderTypeWithAgreementDocuments(
ProviderInformationType providerInformationType
) {
return getProviderTypeWithNamedEntityGraph(
providerInformationType,
"ProviderType with AgreementDocuments"
);
}

@Override
public ProviderType getProviderTypeWithLicenseTypes(
ProviderInformationType providerInformationType
) {
return getProviderTypeWithNamedEntityGraph(
providerInformationType,
"ProviderType with LicenseTypes"
);
}

private ProviderType getProviderTypeWithNamedEntityGraph(
ProviderInformationType providerInformationType,
String entityGraphName
) {
EntityGraph graph = em.getEntityGraph(entityGraphName);
return em.createQuery(
"FROM ProviderType WHERE description = :description",
ProviderType.class
).setParameter(
"description", providerInformationType.getProviderType()
).setHint(
"javax.persistence.loadgraph", graph
).getSingleResult();
}

/**
* Retrieves the lookup with the given description.
*
Expand Down Expand Up @@ -254,31 +187,4 @@ public List<BeneficialOwnerType> findBeneficialOwnerTypes(String entityType) {
}
return results;
}

@Override
public void updateProviderTypeAgreementSettings(
ProviderType providerType,
long[] agreementIds
) {
providerType.setAgreementDocuments(
getAgreementDocuments(agreementIds)
);
em.merge(providerType);
}

private List<AgreementDocument> getAgreementDocuments(long[] agreementIds) {
if (agreementIds.length == 0) {
return new ArrayList<>();
} else {
return em.createQuery(
"FROM AgreementDocument WHERE id IN :ids",
AgreementDocument.class
).setParameter(
"ids",
Arrays.stream(agreementIds)
.boxed()
.collect(Collectors.toList())
).getResultList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package gov.medicaid.services.impl;

import gov.medicaid.domain.model.ApplicantType;
import gov.medicaid.entities.AgreementDocument;
import gov.medicaid.entities.LicenseType;
import gov.medicaid.entities.ProviderType;
import gov.medicaid.entities.ProviderTypeSearchCriteria;
import gov.medicaid.entities.SearchResult;
Expand All @@ -30,10 +33,15 @@
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.EntityGraph;
import javax.persistence.PersistenceException;
import javax.persistence.Query;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

/**
* This class provides an implementation of the <code>ProviderTypeDAO</code> as a local EJB.
Expand Down Expand Up @@ -72,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 Expand Up @@ -152,21 +160,43 @@ public ProviderType get(String id) throws PortalServiceException {
return getEm().find(
ProviderType.class,
id,
hintEntityGraph("ProviderType with AgreementDocuments")
hintEntityGraph("ProviderType with AgreementDocuments and LicenseTypes")
);
} catch (PersistenceException e) {
throw new PortalServiceException("Could not complete database operation.", e);
}
}

/**
* This method gets a provider type by its description. If not found, returns null.
*
* @param description - the description of the provider type to retrieve
* @return - the requested provider type, null if not found
*
* @throws PortalServiceException - If there are any errors during the execution of this method
*/
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public ProviderType getByDescription(String description) {
EntityGraph graph = getEm().getEntityGraph(
"ProviderType with AgreementDocuments and LicenseTypes"
);
return getEm().createQuery(
"FROM ProviderType WHERE description = :description",
ProviderType.class
).setParameter("description", description)
.setHint("javax.persistence.loadgraph", graph)
.getSingleResult();
}

/**
* This method deletes the provider type with the given ID.
*
* @param id - the ID of the provider type to delete
* @throws PortalServiceException - If there are any errors during the execution of this method
*/
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void delete(long id) throws PortalServiceException {
@Override
public void delete(String id) throws PortalServiceException {
try {
ProviderType obj = getEm().find(ProviderType.class, id);
if (obj == null) {
Expand Down Expand Up @@ -226,6 +256,96 @@ public SearchResult<ProviderType> search(ProviderTypeSearchCriteria criteria) th
return results;
}

public List<ProviderType> getAllProviderTypes() {
return getEm().createQuery(
"FROM ProviderType",
ProviderType.class
).getResultList();
}

/**
* Retrieves the provider types filtered by applicant type.
*
* @param applicantType
* individual or organizations
* @return the filtered provider types
*/
public List<ProviderType> getProviderTypes(ApplicantType applicantType) {
return getEm().createQuery(
"FROM ProviderType WHERE applicantType = :type",
ProviderType.class
).setParameter(
"type",
applicantType
).getResultList();
}

@Override
public void updateProviderTypeAgreementSettings(
ProviderType providerType,
long[] agreementIds
) {
providerType.setAgreementDocuments(
new HashSet<>(getAgreementDocuments(agreementIds))
);
getEm().merge(providerType);
}

@Override
public void updateProviderTypeLicenseSettings(
ProviderType providerType,
String[] licenseCodes
) {
providerType.setLicenseTypes(
new HashSet<>(getLicenseTypes(licenseCodes))
);
getEm().merge(providerType);
}

@Override
public void updateProviderTypeCanDelete(ProviderType providerType) {
providerType.setCanDelete(
0 == ((Number) (getEm().createQuery("SELECT count(*) FROM Entity WHERE providerType = :providerType")
.setParameter("providerType", providerType)
.getSingleResult()))
.intValue() &&
0 == ((Number) (getEm().createQuery("SELECT count(*) FROM ProviderTypeSetting WHERE providerTypeCode = :providerTypeCode")
.setParameter("providerTypeCode", providerType.getCode())
.getSingleResult()))
.intValue()
);
}

private List<AgreementDocument> getAgreementDocuments(long[] agreementIds) {
if (agreementIds.length == 0) {
return new ArrayList<>();
} else {
return getEm().createQuery(
"FROM AgreementDocument WHERE id IN :ids",
AgreementDocument.class
).setParameter(
"ids",
Arrays.stream(agreementIds)
.boxed()
.collect(Collectors.toList())
).getResultList();
}
}

private List<LicenseType> getLicenseTypes(String[] licenseCodes) {
if (licenseCodes.length == 0) {
return new ArrayList<>();
} else {
return getEm().createQuery(
"FROM LicenseType WHERE code IN :codes",
LicenseType.class
).setParameter(
"codes",
Arrays.asList(licenseCodes)
).getResultList();
}
}

/**
* Appends the provider type search criteria to the current buffer.
*
Expand Down
Loading

0 comments on commit 06698f1

Please sign in to comment.