Is There a Replacement for Cohort getMemberIds()?

cohort
core
Tags: #<Tag:0x00007fbad510f238> #<Tag:0x00007fbad510ef40>

(Spencer Stream) #1

I am currently working on the Jira issue REPORT-823 and have run into issues attempting to access the members of a cohort.

From the OpenMRS Core, the Cohort class contains the method getMemberIds() which has been deprecated since 2.1.0 because “cohorts are more complex than just a set of patient ids, so there is no one-line replacement.”

What is the replacement for getting the members of a cohort?


(Moses Mutesasira) #2

@sstream17, have you tried all these methods below ??

/**
	 * @since 2.1.0
	 * @param includeVoided boolean true/false to include/exclude voided memberships
	 * @return Collection of cohort memberships
	 */
	public Collection<CohortMembership> getMemberships(boolean includeVoided) {
		if (includeVoided) {
			return getMemberships();
		}
		return getMemberships().stream().filter(m -> m.getVoided() == includeVoided).collect(Collectors.toList());
	}
	
	/**
	 * @since 2.1.0
	 */
	public Collection<CohortMembership> getMemberships() {
		if (memberships == null) {
			memberships = new TreeSet<>();
		}
		return memberships;
	}
	
	/**
	 * @since 2.1.0
	 * @param asOfDate date used to return active memberships
	 * @return Collection of cohort memberships
	 */
	public Collection<CohortMembership> getActiveMemberships(Date asOfDate) {
		return getMemberships().stream().filter(m -> m.isActive(asOfDate)).collect(Collectors.toList());
	}
	
	public Collection<CohortMembership> getActiveMemberships() {
		return getActiveMemberships(new Date());
	}

(Spencer Stream) #3

@dkayiwa @mozzy, the Reporting Module’s POM seems to be depending on an older version of OpenMRS. Should I update the POM so the above methods are compatible or would it be better to keep the backwards compatibility and continue to use the deprecated getMemberIds() method?


(Daniel Kayiwa) #4

It depends on whether you want sites running older platform versions to still be in position to use the module, or not. :smile:


(Spencer Stream) #5

Okay, I will keep the backwards compatibility and continue to use getMemberIds().