Exemple #1
0
        static async Task <ResultCadastroLaudo> SendLaudoAsync(HttpClient client, CadastraLaudo cadastraLaudo)
        {
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "webapi/api/integracoes/laudo/cadastrarLaudo");

            request.Content = new StringContent(JsonConvert.SerializeObject(cadastraLaudo), Encoding.UTF8, "application/json");
            var response = await client.SendAsync(request);


            var result = new ResultCadastroLaudo();



            result.Descricao = $"resposta: {response.ReasonPhrase} - {((int)response.StatusCode).ToString()} \r\n";
            if (response != null)
            {
                var data = await response.Content.ReadAsStringAsync();

                if (!string.IsNullOrEmpty(data))
                {
                    result = JsonConvert.DeserializeObject <ResultCadastroLaudo>(data);
                }
            }
            // return URI of the created resource.
            return(result);
        }
Exemple #2
0
        static async Task RunAsync(string ACCESSNUMBER, string STUDY_KEY, string report, string patient_name, string creation_data, OracleCommand command, OracleConnection connection, string CRM, OracleTransaction transaction)
        {
            var client = new HttpClient();
            var host   = ConfigurationManager.AppSettings["host"];
            var token  = "username=tor&password=tor@1234&grant_type=password";

            client.BaseAddress = new Uri(host);
            client.DefaultRequestHeaders.Accept.Clear();
            error += $"Start: {STUDY_KEY} \r\n";
            var teste = default(string);

            command = new OracleCommand();
            try
            {
                /*Token token = new Token {
                 *              UserName = "******",
                 *              Password = "******",
                 *              Operations = new string[] { "CadastraLaudo" }
                 * };*/
                //teste = JsonConvert.SerializeObject(token);
                var tk = await GetTokenAsync(client, token);

                error += $" token: {JsonConvert.SerializeObject(tk)} \r\n";
                teste += $" token: {JsonConvert.SerializeObject(tk)} \r\n";
                var chv = string.Empty;
                var os  = string.Empty;
                if (ACCESSNUMBER.Length >= 10)
                {
                    chv = ACCESSNUMBER.Substring(ACCESSNUMBER.Length - 2);
                    os  = ACCESSNUMBER.Substring(0, ACCESSNUMBER.Length - 2);
                }
                else
                {
                    chv = ACCESSNUMBER;
                }

                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tk.access_token);

                var laudo = new Laudos {
                    Id    = !string.IsNullOrEmpty(chv) ? Convert.ToInt32(chv) : 0,
                    Laudo = PlainTextToRtf(report),
                    Crm   = CRM ?? V
                };



                // Create a new product
                var cadastroLaudo = new CadastraLaudo {
                    Laudos       = new object[] { laudo },
                    NomePaciente = patient_name,
                    Os           = !string.IsNullOrEmpty(os) ? Convert.ToInt64(os) : 0
                };
                error += $"laudo:  {JsonConvert.SerializeObject(cadastroLaudo)} \r\n";
                teste += $"laudo:  {JsonConvert.SerializeObject(cadastroLaudo)} \r\n";
                var ret = await SendLaudoAsync(client, cadastroLaudo);

                error += $"retorno laudo: {JsonConvert.SerializeObject(ret)}";
                teste += $"retorno laudo: {JsonConvert.SerializeObject(ret)}";

                command             = new OracleCommand();
                command.Connection  = connection;
                command.CommandText = $"UPDATE MOVEREPORT SET STATUS = 1, ERROR = :clobparam WHERE STUDY_KEY = '{STUDY_KEY}'";
                OracleParameter clobparam = new OracleParameter("clobparam", OracleDbType.Clob, teste.Length);
                clobparam.Direction = ParameterDirection.Input;
                clobparam.Value     = teste;
                command.Parameters.Add(clobparam);
                command.Transaction = transaction;
                command.ExecuteNonQuery();
                transaction.Commit();
                //command.Transaction.Commit();

                /*if(ret.Descricao.Contains("Requisição não encontrada"))
                 * {
                 *  command = new OracleCommand($"UPDATE STUDY SET STUDY_COMMENTS = '{teste}' WHERE STUDY_KEY = '{STUDY_KEY}'", connection);
                 *  command.ExecuteNonQuery();
                 *  //command.Transaction.Commit();
                 * }*/
            }
            catch (Exception e)
            {
                transaction.Rollback();
                teste               = $" laudo: {teste} exception: {e} \r\n ";
                command             = new OracleCommand();
                command.Connection  = connection;
                command.CommandText = $"UPDATE MOVEREPORT SET STATUS = 1, ERROR = :clobparam WHERE STUDY_KEY = '{STUDY_KEY}'";
                OracleParameter clobparam = new OracleParameter("clobparam", OracleDbType.Clob, teste.Length);
                clobparam.Direction = ParameterDirection.Input;
                clobparam.Value     = teste;
                command.Parameters.Add(clobparam);
                command.Transaction = transaction;
                command.ExecuteNonQuery();
                transaction.Commit();
            }
            finally
            {
                connection.Close();
            }
            error += "End \r\n";
        }