docs: protected EncodedResource populateResourceIntoEntity(RequestDetails theRequest, IBaseResource theResource, ResourceTable theEntity, boolean theUpdateHash) {
  		if (theEntity.getResourceType() == null) {
  			theEntity.setResourceType(toResourceName(theResource));
  		}
  
  		if (theResource != null) {
  			List<BaseResourceReferenceDt> refs = myContext.newTerser().getAllPopulatedChildElementsOfType(theResource, BaseResourceReferenceDt.class);
  			for (BaseResourceReferenceDt nextRef : refs) {
  				if (nextRef.getReference().isEmpty() == false) {
  					if (nextRef.getReference().hasVersionIdPart()) {
  						nextRef.setReference(nextRef.getReference().toUnqualifiedVersionless());
  					}
  				}
  			}
  		}
  
  		byte[] bytes;
  		ResourceEncodingEnum encoding;
  		boolean changed = false;
  
  		if (theEntity.getDeleted() == null) {
  
  			encoding = myConfig.getResourceEncoding();
  			Set<String> excludeElements = ResourceMetaParams.EXCLUDE_ELEMENTS_IN_ENCODED;
  			theEntity.setFhirVersion(myContext.getVersion().getVersion());
  
  			bytes = encodeResource(theResource, encoding, excludeElements, myContext);
  
  			if (theUpdateHash) {
  				HashFunction sha256 = Hashing.sha256();
  				String hashSha256 = sha256.hashBytes(bytes).toString();
  				if (hashSha256.equals(theEntity.getHashSha256()) == false) {
  					changed = true;
  				}
  				theEntity.setHashSha256(hashSha256);
  			}
  
  			Set<ResourceTag> allDefs = new HashSet<>();
  			Set<ResourceTag> allTagsOld = getAllTagDefinitions(theEntity);
  
  			if (theResource instanceof IResource) {
  				extractTagsHapi((IResource) theResource, theEntity, allDefs);
  			} else {
  				extractTagsRi((IAnyResource) theResource, theEntity, allDefs);
  			}
  
  			RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
  			if (def.isStandardType() == false) {
  				String profile = def.getResourceProfile("");
  				if (isNotBlank(profile)) {
  					TagDefinition profileDef = getTagOrNull(TagTypeEnum.PROFILE, NS_JPA_PROFILE, profile, null);
  					if (def != null) {
  						ResourceTag tag = theEntity.addTag(profileDef);
  						allDefs.add(tag);
  						theEntity.setHasTags(true);
  					}
  				}
  			}
  
  			Set<ResourceTag> allTagsNew = getAllTagDefinitions(theEntity);
  			Set<TagDefinition> allDefsPresent = new HashSet<>();
  			allTagsNew.forEach(tag -> {
  
  				// Don't keep duplicate tags
  				if (!allDefsPresent.add(tag.getTag())) {
  					theEntity.getTags().remove(tag);
  				}
  
  				// Drop any tags that have been removed
  				if (!allDefs.contains(tag)) {
  					if (shouldDroppedTagBeRemovedOnUpdate(theRequest, tag)) {
  						theEntity.getTags().remove(tag);
  					}
  				}
  
  			});
  
  			if (!allTagsOld.equals(allTagsNew)) {
  				changed = true;
  			}
  			theEntity.setHasTags(!allTagsNew.isEmpty());
  
  		} else {
  			theEntity.setHashSha256(null);
  			bytes = null;
  			encoding = ResourceEncodingEnum.DEL;
  		}
  
  		if (changed == false) {
  			if (theEntity.getId() == null) {
  				changed = true;
  			} else {
  				ResourceHistoryTable currentHistoryVersion = myResourceHistoryTableDao.findForIdAndVersion(theEntity.getId(), theEntity.getVersion());
  				if (currentHistoryVersion == null || currentHistoryVersion.getResource() == null) {
  					changed = true;
  				} else {
  					changed = !Arrays.equals(currentHistoryVersion.getResource(), bytes);
  				}
  			}
  		}
  
  		EncodedResource retVal = new EncodedResource();
  		retVal.setEncoding(encoding);
  		retVal.setResource(bytes);
  		retVal.setChanged(changed);
  
  		return retVal;
  	}