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

FLAG-69: Improve the performance of generate flags for patient #92

Open
wants to merge 3 commits 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 @@ -96,23 +96,28 @@ public List<Flag> generateFlagsForPatient(Patient patient, Map<Object, Object> c
* @see org.openmrs.module.patientflags.api.FlagService#generateFlagsForPatient(Patient, Filter, Map<Object, Object>)
*/
public List<Flag> generateFlagsForPatient(Patient patient, Filter filter, Map<Object, Object> context) {
List<Flag> results = new ArrayList<Flag>();
List<Flag> results = Collections.synchronizedList(new ArrayList<>());

// we can get rid of this once onStartup is implemented
if (!isInitialized)
refreshCache();

// test each Flag in the cache against the specific Patient
for (Flag flag : filter.filter(flagCache)) {
// trap bad flags so that they don't hang the system
filter.filter(flagCache).parallelStream().forEach(flag -> {
try {
if (flag.eval(patient, context))
Context.openSession();
if (flag.eval(patient, context)) {
results.add(flag);
}
}
catch (Exception e) {
log.error("Unable to test flag " + flag.getName() + " on patient #" + patient.getId(), e);
}
}
finally {
Context.closeSession();
}
});

return results;
}

Expand Down