public async Task <Resource> GetAsync(ResourceKey key, CancellationToken cancellationToken = default(CancellationToken)) { EnsureArg.IsNotNull(key, nameof(key)); var currentDoc = await _dataStore.GetAsync(key, cancellationToken); if (currentDoc == null) { if (string.IsNullOrEmpty(key.VersionId)) { throw new ResourceNotFoundException(string.Format(Core.Resources.ResourceNotFoundById, key.ResourceType, key.Id)); } else { throw new ResourceNotFoundException(string.Format(Core.Resources.ResourceNotFoundByIdAndVersion, key.ResourceType, key.Id, key.VersionId)); } } if (currentDoc.IsHistory && _conformanceProvider != null && await _conformanceProvider.Value.CanReadHistory(key.ResourceType, cancellationToken) == false) { throw new MethodNotAllowedException(string.Format(Core.Resources.ReadHistoryDisabled, key.ResourceType)); } if (currentDoc.IsDeleted) { // As per FHIR Spec if the resource was marked as deleted on that version or the latest is marked as deleted then // we need to return a resource gone message. throw new ResourceGoneException(new ResourceKey(currentDoc.ResourceTypeName, currentDoc.ResourceId, currentDoc.Version)); } return(ResourceDeserializer.Deserialize(currentDoc)); }