public diseasesDto GetIsValidateDiseases(ref OperationResult pobjOperationResult, string pstrDiseasesName)
        {
            //mon.IsActive = true;

            try
            {
                SigesoftEntitiesModel dbContext    = new SigesoftEntitiesModel();
                diseasesDto           objDtoEntity = null;

                var objEntity = (from a in dbContext.diseases
                                 where a.v_Name == pstrDiseasesName && a.i_IsDeleted == 0
                                 select a).FirstOrDefault();

                if (objEntity != null)
                {
                    objDtoEntity = diseasesAssembler.ToDTO(objEntity);
                }

                pobjOperationResult.Success = 1;
                return(objDtoEntity);
            }
            catch (Exception ex)
            {
                pobjOperationResult.Success          = 0;
                pobjOperationResult.ExceptionMessage = Common.Utils.ExceptionFormatter(ex);
                return(null);
            }
        }
        private void btnUpdateandSelect_Click(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();
            diseasesDto     objDiseaseDto      = new diseasesDto();
            diseasesDto     objDiseaseDto1     = new diseasesDto();

            if (btnUpdateandSelect.Enabled == false)
            {
                return;
            }

            if (ultraValidator1.Validate(true, false).IsValid)
            {
                if (grdData.Selected.Rows[0].Cells[0].Value != null)
                {
                    objDiseaseDto = _objMedicalExamFieldValuesBL.GetDiseases(ref objOperationResult, grdData.Selected.Rows[0].Cells[0].Value.ToString());

                    objDiseaseDto.v_CIE10Id = grdData.Selected.Rows[0].Cells[1].Value.ToString();
                    objDiseaseDto.v_Name    = txtDiseases.Text;
                    _objMedicalExamFieldValuesBL.UpdateDiseases(ref objOperationResult, objDiseaseDto, Globals.ClientSession.GetAsList());

                    _objDiseasesList.v_DiseasesId = objDiseaseDto.v_DiseasesId;
                    _objDiseasesList.v_CIE10Id    = objDiseaseDto.v_CIE10Id;
                    _objDiseasesList.v_Name       = objDiseaseDto.v_Name;
                }
                else
                {
                    objDiseaseDto.v_CIE10Id = grdData.Selected.Rows[0].Cells[1].Value.ToString();
                    objDiseaseDto.v_Name    = txtDiseases.Text;


                    objDiseaseDto1 = _objMedicalExamFieldValuesBL.GetIsValidateDiseases(ref objOperationResult, objDiseaseDto.v_Name);

                    if (objDiseaseDto1 == null)
                    {
                        objDiseaseDto.v_DiseasesId = _objMedicalExamFieldValuesBL.AddDiseases(ref objOperationResult, objDiseaseDto, Globals.ClientSession.GetAsList());
                    }
                    else
                    {
                        MessageBox.Show("Escoja uno que tenga código interno", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }


                    //objDiseaseDto.v_DiseasesId=  _objMedicalExamFieldValuesBL.AddDiseases(ref objOperationResult, objDiseaseDto, Globals.ClientSession.GetAsList());

                    _objDiseasesList.v_DiseasesId = objDiseaseDto.v_DiseasesId;
                    _objDiseasesList.v_CIE10Id    = grdData.Selected.Rows[0].Cells[1].Value.ToString();
                    _objDiseasesList.v_Name       = txtDiseases.Text;
                }

                //strEnfermedad = objDiseaseDto.v_DiseasesId;
                this.DialogResult = System.Windows.Forms.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);
            }
        }
Example #3
0
        private void frmMedicalExamEdicion_Load(object sender, EventArgs e)
        {
            #region Mayusculas - Normal
            var _EsMayuscula = int.Parse(Common.Utils.GetApplicationConfigValue("EsMayuscula"));
            if (_EsMayuscula == 1)
            {
                SearchControlAndSetEvents(this);
            }


            #endregion
            OperationResult objOperationResult = new OperationResult();

            MedicalExamFieldValuesBL objMedicalExamFieldValuesBLBL = new MedicalExamFieldValuesBL();

            //Llenado de combos
            Utils.LoadDropDownList(ddlOperatorId, "Value1", "Id", BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 129, "v_Value2"), DropDownListAction.Select);
            //Utils.LoadDropDownList(ddlRestrictionId, "Value1", "Id", BLL.Utils.GetDataHierarchyForCombo(ref objOperationResult, 107, null), DropDownListAction.Select);
            //Utils.LoadDropDownList(ddlRecommendationId, "Value1", "Id", BLL.Utils.GetDataHierarchyForCombo(ref objOperationResult, 112, null), DropDownListAction.Select);
            Utils.LoadDropDownList(ddlIsAnormal, "Value1", "Id", BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 111, null), DropDownListAction.Select);
            Utils.LoadDropDownList(ddlSexTypeId, "Value1", "Id", BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 100, null), DropDownListAction.Select);
            txtAnalyzeValue1.Select();
            if (Mode == "New")
            {
                // Additional logic here.
            }
            else if (Mode == "Edit")
            {
                // Get the Entity Data
                _objmedicalexamfieldValuesDto = new componentfieldvaluesDto();

                _objmedicalexamfieldValuesDto = _objMedicalExamFieldsBL.GetMedicalExamFieldValues(ref objOperationResult, _MedicalExamFliedValueId);

                txtAnalyzeValue1.Text       = _objmedicalexamfieldValuesDto.v_AnalyzingValue1.ToString();
                txtAnalyzeValue2.Text       = _objmedicalexamfieldValuesDto.v_AnalyzingValue2.ToString() == "0" ? string.Empty : _objmedicalexamfieldValuesDto.v_AnalyzingValue2.ToString();
                ddlOperatorId.SelectedValue = _objmedicalexamfieldValuesDto.i_OperatorId.ToString();
                txtLegalStandard.Text       = _objmedicalexamfieldValuesDto.v_LegalStandard;
                ddlIsAnormal.SelectedValue  = _objmedicalexamfieldValuesDto.i_IsAnormal.ToString();
                objdiseasesDto = _objMedicalExamFieldsBL.GetDiseases(ref objOperationResult, _objmedicalexamfieldValuesDto.v_DiseasesId);

                ddlSexTypeId.SelectedValue = _objmedicalexamfieldValuesDto.i_GenderId.ToString();

                txtDiagnostic.Text            = objdiseasesDto == null ? String.Empty : objdiseasesDto.v_Name + " - CÓDIGO CIE10 : " + objdiseasesDto.v_CIE10Id;
                _objDiseasesList.v_DiseasesId = objdiseasesDto == null ? null : objdiseasesDto.v_DiseasesId;
                //_objDiseasesList.

                _TempComponentFieldValuesRestrictionList = objMedicalExamFieldValuesBLBL.GetRestrictionsPagedAndFiltered(ref objOperationResult, 0, null, "", "v_ComponentFieldValuesId==  \"" + _objmedicalexamfieldValuesDto.v_ComponentFieldValuesId + "\"");
                grdDataRestrictions.DataSource           = _TempComponentFieldValuesRestrictionList;

                _TempComponentFieldValuesRecommendationList = objMedicalExamFieldValuesBLBL.GetRecommendationsPagedAndFiltered(ref objOperationResult, 0, null, "", "v_ComponentFieldValuesId==  \"" + _objmedicalexamfieldValuesDto.v_ComponentFieldValuesId + "\"");
                grdDataRecommendation.DataSource            = _TempComponentFieldValuesRecommendationList;
            }
        }
Example #4
0
        protected void btnSaveRefresh_Click(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();
            diseasesDto     objDiseaseDto      = new diseasesDto();
            diseasesDto     objDiseaseDto1     = new diseasesDto();

            if (Session["DiseasesId"] != null)
            {
                objDiseaseDto = oServiceBL.GetDiseases(ref objOperationResult, Session["DiseasesId"].ToString());

                objDiseaseDto.v_CIE10Id = Session["Cie10Id"].ToString();
                objDiseaseDto.v_Name    = txtDxModificado.Text;
                Session["OtroDx"]       = objDiseaseDto.v_Name;
                Session["OtroDxId"]     = objDiseaseDto.v_DiseasesId;
                oServiceBL.UpdateDiseases(ref objOperationResult, objDiseaseDto, ((ClientSession)Session["objClientSession"]).GetAsList());
            }
            else
            {
                objDiseaseDto.v_CIE10Id = Session["Cie10Id"].ToString();
                objDiseaseDto.v_Name    = txtDxModificado.Text;
                Session["OtroDx"]       = objDiseaseDto.v_Name;

                objDiseaseDto1 = oServiceBL.GetIsValidateDiseases(ref objOperationResult, objDiseaseDto.v_Name);

                if (objDiseaseDto1 == null)
                {
                    objDiseaseDto.v_DiseasesId = oServiceBL.AddDiseases(ref objOperationResult, objDiseaseDto, ((ClientSession)Session["objClientSession"]).GetAsList());
                    Session["OtroDxId"]        = objDiseaseDto.v_DiseasesId;
                }
                else
                {
                    Alert.Show("Escoja uno que tenga código interno", "Error de validación", MessageBoxIcon.Warning);
                    return;
                }
            }

            if (objOperationResult.Success == 1)  // Operación sin error
            {
                // Cerrar página actual y hacer postback en el padre para actualizar
                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            }
            else  // Operación con error
            {
                Alert.ShowInTop("Error en operación:" + System.Environment.NewLine + objOperationResult.ExceptionMessage);
                // Se queda en el formulario.
            }
        }
        private void grdData_DoubleClick(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();
            diseasesDto     objDiseaseDto      = new diseasesDto();
            diseasesDto     objDiseaseDto1     = new diseasesDto();

            if (grdData.Selected.Rows == null)
            {
                return;
            }
            if (grdData.Selected.Rows.Count == 0)
            {
                return;
            }

            if (grdData.Selected.Rows[0].Cells[0].Value == null)
            {
                objDiseaseDto.v_CIE10Id = grdData.Selected.Rows[0].Cells[1].Value.ToString();
                objDiseaseDto.v_Name    = grdData.Selected.Rows[0].Cells[2].Value.ToString();

                objDiseaseDto1 = _objMedicalExamFieldValuesBL.GetIsValidateDiseases(ref objOperationResult, objDiseaseDto.v_Name);

                if (objDiseaseDto1 == null)
                {
                    objDiseaseDto.v_DiseasesId = _objMedicalExamFieldValuesBL.AddDiseases(ref objOperationResult, objDiseaseDto, Globals.ClientSession.GetAsList());
                }
                else
                {
                    MessageBox.Show("Escoja uno que tenga código interno", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                _objDiseasesList.v_DiseasesId = objDiseaseDto.v_DiseasesId;
                _objDiseasesList.v_CIE10Id    = objDiseaseDto.v_CIE10Id;
                _objDiseasesList.v_Name       = objDiseaseDto.v_Name;
            }
            else
            {
                _objDiseasesList.v_DiseasesId = grdData.Selected.Rows[0].Cells[0].Value.ToString();
                _objDiseasesList.v_CIE10Id    = grdData.Selected.Rows[0].Cells[1].Value.ToString();
                _objDiseasesList.v_Name       = grdData.Selected.Rows[0].Cells[2].Value.ToString();
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
        public string AddDiseases(ref OperationResult pobjOperationResult, diseasesDto pobjDtoEntity, List <string> ClientSession)
        {
            //mon.IsActive = true;
            string NewId = "(No generado)";

            try
            {
                SigesoftEntitiesModel dbContext = new SigesoftEntitiesModel();
                diseases objEntity = diseasesAssembler.ToEntity(pobjDtoEntity);

                objEntity.d_InsertDate   = DateTime.Now;
                objEntity.i_InsertUserId = Int32.Parse(ClientSession[2]);
                objEntity.i_IsDeleted    = 0;
                // Autogeneramos el Pk de la tabla
                int intNodeId = int.Parse(ClientSession[0]);
                NewId = Common.Utils.GetNewId(intNodeId, Utils.GetNextSecuentialId(intNodeId, 27), "DD");
                objEntity.v_DiseasesId = NewId;


                dbContext.AddTodiseases(objEntity);
                dbContext.SaveChanges();

                pobjOperationResult.Success = 1;
                // Llenar entidad Log
                LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.CREACION, "ENFERMEDAD", "v_Diseases=" + NewId.ToString(), Success.Ok, null);
                return(NewId);
            }
            catch (Exception ex)
            {
                pobjOperationResult.Success          = 0;
                pobjOperationResult.ExceptionMessage = Common.Utils.ExceptionFormatter(ex);
                // Llenar entidad Log
                LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.CREACION, "ENFERMEDAD", "v_Diseases=" + NewId.ToString(), Success.Failed, pobjOperationResult.ExceptionMessage);
                return(null);
            }
        }
Example #7
0
        protected void btnSaveRefresh_Click(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();
            diseasesDto     objDiseaseDto      = new diseasesDto();
            diseasesDto     objDiseaseDto1     = new diseasesDto();

            if (Session["DiseasesId"] != null)
            {
                objDiseaseDto = oServiceBL.GetDiseases(ref objOperationResult, Session["DiseasesId"].ToString());

                objDiseaseDto.v_CIE10Id = Session["Cie10Id"].ToString();
                objDiseaseDto.v_Name    = txtDxModificado.Text;
                oServiceBL.UpdateDiseases(ref objOperationResult, objDiseaseDto, ((ClientSession)Session["objClientSession"]).GetAsList());

                //_objDiseasesList.v_DiseasesId = objDiseaseDto.v_DiseasesId;
                //_objDiseasesList.v_CIE10Id = objDiseaseDto.v_CIE10Id;
                //_objDiseasesList.v_Name = objDiseaseDto.v_Name;
            }
            else
            {
                objDiseaseDto.v_CIE10Id = Session["Cie10Id"].ToString();
                objDiseaseDto.v_Name    = txtDxModificado.Text;


                objDiseaseDto1 = oServiceBL.GetIsValidateDiseases(ref objOperationResult, objDiseaseDto.v_Name);

                if (objDiseaseDto1 == null)
                {
                    objDiseaseDto.v_DiseasesId = oServiceBL.AddDiseases(ref objOperationResult, objDiseaseDto, ((ClientSession)Session["objClientSession"]).GetAsList());
                }
                else
                {
                    Alert.Show("Escoja uno que tenga código interno", "Error de validación", MessageBoxIcon.Warning);
                    return;
                }
            }

            //Grabar el Dx en el servicio


            Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList        _diagnosticRepository      = new Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList();
            List <Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList> _ListadiagnosticRepository = new List <Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList>();

            _diagnosticRepository.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
            _diagnosticRepository.v_DiseasesId             = Session["DiseasesId"] == null ? objDiseaseDto.v_DiseasesId : Session["DiseasesId"].ToString();
            _diagnosticRepository.i_AutoManualId           = 1;
            _diagnosticRepository.i_PreQualificationId     = 1;
            _diagnosticRepository.i_FinalQualificationId   = (int)FinalQualification.Definitivo;
            _diagnosticRepository.i_DiagnosticTypeId       = (int)TipoDx.Enfermedad_Comun;

            _diagnosticRepository.v_ServiceId    = Session["ServiceId"].ToString();
            _diagnosticRepository.v_ComponentId  = ddlExamen.SelectedValue.ToString(); //_componentId;
            _diagnosticRepository.v_DiseasesName = objDiseaseDto.v_Name;
            _diagnosticRepository.i_RecordStatus = (int)RecordStatus.Agregado;
            _diagnosticRepository.i_RecordType   = (int)RecordType.Temporal;
            _diagnosticRepository.Restrictions   = null;
            _diagnosticRepository.Recomendations = null;

            _ListadiagnosticRepository.Add(_diagnosticRepository);

            oServiceBL.AddDiagnosticRepository(ref objOperationResult, _ListadiagnosticRepository, null, ((ClientSession)Session["objClientSession"]).GetAsList(), true);

            if (objOperationResult.Success == 1)  // Operación sin error
            {
                // Cerrar página actual y hacer postback en el padre para actualizar
                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            }
            else  // Operación con error
            {
                Alert.ShowInTop("Error en operación:" + System.Environment.NewLine + objOperationResult.ExceptionMessage);
                // Se queda en el formulario.
            }
        }
        protected void btnSaveRefresh_Click(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();
            diseasesDto     objDiseaseDto      = new diseasesDto();
            diseasesDto     objDiseaseDto1     = new diseasesDto();
            List <dxfrecuentedetalleDto> ListadxfrecuentedetalleDto = new List <dxfrecuentedetalleDto>();

            if (ddlExamen.SelectedValue == null || ddlExamen.SelectedValue == "-1")
            {
                Alert.Show("Por favor seleccione un examen.");
                return;
            }

            if (Session["v_DxFrecuenteId"] != null) // Grabar un Dx frecuente
            {
                //Grabar el Dx en el servicio
                Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList        _diagnosticRepository      = new Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList();
                List <Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList> _ListadiagnosticRepository = new List <Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList>();

                List <Sigesoft.Node.WinClient.BE.RecomendationList> Recomendaciones = new List <Node.WinClient.BE.RecomendationList>();
                Sigesoft.Node.WinClient.BE.RecomendationList        Recomendacion   = null;


                List <Sigesoft.Node.WinClient.BE.RestrictionList> Restricciones = new List <Node.WinClient.BE.RestrictionList>();
                Sigesoft.Node.WinClient.BE.RestrictionList        Restriccion   = null;



                _diagnosticRepository.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
                _diagnosticRepository.v_DiseasesId             = Session["DiseasesId"].ToString();
                _diagnosticRepository.i_AutoManualId           = 1;
                _diagnosticRepository.i_PreQualificationId     = 1;
                _diagnosticRepository.i_FinalQualificationId   = (int)FinalQualification.Definitivo;
                _diagnosticRepository.i_DiagnosticTypeId       = (int)TipoDx.Enfermedad_Comun;

                _diagnosticRepository.v_ServiceId    = Session["ServiceId"].ToString();
                _diagnosticRepository.v_ComponentId  = ddlExamen.SelectedValue.ToString(); //_componentId;
                _diagnosticRepository.i_RecordStatus = (int)RecordStatus.Agregado;
                _diagnosticRepository.i_RecordType   = (int)RecordType.Temporal;

                #region Recomendación
                if (txtRecomendacion1.Text.Trim() != "")
                {
                    //Verficiar si la recomendación se encuentra en la bd
                    MasterRecommendationRestricctionBL oMasterRecommendationRestricctionBL = new MasterRecommendationRestricctionBL();
                    var masterrecommendation = oMasterRecommendationRestricctionBL.GetMasterRecommendationRestricctionByName(txtRecomendacion1.Text.Trim());

                    if (masterrecommendation == null)
                    {
                        masterrecommendationrestricctionDto omasterrecommendationrestricctionDto = new masterrecommendationrestricctionDto();
                        omasterrecommendationrestricctionDto.v_Name        = txtRecomendacion1.Text.Trim();
                        omasterrecommendationrestricctionDto.i_TypifyingId = 1;
                        //Crear Recomendación
                        var MasterRecommendationId = oMasterRecommendationRestricctionBL.AddMasterRecommendationRestricction(ref objOperationResult, omasterrecommendationrestricctionDto, ((ClientSession)Session["objClientSession"]).GetAsList());

                        Recomendacion = new Node.WinClient.BE.RecomendationList();

                        Recomendacion.v_ServiceId              = Session["ServiceId"].ToString();
                        Recomendacion.v_ComponentId            = ddlExamen.SelectedValue.ToString();
                        Recomendacion.v_MasterRecommendationId = MasterRecommendationId;
                        Recomendacion.i_RecordType             = (int)RecordType.Temporal;
                        Recomendacion.i_RecordStatus           = (int)RecordStatus.Agregado;
                        Recomendaciones.Add(Recomendacion);
                    }
                    else
                    {
                        var ListaReco = oServiceBL.ObtenerListaRecomendacionesPorDxFrecuente(Session["v_DxFrecuenteId"].ToString(), 1);

                        foreach (var item in ListaReco)
                        {
                            Recomendacion = new Node.WinClient.BE.RecomendationList();

                            Recomendacion.v_ServiceId              = Session["ServiceId"].ToString();
                            Recomendacion.v_ComponentId            = ddlExamen.SelectedValue.ToString();
                            Recomendacion.v_MasterRecommendationId = item.v_MasterRecommendationRestricctionId;
                            Recomendacion.i_RecordType             = (int)RecordType.Temporal;
                            Recomendacion.i_RecordStatus           = (int)RecordStatus.Agregado;
                            Recomendaciones.Add(Recomendacion);
                        }
                    }
                }

                #endregion

                #region Restricciones

                if (txtRestriccion1.Text.Trim() != "")
                {
                    //Verficiar si la recomendación se encuentra en la bd
                    MasterRecommendationRestricctionBL oMasterRecommendationRestricctionBL = new MasterRecommendationRestricctionBL();
                    var masterrestriccion = oMasterRecommendationRestricctionBL.GetMasterRecommendationRestricctionByName(txtRestriccion1.Text.Trim());
                    if (masterrestriccion == null)
                    {
                        masterrecommendationrestricctionDto omasterrecommendationrestricctionDto = new masterrecommendationrestricctionDto();
                        omasterrecommendationrestricctionDto.v_Name        = txtRestriccion1.Text.Trim();
                        omasterrecommendationrestricctionDto.i_TypifyingId = 2;
                        //Crear Restricción
                        var MasterRestriccionId = oMasterRecommendationRestricctionBL.AddMasterRecommendationRestricction(ref objOperationResult, omasterrecommendationrestricctionDto, ((ClientSession)Session["objClientSession"]).GetAsList());

                        Restriccion = new Node.WinClient.BE.RestrictionList();

                        Restriccion.v_ServiceId           = Session["ServiceId"].ToString();
                        Restriccion.v_ComponentId         = ddlExamen.SelectedValue.ToString();
                        Restriccion.v_MasterRestrictionId = MasterRestriccionId;
                        Restriccion.i_RecordType          = (int)RecordType.Temporal;
                        Restriccion.i_RecordStatus        = (int)RecordStatus.Agregado;
                        Restricciones.Add(Restriccion);
                    }
                    else
                    {
                        var ListaRestri = oServiceBL.ObtenerListaRecomendacionesPorDxFrecuente(Session["v_DxFrecuenteId"].ToString(), 2);

                        foreach (var item1 in ListaRestri)
                        {
                            Restriccion = new Node.WinClient.BE.RestrictionList();

                            Restriccion.v_ServiceId           = Session["ServiceId"].ToString();
                            Restriccion.v_ComponentId         = ddlExamen.SelectedValue.ToString();
                            Restriccion.v_MasterRestrictionId = item1.v_MasterRecommendationRestricctionId;
                            Restriccion.i_RecordType          = (int)RecordType.Temporal;
                            Restriccion.i_RecordStatus        = (int)RecordStatus.Agregado;
                            Restricciones.Add(Restriccion);
                        }
                    }
                }

                #endregion

                _diagnosticRepository.Restrictions   = Restricciones;
                _diagnosticRepository.Recomendations = Recomendaciones;

                _ListadiagnosticRepository.Add(_diagnosticRepository);

                oServiceBL.AddDiagnosticRepository(ref objOperationResult, _ListadiagnosticRepository, null, ((ClientSession)Session["objClientSession"]).GetAsList(), true);

                if (objOperationResult.Success == 1)  // Operación sin error
                {
                    // Cerrar página actual y hacer postback en el padre para actualizar
                    PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
                else  // Operación con error
                {
                    Alert.ShowInTop("Error en operación:" + System.Environment.NewLine + objOperationResult.ExceptionMessage);
                    // Se queda en el formulario.
                }
            }
            else if (Session["DiseasesId"] == null)
            {
                #region Crear el Dx Frecuente

                objDiseaseDto.v_CIE10Id = Session["Cie10Id"].ToString();
                objDiseaseDto.v_Name    = txtDxActualizado.Text;

                objDiseaseDto1 = oServiceBL.GetIsValidateDiseases(ref objOperationResult, objDiseaseDto.v_Name);
                string DxFrecuneteId = null;
                if (objDiseaseDto1 == null)
                {
                    //Creo el Diseases
                    objDiseaseDto.v_DiseasesId = oServiceBL.AddDiseases(ref objOperationResult, objDiseaseDto, ((ClientSession)Session["objClientSession"]).GetAsList());

                    //Crear nuevo Dx Frecuente y lo amarro al diseasesId creado
                    DxFrecuenteBL  oDxFrecuenteBL  = new DxFrecuenteBL();
                    dxfrecuenteDto odxfrecuenteDto = new dxfrecuenteDto();
                    odxfrecuenteDto.v_DiseasesId = objDiseaseDto.v_DiseasesId;
                    odxfrecuenteDto.v_CIE10Id    = Session["Cie10Id"].ToString();
                    DxFrecuneteId = oDxFrecuenteBL.AddDxFrecuente(ref objOperationResult, odxfrecuenteDto, ((ClientSession)Session["objClientSession"]).GetAsList());

                    //Agregar Recomendaciones a Dx Frecuente
                    dxfrecuentedetalleDto odxfrecuentedetalleDto = new dxfrecuentedetalleDto();

                    //Verficiar si la recomendación se encuentra en la bd
                    MasterRecommendationRestricctionBL oMasterRecommendationRestricctionBL = new MasterRecommendationRestricctionBL();
                    var masterrecommendation   = oMasterRecommendationRestricctionBL.GetMasterRecommendationRestricctionByName(txtRecomendacion1.Text.Trim());
                    var MasterRecommendationId = "";
                    if (masterrecommendation == null)
                    {
                        masterrecommendationrestricctionDto omasterrecommendationrestricctionDto = new masterrecommendationrestricctionDto();
                        omasterrecommendationrestricctionDto.v_Name        = txtRecomendacion1.Text.Trim();
                        omasterrecommendationrestricctionDto.i_TypifyingId = 1;
                        //Crear Recomendación
                        MasterRecommendationId = oMasterRecommendationRestricctionBL.AddMasterRecommendationRestricction(ref objOperationResult, omasterrecommendationrestricctionDto, ((ClientSession)Session["objClientSession"]).GetAsList());
                    }
                    odxfrecuentedetalleDto.v_DxFrecuenteId = DxFrecuneteId;
                    odxfrecuentedetalleDto.v_MasterRecommendationRestricctionId = MasterRecommendationId;
                    ListadxfrecuentedetalleDto.Add(odxfrecuentedetalleDto);


                    odxfrecuentedetalleDto = new dxfrecuentedetalleDto();
                    //Agregar Restricciones a Dx Frecuente
                    var masterrestriccion   = oMasterRecommendationRestricctionBL.GetMasterRecommendationRestricctionByName(txtRestriccion1.Text.Trim());
                    var MasterRestriccionId = "";
                    if (masterrestriccion == null)
                    {
                        masterrecommendationrestricctionDto omasterrecommendationrestricctionDto = new masterrecommendationrestricctionDto();
                        omasterrecommendationrestricctionDto.v_Name        = txtRestriccion1.Text.Trim();
                        omasterrecommendationrestricctionDto.i_TypifyingId = 2;
                        //Crear Restricción
                        MasterRestriccionId = oMasterRecommendationRestricctionBL.AddMasterRecommendationRestricction(ref objOperationResult, omasterrecommendationrestricctionDto, ((ClientSession)Session["objClientSession"]).GetAsList());
                    }
                    odxfrecuentedetalleDto.v_DxFrecuenteId = DxFrecuneteId;
                    odxfrecuentedetalleDto.v_MasterRecommendationRestricctionId = MasterRestriccionId;
                    ListadxfrecuentedetalleDto.Add(odxfrecuentedetalleDto);
                    //Agrego el detalle de los dxfrecuentes creados
                    foreach (var item in ListadxfrecuentedetalleDto)
                    {
                        oDxFrecuenteBL.AddDxFrecuenteDetalle(ref objOperationResult, item, ((ClientSession)Session["objClientSession"]).GetAsList());
                    }
                }
                else
                {
                    Alert.Show("Escoja uno que tenga código interno", "Error de validación", MessageBoxIcon.Warning);
                    return;
                }

                #endregion

                #region Grabo el dx al servicio

                //Grabar el Dx en el servicio
                Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList        _diagnosticRepository      = new Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList();
                List <Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList> _ListadiagnosticRepository = new List <Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList>();

                List <Sigesoft.Node.WinClient.BE.RecomendationList> Recomendaciones = new List <Node.WinClient.BE.RecomendationList>();
                Sigesoft.Node.WinClient.BE.RecomendationList        Recomendacion   = null;


                List <Sigesoft.Node.WinClient.BE.RestrictionList> Restricciones = new List <Node.WinClient.BE.RestrictionList>();
                Sigesoft.Node.WinClient.BE.RestrictionList        Restriccion   = null;



                _diagnosticRepository.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
                _diagnosticRepository.v_DiseasesId             = objDiseaseDto.v_DiseasesId;
                _diagnosticRepository.i_AutoManualId           = 1;
                _diagnosticRepository.i_PreQualificationId     = 1;
                _diagnosticRepository.i_FinalQualificationId   = (int)FinalQualification.Definitivo;
                _diagnosticRepository.i_DiagnosticTypeId       = (int)TipoDx.Enfermedad_Comun;

                _diagnosticRepository.v_ServiceId    = Session["ServiceId"].ToString();
                _diagnosticRepository.v_ComponentId  = ddlExamen.SelectedValue.ToString(); //_componentId;
                _diagnosticRepository.i_RecordStatus = (int)RecordStatus.Agregado;
                _diagnosticRepository.i_RecordType   = (int)RecordType.Temporal;

                #region Recomendación
                if (txtRecomendacion1.Text.Trim() != "")
                {
                    //Verficiar si la recomendación se encuentra en la bd
                    MasterRecommendationRestricctionBL oMasterRecommendationRestricctionBL = new MasterRecommendationRestricctionBL();
                    var masterrecommendation = oMasterRecommendationRestricctionBL.GetMasterRecommendationRestricctionByName(txtRecomendacion1.Text.Trim());

                    if (masterrecommendation == null)
                    {
                        masterrecommendationrestricctionDto omasterrecommendationrestricctionDto = new masterrecommendationrestricctionDto();
                        omasterrecommendationrestricctionDto.v_Name        = txtRecomendacion1.Text.Trim();
                        omasterrecommendationrestricctionDto.i_TypifyingId = 1;
                        //Crear Recomendación
                        var MasterRecommendationId = oMasterRecommendationRestricctionBL.AddMasterRecommendationRestricction(ref objOperationResult, omasterrecommendationrestricctionDto, ((ClientSession)Session["objClientSession"]).GetAsList());

                        Recomendacion = new Node.WinClient.BE.RecomendationList();

                        Recomendacion.v_ServiceId              = Session["ServiceId"].ToString();
                        Recomendacion.v_ComponentId            = ddlExamen.SelectedValue.ToString();
                        Recomendacion.v_MasterRecommendationId = MasterRecommendationId;
                        Recomendacion.i_RecordType             = (int)RecordType.Temporal;
                        Recomendacion.i_RecordStatus           = (int)RecordStatus.Agregado;
                        Recomendaciones.Add(Recomendacion);
                    }
                    else
                    {
                        var ListaReco = oServiceBL.ObtenerListaRecomendacionesPorDxFrecuente(DxFrecuneteId, 1);

                        foreach (var item in ListaReco)
                        {
                            Recomendacion = new Node.WinClient.BE.RecomendationList();

                            Recomendacion.v_ServiceId              = Session["ServiceId"].ToString();
                            Recomendacion.v_ComponentId            = ddlExamen.SelectedValue.ToString();
                            Recomendacion.v_MasterRecommendationId = item.v_MasterRecommendationRestricctionId;
                            Recomendacion.i_RecordType             = (int)RecordType.Temporal;
                            Recomendacion.i_RecordStatus           = (int)RecordStatus.Agregado;
                            Recomendaciones.Add(Recomendacion);
                        }
                    }
                }

                #endregion

                #region Restricciones

                if (txtRestriccion1.Text.Trim() != "")
                {
                    //Verficiar si la recomendación se encuentra en la bd
                    MasterRecommendationRestricctionBL oMasterRecommendationRestricctionBL = new MasterRecommendationRestricctionBL();
                    var masterrestriccion = oMasterRecommendationRestricctionBL.GetMasterRecommendationRestricctionByName(txtRestriccion1.Text.Trim());
                    if (masterrestriccion == null)
                    {
                        masterrecommendationrestricctionDto omasterrecommendationrestricctionDto = new masterrecommendationrestricctionDto();
                        omasterrecommendationrestricctionDto.v_Name        = txtRestriccion1.Text.Trim();
                        omasterrecommendationrestricctionDto.i_TypifyingId = 2;
                        //Crear Restricción
                        var MasterRestriccionId = oMasterRecommendationRestricctionBL.AddMasterRecommendationRestricction(ref objOperationResult, omasterrecommendationrestricctionDto, ((ClientSession)Session["objClientSession"]).GetAsList());

                        Restriccion = new Node.WinClient.BE.RestrictionList();

                        Restriccion.v_ServiceId           = Session["ServiceId"].ToString();
                        Restriccion.v_ComponentId         = ddlExamen.SelectedValue.ToString();
                        Restriccion.v_MasterRestrictionId = MasterRestriccionId;
                        Restriccion.i_RecordType          = (int)RecordType.Temporal;
                        Restriccion.i_RecordStatus        = (int)RecordStatus.Agregado;
                        Restricciones.Add(Restriccion);
                    }
                    else
                    {
                        var ListaRestri = oServiceBL.ObtenerListaRecomendacionesPorDxFrecuente(DxFrecuneteId, 2);

                        foreach (var item1 in ListaRestri)
                        {
                            Restriccion = new Node.WinClient.BE.RestrictionList();

                            Restriccion.v_ServiceId           = Session["ServiceId"].ToString();
                            Restriccion.v_ComponentId         = ddlExamen.SelectedValue.ToString();
                            Restriccion.v_MasterRestrictionId = item1.v_MasterRecommendationRestricctionId;
                            Restriccion.i_RecordType          = (int)RecordType.Temporal;
                            Restriccion.i_RecordStatus        = (int)RecordStatus.Agregado;
                            Restricciones.Add(Restriccion);
                        }
                    }
                }

                #endregion

                _diagnosticRepository.Restrictions   = Restricciones;
                _diagnosticRepository.Recomendations = Recomendaciones;

                _ListadiagnosticRepository.Add(_diagnosticRepository);

                oServiceBL.AddDiagnosticRepository(ref objOperationResult, _ListadiagnosticRepository, null, ((ClientSession)Session["objClientSession"]).GetAsList(), true);

                if (objOperationResult.Success == 1)  // Operación sin error
                {
                    // Cerrar página actual y hacer postback en el padre para actualizar
                    PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
                else  // Operación con error
                {
                    Alert.ShowInTop("Error en operación:" + System.Environment.NewLine + objOperationResult.ExceptionMessage);
                    // Se queda en el formulario.
                }
                #endregion
            }
            else if (Session["DiseasesId"] != null)
            {
                string DxFrecuneteId = null;
                objDiseaseDto = oServiceBL.GetDiseases(ref objOperationResult, Session["DiseasesId"].ToString());

                objDiseaseDto.v_CIE10Id = Session["Cie10Id"].ToString();
                objDiseaseDto.v_Name    = txtDxActualizado.Text;
                oServiceBL.UpdateDiseases(ref objOperationResult, objDiseaseDto, ((ClientSession)Session["objClientSession"]).GetAsList());

                #region Crear el Dx Frecuente
                //Crear nuevo Dx Frecuente y lo amarro al diseasesId creado
                DxFrecuenteBL  oDxFrecuenteBL  = new DxFrecuenteBL();
                dxfrecuenteDto odxfrecuenteDto = new dxfrecuenteDto();
                odxfrecuenteDto.v_DiseasesId = objDiseaseDto.v_DiseasesId;
                odxfrecuenteDto.v_CIE10Id    = Session["Cie10Id"].ToString();
                DxFrecuneteId = oDxFrecuenteBL.AddDxFrecuente(ref objOperationResult, odxfrecuenteDto, ((ClientSession)Session["objClientSession"]).GetAsList());

                //Agregar Recomendaciones a Dx Frecuente
                dxfrecuentedetalleDto odxfrecuentedetalleDto = new dxfrecuentedetalleDto();

                //Verficiar si la recomendación se encuentra en la bd
                MasterRecommendationRestricctionBL oMasterRecommendationRestricctionBL = new MasterRecommendationRestricctionBL();
                var masterrecommendation   = oMasterRecommendationRestricctionBL.GetMasterRecommendationRestricctionByName(txtRecomendacion1.Text.Trim());
                var MasterRecommendationId = "";
                if (masterrecommendation == null)
                {
                    masterrecommendationrestricctionDto omasterrecommendationrestricctionDto = new masterrecommendationrestricctionDto();
                    omasterrecommendationrestricctionDto.v_Name        = txtRecomendacion1.Text.Trim();
                    omasterrecommendationrestricctionDto.i_TypifyingId = 1;
                    //Crear Recomendación
                    MasterRecommendationId = oMasterRecommendationRestricctionBL.AddMasterRecommendationRestricction(ref objOperationResult, omasterrecommendationrestricctionDto, ((ClientSession)Session["objClientSession"]).GetAsList());
                }
                odxfrecuentedetalleDto.v_DxFrecuenteId = DxFrecuneteId;
                odxfrecuentedetalleDto.v_MasterRecommendationRestricctionId = MasterRecommendationId;
                ListadxfrecuentedetalleDto.Add(odxfrecuentedetalleDto);


                odxfrecuentedetalleDto = new dxfrecuentedetalleDto();
                //Agregar Restricciones a Dx Frecuente
                var masterrestriccion   = oMasterRecommendationRestricctionBL.GetMasterRecommendationRestricctionByName(txtRestriccion1.Text.Trim());
                var MasterRestriccionId = "";
                if (masterrestriccion == null)
                {
                    masterrecommendationrestricctionDto omasterrecommendationrestricctionDto = new masterrecommendationrestricctionDto();
                    omasterrecommendationrestricctionDto.v_Name        = txtRestriccion1.Text.Trim();
                    omasterrecommendationrestricctionDto.i_TypifyingId = 2;
                    //Crear Restricción
                    MasterRestriccionId = oMasterRecommendationRestricctionBL.AddMasterRecommendationRestricction(ref objOperationResult, omasterrecommendationrestricctionDto, ((ClientSession)Session["objClientSession"]).GetAsList());
                }
                odxfrecuentedetalleDto.v_DxFrecuenteId = DxFrecuneteId;
                odxfrecuentedetalleDto.v_MasterRecommendationRestricctionId = MasterRestriccionId;
                ListadxfrecuentedetalleDto.Add(odxfrecuentedetalleDto);
                //Agrego el detalle de los dxfrecuentes creados
                foreach (var item in ListadxfrecuentedetalleDto)
                {
                    oDxFrecuenteBL.AddDxFrecuenteDetalle(ref objOperationResult, item, ((ClientSession)Session["objClientSession"]).GetAsList());
                }
                #endregion

                #region Grabo el dx al servicio

                //Grabar el Dx en el servicio
                Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList        _diagnosticRepository      = new Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList();
                List <Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList> _ListadiagnosticRepository = new List <Sigesoft.Node.WinClient.BE.DiagnosticRepositoryList>();

                List <Sigesoft.Node.WinClient.BE.RecomendationList> Recomendaciones = new List <Node.WinClient.BE.RecomendationList>();
                Sigesoft.Node.WinClient.BE.RecomendationList        Recomendacion   = null;


                List <Sigesoft.Node.WinClient.BE.RestrictionList> Restricciones = new List <Node.WinClient.BE.RestrictionList>();
                Sigesoft.Node.WinClient.BE.RestrictionList        Restriccion   = null;



                _diagnosticRepository.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
                _diagnosticRepository.v_DiseasesId             = objDiseaseDto.v_DiseasesId;
                _diagnosticRepository.i_AutoManualId           = 1;
                _diagnosticRepository.i_PreQualificationId     = 1;
                _diagnosticRepository.i_FinalQualificationId   = (int)FinalQualification.Definitivo;
                _diagnosticRepository.i_DiagnosticTypeId       = (int)TipoDx.Enfermedad_Comun;

                _diagnosticRepository.v_ServiceId    = Session["ServiceId"].ToString();
                _diagnosticRepository.v_ComponentId  = ddlExamen.SelectedValue.ToString(); //_componentId;
                _diagnosticRepository.i_RecordStatus = (int)RecordStatus.Agregado;
                _diagnosticRepository.i_RecordType   = (int)RecordType.Temporal;

                #region Recomendación
                if (txtRecomendacion1.Text.Trim() != "")
                {
                    //Verficiar si la recomendación se encuentra en la bd
                    masterrecommendation = oMasterRecommendationRestricctionBL.GetMasterRecommendationRestricctionByName(txtRecomendacion1.Text.Trim());

                    if (masterrecommendation == null)
                    {
                        masterrecommendationrestricctionDto omasterrecommendationrestricctionDto = new masterrecommendationrestricctionDto();
                        omasterrecommendationrestricctionDto.v_Name        = txtRecomendacion1.Text.Trim();
                        omasterrecommendationrestricctionDto.i_TypifyingId = 1;
                        //Crear Recomendación
                        MasterRecommendationId = oMasterRecommendationRestricctionBL.AddMasterRecommendationRestricction(ref objOperationResult, omasterrecommendationrestricctionDto, ((ClientSession)Session["objClientSession"]).GetAsList());

                        Recomendacion = new Node.WinClient.BE.RecomendationList();

                        Recomendacion.v_ServiceId              = Session["ServiceId"].ToString();
                        Recomendacion.v_ComponentId            = ddlExamen.SelectedValue.ToString();
                        Recomendacion.v_MasterRecommendationId = MasterRecommendationId;
                        Recomendacion.i_RecordType             = (int)RecordType.Temporal;
                        Recomendacion.i_RecordStatus           = (int)RecordStatus.Agregado;
                        Recomendaciones.Add(Recomendacion);
                    }
                    else
                    {
                        var ListaReco = oServiceBL.ObtenerListaRecomendacionesPorDxFrecuente(DxFrecuneteId, 1);

                        foreach (var item in ListaReco)
                        {
                            Recomendacion = new Node.WinClient.BE.RecomendationList();

                            Recomendacion.v_ServiceId              = Session["ServiceId"].ToString();
                            Recomendacion.v_ComponentId            = ddlExamen.SelectedValue.ToString();
                            Recomendacion.v_MasterRecommendationId = item.v_MasterRecommendationRestricctionId;
                            Recomendacion.i_RecordType             = (int)RecordType.Temporal;
                            Recomendacion.i_RecordStatus           = (int)RecordStatus.Agregado;
                            Recomendaciones.Add(Recomendacion);
                        }
                    }
                }

                #endregion

                #region Restricciones

                if (txtRestriccion1.Text.Trim() != "")
                {
                    //Verficiar si la recomendación se encuentra en la bd

                    masterrestriccion = oMasterRecommendationRestricctionBL.GetMasterRecommendationRestricctionByName(txtRestriccion1.Text.Trim());
                    if (masterrestriccion == null)
                    {
                        masterrecommendationrestricctionDto omasterrecommendationrestricctionDto = new masterrecommendationrestricctionDto();
                        omasterrecommendationrestricctionDto.v_Name        = txtRestriccion1.Text.Trim();
                        omasterrecommendationrestricctionDto.i_TypifyingId = 2;
                        //Crear Restricción
                        MasterRestriccionId = oMasterRecommendationRestricctionBL.AddMasterRecommendationRestricction(ref objOperationResult, omasterrecommendationrestricctionDto, ((ClientSession)Session["objClientSession"]).GetAsList());

                        Restriccion = new Node.WinClient.BE.RestrictionList();

                        Restriccion.v_ServiceId           = Session["ServiceId"].ToString();
                        Restriccion.v_ComponentId         = ddlExamen.SelectedValue.ToString();
                        Restriccion.v_MasterRestrictionId = MasterRestriccionId;
                        Restriccion.i_RecordType          = (int)RecordType.Temporal;
                        Restriccion.i_RecordStatus        = (int)RecordStatus.Agregado;
                        Restricciones.Add(Restriccion);
                    }
                    else
                    {
                        var ListaRestri = oServiceBL.ObtenerListaRecomendacionesPorDxFrecuente(DxFrecuneteId, 2);

                        foreach (var item1 in ListaRestri)
                        {
                            Restriccion = new Node.WinClient.BE.RestrictionList();

                            Restriccion.v_ServiceId           = Session["ServiceId"].ToString();
                            Restriccion.v_ComponentId         = ddlExamen.SelectedValue.ToString();
                            Restriccion.v_MasterRestrictionId = item1.v_MasterRecommendationRestricctionId;
                            Restriccion.i_RecordType          = (int)RecordType.Temporal;
                            Restriccion.i_RecordStatus        = (int)RecordStatus.Agregado;
                            Restricciones.Add(Restriccion);
                        }
                    }
                }

                #endregion

                _diagnosticRepository.Restrictions   = Restricciones;
                _diagnosticRepository.Recomendations = Recomendaciones;

                _ListadiagnosticRepository.Add(_diagnosticRepository);

                oServiceBL.AddDiagnosticRepository(ref objOperationResult, _ListadiagnosticRepository, null, ((ClientSession)Session["objClientSession"]).GetAsList(), true);

                if (objOperationResult.Success == 1)  // Operación sin error
                {
                    // Cerrar página actual y hacer postback en el padre para actualizar
                    PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
                else  // Operación con error
                {
                    Alert.ShowInTop("Error en operación:" + System.Environment.NewLine + objOperationResult.ExceptionMessage);
                    // Se queda en el formulario.
                }
                #endregion
            }
        }