private void btnOK_Click(object sender, EventArgs e)
        {
            if (uvAddTotalDiagnostic.Validate(true, false).IsValid)
            {
                OperationResult objOperationResult = new OperationResult();

                if (_tmpTotalDiagnosticList == null)
                {
                    _tmpTotalDiagnosticList = new List <DiagnosticRepositoryList>();
                }

                DiagnosticRepositoryList diagnosticRepository = new DiagnosticRepositoryList();

                diagnosticRepository.v_ServiceId                = _serviceId;
                diagnosticRepository.v_DiseasesId               = _diagnosticId;
                diagnosticRepository.i_AutoManualId             = (int?)AutoManual.Manual;
                diagnosticRepository.i_PreQualificationId       = (int?)PreQualification.Aceptado;
                diagnosticRepository.i_FinalQualificationId     = int.Parse(cbCalificacionFinal.SelectedValue.ToString());
                diagnosticRepository.i_DiagnosticTypeId         = int.Parse(cbTipoDx.SelectedValue.ToString());
                diagnosticRepository.i_IsSentToAntecedent       = int.Parse(cbEnviarAntecedentes.SelectedValue.ToString());
                diagnosticRepository.d_ExpirationDateDiagnostic = dtpFechaVcto.Checked ? dtpFechaVcto.Value.Date : (DateTime?)null;
                //diagnosticRepository.v_ComponentId = _componentIds[0];
                diagnosticRepository.v_ComponentId = _examenId;

                diagnosticRepository.i_RecordStatus = (int)RecordStatus.Agregado;
                diagnosticRepository.i_RecordType   = (int)RecordType.Temporal;
                diagnosticRepository.Restrictions   = _tmpRestrictionByDiagnosticList;
                diagnosticRepository.Recomendations = _tmpRecomendationList;

                _tmpTotalDiagnosticList.Add(diagnosticRepository);

                // Grabar DX + restricciones / recomendaciones
                _serviceBL.AddDiagnosticRepository(ref objOperationResult,
                                                   _tmpTotalDiagnosticList,
                                                   null,
                                                   Globals.ClientSession.GetAsList(),
                                                   null, null);

                // Analizar el resultado de la operación
                if (objOperationResult.Success == 1)  // Operación sin error
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else  // Operación con error
                {
                    MessageBox.Show(Constants.GenericErrorMessage, "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    // Se queda en el formulario.
                }
            }
            else
            {
                MessageBox.Show("Por favor corrija la información ingresada. Vea los indicadores de error.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (_interconsultations == null)
            {
                _interconsultations = new List <DiagnosticRepositoryList>();
            }

            // Save ListView / recorrer la lista
            foreach (ListViewItem item in lvInterconsultas.Items)
            {
                var fields = item.SubItems;

                var interconsultation = _interconsultations.Find(p => p.v_DiagnosticRepositoryId == fields[2].Text);

                if (interconsultation == null)   // agregar con normalidad [insert]  a la bolsa
                {
                    DiagnosticRepositoryList diagnosticRepository = new DiagnosticRepositoryList();
                    diagnosticRepository.v_DiseasesName           = fields[0].Text;
                    diagnosticRepository.v_OfficeName             = fields[1].Text;
                    diagnosticRepository.v_DiagnosticRepositoryId = fields[2].Text;
                    diagnosticRepository.v_OfficeId = fields[3].Text;
                    diagnosticRepository.i_SendToInterconsultationId = (int)SiNo.SI;

                    diagnosticRepository.i_RecordType   = (int)RecordType.Temporal;
                    diagnosticRepository.i_RecordStatus = (int)RecordStatus.Agregado;
                    _interconsultations.Add(diagnosticRepository);
                }
                else    // el examen ya esta agregado en la bolsa hay que actualizar su estado
                {
                    if (interconsultation.i_RecordStatus == (int)RecordStatus.EliminadoLogico)
                    {
                        if (interconsultation.i_RecordType == (int)RecordType.NoTemporal)   // El registro Tiene in ID de BD
                        {
                            interconsultation.i_RecordStatus = (int)RecordStatus.Grabado;
                        }
                        else if (interconsultation.i_RecordType == (int)RecordType.Temporal)   // El registro tiene un ID temporal [GUID]
                        {
                            interconsultation.i_RecordStatus = (int)RecordStatus.Agregado;
                        }
                    }
                }
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
        // Alejandro
        private DiagnosticRepositoryList SearchDxSugeridoOfSystem(string dx, string componentFieldsId)
        {
            DiagnosticRepositoryList diagnosticRepository = null;
            // Buscar reco / res asociadas a un dx


            var diagnostic = GetDxByName(dx);

            if (diagnostic != null)
            {
                // Insertar DX sugerido (automático) a la bolsa de DX
                diagnosticRepository = new DiagnosticRepositoryList();

                diagnosticRepository.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
                diagnosticRepository.v_DiseasesId             = diagnostic.v_DiseasesId;
                diagnosticRepository.i_AutoManualId           = (int)AutoManual.Automático;
                diagnosticRepository.i_PreQualificationId     = (int)PreQualification.SinPreCalificar;
                diagnosticRepository.i_FinalQualificationId   = (int)FinalQualification.SinCalificar;
                diagnosticRepository.v_ServiceId            = "";
                diagnosticRepository.v_ComponentId          = Constants.ESPIROMETRIA_ID;
                diagnosticRepository.v_DiseasesName         = diagnostic.v_DiseasesName;
                diagnosticRepository.v_AutoManualName       = "AUTOMÁTICO";
                diagnosticRepository.v_RestrictionsName     = string.Join(", ", diagnostic.Restrictions.Select(p => p.v_RestrictionName));
                diagnosticRepository.v_RecomendationsName   = string.Join(", ", diagnostic.Recomendations.Select(p => p.v_RecommendationName));
                diagnosticRepository.v_PreQualificationName = "SIN PRE-CALIFICAR";

                // ID enlace DX automatico para grabar valores dinamicos
                //diagnosticRepository.v_ComponentFieldValuesId = val.v_ComponentFieldValuesId;
                diagnosticRepository.v_ComponentFieldsId = componentFieldsId;
                diagnosticRepository.Recomendations      = diagnostic.Recomendations;
                diagnosticRepository.Restrictions        = diagnostic.Restrictions;
                diagnosticRepository.i_RecordStatus      = (int)RecordStatus.Agregado;
                diagnosticRepository.i_RecordType        = (int)RecordType.Temporal;


                //diagnosticRepository.d_ExpirationDateDiagnostic = DateTime.Now.AddMonths(vm);
            }
            else
            {
            }

            return(diagnosticRepository);
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (uvAddExamDiagnostic.Validate(true, false).IsValid)
            {
                if (_tmpExamDiagnosticComponentList == null)
                {
                    _tmpExamDiagnosticComponentList = new List <DiagnosticRepositoryList>();
                }

                if (_mode == "New")
                {
                    var findResult = _tmpExamDiagnosticComponentList.Find(p => p.v_DiagnosticRepositoryId == _diagnosticRepositoryId);

                    _diagnosticRepository = new DiagnosticRepositoryList();

                    if (findResult == null)   // agregar con normalidad  a la bolsa de DX
                    {
                        _diagnosticRepository.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
                        _diagnosticRepository.v_DiseasesId             = _diagnosticId;
                        _diagnosticRepository.i_AutoManualId           = int.Parse(cbAutoManual.SelectedValue.ToString());
                        _diagnosticRepository.i_PreQualificationId     = int.Parse(cbPreCalificacion.SelectedValue.ToString());
                        _diagnosticRepository.i_FinalQualificationId   = (int)FinalQualification.SinCalificar;
                        _diagnosticRepository.v_ServiceId            = _serviceId;
                        _diagnosticRepository.v_ComponentId          = ddlComponentId.SelectedValue.ToString(); //_componentId;
                        _diagnosticRepository.v_DiseasesName         = lblDiagnostico.Text;
                        _diagnosticRepository.v_AutoManualName       = cbAutoManual.Text;
                        _diagnosticRepository.v_RestrictionsName     = ConcatenateRestrictions();
                        _diagnosticRepository.v_RecomendationsName   = ConcatenateRecommendations();
                        _diagnosticRepository.v_PreQualificationName = cbPreCalificacion.Text;
                        _diagnosticRepository.i_RecordStatus         = (int)RecordStatus.Agregado;
                        _diagnosticRepository.i_RecordType           = (int)RecordType.Temporal;
                        _diagnosticRepository.Restrictions           = _tmpRestrictionByDiagnosticList;
                        _diagnosticRepository.Recomendations         = _tmpRecomendationList;

                        _tmpExamDiagnosticComponentList.Add(_diagnosticRepository);
                    }
                }
                else if (_mode == "Edit")
                {
                    var findResult = _tmpExamDiagnosticComponentList.Find(p => p.v_DiagnosticRepositoryId == _diagnosticRepositoryId);

                    findResult.v_DiseasesId           = _diagnosticId == null ? findResult.v_DiseasesId : _diagnosticId;
                    findResult.i_AutoManualId         = int.Parse(cbAutoManual.SelectedValue.ToString());
                    findResult.i_PreQualificationId   = int.Parse(cbPreCalificacion.SelectedValue.ToString());
                    findResult.i_FinalQualificationId = (int)FinalQualification.SinCalificar;
                    findResult.v_DiseasesName         = lblDiagnostico.Text;
                    findResult.v_AutoManualName       = cbAutoManual.Text;
                    findResult.v_RestrictionsName     = ConcatenateRestrictions();
                    findResult.v_RecomendationsName   = ConcatenateRecommendations();
                    findResult.v_PreQualificationName = cbPreCalificacion.Text;
                    findResult.i_RecordStatus         = (int)RecordStatus.Modificado;
                    findResult.Restrictions           = _tmpRestrictionByDiagnosticList;
                    findResult.Recomendations         = _tmpRecomendationList;
                    findResult.v_ServiceId            = _serviceId;

                    findResult.v_ComponentId = ddlComponentId.SelectedValue.ToString();
                }
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("Por favor corrija la información ingresada. Vea los indicadores de error.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }
        private void btnSeleccionarDx_Click(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();

            if (uvAddExamDiagnostic.Validate(true, false).IsValid)
            {
                if (_tmpTotalDiagnosticList == null)
                {
                    _tmpTotalDiagnosticList = new List <DiagnosticRepositoryList>();
                }


                var findResult = _tmpTotalDiagnosticList.Find(p => p.v_DiagnosticRepositoryId == _diagnosticRepositoryId);

                _diagnosticRepository = new DiagnosticRepositoryList();

                if (findResult == null)       // agregar con normalidad  a la bolsa de DX
                {
                    //_diagnosticRepository.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
                    //_diagnosticRepository.v_DiseasesId = _diagnosticId;
                    //_diagnosticRepository.i_AutoManualId = int.Parse(cbAutoManual.SelectedValue.ToString());
                    //_diagnosticRepository.i_PreQualificationId = int.Parse(cbPreCalificacion.SelectedValue.ToString());
                    ////_diagnosticRepository.i_FinalQualificationId = (int)FinalQualification.SinCalificar;
                    //_diagnosticRepository.i_FinalQualificationId = (int)FinalQualification.Definitivo;
                    //_diagnosticRepository.i_DiagnosticTypeId = (int)TipoDx.Enfermedad_Comun;
                    //_diagnosticRepository.v_ServiceId = _serviceId;
                    //_diagnosticRepository.v_ComponentId = ddlComponentId.SelectedValue.ToString();  //_componentId;
                    //_diagnosticRepository.v_DiseasesName = lblDiagnostico.Text;
                    //_diagnosticRepository.v_AutoManualName = cbAutoManual.Text;
                    //_diagnosticRepository.v_RestrictionsName = ConcatenateRestrictions();
                    //_diagnosticRepository.v_RecomendationsName = ConcatenateRecommendations();
                    //_diagnosticRepository.v_PreQualificationName = cbPreCalificacion.Text;
                    //_diagnosticRepository.i_RecordStatus = (int)RecordStatus.Agregado;
                    //_diagnosticRepository.i_RecordType = (int)RecordType.Temporal;
                    //_diagnosticRepository.Restrictions = _tmpRestrictionByDiagnosticList;
                    //_diagnosticRepository.Recomendations = _tmpRecomendationList;


                    _diagnosticRepository.v_ServiceId                = _serviceId;
                    _diagnosticRepository.v_DiseasesId               = _diagnosticId;
                    _diagnosticRepository.i_AutoManualId             = (int?)AutoManual.Manual;
                    _diagnosticRepository.i_PreQualificationId       = (int?)PreQualification.Aceptado;
                    _diagnosticRepository.i_FinalQualificationId     = int.Parse(cbCalificacionFinal.SelectedValue.ToString());
                    _diagnosticRepository.i_DiagnosticTypeId         = int.Parse(cbTipoDx.SelectedValue.ToString());
                    _diagnosticRepository.i_IsSentToAntecedent       = int.Parse(cbEnviarAntecedentes.SelectedValue.ToString());
                    _diagnosticRepository.d_ExpirationDateDiagnostic = dtpFechaVcto.Checked ? dtpFechaVcto.Value.Date : (DateTime?)null;
                    //_diagnosticRepository.v_ComponentId = _componentIds[0];
                    _diagnosticRepository.v_ComponentId = _examenId;

                    _diagnosticRepository.i_RecordStatus = (int)RecordStatus.Agregado;
                    _diagnosticRepository.i_RecordType   = (int)RecordType.Temporal;
                    _diagnosticRepository.Restrictions   = _tmpRestrictionByDiagnosticList;
                    _diagnosticRepository.Recomendations = _tmpRecomendationList;



                    _tmpTotalDiagnosticList.Add(_diagnosticRepository);

                    // Grabar DX + restricciones / recomendaciones
                    _serviceBL.AddDiagnosticRepository(ref objOperationResult,
                                                       _tmpTotalDiagnosticList,
                                                       null,
                                                       Globals.ClientSession.GetAsList(),
                                                       null, false);

                    // Analizar el resultado de la operación
                    if (objOperationResult.Success == 1)      // Operación sin error
                    {
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    else      // Operación con error
                    {
                        MessageBox.Show(Constants.GenericErrorMessage, "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        // Se queda en el formulario.
                    }
                }

                //else if (_mode == "Edit")
                //{
                //    var findResult = _tmpTotalDiagnosticList.Find(p => p.v_DiagnosticRepositoryId == _diagnosticRepositoryId);

                //    findResult.v_DiseasesId = _diagnosticId == null ? findResult.v_DiseasesId : _diagnosticId;
                //    findResult.i_AutoManualId = int.Parse(cbAutoManual.SelectedValue.ToString());
                //    findResult.i_PreQualificationId = int.Parse(cbPreCalificacion.SelectedValue.ToString());
                //    //findResult.i_FinalQualificationId = (int)FinalQualification.SinCalificar;
                //    _diagnosticRepository.i_FinalQualificationId = (int)FinalQualification.Definitivo;
                //    _diagnosticRepository.i_DiagnosticTypeId = (int)TipoDx.Enfermedad_Comun;
                //    findResult.v_DiseasesName = lblDiagnostico.Text;
                //    findResult.v_AutoManualName = cbAutoManual.Text;
                //    findResult.v_RestrictionsName = ConcatenateRestrictions();
                //    findResult.v_RecomendationsName = ConcatenateRecommendations();
                //    findResult.v_PreQualificationName = cbPreCalificacion.Text;
                //    findResult.i_RecordStatus = (int)RecordStatus.Modificado;
                //    findResult.Restrictions = _tmpRestrictionByDiagnosticList;
                //    findResult.Recomendations = _tmpRecomendationList;
                //    findResult.v_ServiceId = _serviceId;

                //    findResult.v_ComponentId = ddlComponentId.SelectedValue.ToString();
                //}
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("Por favor corrija la información ingresada. Vea los indicadores de error.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }
Exemple #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ReportDocument  rp = new ReportDocument();
            OperationResult objOperationResult = new OperationResult();
            List <string>   _filesNameToMerge  = new List <string>();
            string          ServiceId          = null;

            //setear dato de aptitud
            if (Request.QueryString["v_ServiceId"] != null)
            {
                ServiceId = Request.QueryString["v_ServiceId"].ToString();
            }


            if (Session["ConsultorioId"] == null)
            {
                _tempSourcePath = Path.Combine(Server.MapPath("/TempMerge"));
                List <MyListWeb> ListaServicios = (List <MyListWeb>)Session["objLista"];

                foreach (var item in ListaServicios)
                {
                    var aptitudeCertificate = new ServiceBL().GetAptitudeCertificate(ref objOperationResult, item.IdServicio).ToList();

                    DataSet   ds = new DataSet();
                    DataTable dt = Sigesoft.Server.WebClientAdmin.UI.Utils.ConvertToDatatable(aptitudeCertificate);
                    dt.TableName = "AptitudeCertificate";
                    ds.Tables.Add(dt);

                    if (aptitudeCertificate[0].i_NumberQuotasMen == (int)EmpresaDx.ConDx)
                    {
                        if (aptitudeCertificate[0].i_EsoTypeId == ((int)TypeESO.Retiro).ToString())
                        {
                            rp.Load(Server.MapPath("crOccupationalMedicalAptitudeCertificateRetiros.rpt"));
                        }
                        else
                        {
                            if (aptitudeCertificate[0].i_AptitudeStatusId == (int)AptitudeStatus.AptoObs)
                            {
                                rp.Load(Server.MapPath("cr.CertficadoObservado.rpt"));
                            }
                            else
                            {
                                rp.Load(Server.MapPath("crOccupationalMedicalAptitudeCertificate.rpt"));
                            }
                        }
                    }
                    else
                    {
                        if (aptitudeCertificate[0].i_EsoTypeId == ((int)TypeESO.Retiro).ToString())
                        {
                            rp.Load(Server.MapPath("crOccupationalRetirosSinDx.rpt"));
                        }
                        else
                        {
                            if (aptitudeCertificate[0].i_AptitudeStatusId == (int)AptitudeStatus.AptoObs)
                            {
                                rp.Load(Server.MapPath("cr.CertficadoObservadoSinDx.rpt"));
                            }
                            else
                            {
                                rp.Load(Server.MapPath("crOccupationalMedicalAptitudeCertificateSinDx.rpt"));
                            }
                        }
                    }



                    //rp.Load(Server.MapPath("crOccupationalMedicalAptitudeCertificate.rpt"));
                    rp.SetDataSource(ds);

                    rp.SetDataSource(ds);
                    var ruta = Server.MapPath("files/CM" + item.IdServicio.ToString() + ".pdf");


                    _filesNameToMerge.Add(ruta);

                    rp.ExportToDisk(ExportFormatType.PortableDocFormat, ruta);
                }
                _mergeExPDF.FilesName = _filesNameToMerge;
                string Dif     = Guid.NewGuid().ToString();
                string NewPath = Server.MapPath("files/" + Dif + ".pdf");
                _mergeExPDF.DestinationFile = NewPath;
                _mergeExPDF.Execute();
                ShowPdf1.FilePath = "files/" + Dif + ".pdf";
            }



            else if (Session["ConsultorioId"].ToString() == "6")  // RX
            {
                var RX_TORAX_ID = new ServiceBL().ReportRadiologico(ServiceId, Constants.RX_TORAX_ID);

                DataSet   ds = new DataSet();
                DataTable dt = Sigesoft.Server.WebClientAdmin.UI.Utils.ConvertToDatatable(RX_TORAX_ID);
                dt.TableName = "dtRadiologico";
                ds.Tables.Add(dt);

                rp.Load(Server.MapPath("crInformeRadiologico.rpt"));

                rp.SetDataSource(ds);

                rp.SetDataSource(ds);
                var ruta = Server.MapPath("files/CM" + ServiceId + ".pdf");


                _filesNameToMerge.Add(ruta);


                var OIT_ID = new ServiceBL().ReportInformeRadiografico(ServiceId, Constants.OIT_ID);
                if (OIT_ID.Count != 0)
                {
                    DataSet   dsOIT_ID = new DataSet();
                    DataTable dtOIT_ID = Sigesoft.Server.WebClientAdmin.UI.Utils.ConvertToDatatable(OIT_ID);
                    dtOIT_ID.TableName = "dtInformeRadiografico";
                    dsOIT_ID.Tables.Add(dt);

                    rp.Load(Server.MapPath("crInformeRadiograficoOIT.rpt"));

                    rp.SetDataSource(ds);

                    rp.SetDataSource(ds);
                    var ruta1 = Server.MapPath("files/CM" + ServiceId + ".pdf");


                    _filesNameToMerge.Add(ruta1);
                }

                rp.ExportToDisk(ExportFormatType.PortableDocFormat, ruta);


                _mergeExPDF.FilesName = _filesNameToMerge;
                string Dif     = Guid.NewGuid().ToString();
                string NewPath = Server.MapPath("files/" + Dif + ".pdf");
                _mergeExPDF.DestinationFile = NewPath;
                _mergeExPDF.Execute();
                ShowPdf1.FilePath = "files/" + Dif + ".pdf";
            }
            else if (Session["ConsultorioId"].ToString() == "5") // CARDIO
            {
                var ELECTROCARDIOGRAMA_ID = new ServiceBL().GetReportEstudioElectrocardiografico(ServiceId, Constants.ELECTROCARDIOGRAMA_ID);

                DataSet   ds = new DataSet();
                DataTable dt = Sigesoft.Server.WebClientAdmin.UI.Utils.ConvertToDatatable(ELECTROCARDIOGRAMA_ID);
                dt.TableName = "dtEstudioElectrocardiografico";
                ds.Tables.Add(dt);

                rp.Load(Server.MapPath("crEstudioElectrocardiografico.rpt"));

                rp.SetDataSource(ds);

                rp.SetDataSource(ds);
                var ruta = Server.MapPath("files/CM" + ServiceId + ".pdf");


                _filesNameToMerge.Add(ruta);

                rp.ExportToDisk(ExportFormatType.PortableDocFormat, ruta);


                _mergeExPDF.FilesName = _filesNameToMerge;
                string Dif     = Guid.NewGuid().ToString();
                string NewPath = Server.MapPath("files/" + Dif + ".pdf");
                _mergeExPDF.DestinationFile = NewPath;
                _mergeExPDF.Execute();
                ShowPdf1.FilePath = "files/" + Dif + ".pdf";
            }
            else if (Session["ConsultorioId"].ToString() == "15") // AUDIO
            {
                DataSet dsAudiometria = new DataSet();
                var     dxList        = new ServiceBL().GetDiagnosticRepositoryByComponent(ServiceId, Constants.AUDIOMETRIA_ID);
                if (dxList.Count == 0)
                {
                    DiagnosticRepositoryList        oDiagnosticRepositoryList = new DiagnosticRepositoryList();
                    List <DiagnosticRepositoryList> Lista = new List <DiagnosticRepositoryList>();
                    oDiagnosticRepositoryList.v_ServiceId              = "Sin Id";
                    oDiagnosticRepositoryList.v_DiseasesName           = "Sin Alteración";
                    oDiagnosticRepositoryList.v_DiagnosticRepositoryId = "Sin Id";
                    Lista.Add(oDiagnosticRepositoryList);
                    var dtDx = Sigesoft.Node.WinClient.BLL.Utils.ConvertToDatatable(Lista);
                    dtDx.TableName = "dtDiagnostic";
                    dsAudiometria.Tables.Add(dtDx);
                }
                else
                {
                    var dtDx = Sigesoft.Node.WinClient.BLL.Utils.ConvertToDatatable(dxList);
                    dtDx.TableName = "dtDiagnostic";
                    dsAudiometria.Tables.Add(dtDx);
                }


                var recom = dxList.SelectMany(s1 => s1.Recomendations).ToList();
                if (recom.Count == 0)
                {
                    Sigesoft.Node.WinClient.BE.RecomendationList        oRecomendationList = new Sigesoft.Node.WinClient.BE.RecomendationList();
                    List <Sigesoft.Node.WinClient.BE.RecomendationList> Lista = new List <Sigesoft.Node.WinClient.BE.RecomendationList>();

                    oRecomendationList.v_ServiceId              = "Sin Id";
                    oRecomendationList.v_RecommendationName     = "Sin Recomendaciones";
                    oRecomendationList.v_DiagnosticRepositoryId = "Sin Id";
                    Lista.Add(oRecomendationList);
                    var dtReco = Sigesoft.Node.WinClient.BLL.Utils.ConvertToDatatable(Lista);
                    dtReco.TableName = "dtRecomendation";
                    dsAudiometria.Tables.Add(dtReco);
                }
                else
                {
                    var dtReco = Sigesoft.Node.WinClient.BLL.Utils.ConvertToDatatable(recom);
                    dtReco.TableName = "dtRecomendation";
                    dsAudiometria.Tables.Add(dtReco);
                }

                var audioUserControlList     = new ServiceBL().ReportAudiometriaUserControl(ServiceId, Constants.AUDIOMETRIA_ID);
                var audioCabeceraList        = new ServiceBL().ReportAudiometria(ServiceId, Constants.AUDIOMETRIA_ID);
                var dtAudiometriaUserControl = Sigesoft.Node.WinClient.BLL.Utils.ConvertToDatatable(audioUserControlList);
                var dtCabecera = Sigesoft.Node.WinClient.BLL.Utils.ConvertToDatatable(audioCabeceraList);


                dtCabecera.TableName = "dtAudiometria";
                dtAudiometriaUserControl.TableName = "dtAudiometriaUserControl";

                dsAudiometria.Tables.Add(dtCabecera);
                dsAudiometria.Tables.Add(dtAudiometriaUserControl);

                rp.Load(Server.MapPath("crFichaAudiometria.rpt"));

                rp.SetDataSource(dsAudiometria);


                var ruta = Server.MapPath("files/AU" + ServiceId + ".pdf");

                _filesNameToMerge.Add(ruta);

                rp.ExportToDisk(ExportFormatType.PortableDocFormat, ruta);



                //HISTORIA OCUPACIONAL AUDIOMETRÍA

                var dataListForReport_1 = new ServiceBL().ReportHistoriaOcupacionalAudiometria(ServiceId);

                DataSet   ds = new DataSet();
                DataTable dt = Sigesoft.Server.WebClientAdmin.UI.Utils.ConvertToDatatable(dataListForReport_1);
                dt.TableName = "dtHistoriaOcupacional";
                ds.Tables.Add(dt);

                rp.Load(Server.MapPath("crHistoriaOcupacionalAudiometria.rpt"));

                rp.SetDataSource(ds);

                rp.SetDataSource(ds);
                var ruta1 = Server.MapPath("files/CM" + ServiceId + ".pdf");


                _filesNameToMerge.Add(ruta1);

                rp.ExportToDisk(ExportFormatType.PortableDocFormat, ruta1);


                _mergeExPDF.FilesName = _filesNameToMerge;
                string Dif     = Guid.NewGuid().ToString();
                string NewPath = Server.MapPath("files/" + Dif + ".pdf");
                _mergeExPDF.DestinationFile = NewPath;
                _mergeExPDF.Execute();
                ShowPdf1.FilePath = "files/" + Dif + ".pdf";
            }

            else if (Session["ConsultorioId"].ToString() == "1") // LAB
            {
                var ruta = Server.MapPath("files/INFLAB" + ServiceId + ".pdf");

                GenerateLaboratorioReport(ruta, ServiceId);
                _filesNameToMerge.Add(ruta);

                _mergeExPDF.FilesName = _filesNameToMerge;
                string Dif     = Guid.NewGuid().ToString();
                string NewPath = Server.MapPath("files/" + Dif + ".pdf");
                _mergeExPDF.DestinationFile = NewPath;
                _mergeExPDF.Execute();
                ShowPdf1.FilePath = "files/" + Dif + ".pdf";
            }
            else if (Session["ConsultorioId"].ToString() == "14") // OFTALMO
            {
                var OFTALMOLOGIA_ID = new PacientBL().GetOftalmologia(ServiceId, Constants.OFTALMOLOGIA_ID);

                DataSet   ds = new DataSet();
                DataTable dt = Sigesoft.Server.WebClientAdmin.UI.Utils.ConvertToDatatable(OFTALMOLOGIA_ID);
                dt.TableName = "dtOftalmologia";
                ds.Tables.Add(dt);

                rp.Load(Server.MapPath("crOftalmologia.rpt"));

                rp.SetDataSource(ds);

                rp.SetDataSource(ds);
                var ruta = Server.MapPath("files/CM" + ServiceId + ".pdf");

                _filesNameToMerge.Add(ruta);

                rp.ExportToDisk(ExportFormatType.PortableDocFormat, ruta);

                _mergeExPDF.FilesName = _filesNameToMerge;
                string Dif     = Guid.NewGuid().ToString();
                string NewPath = Server.MapPath("files/" + Dif + ".pdf");
                _mergeExPDF.DestinationFile = NewPath;
                _mergeExPDF.Execute();
                ShowPdf1.FilePath = "files/" + Dif + ".pdf";
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (uvAddTotalDiagnostic.Validate(true, false).IsValid)
            {
                if (_tmpDiagnosticList == null)
                {
                    _tmpDiagnosticList = new List <DiagnosticRepositoryList>();
                }

                if (_mode == "New")
                {
                    var findResult = _tmpDiagnosticList.Find(p => p.v_DiagnosticRepositoryId == _diagnosticRepositoryId);

                    _diagnosticRepository = new DiagnosticRepositoryList();

                    if (findResult == null)   // agregar con normalidad  a la bolsa de DX
                    {
                        _diagnosticRepository.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
                        _diagnosticRepository.v_ServiceId            = _serviceId;
                        _diagnosticRepository.v_DiseasesId           = _objDiseasesList.v_DiseasesId;
                        _diagnosticRepository.i_FinalQualificationId = int.Parse(cbCalificacionFinal.SelectedValue.ToString());
                        _diagnosticRepository.i_IsSentToAntecedent   = int.Parse(cbEnviarAntecedentes.SelectedValue.ToString());
                        _diagnosticRepository.i_DiagnosticTypeId     = int.Parse(cbTipoOcurrencia.SelectedValue.ToString());
                        _diagnosticRepository.i_DiagnosticSourceId   = int.Parse(cbOrigenOcurrencia.SelectedValue.ToString());
                        // Accidente laboral
                        _diagnosticRepository.i_ShapeAccidentId = int.Parse(((KeyValueDTO)cbFormaAccidente.SelectedValue).Id);
                        _diagnosticRepository.i_BodyPartId      = int.Parse(((KeyValueDTO)cbParteCuerpo.SelectedValue).Id);
                        _diagnosticRepository.i_ClassificationOfWorkAccidentId = int.Parse(((KeyValueDTO)cbClasificacionAccLab.SelectedValue).Id);
                        // Enfermedad laboral
                        _diagnosticRepository.i_RiskFactorId = int.Parse(((KeyValueDTO)cbFactorRiesgo.SelectedValue).Id);
                        _diagnosticRepository.i_ClassificationOfWorkdiseaseId = int.Parse(((KeyValueDTO)cbClasificacionEnfLab.SelectedValue).Id);

                        _diagnosticRepository.i_RecordStatus = (int)RecordStatus.Agregado;
                        _diagnosticRepository.i_RecordType   = (int)RecordType.Temporal;

                        _diagnosticRepository.v_FinalQualificationName          = cbCalificacionFinal.Text;
                        _diagnosticRepository.v_DiseasesName                    = lblDiagnostico.Text;
                        _diagnosticRepository.v_RiskFactorName                  = cbFactorRiesgo.Text;
                        _diagnosticRepository.v_ClassificationOfWorkdiseaseName = cbClasificacionEnfLab.Text;
                        _diagnosticRepository.v_IsSentToAntecedentName          = _diagnosticRepository.i_IsSentToAntecedent == (int)SiNo.SI ? "SI" : "NO";
                        _diagnosticRepository.v_FinalQualificationName          = cbCalificacionFinal.Text;
                        _diagnosticRepository.v_DiagnosticTypeName              = cbTipoOcurrencia.Text;
                        _diagnosticRepository.v_DiagnosticSourceName            = cbOrigenOcurrencia.Text;

                        _tmpDiagnosticList.Add(_diagnosticRepository);
                    }
                }
                else if (_mode == "Edit")
                {
                    var findResult = _tmpDiagnosticList.Find(p => p.v_DiagnosticRepositoryId == _diagnosticRepositoryId);

                    findResult.i_FinalQualificationId = int.Parse(cbCalificacionFinal.SelectedValue.ToString());
                    findResult.i_IsSentToAntecedent   = int.Parse(cbEnviarAntecedentes.SelectedValue.ToString());
                    findResult.i_DiagnosticTypeId     = int.Parse(cbTipoOcurrencia.SelectedValue.ToString());
                    findResult.i_DiagnosticSourceId   = int.Parse(cbOrigenOcurrencia.SelectedValue.ToString());
                    // Accidente laboral
                    findResult.i_ShapeAccidentId = int.Parse(((KeyValueDTO)cbFormaAccidente.SelectedValue).Id);
                    findResult.i_BodyPartId      = int.Parse(((KeyValueDTO)cbParteCuerpo.SelectedValue).Id);
                    findResult.i_ClassificationOfWorkAccidentId = int.Parse(((KeyValueDTO)cbClasificacionAccLab.SelectedValue).Id);
                    // Enfermedad laboral
                    findResult.i_RiskFactorId = int.Parse(((KeyValueDTO)cbFactorRiesgo.SelectedValue).Id);
                    findResult.i_ClassificationOfWorkdiseaseId = int.Parse(((KeyValueDTO)cbClasificacionEnfLab.SelectedValue).Id);

                    findResult.i_RecordStatus                    = (int)RecordStatus.Modificado;
                    findResult.v_FinalQualificationName          = cbCalificacionFinal.Text;
                    findResult.v_DiseasesName                    = lblDiagnostico.Text;
                    findResult.v_RiskFactorName                  = cbFactorRiesgo.Text;
                    findResult.v_ClassificationOfWorkdiseaseName = cbClasificacionEnfLab.Text;
                    findResult.v_IsSentToAntecedentName          = findResult.i_IsSentToAntecedent == (int)SiNo.SI ? "SI" : "NO";
                    findResult.v_FinalQualificationName          = cbCalificacionFinal.Text;
                    findResult.v_DiagnosticTypeName              = cbTipoOcurrencia.Text;
                    findResult.v_DiagnosticSourceName            = cbOrigenOcurrencia.Text;
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("Por favor corrija la información ingresada. Vea los indicadores de error.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }
        private void btnGrabar_Click(object sender, EventArgs e)
        {
            if (uvValidador.Validate(true, false).IsValid)
            {
                if (double.Parse(txtTalla.Text) < 0.5 || double.Parse(txtTalla.Text) > 2.5)
                {
                    MessageBox.Show("Talla: valor entre 0.5 y 2.5  ", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (double.Parse(txtPeso.Text) < 1 || double.Parse(txtPeso.Text) > 200)
                {
                    MessageBox.Show("Peso: valor entre 1 y 200  ", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (txtPerAbd.Text != "")
                {
                    if (double.Parse(txtPerAbd.Text) < 1 || double.Parse(txtPerAbd.Text) > 300)
                    {
                        MessageBox.Show("Perímetro Abdominal: valor entre 1 y 300  ", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
                if (txtPerCad.Text != "")
                {
                    if (double.Parse(txtPerCad.Text) < 1 || double.Parse(txtPerCad.Text) > 300)
                    {
                        MessageBox.Show("Perímetro Cadera: valor entre 1 y 300  ", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
                if (txtTemperatura.Text != "")
                {
                    if (double.Parse(txtTemperatura.Text) < 15 || double.Parse(txtTemperatura.Text) > 50)
                    {
                        MessageBox.Show("Temperatura: valor entre 15 y 50  ", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

                if (int.Parse(txtPAS.Text) < 40 || int.Parse(txtPAS.Text) > 350)
                {
                    MessageBox.Show("PAS: valor entre 40 y 350  ", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (int.Parse(txtPAD.Text) < 40 || int.Parse(txtPAD.Text) > 350)
                {
                    MessageBox.Show("PAD: valor entre 40 y 350  ", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtFrecResp.Text != "")
                {
                    if (int.Parse(txtFrecResp.Text) < 0 || int.Parse(txtFrecResp.Text) > 60)
                    {
                        MessageBox.Show("Frecuencia Respiratoria: valor entre 0 y 60  ", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

                if (txtFrecCard.Text != "")
                {
                    if (int.Parse(txtFrecCard.Text) < 0 || int.Parse(txtFrecCard.Text) > 250)
                    {
                        MessageBox.Show("Frecuencia Cardiaca: valor entre 0 y 250  ", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

                OperationResult objOperationResult = new OperationResult();
                ServiceBL       _serviceBL         = new ServiceBL();
                ServiceComponentFieldValuesList        serviceComponentFieldValues      = null;
                ServiceComponentFieldsList             serviceComponentFields           = null;
                List <ServiceComponentFieldValuesList> _serviceComponentFieldValuesList = null;
                List <ServiceComponentFieldsList>      _serviceComponentFieldsList      = null;

                if (_serviceComponentFieldsList == null)
                {
                    _serviceComponentFieldsList = new List <ServiceComponentFieldsList>();
                }


                //Talla**-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-
                serviceComponentFields = new ServiceComponentFieldsList();

                serviceComponentFields.v_ComponentFieldsId  = Constants.ANTROPOMETRIA_TALLA_ID;
                serviceComponentFields.v_ServiceComponentId = _ServiceComponentId;

                _serviceComponentFieldValuesList = new List <ServiceComponentFieldValuesList>();
                serviceComponentFieldValues      = new ServiceComponentFieldValuesList();

                serviceComponentFieldValues.v_ComponentFieldValuesId = null;
                serviceComponentFieldValues.v_Value1 = txtTalla.Text;
                _serviceComponentFieldValuesList.Add(serviceComponentFieldValues);

                serviceComponentFields.ServiceComponentFieldValues = _serviceComponentFieldValuesList;

                // Agregar a mi lista
                _serviceComponentFieldsList.Add(serviceComponentFields);


                //Temperatura**-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-
                serviceComponentFields = new ServiceComponentFieldsList();

                serviceComponentFields.v_ComponentFieldsId  = Constants.FUNCIONES_VITALES_TEMPERATURA_ID;
                serviceComponentFields.v_ServiceComponentId = _ServiceComponentId;

                _serviceComponentFieldValuesList = new List <ServiceComponentFieldValuesList>();
                serviceComponentFieldValues      = new ServiceComponentFieldValuesList();

                serviceComponentFieldValues.v_ComponentFieldValuesId = null;
                serviceComponentFieldValues.v_Value1 = txtTemperatura.Text;
                _serviceComponentFieldValuesList.Add(serviceComponentFieldValues);

                serviceComponentFields.ServiceComponentFieldValues = _serviceComponentFieldValuesList;

                // Agregar a mi lista
                _serviceComponentFieldsList.Add(serviceComponentFields);

                //Peso**-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-
                serviceComponentFields = new ServiceComponentFieldsList();

                serviceComponentFields.v_ComponentFieldsId  = Constants.ANTROPOMETRIA_PESO_ID;
                serviceComponentFields.v_ServiceComponentId = _ServiceComponentId;

                _serviceComponentFieldValuesList = new List <ServiceComponentFieldValuesList>();
                serviceComponentFieldValues      = new ServiceComponentFieldValuesList();

                serviceComponentFieldValues.v_ComponentFieldValuesId = null;
                serviceComponentFieldValues.v_Value1 = txtPeso.Text;
                _serviceComponentFieldValuesList.Add(serviceComponentFieldValues);

                serviceComponentFields.ServiceComponentFieldValues = _serviceComponentFieldValuesList;

                // Agregar a mi lista
                _serviceComponentFieldsList.Add(serviceComponentFields);



                //PAS**-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-
                serviceComponentFields = new ServiceComponentFieldsList();

                serviceComponentFields.v_ComponentFieldsId  = Constants.FUNCIONES_VITALES_PAS_ID;
                serviceComponentFields.v_ServiceComponentId = _ServiceComponentId;

                _serviceComponentFieldValuesList = new List <ServiceComponentFieldValuesList>();
                serviceComponentFieldValues      = new ServiceComponentFieldValuesList();

                serviceComponentFieldValues.v_ComponentFieldValuesId = null;
                serviceComponentFieldValues.v_Value1 = txtPAS.Text;
                _serviceComponentFieldValuesList.Add(serviceComponentFieldValues);

                serviceComponentFields.ServiceComponentFieldValues = _serviceComponentFieldValuesList;

                // Agregar a mi lista
                _serviceComponentFieldsList.Add(serviceComponentFields);


                //IMC**-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-
                serviceComponentFields = new ServiceComponentFieldsList();

                serviceComponentFields.v_ComponentFieldsId  = Constants.ANTROPOMETRIA_IMC_ID;
                serviceComponentFields.v_ServiceComponentId = _ServiceComponentId;

                _serviceComponentFieldValuesList = new List <ServiceComponentFieldValuesList>();
                serviceComponentFieldValues      = new ServiceComponentFieldValuesList();

                serviceComponentFieldValues.v_ComponentFieldValuesId = null;
                serviceComponentFieldValues.v_Value1 = txtImc.Text;
                _serviceComponentFieldValuesList.Add(serviceComponentFieldValues);

                serviceComponentFields.ServiceComponentFieldValues = _serviceComponentFieldValuesList;

                // Agregar a mi lista
                _serviceComponentFieldsList.Add(serviceComponentFields);


                //PAD**-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-
                serviceComponentFields = new ServiceComponentFieldsList();

                serviceComponentFields.v_ComponentFieldsId  = Constants.FUNCIONES_VITALES_PAD_ID;
                serviceComponentFields.v_ServiceComponentId = _ServiceComponentId;

                _serviceComponentFieldValuesList = new List <ServiceComponentFieldValuesList>();
                serviceComponentFieldValues      = new ServiceComponentFieldValuesList();

                serviceComponentFieldValues.v_ComponentFieldValuesId = null;
                serviceComponentFieldValues.v_Value1 = txtPAD.Text;
                _serviceComponentFieldValuesList.Add(serviceComponentFieldValues);

                serviceComponentFields.ServiceComponentFieldValues = _serviceComponentFieldValuesList;

                // Agregar a mi lista
                _serviceComponentFieldsList.Add(serviceComponentFields);



                //Perímetro Abdomen**-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-
                serviceComponentFields = new ServiceComponentFieldsList();

                serviceComponentFields.v_ComponentFieldsId  = Constants.ANTROPOMETRIA_PERIMETRO_ABDOMINAL_ID;
                serviceComponentFields.v_ServiceComponentId = _ServiceComponentId;

                _serviceComponentFieldValuesList = new List <ServiceComponentFieldValuesList>();
                serviceComponentFieldValues      = new ServiceComponentFieldValuesList();

                serviceComponentFieldValues.v_ComponentFieldValuesId = null;
                serviceComponentFieldValues.v_Value1 = txtPerAbd.Text;
                _serviceComponentFieldValuesList.Add(serviceComponentFieldValues);

                serviceComponentFields.ServiceComponentFieldValues = _serviceComponentFieldValuesList;

                // Agregar a mi lista
                _serviceComponentFieldsList.Add(serviceComponentFields);

                //Frecuencia Cardiaca**-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-
                serviceComponentFields = new ServiceComponentFieldsList();

                serviceComponentFields.v_ComponentFieldsId  = Constants.FUNCIONES_VITALES_FREC_CARDIACA_ID;
                serviceComponentFields.v_ServiceComponentId = _ServiceComponentId;

                _serviceComponentFieldValuesList = new List <ServiceComponentFieldValuesList>();
                serviceComponentFieldValues      = new ServiceComponentFieldValuesList();

                serviceComponentFieldValues.v_ComponentFieldValuesId = null;
                serviceComponentFieldValues.v_Value1 = txtFrecCard.Text;
                _serviceComponentFieldValuesList.Add(serviceComponentFieldValues);

                serviceComponentFields.ServiceComponentFieldValues = _serviceComponentFieldValuesList;

                // Agregar a mi lista
                _serviceComponentFieldsList.Add(serviceComponentFields);

                //Perímetro Cadera**-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-
                serviceComponentFields = new ServiceComponentFieldsList();

                serviceComponentFields.v_ComponentFieldsId  = Constants.ANTROPOMETRIA_PERIMETRO_CADERA_ID;
                serviceComponentFields.v_ServiceComponentId = _ServiceComponentId;

                _serviceComponentFieldValuesList = new List <ServiceComponentFieldValuesList>();
                serviceComponentFieldValues      = new ServiceComponentFieldValuesList();

                serviceComponentFieldValues.v_ComponentFieldValuesId = null;
                serviceComponentFieldValues.v_Value1 = txtPerCad.Text;
                _serviceComponentFieldValuesList.Add(serviceComponentFieldValues);

                serviceComponentFields.ServiceComponentFieldValues = _serviceComponentFieldValuesList;

                // Agregar a mi lista
                _serviceComponentFieldsList.Add(serviceComponentFields);

                //Frecuencia Respiratoria**-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-
                serviceComponentFields = new ServiceComponentFieldsList();

                serviceComponentFields.v_ComponentFieldsId  = Constants.FUNCIONES_VITALES_FREC_RESPIRATORIA_ID;
                serviceComponentFields.v_ServiceComponentId = _ServiceComponentId;

                _serviceComponentFieldValuesList = new List <ServiceComponentFieldValuesList>();
                serviceComponentFieldValues      = new ServiceComponentFieldValuesList();

                serviceComponentFieldValues.v_ComponentFieldValuesId = null;
                serviceComponentFieldValues.v_Value1 = txtFrecResp.Text;
                _serviceComponentFieldValuesList.Add(serviceComponentFieldValues);

                serviceComponentFields.ServiceComponentFieldValues = _serviceComponentFieldValuesList;

                // Agregar a mi lista
                _serviceComponentFieldsList.Add(serviceComponentFields);


                //ICC**-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-
                serviceComponentFields = new ServiceComponentFieldsList();

                serviceComponentFields.v_ComponentFieldsId  = Constants.ANTROPOMETRIA_INDICE_CINTURA_ID;
                serviceComponentFields.v_ServiceComponentId = _ServiceComponentId;

                _serviceComponentFieldValuesList = new List <ServiceComponentFieldValuesList>();
                serviceComponentFieldValues      = new ServiceComponentFieldValuesList();

                serviceComponentFieldValues.v_ComponentFieldValuesId = null;
                serviceComponentFieldValues.v_Value1 = txtICC.Text;
                _serviceComponentFieldValuesList.Add(serviceComponentFieldValues);

                serviceComponentFields.ServiceComponentFieldValues = _serviceComponentFieldValuesList;

                // Agregar a mi lista
                _serviceComponentFieldsList.Add(serviceComponentFields);


                //Saturación Oxígeno**-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-
                serviceComponentFields = new ServiceComponentFieldsList();

                serviceComponentFields.v_ComponentFieldsId  = Constants.FUNCIONES_VITALES_SAT_O2_ID;
                serviceComponentFields.v_ServiceComponentId = _ServiceComponentId;

                _serviceComponentFieldValuesList = new List <ServiceComponentFieldValuesList>();
                serviceComponentFieldValues      = new ServiceComponentFieldValuesList();

                serviceComponentFieldValues.v_ComponentFieldValuesId = null;
                serviceComponentFieldValues.v_Value1 = txtSatOx.Text;
                _serviceComponentFieldValuesList.Add(serviceComponentFieldValues);

                serviceComponentFields.ServiceComponentFieldValues = _serviceComponentFieldValuesList;

                // Agregar a mi lista
                _serviceComponentFieldsList.Add(serviceComponentFields);



                var result = _serviceBL.AddServiceComponentValues(ref objOperationResult,
                                                                  _serviceComponentFieldsList,
                                                                  Globals.ClientSession.GetAsList(),
                                                                  _PersonId,
                                                                  _ServiceComponentId);

                //lIMPIAR LA LISTA DE DXS
                List <DiagnosticRepositoryList> ListaDxByComponent        = new List <DiagnosticRepositoryList>();
                MedicalExamFieldValuesBL        oMedicalExamFieldValuesBL = new MedicalExamFieldValuesBL();
                //Elminar los Dx antiguos
                _serviceBL.EliminarDxAniguosPorComponente(_ServiceId, Constants.FUNCIONES_VITALES_ID, Globals.ClientSession.GetAsList());
                _serviceBL.EliminarDxAniguosPorComponente(_ServiceId, Constants.ANTROPOMETRIA_ID, Globals.ClientSession.GetAsList());
                ListaDxByComponent = new List <DiagnosticRepositoryList>();

                if (txtImc.Text != "")
                {
                    double IMC = double.Parse(txtImc.Text.ToString());
                    DiagnosticRepositoryList DxByComponent = new DiagnosticRepositoryList();

                    List <RecomendationList> Recomendations = new List <RecomendationList>();
                    List <RestrictionList>   Restrictions   = new List <RestrictionList>();

                    DxByComponent.i_AutoManualId         = 1;
                    DxByComponent.i_FinalQualificationId = (int)FinalQualification.Definitivo;
                    DxByComponent.i_PreQualificationId   = 1;
                    DxByComponent.v_ComponentFieldsId    = Constants.ANTROPOMETRIA_IMC_ID;

                    //Obtener el Componente que está amarrado al DX
                    string ComponentDx = oMedicalExamFieldValuesBL.ObtenerComponentDx(Constants.ANTROPOMETRIA_IMC_ID);
                    string DiseasesId  = "";
                    if (IMC <= 18.49)
                    {
                        DiseasesId = "N009-DD000000300";
                    }
                    else if (IMC >= 18.5 && IMC <= 24.99)
                    {
                        DiseasesId = "N009-DD000000788";
                    }
                    else if (IMC >= 25 && IMC <= 29.99)
                    {
                        DiseasesId = "N009-DD000000601";
                    }
                    else if (IMC >= 30 && IMC <= 34.99)
                    {
                        DiseasesId = "N009-DD000000602";
                    }
                    else if (IMC >= 35 && IMC <= 39.99)
                    {
                        DiseasesId = "N009-DD000000603";
                    }
                    else if (IMC >= 40)
                    {
                        DiseasesId = "N009-DD000000604";
                    }
                    string ComponentFieldId = Constants.ANTROPOMETRIA_IMC_ID;

                    DiagnosticRepositoryList oDiagnosticRepositoryListOld = _serviceBL.VerificarDxExistente(_ServiceId, DiseasesId, ComponentDx, ComponentFieldId);
                    if (oDiagnosticRepositoryListOld != null)
                    {
                        oDiagnosticRepositoryListOld.v_DiagnosticRepositoryId = oDiagnosticRepositoryListOld.v_DiagnosticRepositoryId;
                        oDiagnosticRepositoryListOld.i_RecordType             = (int)RecordType.NoTemporal;
                        oDiagnosticRepositoryListOld.i_RecordStatus           = (int)RecordStatus.EliminadoLogico;
                        oDiagnosticRepositoryListOld.i_DiagnosticTypeId       = (int)TipoDx.Enfermedad_Comun;
                        ListaDxByComponent.Add(oDiagnosticRepositoryListOld);
                    }

                    DxByComponent.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
                    DxByComponent.i_RecordType             = (int)RecordType.Temporal;
                    DxByComponent.i_RecordStatus           = (int)RecordStatus.Agregado;
                    DxByComponent.i_DiagnosticTypeId       = (int)TipoDx.Enfermedad_Comun;



                    DxByComponent.d_ExpirationDateDiagnostic = DateTime.Now;

                    string ComponentFieldValuesId = oMedicalExamFieldValuesBL.ObtenerIdComponentFieldValues(ComponentFieldId, DiseasesId);
                    DxByComponent.v_ComponentFieldValuesId = ComponentFieldValuesId;


                    DxByComponent.v_ComponentId = ComponentDx;
                    DxByComponent.v_DiseasesId  = DiseasesId;
                    DxByComponent.v_ServiceId   = _ServiceId;


                    //Obtener las recomendaciones

                    DxByComponent.Recomendations = oMedicalExamFieldValuesBL.ObtenerListaRecomendaciones(ComponentFieldValuesId, _ServiceId, Constants.FUNCIONES_VITALES_ID);

                    ListaDxByComponent.Add(DxByComponent);



                    //Llenar entidad ServiceComponent
                    servicecomponentDto serviceComponentDto = new servicecomponentDto();
                    serviceComponentDto.v_ServiceComponentId       = _ServiceComponentId;
                    serviceComponentDto.v_Comment                  = "";
                    serviceComponentDto.i_ServiceComponentStatusId = (int)ServiceComponentStatus.Evaluado;
                    serviceComponentDto.i_ExternalInternalId       = (int)ComponenteProcedencia.Interno;
                    serviceComponentDto.i_IsApprovedId             = (int)SiNo.NO;
                    serviceComponentDto.v_ComponentId              = Constants.FUNCIONES_VITALES_ID;
                    serviceComponentDto.v_ServiceId                = _ServiceId;


                    _serviceBL.AddDiagnosticRepository(ref objOperationResult,
                                                       ListaDxByComponent,
                                                       serviceComponentDto,
                                                       Globals.ClientSession.GetAsList(),
                                                       true);
                }

                ListaDxByComponent = new List <DiagnosticRepositoryList>();

                if (txtPAS.Text != "")
                {
                    DiagnosticRepositoryList DxByComponent = new DiagnosticRepositoryList();

                    List <RecomendationList> Recomendations = new List <RecomendationList>();
                    List <RestrictionList>   Restrictions   = new List <RestrictionList>();
                    int PAS = int.Parse(txtPAS.Text.ToString());

                    DxByComponent.i_AutoManualId         = 1;
                    DxByComponent.i_FinalQualificationId = (int)FinalQualification.Definitivo;
                    DxByComponent.i_PreQualificationId   = 1;
                    DxByComponent.v_ComponentFieldsId    = Constants.FUNCIONES_VITALES_PAS_ID;
                    //Obtener el Componente que está amarrado al DX
                    string ComponentDx = oMedicalExamFieldValuesBL.ObtenerComponentDx(Constants.FUNCIONES_VITALES_PAS_ID);
                    string DiseasesId  = "";
                    if (PAS > 140)
                    {
                        DiseasesId = "N009-DD000000606";
                        string ComponentFieldId = Constants.FUNCIONES_VITALES_PAS_ID;

                        DiagnosticRepositoryList oDiagnosticRepositoryListOld = _serviceBL.VerificarDxExistente(_ServiceId, DiseasesId, ComponentDx, ComponentFieldId);
                        if (oDiagnosticRepositoryListOld != null)
                        {
                            oDiagnosticRepositoryListOld.v_DiagnosticRepositoryId = oDiagnosticRepositoryListOld.v_DiagnosticRepositoryId;
                            oDiagnosticRepositoryListOld.i_RecordType             = (int)RecordType.NoTemporal;
                            oDiagnosticRepositoryListOld.i_RecordStatus           = (int)RecordStatus.EliminadoLogico;
                            oDiagnosticRepositoryListOld.i_DiagnosticTypeId       = (int)TipoDx.Enfermedad_Comun;
                            ListaDxByComponent.Add(oDiagnosticRepositoryListOld);
                        }

                        DxByComponent.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
                        DxByComponent.i_RecordType             = (int)RecordType.Temporal;
                        DxByComponent.i_RecordStatus           = (int)RecordStatus.Agregado;
                        DxByComponent.i_DiagnosticTypeId       = (int)TipoDx.Enfermedad_Comun;



                        DxByComponent.d_ExpirationDateDiagnostic = DateTime.Now;

                        string ComponentFieldValuesId = oMedicalExamFieldValuesBL.ObtenerIdComponentFieldValues(ComponentFieldId, DiseasesId);
                        DxByComponent.v_ComponentFieldValuesId = ComponentFieldValuesId;


                        DxByComponent.v_ComponentId = ComponentDx;
                        DxByComponent.v_DiseasesId  = DiseasesId;
                        DxByComponent.v_ServiceId   = _ServiceId;


                        //Obtener las recomendaciones

                        DxByComponent.Recomendations = oMedicalExamFieldValuesBL.ObtenerListaRecomendaciones(ComponentFieldValuesId, _ServiceId, Constants.FUNCIONES_VITALES_ID);

                        ListaDxByComponent.Add(DxByComponent);

                        //Llenar entidad ServiceComponent
                        servicecomponentDto serviceComponentDto = new servicecomponentDto();
                        serviceComponentDto.v_ServiceComponentId       = _ServiceComponentId;
                        serviceComponentDto.v_Comment                  = "";
                        serviceComponentDto.i_ServiceComponentStatusId = (int)ServiceComponentStatus.Evaluado;
                        serviceComponentDto.i_ExternalInternalId       = (int)ComponenteProcedencia.Interno;
                        serviceComponentDto.i_IsApprovedId             = (int)SiNo.NO;
                        serviceComponentDto.v_ComponentId              = Constants.FUNCIONES_VITALES_ID;
                        serviceComponentDto.v_ServiceId                = _ServiceId;


                        _serviceBL.AddDiagnosticRepository(ref objOperationResult,
                                                           ListaDxByComponent,
                                                           serviceComponentDto,
                                                           Globals.ClientSession.GetAsList(),
                                                           true);
                    }
                }


                ListaDxByComponent = new List <DiagnosticRepositoryList>();
                if (txtICC.Text != "")
                {
                    DiagnosticRepositoryList DxByComponent = new DiagnosticRepositoryList();

                    List <RecomendationList> Recomendations = new List <RecomendationList>();
                    List <RestrictionList>   Restrictions   = new List <RestrictionList>();
                    double ICC = double.Parse(txtICC.Text.ToString());

                    DxByComponent.i_AutoManualId         = 1;
                    DxByComponent.i_FinalQualificationId = (int)FinalQualification.Definitivo;
                    DxByComponent.i_PreQualificationId   = 1;
                    DxByComponent.v_ComponentFieldsId    = Constants.ANTROPOMETRIA_INDICE_CINTURA_ID;
                    //Obtener el Componente que está amarrado al DX
                    string ComponentDx = oMedicalExamFieldValuesBL.ObtenerComponentDx(Constants.ANTROPOMETRIA_INDICE_CINTURA_ID);
                    string DiseasesId  = "";
                    if (ICC > 1)
                    {
                        DiseasesId = "N009-DD000000605";

                        string ComponentFieldId = Constants.ANTROPOMETRIA_INDICE_CINTURA_ID;

                        DiagnosticRepositoryList oDiagnosticRepositoryListOld = _serviceBL.VerificarDxExistente(_ServiceId, DiseasesId, ComponentDx, ComponentFieldId);
                        if (oDiagnosticRepositoryListOld != null)
                        {
                            oDiagnosticRepositoryListOld.v_DiagnosticRepositoryId = oDiagnosticRepositoryListOld.v_DiagnosticRepositoryId;
                            oDiagnosticRepositoryListOld.i_RecordType             = (int)RecordType.NoTemporal;
                            oDiagnosticRepositoryListOld.i_RecordStatus           = (int)RecordStatus.EliminadoLogico;
                            oDiagnosticRepositoryListOld.i_DiagnosticTypeId       = (int)TipoDx.Enfermedad_Comun;
                            ListaDxByComponent.Add(oDiagnosticRepositoryListOld);
                        }

                        DxByComponent.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
                        DxByComponent.i_RecordType             = (int)RecordType.Temporal;
                        DxByComponent.i_RecordStatus           = (int)RecordStatus.Agregado;
                        DxByComponent.i_DiagnosticTypeId       = (int)TipoDx.Enfermedad_Comun;



                        DxByComponent.d_ExpirationDateDiagnostic = DateTime.Now;

                        string ComponentFieldValuesId = oMedicalExamFieldValuesBL.ObtenerIdComponentFieldValues(ComponentFieldId, DiseasesId);
                        DxByComponent.v_ComponentFieldValuesId = ComponentFieldValuesId;


                        DxByComponent.v_ComponentId = ComponentDx;
                        DxByComponent.v_DiseasesId  = DiseasesId;
                        DxByComponent.v_ServiceId   = _ServiceId;


                        //Obtener las recomendaciones

                        DxByComponent.Recomendations = oMedicalExamFieldValuesBL.ObtenerListaRecomendaciones(ComponentFieldValuesId, _ServiceId, Constants.FUNCIONES_VITALES_ID);

                        ListaDxByComponent.Add(DxByComponent);

                        //Llenar entidad ServiceComponent
                        servicecomponentDto serviceComponentDto = new servicecomponentDto();
                        serviceComponentDto.v_ServiceComponentId       = _ServiceComponentId;
                        serviceComponentDto.v_Comment                  = "";
                        serviceComponentDto.i_ServiceComponentStatusId = (int)ServiceComponentStatus.Evaluado;
                        serviceComponentDto.i_ExternalInternalId       = (int)ComponenteProcedencia.Interno;
                        serviceComponentDto.i_IsApprovedId             = (int)SiNo.NO;
                        serviceComponentDto.v_ComponentId              = Constants.FUNCIONES_VITALES_ID;
                        serviceComponentDto.v_ServiceId                = _ServiceId;


                        _serviceBL.AddDiagnosticRepository(ref objOperationResult,
                                                           ListaDxByComponent,
                                                           serviceComponentDto,
                                                           Globals.ClientSession.GetAsList(),
                                                           true);
                    }
                }
                _serviceBL.ActualizarEstadoComponentesPorCategoria(ref objOperationResult, 10, _ServiceId, (int)ServiceComponentStatus.Evaluado, Globals.ClientSession.GetAsList());


                MessageBox.Show("Los datos se grabaron correctamente", "VALIDACIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Por favor corrija la información ingresada. Vea los indicadores de error.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }