Beispiel #1
0
        public DPFDadosPacienteModel ConsultarDadosPacientePreencherPDF(int idPaciente)
        {
            try {
                MySqlConnection connection = new MySqlConnection(getStringConnection());
                connection.Open();

                var          DALSQL           = new PDFDALSQL();
                MySqlCommand cmdDadosPaciente = new MySqlCommand(DALSQL.ConsultarDadosPacientePreencherPDF(), connection);

                cmdDadosPaciente.Parameters.AddWithValue("@IDPACIENTE", idPaciente);

                var teste = getGeneratedSql(cmdDadosPaciente);

                MySqlDataReader       reader        = cmdDadosPaciente.ExecuteReader();
                DPFDadosPacienteModel dadosPaciente = new DPFDadosPacienteModel();
                dadosPaciente.ListPaciente = new List <ListPaciente>();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ListPaciente paciente = new ListPaciente();

                        if (dadosPaciente.nome == null || dadosPaciente.nome == string.Empty)
                        {
                            dadosPaciente.nome = reader.GetString(0);
                        }
                        if (dadosPaciente.rg == null || dadosPaciente.rg == string.Empty)
                        {
                            dadosPaciente.rg = reader.GetString(1);
                        }
                        if (dadosPaciente.dataNascimento == null || dadosPaciente.dataNascimento != default(DateTime))
                        {
                            dadosPaciente.dataNascimento = reader.GetDateTime(2);
                        }

                        paciente.dataConsulta = reader.GetDateTime(3);
                        paciente.status       = reader.GetInt32(4);

                        dadosPaciente.ListPaciente.Add(paciente);
                    }
                    reader.Close();
                    connection.Close();
                }
                else
                {
                    dadosPaciente = null;
                    reader.Close();
                    connection.Close();
                }

                return(dadosPaciente);
            } catch (Exception ex) {
                throw ex;
            }
        }
Beispiel #2
0
        public Document LayoutPDFPaciente(Document doc, DPFDadosPacienteModel dadosPaciente)
        {
            doc.Open();

            BaseFont bf   = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
            Font     font = new Font(bf, 11);

            BaseFont bfTitulo   = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
            Font     fontTitulo = new Font(bfTitulo, 14);

            // CREANDO A TABLE
            PdfPTable table = new PdfPTable(3);

            table.HorizontalAlignment = 0;
            table.TotalWidth          = 500f;
            table.LockedWidth         = true;
            float[] widths = new float[] { 84f, 208f, 208f };
            table.SetWidths(widths);

            // Celula LOGO
            Image    myImage   = Image.GetInstance("C:\\Users\\mselm\\source\\repos\\SGCM\\wwwroot\\images\\SGCM_logo.png");
            PdfPCell cellImage = new PdfPCell(myImage);

            cellImage.PaddingTop    = (float)2;
            cellImage.PaddingLeft   = (float)2;
            cellImage.Rowspan       = 3;
            cellImage.MinimumHeight = 40;
            table.AddCell(cellImage);

            // CELULA NOME SISTEMA
            PdfPCell cellSistemaNome = new PdfPCell(new Phrase("Sistema de Gerenciamento de Clínica Médica", fontTitulo));

            cellSistemaNome.Colspan             = 3;
            cellSistemaNome.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cellSistemaNome);

            // CELULA PACIENTE: NOME
            PdfPCell cellPacienteNome = new PdfPCell(new Phrase("Paciente: " + dadosPaciente.nome, font));

            cellPacienteNome.PaddingBottom = (float)3;
            table.AddCell(cellPacienteNome);

            // CELULA CPF/RG: NÚMERO
            PdfPCell cellCpfRg = new PdfPCell(new Phrase("CPF/RG: " + dadosPaciente.rg, font));

            cellCpfRg.PaddingBottom = (float)3;
            table.AddCell(cellCpfRg);

            var dataNascimento = dadosPaciente.dataNascimento;
            var hoje           = DateTime.Now;
            var idade          = hoje.Year - dataNascimento.Year;

            if (dataNascimento > hoje.AddYears(-idade))
            {
                idade--;
            }

            // CELULA Idade: IDADE
            PdfPCell cellIdade = new PdfPCell(new Phrase("Idade: " + idade, font));

            cellIdade.PaddingBottom = (float)3;
            table.AddCell(cellIdade);

            // CELULA Data Atendimento: DATA
            PdfPCell cellDataAtend = new PdfPCell(new Phrase("Data Consulta: " + DateTime.Now.ToShortDateString(), font));

            cellDataAtend.PaddingBottom = (float)3;
            table.AddCell(cellDataAtend);

            doc.Add(table);

            Paragraph paragrafo = new Paragraph();

            paragrafo.Add(" ");

            doc.Add(paragrafo);

            // CREANDO A TABLE
            PdfPTable tableConsulta = new PdfPTable(3);

            tableConsulta.HorizontalAlignment = 0;
            tableConsulta.TotalWidth          = 500f;
            tableConsulta.LockedWidth         = true;
            float[] widthsConsulta = new float[] { 84f, 208f, 208f };
            tableConsulta.SetWidths(widthsConsulta);

            PdfPCell cellNumeracaoCabecalho = new PdfPCell(new Phrase("Numeração", font));

            cellNumeracaoCabecalho.PaddingBottom = (float)3;
            tableConsulta.AddCell(cellNumeracaoCabecalho);

            PdfPCell cellDataConsultaCabecalho = new PdfPCell(new Phrase("Data e Hora da Consulta", font));

            cellDataConsultaCabecalho.PaddingBottom = (float)3;
            tableConsulta.AddCell(cellDataConsultaCabecalho);

            PdfPCell cellStatusCabecalho = new PdfPCell(new Phrase("Status Consulta", font));

            cellStatusCabecalho.PaddingBottom = (float)3;
            tableConsulta.AddCell(cellStatusCabecalho);

            var numeracao = 1;

            foreach (var consulta in dadosPaciente.ListPaciente)
            {
                // CELULA PACIENTE: NUMERAÇÃO
                PdfPCell cellNumeracao = new PdfPCell(new Phrase("" + numeracao, font));
                cellNumeracao.PaddingBottom = (float)3;
                tableConsulta.AddCell(cellNumeracao);

                // CELULA PACIENTE: DATA CONSULTA
                PdfPCell cellDataConsulta = new PdfPCell(new Phrase("" + dadosPaciente.ListPaciente[1].dataConsulta, font));
                cellDataConsulta.PaddingBottom = (float)3;
                tableConsulta.AddCell(cellDataConsulta);

                // CELULA PACIENTE: STATUS

                var status = "";

                if (dadosPaciente.ListPaciente[1].status == 1)
                {
                    status = "Finalizada";
                }
                else if (dadosPaciente.ListPaciente[1].status == 0)
                {
                    status = "Aberta";
                }

                PdfPCell cellStatus = new PdfPCell(new Phrase("" + status, font));
                cellStatus.PaddingBottom = (float)3;
                tableConsulta.AddCell(cellStatus);

                numeracao++;
            }

            doc.Add(tableConsulta);

            doc.Close();
            return(doc);
        }
Beispiel #3
0
        public IActionResult MostrarRelatorioPaciente(int id)
        {
            try {
                ViewBag.MensagemBodyController = "";
                ViewBag.MensagemBodyAction     = "";
                ViewBag.MensagemBody           = "";
                CarregarDadosUsuarioParaTela();
                if ((ViewData["idUsuario"] != null) && ((int)ViewData["idUsuario"] != 0))
                {
                    if ((int)ViewData["flPacienteC"] != 0 && (int)ViewData["flExamesC"] != 0)
                    {
                        MemoryStream workStream = new MemoryStream();
                        Document     doc        = CriarDocumentoPDF(true);

                        PdfWriter.GetInstance(doc, workStream).CloseStream = false;

                        if (id != 0)
                        {
                            PDFBLL pdfBLL = new PDFBLL();
                            DPFDadosPacienteModel dadosPaciente = new DPFDadosPacienteModel();
                            dadosPaciente = pdfBLL.ConsultarDadosPacientePreencherPDF(Convert.ToInt32(id));

                            if (dadosPaciente != null)
                            {
                                doc = LayoutPDFPaciente(doc, dadosPaciente);
                            }
                            else
                            {
                                HttpContext.Session.SetString("MensagemTitle", "Erro na consulta dos dados");
                                HttpContext.Session.SetString("MensagemBody", "O paciente não tem consulta cadastrada!");
                                return(RedirectToAction("Index", "Home"));
                            }
                        }
                        else
                        {
                            HttpContext.Session.SetString("MensagemTitle", "Erro na consulta dos dados");
                            HttpContext.Session.SetString("MensagemBody", "Verifique os parametros passados na URL!");
                            return(RedirectToAction("Index", "Home"));
                        }

                        byte[] byteInfo = workStream.ToArray();
                        return(new FileContentResult(byteInfo, "application/pdf"));
                    }
                    else
                    {
                        HttpContext.Session.SetString("MensagemTitle", "Erro");
                        HttpContext.Session.SetString("MensagemBody", "O usuário " + ViewData["nome"] + " não tem acesso a página: 'Consulta/CadastrarConsulta'");
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ViewData.Add("ReturnUrl", ((object[])this.ControllerContext.RouteData.Values.Values)[0] + "/" + ((object[])this.ControllerContext.RouteData.Values.Values)[1]);
                    return(RedirectToAction("Signin", "Login", new { ReturnUrl = ViewData["ReturnUrl"] }));
                }
            }
            catch (Exception ex)
            {
                HttpContext.Session.SetString("MensagemTitle", "Erro");
                HttpContext.Session.SetString("MensagemBody", "Exceção: " + ex.Message);
                return(RedirectToAction("Index", "Home"));
            }
        }