QueryComposerCriteriaDTO[] ConvertToQueryComposerCriteria(IEnumerable <CodeImport> codes) { Guid DiagnosisCodeTermID = new Guid("86110001-4bab-4183-b0ea-a4bc0125a6a7"); Guid ProcedureCodeTermID = new Guid("f81ae5de-7b35-4d7a-b398-a72200ce7419"); QueryComposerCriteriaDTO[] export = new QueryComposerCriteriaDTO[codes.Max(c => c.CriteriaIndex + 1)]; foreach (var criteriaGrouping in codes.GroupBy(c => c.CriteriaIndex)) { List <QueryComposerTermDTO> terms = new List <QueryComposerTermDTO>(); foreach (var grouping in criteriaGrouping.GroupBy(k => new { k.CodeType, k.NumericCodeType, k.SearchMethodType })) { Guid termID; if (grouping.Key.CodeType.StartsWith("DX-", StringComparison.OrdinalIgnoreCase)) { termID = DiagnosisCodeTermID; } else if (grouping.Key.CodeType.StartsWith("PX-", StringComparison.OrdinalIgnoreCase)) { termID = ProcedureCodeTermID; } else { throw new ArgumentOutOfRangeException("CodeType", grouping.Key.CodeType, string.Format("The CodeType \"{0}\" is invalid, all CodeTypes must start with \"DX-\" or \"PX-\".", grouping.Key.CodeType)); } var values = grouping.Select(c => c.Code).Where(c => !string.IsNullOrWhiteSpace(c)).Distinct(StringComparer.OrdinalIgnoreCase); terms.Add( new QueryComposerTermDTO { Operator = DTO.Enums.QueryComposerOperators.And, Type = termID, Values = new Dictionary <string, object> { { "Values", new { CodeType = grouping.Key.NumericCodeType, CodeValues = string.Join("; ", values), grouping.Key.SearchMethodType } } } } ); } var innerCriteria = new QueryComposerCriteriaDTO { ID = DatabaseEx.NewGuid(), Name = "i_codeterms", Operator = DTO.Enums.QueryComposerOperators.And, Terms = terms.ToArray(), Type = DTO.Enums.QueryComposerCriteriaTypes.Paragraph }; export[criteriaGrouping.Key] = new QueryComposerCriteriaDTO { Criteria = new[] { innerCriteria } }; } return(export); }
public int DeleteAll() { using (var context = new GreenWerxDbContext(_dbConnectionKey)) { string table = DatabaseEx.GetTableName <LogEntry>(); return(context.ExecuteNonQuery("DELETE FROM " + table, null)); } }
public SQLiteNetRepository(Func <T, TId> getId, string?dbName = null, string?dbDirectory = null) { this.getId = getId; dbDirectory ??= Directory.CreateDirectory(Constants.Default.Directory).FullName; dbName ??= DatabaseEx.GetConnectionString(providerName, false); connection = new SQLiteConnection(string.IsNullOrEmpty(dbName) || string.IsNullOrWhiteSpace(dbName) ? Path.Combine(dbDirectory, typeof(T).Name + "." + Constants.FileExtension.Sqlite) : dbName); connection.CreateTable <T>(); }
protected DataQuery BuildQuery(string typeName, List <DataScreen> screens) { DataQuery dq = new DataQuery(); string table = DatabaseEx.GetTableName(typeName); if (string.IsNullOrEmpty(table)) { dq.SQL = "ERROR: Table name could not be found."; return(dq); } //Set default sql query dq.SQL = "SELECT * FROM " + table; dq.Parameters = null; if (screens == null || screens.Count == 0) { return(dq); } //Check if we do a distinct query. // DataScreen distinctDataScreen = screens.FirstOrDefault(w => w.Command?.ToLower() == "distinct"); if (distinctDataScreen == null) { dq.SQL += GetWhereClause(screens); } else { dq.SQL = "SELECT DISTINCT( " + distinctDataScreen.Field + " ) FROM " + table + GetWhereClause(screens); } return(dq); }
/// <summary> /// returns a query based on the screens /// Not using parameters. kept throwing “Invalid type owner for DynamicMethod” error /// </summary> /// <param name="screens"></param> /// <returns></returns> protected DataQuery BuildQuery <T>(List <DataScreen> screens) where T : class { DataQuery dq = new DataQuery(); string table = DatabaseEx.GetTableName <T>(); if (string.IsNullOrEmpty(table)) { dq.SQL = "ERROR: Table name could not be parsed."; return(dq); } dq.SQL = "SELECT * FROM " + table; if (screens.Count() == 0) { return(dq); } dq.SQL += GetWhereClause(screens); dq.Parameters = null; return(dq); }
public UserAuthenticationLogs() { this.EventID = EventIdentifiers.User.Authentication.ID; this.ID = DatabaseEx.NewGuid(); }
public async Task PostParticipantResponseDocuments([FromBody] Guid responseID) { var details = await(from rsp in DataContext.NetworkRequestResponses let pNetwork = rsp.NetworkRequestRoute.Participant.Network let sNetwork = rsp.NetworkRequestRoute.Participant.NetworkRequest.Network where rsp.ID == responseID select new { ParticipantNetwork = new { ID = pNetwork.ID, pNetwork.Name, pNetwork.ServiceUrl, pNetwork.ServiceUserName, pNetwork.ServicePassword }, SourceNetwork = new { ID = sNetwork.ID, sNetwork.Name, sNetwork.ServiceUrl, sNetwork.ServiceUserName, sNetwork.ServicePassword } }).FirstOrDefaultAsync(); if (details == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Unable to determine the response details.")); } using (var participantNetworkAPI = new Dns.ApiClient.DnsClient(details.ParticipantNetwork.ServiceUrl, details.ParticipantNetwork.ServiceUserName, Utilities.Crypto.DecryptString(details.ParticipantNetwork.ServicePassword))) { try { var participantDocuments = await participantNetworkAPI.Documents.ByResponse(new[] { responseID }); var cndsDocuments = participantDocuments.Select(d => { Guid docID = DatabaseEx.NewGuid(); return(new Data.Requests.NetworkRequestDocument { //create the ID of the document for the source network document ID = docID, DestinationRevisionSetID = docID, ResponseID = responseID, //the source document will the the document in the participant network SourceDocumentID = d.ID.Value }); }).ToArray(); foreach (var cndsDocument in cndsDocuments) { var sourceResponseID = DataContext.NetworkRequestResponses.Where(x => x.ID == responseID).Select(x => x.SourceResponseID).FirstOrDefault(); Dns.DTO.ExtendedDocumentDTO participantDocument = participantDocuments.FirstOrDefault(d => d.ID.Value == cndsDocument.SourceDocumentID); if (participantDocument == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Participant document information not found.")); } using (MultipartFormDataContent docData = new MultipartFormDataContent()) using (var web = new System.Net.Http.HttpClient()) { var creds = Convert.ToBase64String(Encoding.UTF8.GetBytes(details.SourceNetwork.ServiceUserName + ":" + Utilities.Crypto.DecryptString(details.SourceNetwork.ServicePassword))); web.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", creds); HttpResponseMessage response = new HttpResponseMessage(); { docData.Add(new StringContent(sourceResponseID.ToString("D")), "responseID"); docData.Add(new StringContent(cndsDocument.ID.ToString("D")), "id"); docData.Add(new StringContent(details.ParticipantNetwork.ID.ToString("D")), "uploadedByID"); docData.Add(new StringContent(details.ParticipantNetwork.Name), "uploadedBy"); docData.Add(new StringContent(cndsDocument.DestinationRevisionSetID.ToString("D")), "revisionSetID"); if (participantDocument.ParentDocumentID.HasValue) { Guid?parentCNDSDocumentID = await DataContext.NetworkRequestDocuments.Where(d => d.SourceDocumentID == participantDocument.ParentDocumentID.Value).Select(d => d.ID).FirstOrDefaultAsync(); if (parentCNDSDocumentID.HasValue) { docData.Add(new StringContent(parentCNDSDocumentID.Value.ToString("D")), "parentDocumentID"); } } if (!string.IsNullOrEmpty(participantDocument.Description)) { docData.Add(new StringContent(participantDocument.Description), "description"); } docData.Add(new StringContent(participantDocument.Name), "documentName"); if (!string.IsNullOrEmpty(participantDocument.Kind)) { docData.Add(new StringContent(participantDocument.Kind), "kind"); } //docData.Headers.ContentDisposition.FileName = participantDocument.FileName; var sourceReadResponse = await participantNetworkAPI.Documents.Download(participantDocument.ID.Value); var sourceResponse = await sourceReadResponse.Content.ReadAsStreamAsync(); docData.Add(new StreamContent(sourceResponse), "files"); docData.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") { FileName = participantDocument.FileName, Size = participantDocument.Length }; response = await web.PostAsync(details.SourceNetwork.ServiceUrl + "/Documents/UploadResponseOutput", docData); } } } } catch (Exception ex) { Logger.Error(ex.Message, ex); throw; } } }
public async Task <HttpResponseMessage> ResubmitSourceRouting(IEnumerable <DTO.Requests.ResubmitRouteDTO> dtos) { foreach (var dm in dtos) { var details = await(from route in DataContext.NetworkRequestRoutes let network = route.Participant.NetworkRequest.Network where route.ID == dm.RequestDatamartID select new { ID = network.ID, network.Name, network.ServiceUrl, network.ServiceUserName, network.ServicePassword, NetworkRouteID = route.ID, route.SourceRequestDataMartID }).FirstOrDefaultAsync(); using (var participantNetworkAPI = new Dns.ApiClient.DnsClient(details.ServiceUrl, details.ServiceUserName, Utilities.Crypto.DecryptString(details.ServicePassword))) { var response = new Data.Requests.NetworkRequestResponse { ID = dm.ResponseID, IterationIndex = 1, NetworkRequestRouteID = details.NetworkRouteID, SourceResponseID = DatabaseEx.NewGuid() }; DataContext.NetworkRequestResponses.Add(response); var resp = await participantNetworkAPI.CNDSRequests.ResubmitRoute(new Dns.DTO.CNDSResubmitRouteDTO { RequestDatamartID = details.SourceRequestDataMartID, ResponseID = response.SourceResponseID, Message = dm.Message }); if (!resp.IsSuccessStatusCode) { return(Request.CreateErrorResponse(resp.StatusCode, resp.ReasonPhrase)); } await DataContext.SaveChangesAsync(); } } return(Request.CreateResponse(HttpStatusCode.OK)); }
public async Task <HttpResponseMessage> Submit(DTO.Requests.SubmitRequestDTO dto) { //register the request with CNDS var request = DataContext.NetworkRequests.Add(new Data.Requests.NetworkRequest { ID = dto.SourceRequestID, NetworkID = dto.SourceNetworkID }); await DataContext.SaveChangesAsync(); var routeDefinitionIDs = dto.Routes.Select(rt => rt.NetworkRouteDefinitionID).ToArray(); var routeDefinitions = await DataContext.NetworkRequestTypeDefinitions.Where(rt => routeDefinitionIDs.Contains(rt.ID)).ToArrayAsync(); var networkIDs = (new[] { dto.SourceNetworkID }).Union(routeDefinitions.Select(rt => rt.NetworkID).Distinct()); var networkDetails = (await DataContext.Networks.Where(n => networkIDs.Contains(n.ID)).Select(n => new { n.ID, n.Name, n.ServiceUrl, n.ServiceUserName, n.ServicePassword }).ToArrayAsync()).ToDictionary(n => n.ID); var datasourceIDs = routeDefinitions.Select(rt => rt.DataSourceID).Distinct(); var dataSourceEntities = (await DataContext.NetworkEntities.Where(ne => datasourceIDs.Contains(ne.ID)).ToArrayAsync()).ToDictionary(ne => ne.ID); //TODO: make this an asynchronous parallel loop for the registering foreach (var participatingRoute in routeDefinitions.GroupBy(k => new { k.NetworkID, k.ProjectID, k.RequestTypeID })) { var participant = new Data.Requests.NetworkRequestParticipant { NetworkRequestID = request.ID, NetworkID = participatingRoute.Key.NetworkID, ProjectID = participatingRoute.Key.ProjectID, RequestTypeID = participatingRoute.Key.RequestTypeID }; request.Participants.Add(participant); var requestDocuments = dto.Documents.Select(d => { Guid docID = DatabaseEx.NewGuid(); return(new { SourceDocumentID = d.DocumentID, SourceRequestDataMartID = d.SourceRequestDataSourceID, DTO = new Dns.DTO.CNDSRegisterDocumentDTO { SourceDocumentID = d.DocumentID, SourceRevisionSetID = d.RevisionSetID, DocumentID = docID, RevisionSetID = docID, Name = d.Name, FileName = d.FileName, Kind = d.Kind, MimeType = d.MimeType, Length = d.Length, IsViewable = d.IsViewable, Description = d.Description } }); }).ToArray(); var network = networkDetails[participatingRoute.Key.NetworkID]; using (var pmnAPI = new Dns.ApiClient.DnsClient(network.ServiceUrl, network.ServiceUserName, Lpp.Utilities.Crypto.DecryptString(network.ServicePassword))) { var requestDto = new Dns.DTO.CNDSRegisterRequestDTO { ParticipantID = participant.ID, ProjectID = participatingRoute.Key.ProjectID, RequestTypeID = participatingRoute.Key.RequestTypeID, SourceNetworkID = request.NetworkID, SourceNetworkName = networkDetails[request.NetworkID].Name, RequestDetails = dto.SerializedSourceRequest, Documents = requestDocuments.Select(d => d.DTO).ToArray() }; HashSet <Dns.DTO.CNDSRegisterRouteDTO> routeDTOs = new HashSet <Dns.DTO.CNDSRegisterRouteDTO>(); foreach (var rt in participatingRoute) { var rtDTO = dto.Routes.First(x => x.NetworkRouteDefinitionID == rt.ID); var route = new Data.Requests.NetworkRequestRoute { DataSourceID = rt.DataSourceID, ParticipantID = participant.ID, SourceRequestDataMartID = rtDTO.SourceRequestDataMartID }; var response = new Data.Requests.NetworkRequestResponse { IterationIndex = 1, NetworkRequestRouteID = route.ID, SourceResponseID = rtDTO.SourceResponseID }; var responseDocuments = new HashSet <Data.Requests.NetworkRequestDocument>(); foreach (var requestDocument in requestDocuments.Where(rd => rtDTO.RequestDocumentIDs.Contains(rd.SourceDocumentID) && rd.SourceRequestDataMartID == route.SourceRequestDataMartID)) { responseDocuments.Add(new Data.Requests.NetworkRequestDocument { //the ID of the request document in CNDS will be the ID of the document in the destination network ID = requestDocument.DTO.DocumentID, DestinationRevisionSetID = requestDocument.DTO.RevisionSetID, ResponseID = response.ID, SourceDocumentID = requestDocument.SourceDocumentID }); } response.Documents = responseDocuments; route.Responses.Add(response); participant.Routes.Add(route); routeDTOs.Add(new Dns.DTO.CNDSRegisterRouteDTO { RouteID = route.ID, //Specify the destination networks DataMart ID, not the CNDS DataSource ID DataMartID = dataSourceEntities[rt.DataSourceID].NetworkEntityID, DueDate = rtDTO.DueDate, Priority = (Dns.DTO.Enums.Priorities)rtDTO.Priority, ResponseID = response.ID, //The ID will be the ID of the document in the destination network DocumentIDs = response.Documents.Select(d => d.ID).ToArray() }); } requestDto.Routes = routeDTOs; try { await DataContext.SaveChangesAsync(); } catch (Exception ex) { Logger.Error(ex.Message, ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } //has to be saved prior to registering in the participating network to allow for the documents to exist when the participant tries to get the document content. var resp = await pmnAPI.CNDSRequests.Register(requestDto); if (!resp.IsSuccessStatusCode) { return(Request.CreateErrorResponse(resp.StatusCode, resp.ReasonPhrase)); } } } return(Request.CreateResponse(HttpStatusCode.OK)); }
public ExternalCommunicationLog() { this.EventID = EventIdentifiers.ExternalCommunication.CommunicationFailed.ID; this.ID = DatabaseEx.NewGuid(); }
public EntityWithID() { this.ID = DatabaseEx.NewGuid(); }