private static void SetCaseStatus(DbCase dcase, string status, string statusMsg) { dcase.status = status; dcase.status_message = statusMsg; APetaPoco.SetConnectionString("cn1"); var bm = APetaPoco.PpUpdate(dcase); }
public static void RefreshToken(string refreshToken, string caseid) { try { var api = ACFG.GetSiteApiDetails(); string responseFromServer = null; try { WebRequest request = WebRequest.Create(api.oauth_url + "token?client_id=" + api.site_id + "&client_secret=" + api.site_secret + "&refresh_token=" + refreshToken + "&grant_type=refresh_token"); request.Method = "POST"; WebResponse response = request.GetResponse(); var dataStream = response.GetResponseStream(); System.IO.StreamReader reader = new System.IO.StreamReader(dataStream); responseFromServer = reader.ReadToEnd(); reader.Close(); dataStream.Close(); response.Close(); } catch (WebException ex) { using (var stream = ex.Response.GetResponseStream()) using (var reader = new System.IO.StreamReader(stream)) { string errorResponse = reader.ReadToEnd(); LOG.InsertEvent("Unable to upload zip", "API", errorResponse, caseid); } GC.Collect(); return; } var tokenResp = JsonConvert.DeserializeObject <TokenResponse>(responseFromServer); if (tokenResp == null || tokenResp == default(TokenResponse)) { throw new Exception("Unable to retrieve valid token response"); } APetaPoco.SetConnectionString("cn1"); var bm = APetaPoco.PpRetrieveOne <User>("Users", "[refresh_token] = '" + refreshToken + "'"); if (bm.Success) { var user = (User)bm.Data; user.access_token = tokenResp.access_token; user.refresh_token = tokenResp.refresh_token; user.expiry_date = DateTime.Now.AddSeconds(tokenResp.expires_in - 10); bm = APetaPoco.PpUpdate(user); if (!bm.Success) { throw new Exception("Unable to update user details with new token"); } } } catch (Exception ex) { string errorString = "Error at :" + System.Reflection.MethodBase.GetCurrentMethod().Name; LOG.Write(errorString); LOG.Write(ex.Message); LOG.InsertEvent(errorString, "API", ex.Message, caseid); } finally { GC.Collect(); } }
public static BoolMessage CheckIfOnlySelected(Node node) { var rbm = new BoolMessage(); rbm.Data = null; try { APetaPoco.SetConnectionString("cn1"); var bm = APetaPoco.PpRetrieveOne <Node>("PACS", "[Selected] = 1"); Node currentSelectedNode = null; if (bm.Success) { currentSelectedNode = (Node)bm.Data; } else { return(bm); } if (currentSelectedNode == null || currentSelectedNode == default(Node)) { if (node.Selected) { rbm.Success = true; } else { throw new Exception("There's no selected node in the database"); } } else { if (node.Selected) { if (node.Id == currentSelectedNode.Id) { rbm.Success = true; } else { currentSelectedNode.Selected = false; bm = APetaPoco.PpUpdate(currentSelectedNode); if (bm.Success) { rbm.Success = true; } else { return(bm); } } } else { if (currentSelectedNode.Id != node.Id) { rbm.Success = true; } else { throw new Exception("Can't unselect the only selected node in database"); } } } } catch (Exception ex) { rbm.Success = false; rbm.Message = ex.Message; } return(rbm); }
public static string CreateCase(DbCase dbcase) { try { var ucase = new UploadCase(); ucase.age = dbcase.age; ucase.body = dbcase.body; ucase.diagnostic_certainty_id = dbcase.diagnostic_certainty_id; ucase.presentation = dbcase.presentation; ucase.suitable_for_quiz = dbcase.suitable_for_quiz; ucase.system_id = dbcase.system_id; ucase.title = dbcase.title; string postData = JsonConvert.SerializeObject(ucase); byte[] data = System.Text.Encoding.UTF8.GetBytes(postData); var api = ACFG.GetSiteApiDetails(); var user = AOA.GetUserRefreshIfNecessary(dbcase.username, dbcase.case_id); string responseFromServer = null; try { WebRequest request = WebRequest.Create(api.cases_url); request.Method = "POST"; request.ContentType = "application/json"; request.Headers.Add("Authorization", "Bearer " + user.access_token); Stream stream = request.GetRequestStream(); stream.Write(data, 0, data.Length); stream.Close(); WebResponse response = request.GetResponse(); var dataStream = response.GetResponseStream(); System.IO.StreamReader reader = new System.IO.StreamReader(dataStream); responseFromServer = reader.ReadToEnd(); if (string.IsNullOrEmpty(responseFromServer)) { throw new Exception("Unable to get response from server when creating case"); } reader.Close(); dataStream.Close(); response.Close(); } catch (WebException ex) { using (var stream = ex.Response.GetResponseStream()) using (var reader = new StreamReader(stream)) { string errorResponse = reader.ReadToEnd(); LOG.InsertEvent("Unable to create new case on Radiopedia server", "API", errorResponse, dbcase.case_id); } return(null); } var respObj = JsonConvert.DeserializeObject <CaseResponse>(responseFromServer); dbcase.r_case_id = respObj.id; APetaPoco.SetConnectionString("cn1"); var bm = APetaPoco.PpUpdate(dbcase); if (!bm.Success) { throw new Exception("Unable to update Case in database"); } LOG.InsertEvent("Successfully created Case on Radiopaedia:\n" + respObj.id, "API", responseFromServer, dbcase.case_id); return(respObj.id); } catch (Exception ex) { string errorString = "Error at :" + System.Reflection.MethodBase.GetCurrentMethod().Name; LOG.Write(errorString); LOG.Write(ex.Message); LOG.InsertEvent(errorString, "API", ex.Message, dbcase.case_id); return(null); } }
public static string CreateStudy(DbStudy dbstudy, string username, string caseId) { try { var ustudy = new StudyUpload(); ustudy.modality = GetModality(dbstudy.modality); ustudy.caption = dbstudy.caption; ustudy.findings = dbstudy.findings; ustudy.position = dbstudy.position; string postData = JsonConvert.SerializeObject(ustudy); byte[] data = System.Text.Encoding.UTF8.GetBytes(postData); string responseFromServer = null; try { var api = ACFG.GetSiteApiDetails(); var user = AOA.GetUserRefreshIfNecessary(username, caseId); WebRequest request = WebRequest.Create(api.cases_url + caseId + "/studies"); request.Method = "POST"; request.ContentType = "application/json"; request.Headers.Add("Authorization", "Bearer " + user.access_token); Stream stream = request.GetRequestStream(); stream.Write(data, 0, data.Length); stream.Close(); WebResponse response = request.GetResponse(); var dataStream = response.GetResponseStream(); System.IO.StreamReader reader = new System.IO.StreamReader(dataStream); responseFromServer = reader.ReadToEnd(); reader.Close(); dataStream.Close(); response.Close(); } catch (WebException ex) { using (var stream = ex.Response.GetResponseStream()) using (var reader = new StreamReader(stream)) { string errorResponse = reader.ReadToEnd(); LOG.InsertEvent("Unable to create new study on Radiopedia server", "API", errorResponse, dbstudy.case_id, dbstudy.study_uid); } return(null); } catch (Exception ex) { string errorString = "Error at :" + System.Reflection.MethodBase.GetCurrentMethod().Name; LOG.Write(errorString); LOG.Write(ex.Message); LOG.InsertEvent(errorString, "API", ex.Message, dbstudy.case_id, dbstudy.study_uid); return(null); } var respObj = JsonConvert.DeserializeObject <StudyResponse>(responseFromServer); dbstudy.r_study_id = respObj.id; APetaPoco.SetConnectionString("cn1"); var bm = APetaPoco.PpUpdate(dbstudy); if (!bm.Success) { throw new Exception("Unable to update Study in database"); } LOG.InsertEvent("Successfully created new study:\n" + respObj.id, "API", responseFromServer, dbstudy.case_id, dbstudy.study_uid); return(respObj.id); } catch (Exception ex) { string errorString = "Error at :" + System.Reflection.MethodBase.GetCurrentMethod().Name; LOG.Write(errorString); LOG.Write(ex.Message); LOG.InsertEvent(errorString, "API", ex.Message, dbstudy.case_id, dbstudy.study_uid); return(null); } finally { GC.Collect(); } }