Skip to content

Commit

Permalink
FLAG-69: improve the performance of generate flags for patient function
Browse files Browse the repository at this point in the history
  • Loading branch information
ManojLL committed Aug 2, 2024
1 parent 8937a86 commit 96ea6db
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,27 @@ 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>();
public List<Flag> generateFlagsForPatient(final Patient patient, Filter filter, final Map<Object, Object> context) {
final 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) {
}
} catch (Exception e) {
log.error("Unable to test flag " + flag.getName() + " on patient #" + patient.getId(), e);
} finally {
Context.closeSession();
}
}
});

return results;
}

Expand Down

0 comments on commit 96ea6db

Please sign in to comment.