public IDatabaseOperationOutcome GetResourceByFhirIDAndVersionNumber(string FhirResourceId, string ResourceVersionNumber) { IDatabaseOperationOutcome DatabaseOperationOutcome = IDatabaseOperationOutcomeFactory.CreateDatabaseOperationOutcome(); if (!string.IsNullOrWhiteSpace(ResourceVersionNumber)) { DatabaseOperationOutcome.SingleResourceRead = true; var ResourceHistoryEntity = DbGet <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType>(x => x.FhirId == FhirResourceId && x.VersionId == ResourceVersionNumber); if (ResourceHistoryEntity != null) { DatabaseOperationOutcome.ReturnedResourceList.Add(IndexSettingSupport.SetDtoResource(ResourceHistoryEntity, this.RepositoryResourceType)); } } else { DatabaseOperationOutcome.SingleResourceRead = false; var Predicate = LinqKit.PredicateBuilder.New <ResCurrentType>(true); Predicate = Predicate.And(x => x.FhirId == FhirResourceId); int TotalRecordCount = DbGetALLCount <ResCurrentType>(Predicate); var Query = DbGetAll <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType>(Predicate); //Todo: Sort not implemented just defaulting to last update order //Query = Query.OrderBy(x => x.lastUpdated); //int ClaculatedPageRequired = PaginationSupport.CalculatePageRequired(DtoSearchParameters.RequiredPageNumber, _NumberOfRecordsPerPage, TotalRecordCount); //Query = Query.Paging(ClaculatedPageRequired, _NumberOfRecordsPerPage); var DtoResourceList = new List <DtoResource>(); Query.ToList().ForEach(x => DtoResourceList.Add(IndexSettingSupport.SetDtoResource <ResourceBase>(x, this.RepositoryResourceType))); } return(DatabaseOperationOutcome); }
public IDatabaseOperationOutcome AddResource(Resource Resource, IPyroRequestUri FhirRequestUri) { var ResourceEntity = new ResCurrentType(); DtoFhirRelease DtoFhirRelease = IFhirReleaseCache.GetFhirReleaseByFhirVersion(Hl7.Fhir.Model.ModelInfo.Version); IndexSettingSupport.SetResourceBaseAddOrUpdate(Resource, ResourceEntity, Common.Tools.ResourceVersionNumber.FirstVersion(), false, Bundle.HTTPVerb.POST, DtoFhirRelease.Id); this.PopulateResourceEntity(ResourceEntity, Resource, FhirRequestUri); ResourceEntity.IsCurrent = true; this.DbAddEntity <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType>(ResourceEntity); IDatabaseOperationOutcome DatabaseOperationOutcome = IDatabaseOperationOutcomeFactory.CreateDatabaseOperationOutcome(); DatabaseOperationOutcome.SingleResourceRead = true; DatabaseOperationOutcome.ReturnedResourceList.Add(IndexSettingSupport.SetDtoResource(ResourceEntity, this.RepositoryResourceType)); return(DatabaseOperationOutcome); }
public IDatabaseOperationOutcome GetResourceHistoryByFhirID(string FhirResourceId, PyroSearchParameters DtoSearchParameters) { IDatabaseOperationOutcome DatabaseOperationOutcome = IDatabaseOperationOutcomeFactory.CreateDatabaseOperationOutcome(); DatabaseOperationOutcome.SingleResourceRead = false; //SetNumberOfRecordsPerPage(DtoSearchParameters); var Predicate = LinqKit.PredicateBuilder.New <ResCurrentType>(true); Predicate = Predicate.And(x => x.FhirId == FhirResourceId); //Query for total count int TotalRecordCount = DbGetALLCount <ResCurrentType>(Predicate); //Paging set-up var Query = DbGetAll <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType>(Predicate); //Which way to order, touchstone tests failing for history due to wrong way, have changed to Descending to see if they pass //Query = Query.OrderBy(x => x.LastUpdated); Query = Query.OrderByDescending(x => x.LastUpdated); int ClaculatedPageRequired = IPagingSupport.CalculatePageRequired(DtoSearchParameters.RequiredPageNumber, DtoSearchParameters.CountOfRecordsRequested, TotalRecordCount); Query = Query.Paging(ClaculatedPageRequired, IPagingSupport.SetNumberOfRecordsPerPage(DtoSearchParameters.CountOfRecordsRequested)); int PagesTotal = IPagingSupport.CalculateTotalPages(DtoSearchParameters.CountOfRecordsRequested, TotalRecordCount); //Query for Resources var HistoryEntityList = Query.ToList(); //Convert to DTO var DtoResourceList = new List <DtoResource>(); if (HistoryEntityList != null) { HistoryEntityList.ForEach(x => DtoResourceList.Add(IndexSettingSupport.SetDtoResource(x, this.RepositoryResourceType))); } DatabaseOperationOutcome.SingleResourceRead = false; DatabaseOperationOutcome.SearchTotal = TotalRecordCount; DatabaseOperationOutcome.PagesTotal = IPagingSupport.CalculateTotalPages(DtoSearchParameters.CountOfRecordsRequested, TotalRecordCount); DatabaseOperationOutcome.PageRequested = IPagingSupport.CalculatePageRequired(DtoSearchParameters.RequiredPageNumber, DtoSearchParameters.CountOfRecordsRequested, TotalRecordCount); DatabaseOperationOutcome.ReturnedResourceList = DtoResourceList; return(DatabaseOperationOutcome); }
public IDatabaseOperationOutcome UpdateResouceIdAsDeleted(string FhirId) { var OldResourceEntity = this.LoadCurrentResourceEntity(FhirId); var NewResourceEntity = new ResCurrentType(); IndexSettingSupport.SetHistoryResourceEntity(OldResourceEntity, NewResourceEntity); string NewDeletedResourceVersion = Common.Tools.ResourceVersionNumber.Increment(OldResourceEntity.VersionId); NewResourceEntity.IsCurrent = true; NewResourceEntity.IsDeleted = true; NewResourceEntity.LastUpdated = DateTimeOffset.Now; NewResourceEntity.Method = Bundle.HTTPVerb.DELETE; NewResourceEntity.XmlBlob = string.Empty; NewResourceEntity.VersionId = NewDeletedResourceVersion; this.DbAddEntity <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType>(NewResourceEntity); OldResourceEntity.IsCurrent = false; this.Save(); IDatabaseOperationOutcome DatabaseOperationOutcome = IDatabaseOperationOutcomeFactory.CreateDatabaseOperationOutcome(); DatabaseOperationOutcome.ReturnedResourceList.Add(IndexSettingSupport.SetDtoResource(NewResourceEntity, this.RepositoryResourceType)); return(DatabaseOperationOutcome); }