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

Disable flags for patients not enrolled in any program #2022

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ public Object getAllPatientFlags(HttpServletRequest request, @RequestParam("pati
}

Patient patient = Context.getPatientService().getPatientByUuid(patientUuid);
ProgramWorkflowService service = Context.getProgramWorkflowService();
List<PatientProgram> programEnrolmentHistory = service.getPatientPrograms(patient, null, null, null, null, null, false);

if (patient == null) {
return new ResponseEntity<Object>("The provided patient was not found in the system!",
Expand All @@ -302,6 +304,13 @@ public Object getAllPatientFlags(HttpServletRequest request, @RequestParam("pati

Map<String,String> patientFlagsMap = new HashMap<>();
ObjectNode flagsObj = JsonNodeFactory.instance.objectNode();

// TODO: Consider flags categorization for a patient who is not in any program
if (programEnrolmentHistory.size() < 1) {
flagsObj.put("results", JsonNodeFactory.instance.arrayNode()); // return an empty list
return flagsObj.toString();
}

CacheManager cacheManager = Context.getRegisteredComponent("apiCacheManager", CacheManager.class);
Cache patientFlagCache = cacheManager.getCache("patientFlagCache");
List<String> patientFlagsToRefreshOnEveryRequest = Arrays.asList(
Expand Down