docs: public boolean isSourceInCompartmentForTarget(String theCompartmentName, IBaseResource theSource, IIdType theTarget) {
  		Validate.notBlank(theCompartmentName, "theCompartmentName must not be null or blank");
  		Validate.notNull(theSource, "theSource must not be null");
  		Validate.notNull(theTarget, "theTarget must not be null");
  		Validate.notBlank(defaultString(theTarget.getResourceType()), "theTarget must have a populated resource type (theTarget.getResourceType() does not return a value)");
  		Validate.notBlank(defaultString(theTarget.getIdPart()), "theTarget must have a populated ID (theTarget.getIdPart() does not return a value)");
  
  		String wantRef = theTarget.toUnqualifiedVersionless().getValue();
  
  		RuntimeResourceDefinition sourceDef = myContext.getResourceDefinition(theSource);
  		if (theSource.getIdElement().hasIdPart()) {
  			if (wantRef.equals(sourceDef.getName() + '/' + theSource.getIdElement().getIdPart())) {
  				return true;
  			}
  		}
  
  		List<RuntimeSearchParam> params = sourceDef.getSearchParamsForCompartmentName(theCompartmentName);
  		for (RuntimeSearchParam nextParam : params) {
  			for (String nextPath : nextParam.getPathsSplit()) {
  
  				/*
  				 * DSTU3 and before just defined compartments as being (e.g.) named
  				 * Patient with a path like CarePlan.subject
  				 *
  				 * R4 uses a fancier format like CarePlan.subject.where(resolve() is Patient)
  				 *
  				 * The following Regex is a hack to make that efficient at runtime.
  				 */
  				String wantType = null;
  				Pattern pattern = COMPARTMENT_MATCHER_PATH;
  				Matcher matcher = pattern.matcher(nextPath);
  				if (matcher.matches()) {
  					nextPath = matcher.group(1);
  					wantType = matcher.group(2);
  				}
  
  				for (IBaseReference nextValue : getValues(theSource, nextPath, IBaseReference.class)) {
  					IIdType nextTargetId = nextValue.getReferenceElement();
  					String nextRef = nextTargetId.toUnqualifiedVersionless().getValue();
  
  					/*
  					 * If the reference isn't an explicit resource ID, but instead is just
  					 * a resource object, we'll calculate its ID and treat the target
  					 * as that.
  					 */
  					if (isBlank(nextRef) && nextValue.getResource() != null) {
  						IBaseResource nextTarget = nextValue.getResource();
  						nextTargetId = nextTarget.getIdElement().toUnqualifiedVersionless();
  						if (!nextTargetId.hasResourceType()) {
  							String resourceType = myContext.getResourceDefinition(nextTarget).getName();
  							nextTargetId.setParts(null, resourceType, nextTargetId.getIdPart(), null);
  						}
  						nextRef = nextTargetId.getValue();
  					}
  
  					if (isNotBlank(wantType)) {
  						if (!nextTargetId.getResourceType().equals(wantType)) {
  							continue;
  						}
  					}
  
  					if (wantRef.equals(nextRef)) {
  						return true;
  					}
  				}
  			}
  		}
  
  		return false;
  	}