Exemplo n.º 1
0
        public bool AddServiceComponentAtx(List <ProtocolComponentCustom> dataProtComponent, ServiceCustom dataService, int nodeId, int userId)
        {
            try
            {
                foreach (var obj in dataProtComponent)
                {
                    var componentId        = obj.ComponentId;
                    var serviceComponentId = new Common.Utils().GetPrimaryKey(nodeId, 24, "SC");
                    ServiceComponentDto oServiceComponentDto = new ServiceComponentDto();
                    oServiceComponentDto.v_ServiceComponentId     = serviceComponentId;
                    oServiceComponentDto.v_ComponentId            = obj.ComponentId;
                    oServiceComponentDto.i_MedicoTratanteId       = dataService.MedicoTratanteId;
                    oServiceComponentDto.v_ServiceId              = dataService.ServiceId;
                    oServiceComponentDto.i_ExternalInternalId     = (int)ComponenteProcedencia.Interno;
                    oServiceComponentDto.i_ServiceComponentTypeId = obj.ComponentTypeId;
                    oServiceComponentDto.i_IsVisibleId            = obj.UIIsVisibleId;
                    oServiceComponentDto.i_IsInheritedId          = (int)SiNo.No;
                    oServiceComponentDto.d_StartDate              = null;
                    oServiceComponentDto.d_EndDate = null;
                    oServiceComponentDto.i_index   = obj.UIIndex;

                    var porcentajes = obj.Porcentajes.Split('-');

                    float p1 = porcentajes[0] == null || porcentajes[0] == "" ? 0 : float.Parse(porcentajes[0]);
                    float p2 = porcentajes[1] == null || porcentajes[1] == "" ? 0 : float.Parse(porcentajes[1]);

                    var pb = obj.Price;
                    oServiceComponentDto.r_Price                    = pb + (pb * p1 / 100) + (pb * p2 / 100);
                    oServiceComponentDto.r_Price                    = SetNewPrice(oServiceComponentDto.r_Price, obj.ComponentId);
                    oServiceComponentDto.i_IsInvoicedId             = (int)SiNo.No;
                    oServiceComponentDto.i_ServiceComponentStatusId = (int)ServiceStatus.PorIniciar;
                    oServiceComponentDto.i_QueueStatusId            = (int)QueueStatusId.Libre;
                    oServiceComponentDto.i_Iscalling                = (int)FlagCall.NoseLlamo;
                    oServiceComponentDto.i_Iscalling_1              = (int)FlagCall.NoseLlamo;
                    oServiceComponentDto.v_IdUnidadProductiva       = obj.IdUnidadProductiva;

                    var resultplan = new PlanDal().GetPlans(dataService.ProtocolId, obj.IdUnidadProductiva);
                    var tienePlan  = false;
                    if (resultplan.Count > 0)
                    {
                        tienePlan = true;
                    }
                    else
                    {
                        tienePlan = false;
                    }
                    if (tienePlan)
                    {
                        if (resultplan[0].i_EsCoaseguro == 1)
                        {
                            oServiceComponentDto.d_SaldoPaciente    = resultplan[0].d_Importe * decimal.Parse(oServiceComponentDto.r_Price.ToString()) / 100;
                            oServiceComponentDto.d_SaldoAseguradora = decimal.Parse(oServiceComponentDto.r_Price.ToString()) - oServiceComponentDto.d_SaldoPaciente;
                        }
                        if (resultplan[0].i_EsDeducible == 1)
                        {
                            oServiceComponentDto.d_SaldoPaciente    = resultplan[0].d_Importe;
                            oServiceComponentDto.d_SaldoAseguradora = decimal.Parse(oServiceComponentDto.r_Price.ToString()) - resultplan[0].d_Importe;
                        }
                    }

                    var conditional = obj.IsConditionalId;
                    if (conditional == (int)SiNo.Si)
                    {
                        var fechaNacimiento = dataService.FechaNacimiento;
                        //Datos del paciente

                        if (fechaNacimiento != null)
                        {
                            var pacientAge = DateTime.Today.AddTicks(-fechaNacimiento.Ticks).Year - 1;

                            var pacientGender = dataService.GeneroId;

                            //Datos del protocolo
                            int         analyzeAge    = obj.Age.Value;
                            int         analyzeGender = obj.GenderId.Value;
                            var         @operator     = (Operator2Values)obj.OperatorId;
                            GrupoEtario oGrupoEtario  = (GrupoEtario)obj.GrupoEtarioId;
                            if ((int)@operator == -1)
                            {
                                //si la condicional del operador queda en --Seleccionar--
                                if (analyzeGender == (int)GenderConditional.Ambos)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else if (pacientGender == analyzeGender)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                }
                            }
                            else
                            {
                                if (analyzeGender == (int)GenderConditional.Masculino)
                                {
                                    oServiceComponentDto.i_IsRequiredId = SwitchOperator2Values(pacientAge, analyzeAge,
                                                                                                @operator, pacientGender.Value, analyzeGender);
                                }
                                else if (analyzeGender == (int)GenderConditional.Femenino)
                                {
                                    oServiceComponentDto.i_IsRequiredId = SwitchOperator2Values(pacientAge, analyzeAge,
                                                                                                @operator, pacientGender.Value, analyzeGender);
                                }
                                else if (analyzeGender == (int)GenderConditional.Ambos)
                                {
                                    oServiceComponentDto.i_IsRequiredId = SwitchOperator2Values(pacientAge, analyzeAge,
                                                                                                @operator, pacientGender.Value, analyzeGender);
                                }
                            }
                            if (componentId == "N009-ME000000402") //Adolecente
                            {
                                if ((int)oGrupoEtario == -1)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else if (13 <= pacientAge && pacientAge <= 18)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                }
                            }
                            else if (componentId == "N009-ME000000403") //Adulto
                            {
                                if ((int)oGrupoEtario == -1)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else if (19 <= pacientAge && pacientAge <= 60)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                }
                            }
                            else if (componentId == "N009-ME000000404") //AdultoMayorCustom
                            {
                                if ((int)oGrupoEtario == -1)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else if (61 <= pacientAge)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                }
                            }
                            else if (componentId == "N009-ME000000406")
                            {
                                if ((int)oGrupoEtario == -1)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else if (12 >= pacientAge)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                }
                            }
                            else if (componentId == "N009-ME000000401") //plan integral
                            {
                                if ((int)oGrupoEtario == -1)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else if (12 >= pacientAge)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                }
                            }
                            else if (componentId == "N009-ME000000400") //atencion integral
                            {
                                if ((int)oGrupoEtario == -1)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else if (12 >= pacientAge)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                }
                            }
                            else if (componentId == "N009-ME000000405") //consulta
                            {
                                if ((int)oGrupoEtario == -1)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else if (12 >= pacientAge)
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                }
                                else
                                {
                                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                }
                            }
                            else
                            {
                                oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                            }
                        }
                    }
                    else
                    {
                        oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                        if (obj.IsAdditional == null)
                        {
                            continue;
                        }
                        var adicional = obj.IsAdditional;
                        if (adicional == 1)
                        {
                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                        }
                    }
                    oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                    oServiceComponentDto.i_ConCargoA    = 0;
                    ctx.ServiceComponent.Add(oServiceComponentDto);
                }
                return(ctx.SaveChanges() > 0);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool AddServiceComponent(List <ProtocolComponentCustom> dataProtComponent, ServiceCustom dataService, int nodeId, int userId)
        {
            try
            {
                foreach (var obj in dataProtComponent)
                {
                    var serviceComponentId = new Common.Utils().GetPrimaryKey(nodeId, 24, "SC");
                    ServiceComponentDto oServiceComponentDto = new ServiceComponentDto();
                    oServiceComponentDto.v_ServiceComponentId     = serviceComponentId;
                    oServiceComponentDto.v_ComponentId            = obj.ComponentId;
                    oServiceComponentDto.i_MedicoTratanteId       = dataService.MedicoTratanteId;
                    oServiceComponentDto.v_ServiceId              = dataService.ServiceId;
                    oServiceComponentDto.i_ExternalInternalId     = (int)ComponenteProcedencia.Interno;
                    oServiceComponentDto.i_ServiceComponentTypeId = obj.ComponentTypeId;
                    oServiceComponentDto.i_IsVisibleId            = obj.UIIsVisibleId;
                    oServiceComponentDto.i_IsInheritedId          = (int)SiNo.No;
                    oServiceComponentDto.d_StartDate              = null;
                    oServiceComponentDto.d_EndDate      = null;
                    oServiceComponentDto.i_index        = obj.UIIndex;
                    oServiceComponentDto.i_IsDeleted    = (int)SiNo.No;
                    oServiceComponentDto.d_InsertDate   = DateTime.Now;
                    oServiceComponentDto.i_InsertUserId = userId;
                    var porcentajes = obj.Porcentajes.Split('-');

                    float p1 = porcentajes[0] == null || porcentajes[0] == "" ? 0 : float.Parse(porcentajes[0]);
                    float p2 = porcentajes[1] == null || porcentajes[1] == "" ? 0 : float.Parse(porcentajes[1]);

                    var pb = obj.Price;
                    oServiceComponentDto.r_Price                    = pb + (pb * p1 / 100) + (pb * p2 / 100);
                    oServiceComponentDto.r_Price                    = SetNewPrice(oServiceComponentDto.r_Price, obj.ComponentId);
                    oServiceComponentDto.i_IsInvoicedId             = (int)SiNo.No;
                    oServiceComponentDto.i_ServiceComponentStatusId = (int)ServiceStatus.PorIniciar;
                    oServiceComponentDto.i_QueueStatusId            = (int)QueueStatusId.Libre;
                    oServiceComponentDto.i_Iscalling                = (int)FlagCall.NoseLlamo;
                    oServiceComponentDto.i_Iscalling_1              = (int)FlagCall.NoseLlamo;
                    oServiceComponentDto.v_IdUnidadProductiva       = obj.IdUnidadProductiva;

                    var resultplan = new PlanDal().GetPlans(dataService.ProtocolId, obj.IdUnidadProductiva);
                    var tienePlan  = false;
                    if (resultplan.Count > 0)
                    {
                        tienePlan = true;
                    }
                    else
                    {
                        tienePlan = false;
                    }
                    if (tienePlan)
                    {
                        if (resultplan[0].i_EsCoaseguro == 1)
                        {
                            oServiceComponentDto.d_SaldoPaciente    = resultplan[0].d_Importe * decimal.Parse(oServiceComponentDto.r_Price.ToString()) / 100;
                            oServiceComponentDto.d_SaldoAseguradora = decimal.Parse(oServiceComponentDto.r_Price.ToString()) - oServiceComponentDto.d_SaldoPaciente;
                        }
                        if (resultplan[0].i_EsDeducible == 1)
                        {
                            oServiceComponentDto.d_SaldoPaciente    = resultplan[0].d_Importe;
                            oServiceComponentDto.d_SaldoAseguradora = decimal.Parse(oServiceComponentDto.r_Price.ToString()) - resultplan[0].d_Importe;
                        }
                    }

                    //Condicionales
                    var conditional = obj.IsConditionalId;
                    if (conditional == (int)SiNo.Si)
                    {
                        var fechaNacimiento = dataService.FechaNacimiento;
                        //Datos del paciente

                        if (fechaNacimiento != null)
                        {
                            var pacientAge = DateTime.Today.AddTicks(-fechaNacimiento.Ticks).Year - 1;

                            var pacientGender = dataService.GeneroId;

                            //Datos del protocolo
                            int         analyzeAge    = obj.Age.Value;
                            int         analyzeGender = obj.GenderId.Value;
                            var         @operator     = (Operator2Values)obj.OperatorId;
                            GrupoEtario oGrupoEtario  = (GrupoEtario)obj.GrupoEtarioId;
                            if (analyzeAge >= 0)                                   //condicional edad (SI)
                            {
                                if (analyzeGender != (int)GenderConditional.Ambos) //condicional genero (SI)
                                {
                                    if (@operator == Operator2Values.X_esIgualque_A)
                                    {
                                        if (pacientAge == analyzeAge && pacientGender == analyzeGender)
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                        }
                                        else
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                        }
                                    }
                                    if (@operator == Operator2Values.X_esMayorIgualque_A)
                                    {
                                        if (pacientAge >= analyzeAge && pacientGender == analyzeGender)
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                        }
                                        else
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                        }
                                    }
                                    if (@operator == Operator2Values.X_esMayorque_A)
                                    {
                                        if (pacientAge > analyzeAge && pacientGender == analyzeGender)
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                        }
                                        else
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                        }
                                    }
                                    if (@operator == Operator2Values.X_esMenorIgualque_A)
                                    {
                                        if (pacientAge <= analyzeAge && pacientGender == analyzeGender)
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                        }
                                        else
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                        }
                                    }
                                }
                                else//condicional genero (NO)
                                {
                                    if (@operator == Operator2Values.X_esIgualque_A)
                                    {
                                        if (pacientAge == analyzeAge)
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                        }
                                        else
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                        }
                                    }
                                    if (@operator == Operator2Values.X_esMayorIgualque_A)
                                    {
                                        if (pacientAge >= analyzeAge)
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                        }
                                        else
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                        }
                                    }
                                    if (@operator == Operator2Values.X_esMayorque_A)
                                    {
                                        if (pacientAge > analyzeAge)
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                        }
                                        else
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                        }
                                    }
                                    if (@operator == Operator2Values.X_esMenorIgualque_A)
                                    {
                                        if (pacientAge <= analyzeAge)
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                                        }
                                        else
                                        {
                                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        oServiceComponentDto.i_IsRequiredId = (int)SiNo.Si;
                        if (obj.IsAdditional == null)
                        {
                            continue;
                        }
                        var adicional = obj.IsAdditional;
                        if (adicional == 1)
                        {
                            oServiceComponentDto.i_IsRequiredId = (int)SiNo.No;
                        }
                    }

                    oServiceComponentDto.i_ConCargoA         = 0;
                    oServiceComponentDto.i_IsManuallyAddedId = (int)SiNo.No;
                    ctx.ServiceComponent.Add(oServiceComponentDto);
                }
                return(ctx.SaveChanges() > 0);
            }
            catch (Exception)
            {
                return(false);
            }
        }