Skip to content
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

[CCAP-651] - applications should only route to active SDAs #1199

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/org/ilgcc/app/data/CCMSDataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public interface CCMSDataService {
*/
Optional<County> getCountyByZipCode(String zipCode);

/**
* Retrieves a county based on the given county name.
*
* @param countyName the county we are searching for
* @return a List of Counties containing the matching counties if found, or an empty list not found
*/
List<County> getCountyByCountyName(String countyName);

/**
* Retrieves a provider based on the given provider ID.
*
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/ilgcc/app/data/CCMSDataServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ilgcc.app.data;

import java.math.BigInteger;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -32,6 +33,16 @@ public Optional<County> getCountyByZipCode(String zipCode) {
}
}

@Override
public List<County> getCountyByCountyName(String countyName) {
try {
return countyRepository.findByCounty(countyName);
} catch (Exception e) {
log.error(String.format("Could not find a County with the county name (%s)", countyName));
return Collections.emptyList();
}
}

@Override
public Optional<Provider> getProviderById(BigInteger providerId) {
return providerRepository.findById(providerId);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/ilgcc/app/data/CountyRepository.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ilgcc.app.data;

import java.math.BigInteger;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand All @@ -9,4 +10,5 @@
public interface CountyRepository extends JpaRepository<County, String> {

Optional<County> findByZipCode(BigInteger truncatedZip);
List<County> findByCounty(String countyName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import org.ilgcc.app.submission.router.ApplicationRouterService;
import formflow.library.data.SubmissionRepositoryService;
import lombok.extern.slf4j.Slf4j;
import org.ilgcc.app.utils.CountyOption;
import org.ilgcc.app.utils.ZipcodeOption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -33,7 +31,6 @@ public class SetOrganizationIdAndCCRRName implements Action {
private static final String UNVALIDATED_ZIPCODE_INPUT_NAME = "parentHomeZipCode";
private static final String APPLICATION_COUNTY_INPUT_NAME = "applicationCounty";
private static final String APPLICATION_ZIPCODE_INPUT_NAME = "applicationZipCode";

private static final String APPLICANT_COUNTY_INPUT_NAME = "applicantAddressCounty";

@Override
Expand All @@ -47,11 +44,12 @@ public void run(Submission submission) {

if (!experiencingHomelessness && hasValidValue(inputData, UNVALIDATED_ZIPCODE_INPUT_NAME)) {
final String unvalidatedZip = (String) submission.getInputData().get(UNVALIDATED_ZIPCODE_INPUT_NAME);
saveCountyFromZip(submission, unvalidatedZip);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only saves county from home zip code address


final Optional<ResourceOrganization> org = applicationRouterService.getOrganizationIdByZipCode(unvalidatedZip);

if (org.isPresent()) {
saveOrganizationIdAndNameAndPhoneNumber(submission, org.get());
saveCountyFromZip(submission, unvalidatedZip);
return;
} else {
log.info(String.format("Submission: %s has a zipCode (%s) without a matching organization id", submission.getId(),
Expand All @@ -61,26 +59,24 @@ public void run(Submission submission) {

if (hasValidValue(inputData, APPLICATION_COUNTY_INPUT_NAME)) {
final String applicationCounty = (String) submission.getInputData().get(APPLICATION_COUNTY_INPUT_NAME);
final Optional<ZipcodeOption> zipCode = CountyOption.getZipCodeFromCountyName(applicationCounty);

if (zipCode.isPresent()) {
Optional<ResourceOrganization> organization = applicationRouterService.getOrganizationIdByZipCode(zipCode.get().getValue());
if (organization.isPresent()) {
saveOrganizationIdAndNameAndPhoneNumber(submission, organization.get());
saveCounty(submission, applicationCounty);
return;
} else {
log.info(String.format("Submission: %s has a zipCode (%s) without a matching organization id", submission.getId(), zipCode));
}
Optional<ResourceOrganization> organization = applicationRouterService.getOrganizationByCountyName(applicationCounty);

if (organization.isPresent()) {
saveOrganizationIdAndNameAndPhoneNumber(submission, organization.get());
return;
} else {
log.info(
String.format("Submission: %s has a countyName %s without a matching organization id", submission.getId(),
applicationCounty));
}
}

if (hasValidValue(inputData, APPLICATION_ZIPCODE_INPUT_NAME)) {
final String applicationZipCode = (String) submission.getInputData().get(APPLICATION_ZIPCODE_INPUT_NAME);
final Optional<ResourceOrganization> org = applicationRouterService.getOrganizationIdByZipCode(applicationZipCode);
final Optional<ResourceOrganization> org = applicationRouterService.getOrganizationIdByZipCode(
applicationZipCode);
if (org.isPresent()) {
saveOrganizationIdAndNameAndPhoneNumber(submission, org.get());
saveCountyFromZip(submission, applicationZipCode);
return;
}
}
Expand All @@ -90,26 +86,22 @@ public void run(Submission submission) {

private void saveOrganizationIdAndNameAndPhoneNumber(Submission submission, ResourceOrganization org) {
submission.getInputData().put(ORGANIZATION_ID_INPUT, org.getResourceOrgId());
submission.getInputData().put("ccrrName", org.getName());
submission.getInputData().put("ccrrName", org.getName());
submission.getInputData().put("ccrrPhoneNumber", org.getPhone());
submissionRepositoryService.save(submission);
}

private void saveCountyFromZip(Submission submission, String zipCode) {
Optional<County> county = ccmsDataServiceImpl.getCountyByZipCode(zipCode);
if (county.isPresent()) {
saveCounty(submission, county.get().getCounty());
submission.getInputData().put(APPLICANT_COUNTY_INPUT_NAME, county.get().getCounty());
submissionRepositoryService.save(submission);
} else {
log.info(String.format("could not assign a zip code to this application: %s", submission.getId()));
}

}

private void saveCounty(Submission submission, String county) {
submission.getInputData().put(APPLICANT_COUNTY_INPUT_NAME, county);
submissionRepositoryService.save(submission);
}

private boolean hasValidValue(Map<String, Object> inputData, String inputKey) {
return !inputData.getOrDefault(inputKey, "").toString().isBlank();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public interface ApplicationRouterService {
*/
Optional<ResourceOrganization> getOrganizationIdByZipCode(String zipCode);

/**
* Returns the organization ID for a given county name
*
* @param countyName The county name to look up
* @return The corresponding organization ID
*/
Optional<ResourceOrganization> getOrganizationByCountyName(String countyName);

/**
* Returns the organization ID for a given provider ID
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@Service
public class ApplicationRoutingServiceImpl implements ApplicationRouterService{

private final List<String> activeCaseLoadCodes = List.of("BB", "QQ");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limits resources orgs to those that are included in this list.

private final CCMSDataService ccmsDataService;

@Autowired
Expand All @@ -26,9 +26,22 @@ public Optional<ResourceOrganization> getOrganizationIdByZipCode(String zipCode)
}
final String truncatedZip = zipCode.substring(0, 5);
Optional<County> countyByZipCode = ccmsDataService.getCountyByZipCode(truncatedZip);
if (countyByZipCode.isPresent()) {
County county = countyByZipCode.get();
List<ResourceOrganization> resourceOrganizationsByCaseloadCode = ccmsDataService.getResourceOrganizationsByCaseloadCode(county.getCaseloadCode());
if (countyByZipCode.isPresent() && activeCaseLoadCodes.contains(countyByZipCode.get().getCaseloadCode())) {
List<ResourceOrganization> resourceOrganizationsByCaseloadCode = ccmsDataService.getResourceOrganizationsByCaseloadCode(countyByZipCode.get().getCaseloadCode());
return resourceOrganizationsByCaseloadCode.stream().filter((r) -> !r.getCaseloadCode().equals("SITE")).findFirst();
}
return Optional.empty();
}

@Override
public Optional<ResourceOrganization> getOrganizationByCountyName(String countyName) {
if(countyName == null || countyName.isBlank()){
return Optional.empty();
}
List<County> counties = ccmsDataService.getCountyByCountyName(countyName);
Optional<County> activeCounty = counties.stream().filter((c) -> c != null && activeCaseLoadCodes.contains(c.getCaseloadCode())).findFirst();
if (activeCounty.isPresent()) {
List<ResourceOrganization> resourceOrganizationsByCaseloadCode = ccmsDataService.getResourceOrganizationsByCaseloadCode(activeCounty.get().getCaseloadCode());
return resourceOrganizationsByCaseloadCode.stream().filter((r) -> !r.getCaseloadCode().equals("SITE")).findFirst();
}
return Optional.empty();
Expand Down
102 changes: 47 additions & 55 deletions src/test/java/org/ilgcc/app/data/FakeResourceOrganization.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.ilgcc.app.data;

import static org.ilgcc.app.utils.ZipcodeOption.zip_60001;
import static org.ilgcc.app.utils.ZipcodeOption.zip_60115;
import static org.ilgcc.app.utils.ZipcodeOption.zip_60304;
import static org.ilgcc.app.utils.ZipcodeOption.zip_60482;
import static org.ilgcc.app.utils.ZipcodeOption.zip_62863;

import java.math.BigInteger;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -16,73 +15,66 @@
@Slf4j
@Profile({"test"})
public class FakeResourceOrganization implements InitializingBean {

@Autowired
private ResourceOrganizationRepository resourceOrganizationRepository;
@Autowired
private CountyRepository countyRepository;
public static ResourceOrganization FOUR_C_TEST_DATA;
public static County ACTIVE_FOUR_C_COUNTY;
public static ResourceOrganization PROJECT_CHILD_TEST_DATA;
public static County ACTIVE_PROJECT_CHILD_COUNTY;
public static ResourceOrganization OUT_OF_SCOPE_DATA;
public static County ACTIVE_OUT_OF_SCOPE_COUNTY;

@Override
public void afterPropertiesSet() {
log.info("Starting creating fake provider data.");

if (!resourceOrganizationRepository.existsById(new BigInteger("12345678901"))) {
ResourceOrganization org = new ResourceOrganization();
org.setResourceOrgId(new BigInteger("56522729391679"));
org.setName("4C: Community Coordinated Child Care");
org.setSda(Short.valueOf("2"));
org.setPhone("123456789");
org.setEmail("[email protected]");
org.setCaseloadCode("BB");
resourceOrganizationRepository.save(org);
}

if (!resourceOrganizationRepository.existsById(new BigInteger("56522729391679"))) {
ResourceOrganization org = new ResourceOrganization();
org.setResourceOrgId(new BigInteger("56522729391679"));
org.setName("Project CHILD");
org.setSda(Short.valueOf("15"));
org.setCaseloadCode("QQ");
org.setPhone("123456789");
org.setEmail("[email protected]");
resourceOrganizationRepository.save(org);
}

if (!resourceOrganizationRepository.existsById(new BigInteger("47522729391670"))) {
ResourceOrganization org = new ResourceOrganization();
org.setResourceOrgId(new BigInteger("47522729391670"));
org.setName("Illinois Action for Children");
org.setSda(Short.valueOf("6"));
org.setCaseloadCode("GG");
org.setPhone("123456789");
org.setEmail("[email protected]");
resourceOrganizationRepository.save(org);
}
FOUR_C_TEST_DATA = new ResourceOrganization();
FOUR_C_TEST_DATA.setResourceOrgId(new BigInteger("12345678901234"));
FOUR_C_TEST_DATA.setName("4C: Community Coordinated Child Care");
FOUR_C_TEST_DATA.setSda(Short.valueOf("2"));
FOUR_C_TEST_DATA.setPhone("123456789");
FOUR_C_TEST_DATA.setEmail("[email protected]");
FOUR_C_TEST_DATA.setCaseloadCode("BB");
resourceOrganizationRepository.save(FOUR_C_TEST_DATA);

if (!countyRepository.existsById(zip_60115.getValue())) {
County county = new County();
county.setCounty("DeKalb");
county.setZipCode(new BigInteger(zip_60482.getValue()));
county.setCaseloadCode("GG");
countyRepository.save(county);
}
ACTIVE_FOUR_C_COUNTY = new County();
ACTIVE_FOUR_C_COUNTY.setCounty("DeKalb");
ACTIVE_FOUR_C_COUNTY.setZipCode(new BigInteger(zip_60001.getValue()));
ACTIVE_FOUR_C_COUNTY.setCaseloadCode("BB");
countyRepository.save(ACTIVE_FOUR_C_COUNTY);

if (!countyRepository.existsById(zip_60001.getValue())) {
County county = new County();
county.setCounty("DeKalb");
county.setZipCode(new BigInteger(zip_60001.getValue()));
county.setCaseloadCode("BB");
countyRepository.save(county);
}
PROJECT_CHILD_TEST_DATA = new ResourceOrganization();
PROJECT_CHILD_TEST_DATA.setResourceOrgId(new BigInteger("12345678901235"));
PROJECT_CHILD_TEST_DATA.setName("Project CHILD");
PROJECT_CHILD_TEST_DATA.setSda(Short.valueOf("15"));
PROJECT_CHILD_TEST_DATA.setCaseloadCode("QQ");
PROJECT_CHILD_TEST_DATA.setPhone("123456789");
PROJECT_CHILD_TEST_DATA.setEmail("[email protected]");
resourceOrganizationRepository.save(PROJECT_CHILD_TEST_DATA);

if (!countyRepository.existsById(zip_60001.getValue())) {
County county = new County();
county.setCounty("Cook");
county.setZipCode(new BigInteger(zip_60304.getValue()));
county.setCaseloadCode("GG");
countyRepository.save(county);
}
ACTIVE_PROJECT_CHILD_COUNTY = new County();
ACTIVE_PROJECT_CHILD_COUNTY.setCounty("Ramsey");
ACTIVE_PROJECT_CHILD_COUNTY.setZipCode(new BigInteger(zip_62863.getValue()));
ACTIVE_PROJECT_CHILD_COUNTY.setCaseloadCode("QQ");
countyRepository.save(ACTIVE_PROJECT_CHILD_COUNTY);

OUT_OF_SCOPE_DATA = new ResourceOrganization();
OUT_OF_SCOPE_DATA.setResourceOrgId(new BigInteger("12345678901236"));
OUT_OF_SCOPE_DATA.setName("Illinois Action for Children");
OUT_OF_SCOPE_DATA.setSda(Short.valueOf("6"));
OUT_OF_SCOPE_DATA.setCaseloadCode("GG");
OUT_OF_SCOPE_DATA.setPhone("123456789");
OUT_OF_SCOPE_DATA.setEmail("[email protected]");
resourceOrganizationRepository.save(OUT_OF_SCOPE_DATA);

ACTIVE_OUT_OF_SCOPE_COUNTY = new County();
ACTIVE_OUT_OF_SCOPE_COUNTY.setCounty("Chicago");
ACTIVE_OUT_OF_SCOPE_COUNTY.setZipCode(new BigInteger(zip_60482.getValue()));
ACTIVE_OUT_OF_SCOPE_COUNTY.setCaseloadCode("GG");
countyRepository.save(ACTIVE_OUT_OF_SCOPE_COUNTY);


}
Expand Down
Loading