<commit_before>package org.opencds.cqf.ruler.plugin.utility;

import java.util.List;

import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;

import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.UriParam;

/**
 * This interface provides utility functions for resolving FHIR resources based
 * on id, name and version, or url. It supplies Tenant-aware overloads for the
 * resolution functions as well.
 * 
 * TODO: Eventually we need FhirDal versions of these functions.
 */
public interface ResolutionUtilities extends IdUtilities, VersionUtilities {
	/**
	 * Returns the Resource with a matching Id
	 * 
	 * @param <ResourceType>  an IBaseResource type
	 * @param theDaoRegistry  the DaoRegistry to use for resolution
	 * @param theResourceType the class of the Resource
	 * @param theId           the Id of the Resource to resolve
	 * @return the Resource matching the criteria
	 */
	public default <ResourceType extends IBaseResource> ResourceType resolveById(DaoRegistry theDaoRegistry,
			Class<ResourceType> theResourceType, String theId) {
		return this.resolveById(theDaoRegistry.getResourceDao(theResourceType), theId, null);
	}

	/**
	 * Returns the Resource with a matching Id. Tenant aware.
	 * 
	 * @param <ResourceType>    an IBaseResource type
	 * @param theDaoRegistry    the DaoRegistry to use for resolution
	 * @param theResourceType   the class of the Resource
	 * @param theId             the Id of the Resource to resolve
	 * @param theRequestDetails the RequestDetails to use for resolution. Use this
	 *                          parameter to select a tenant.
	 * @return the Resource matching the criteria
	 */
	public default <ResourceType extends IBaseResource> ResourceType resolveById(DaoRegistry theDaoRegistry,
			Class<ResourceType> theResourceType, String theId, RequestDetails theRequestDetails) {
		return this.resolveById(theDaoRegistry.getResourceDao(theResourceType), theId, theRequestDetails);
	}

	/**
	 * Returns the Resource with a matching Id
	 * 
	 * @param <ResourceType> an IBaseResource type
	 * @param theResourceDao the IFhirResourceDao to use for resolution
	 * @param theId          the Id of the Resource to resolve.
	 * @return the Resource matching the criteria
	 */
	public default <ResourceType extends IBaseResource> ResourceType resolveById(
			IFhirResourceDao<ResourceType> theResourceDao, String theId) {
		return this.resolveById(theResourceDao, theId, null);
	}

	/**
	 * Returns the Resource with a matching Id, tenant aware
	 * 
	 * @param <ResourceType>    an IBaseResource type
	 * @param theResourceDao    the IFhirResourceDao to use for resolution
	 * @param theId             the Id of the Resource to resolve.
	 * @param theRequestDetails the RequestDetails to use for resolution. Use this
	 *                          parameter to select a tenant.
	 * @return the Resource matching the criteria
	 */
	public default <ResourceType extends IBaseResource> ResourceType resolveById(
			IFhirResourceDao<ResourceType> theResourceDao, String theId, RequestDetails theRequestDetails) {
		IIdType id = this.createId(theResourceDao.getContext(), theId);
		return theResourceDao.read(id, theRequestDetails);<commit_msg>More resolve by Id overloads<commit_after>package org.opencds.cqf.ruler.plugin.utility;

import java.util.List;

import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;

import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.UriParam;

/**
 * This interface provides utility functions for resolving FHIR resources based
 * on id, name and version, or url. It supplies Tenant-aware overloads for the
 * resolution functions as well.
 * 
 * TODO: Eventually we need FhirDal versions of these functions.
 */
public interface ResolutionUtilities extends IdUtilities, VersionUtilities {
	/**
	 * Returns the Resource with a matching Id
	 * 
	 * @param <ResourceType>    an IBaseResource type
	 * @param theDaoRegistry    the DaoRegistry to use for resolution
	 * @param theId             the Id of the Resource to resolve
	 * @param theRequestDetails the RequestDetails to use for resolution. Use this
	 *                          parameter to select a tenant.
	 * @return the Resource matching the criteria
	 */
	public default <ResourceType extends IBaseResource> ResourceType resolveById(DaoRegistry theDaoRegistry,
			IIdType theId) {
		return this.resolveById(theDaoRegistry, theId, null);
	}

	/**
	 * Returns the Resource with a matching Id
	 * 
	 * @param <ResourceType> an IBaseResource type
	 * @param theDaoRegistry the DaoRegistry to use for resolution
	 * @param theId          the Id of the Resource to resolve
	 * @return the Resource matching the criteria
	 */
	@SuppressWarnings("unchecked")
	public default <ResourceType extends IBaseResource> ResourceType resolveById(DaoRegistry theDaoRegistry,
			IIdType theId, RequestDetails requestDetails) {
		if (theId.getResourceType() == null) {
			throw new IllegalArgumentException("theId does not have a resourceType set.");
		}
		return (ResourceType) this.resolveById(theDaoRegistry.getResourceDao(theId.getResourceType()), theId,
				requestDetails);
	}

	/**
	 * Returns the Resource with a matching Id
	 * 
	 * @param <ResourceType>  an IBaseResource type
	 * @param theDaoRegistry  the DaoRegistry to use for resolution
	 * @param theResourceType the class of the Resource
	 * @param theId           the Id of the Resource to resolve
	 * @return the Resource matching the criteria
	 */
	public default <ResourceType extends IBaseResource> ResourceType resolveById(DaoRegistry theDaoRegistry,
			Class<ResourceType> theResourceType, IIdType theId) {
		return this.resolveById(theDaoRegistry.getResourceDao(theResourceType), theId, null);
	}

	/**
	 * Returns the Resource with a matching Id
	 * 
	 * @param <ResourceType>  an IBaseResource type
	 * @param theDaoRegistry  the DaoRegistry to use for resolution
	 * @param theResourceType the class of the Resource
	 * @param theId           the Id of the Resource to resolve
	 * @return the Resource matching the criteria
	 */
	public default <ResourceType extends IBaseResource> ResourceType resolveById(DaoRegistry theDaoRegistry,
			Class<ResourceType> theResourceType, String theId) {
		return this.resolveById(theDaoRegistry.getResourceDao(theResourceType), theId, null);
	}

	/**
	 * Returns the Resource with a matching Id. Tenant aware.
	 * 
	 * @param <ResourceType>    an IBaseResource type
	 * @param theDaoRegistry    the DaoRegistry to use for resolution
	 * @param theResourceType   the class of the Resource
	 * @param theId             the Id of the Resource to resolve
	 * @param theRequestDetails the RequestDetails to use for resolution. Use this
	 *                          parameter to select a tenant.
	 * @return the Resource matching the criteria
	 */
	public default <ResourceType extends IBaseResource> ResourceType resolveById(DaoRegistry theDaoRegistry,
			Class<ResourceType> theResourceType, IIdType theId, RequestDetails theRequestDetails) {
		return this.resolveById(theDaoRegistry.getResourceDao(theResourceType), theId, theRequestDetails);
	}

	/**
	 * Returns the Resource with a matching Id. Tenant aware.
	 * 
	 * @param <ResourceType>    an IBaseResource type
	 * @param theDaoRegistry    the DaoRegistry to use for resolution
	 * @param theResourceType   the class of the Resource
	 * @param theId             the Id of the Resource to resolve
	 * @param theRequestDetails the RequestDetails to use for resolution. Use this
	 *                          parameter to select a tenant.
	 * @return the Resource matching the criteria
	 */
	public default <ResourceType extends IBaseResource> ResourceType resolveById(DaoRegistry theDaoRegistry,
			Class<ResourceType> theResourceType, String theId, RequestDetails theRequestDetails) {
		return this.resolveById(theDaoRegistry.getResourceDao(theResourceType), theId, theRequestDetails);
	}

	/**
	 * Returns the Resource with a matching Id
	 * 
	 * @param <ResourceType> an IBaseResource type
	 * @param theResourceDao the IFhirResourceDao to use for resolution
	 * @param theId          the Id of the Resource to resolve.
	 * @return the Resource matching the criteria
	 */
	public default <ResourceType extends IBaseResource> ResourceType resolveById(
			IFhirResourceDao<ResourceType> theResourceDao, IIdType theId) {
		return this.resolveById(theResourceDao, theId, null);
	}

	/**
	 * Returns the Resource with a matching Id
	 * 
	 * @param <ResourceType> an IBaseResource type
	 * @param theResourceDao the IFhirResourceDao to use for resolution
	 * @param theId          the Id of the Resource to resolve.
	 * @return the Resource matching the criteria
	 */
	public default <ResourceType extends IBaseResource> ResourceType resolveById(
			IFhirResourceDao<ResourceType> theResourceDao, String theId) {
		return this.resolveById(theResourceDao, theId, null);
	}

	/**
	 * Returns the Resource with a matching Id, tenant aware
	 * 
	 * @param <ResourceType>    an IBaseResource type
	 * @param theResourceDao    the IFhirResourceDao to use for resolution
	 * @param theId             the Id of the Resource to resolve.
	 * @param theRequestDetails the RequestDetails to use for resolution. Use this
	 *                          parameter to select a tenant.
	 * @return the Resource matching the criteria
	 */
	public default <ResourceType extends IBaseResource> ResourceType resolveById(
			IFhirResourceDao<ResourceType> theResourceDao, String theId, RequestDetails theRequestDetails) {
		IIdType id = this.createId(theResourceDao.getContext(), theId);
		return this.resolveById(theResourceDao, id, theRequestDetails);
	}

	/**
	 * Returns the Resource with a matching Id, tenant aware
	 * 
	 * @param <ResourceType>    an IBaseResource type
	 * @param theResourceDao    the IFhirResourceDao to use for resolution
	 * @param theId             the Id of the Resource to resolve.
	 * @param theRequestDetails the RequestDetails to use for resolution. Use this
	 *                          parameter to select a tenant.
	 * @return the Resource matching the criteria
	 */
	public default <ResourceType extends IBaseResource> ResourceType resolveById(
			IFhirResourceDao<ResourceType> theResourceDao, IIdType theId, RequestDetails theRequestDetails) {
		return theResourceDao.read(theId, theRequestDetails);
{'fraction_non_alphanumeric': 0.06963762811127379, 'fraction_numerical': 0.0005490483162518302, 'mean_word_length': 3.954215775158658, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '263951', 'n_tokens_mistral': 3040, 'n_tokens_neox': 2927, 'n_words': 1028}