public List <Categoria> GetAdditionalExamByServiceId(string serviceId)
        {
            List <string> ComponentAdditionalList = new List <string>();
            List <string> ComponentNewService     = new List <string>();
            var           ListAdditionalExams     = new AdditionalExamDal().GetAdditionalExamByServiceId(serviceId);

            foreach (var obj in ListAdditionalExams)
            {
                ComponentAdditionalList.Add(obj.ComponentId);
                if (obj.IsNewService == (int)SiNo.Si)
                {
                    ComponentNewService.Add(obj.ComponentId);
                }
            }

            List <Categoria> DataSource = new List <Categoria>();

            foreach (var componentId in ComponentAdditionalList)
            {
                var ListServiceComponent = new ServiceDal().GetAllComponents((int)TipoBusqueda.ComponentId, componentId);



                Categoria categoria = DataSource.Find(x => x.i_CategoryId == ListServiceComponent[0].i_CategoryId);
                if (categoria != null)
                {
                    List <ComponentDetailList> componentDetail = new List <ComponentDetailList>();
                    componentDetail = ListServiceComponent[0].Componentes;
                    DataSource.Find(x => x.i_CategoryId == ListServiceComponent[0].i_CategoryId).Componentes.AddRange(componentDetail);
                }
                else
                {
                    DataSource.AddRange(ListServiceComponent);
                }
            }
            foreach (var item in ListAdditionalExams)
            {
                foreach (var data in DataSource)
                {
                    foreach (var comp in data.Componentes)
                    {
                        if (comp.v_ComponentId == item.ComponentId)
                        {
                            if (item.IsNewService == 1)
                            {
                                comp.i_NewService = 1;
                            }
                            else
                            {
                                comp.i_NewService = 0;
                            }
                        }
                    }
                }
            }
            return(DataSource);
        }
        public MessageCustom SaveDeletedAdditionalExam(string additionalExamId, int userId, string comentario, string _serviceId)
        {
            comentario = comentario == null ? "SIN COMENTARIOS" : comentario;
            var           result         = new AdditionalExamDal().DeleteAdditionalExam(additionalExamId, userId);
            MessageCustom _MessageCustom = new MessageCustom();

            if (result)
            {
                comentario = comentario == null ? "SIN COMENTARIOS" : comentario;
                string CMP        = "SIN-PROFESIONAL";
                var    ruta       = HttpContext.Current.Server.MapPath("~/" + System.Configuration.ConfigurationManager.AppSettings["directorioExamAdicional"]);
                var    rutaWeb    = string.Format("{0}.pdf", Path.Combine(_serviceId + "-" + "ORDEN-EX-MED-ADICI-SIN-PROFESIONAL"));
                string pathFile   = string.Format("{0}.pdf", Path.Combine(ruta, _serviceId + "-" + "ORDEN-EX-MED-ADICI-SIN-PROFESIONAL"));
                var    datosGrabo = new ServiceBl().DevolverDatosUsuarioFirma(userId);
                if (datosGrabo != null)
                {
                    CMP      = datosGrabo.CMP;
                    pathFile = string.Format("{0}.pdf", Path.Combine(ruta, _serviceId + "-" + "ORDEN-EX-MED-ADICI-" + datosGrabo.CMP));
                    rutaWeb  = string.Format("{0}.pdf", Path.Combine(_serviceId + "-" + "ORDEN-EX-MED-ADICI-" + datosGrabo.CMP));
                }



                List <Categoria> AdditionalExam = new List <Categoria>();
                List <Categoria> DataSource     = new List <Categoria>();
                List <string>    ComponentList  = new List <string>();
                var ListadditExam = new ServiceDal().GetAdditionalExamByServiceId_all(_serviceId, userId);

                foreach (var componenyId in ListadditExam)
                {
                    ComponentList.Add(componenyId.ComponentId);
                }

                foreach (var componentId in ComponentList)
                {
                    var ListServiceComponent = new ServiceDal().GetAllComponents((int)TipoBusqueda.ComponentId, componentId);

                    Categoria categoria = DataSource.Find(x => x.i_CategoryId == ListServiceComponent[0].i_CategoryId);
                    if (categoria != null)
                    {
                        List <ComponentDetailList> componentDetail = new List <ComponentDetailList>();
                        componentDetail = ListServiceComponent[0].Componentes;
                        DataSource.Find(x => x.i_CategoryId == ListServiceComponent[0].i_CategoryId).Componentes.AddRange(componentDetail);
                    }
                    else
                    {
                        DataSource.AddRange(ListServiceComponent);
                    }
                }


                var MedicalCenter = new ServiceBl().GetInfoMedicalCenter();
                var DatosPaciente = new PacientBL().DevolverDatosPaciente(_serviceId);

                new PrintAdditionalExam().GenerateAdditionalexam(pathFile, MedicalCenter, DatosPaciente, datosGrabo, comentario, DataSource, ListadditExam);



                _MessageCustom.Error   = false;
                _MessageCustom.Status  = 200;
                _MessageCustom.Message = "Se eliminó correctamente";
                _MessageCustom.Id      = rutaWeb;
            }
            else
            {
                _MessageCustom.Error   = true;
                _MessageCustom.Status  = 500;
                _MessageCustom.Message = "Sucedió un error, vuelva a intentar";
            }
            return(_MessageCustom);
        }
Exemplo n.º 3
0
        public bool SaveAdditionalExamsForCalendar(List <AdditionalExamCreate> data, int userId, int nodeId)
        {
            try
            {
                DatabaseContext dbContext = new DatabaseContext();
                using (var ts = new TransactionScope())
                {
                    foreach (var objExam in data)
                    {
                        if (objExam.IsNewService == (int)SiNo.No)
                        {
                            var unidadProductiva = GetMedicalExam(objExam.ComponentId);
                            var newId            = new Common.Utils().GetPrimaryKey(nodeId, 24, "SC");;
                            ServiceComponentDto objServiceComponentDto = new ServiceComponentDto();
                            objServiceComponentDto.v_ServiceComponentId     = newId;
                            objServiceComponentDto.i_ConCargoA              = -1;
                            objServiceComponentDto.v_ServiceId              = objExam.ServiceId;
                            objServiceComponentDto.i_ExternalInternalId     = (int)ComponenteProcedencia.Interno;
                            objServiceComponentDto.i_ServiceComponentTypeId = 1;
                            objServiceComponentDto.i_IsVisibleId            = 1;
                            objServiceComponentDto.i_IsInheritedId          = (int)SiNo.No;
                            objServiceComponentDto.d_StartDate              = null;
                            objServiceComponentDto.d_EndDate                  = null;
                            objServiceComponentDto.i_index                    = 1;
                            objServiceComponentDto.r_Price                    = objExam.Price;
                            objServiceComponentDto.v_ComponentId              = objExam.ComponentId;
                            objServiceComponentDto.i_IsInvoicedId             = (int)SiNo.No;
                            objServiceComponentDto.i_ServiceComponentStatusId = (int)ServiceStatus.PorIniciar;
                            objServiceComponentDto.i_QueueStatusId            = (int)QueueStatusId.Libre;
                            objServiceComponentDto.i_Iscalling                = (int)Flag_Call.NoseLlamo;
                            objServiceComponentDto.i_Iscalling_1              = (int)Flag_Call.NoseLlamo;
                            objServiceComponentDto.i_IsManuallyAddedId        = (int)SiNo.No;
                            objServiceComponentDto.i_IsRequiredId             = (int)SiNo.Si;
                            objServiceComponentDto.v_IdUnidadProductiva       = unidadProductiva;
                            objServiceComponentDto.i_MedicoTratanteId         = objExam.MedicoTratante;
                            objServiceComponentDto.d_SaldoPaciente            = 0;
                            objServiceComponentDto.d_SaldoAseguradora         = 0;
                            objServiceComponentDto.i_IsDeleted                = 0;
                            objServiceComponentDto.d_InsertDate               = DateTime.Now;
                            dbContext.ServiceComponent.Add(objServiceComponentDto);
                            dbContext.SaveChanges();
                        }
                        else
                        {
                            CalendarDto _CalendarDto = new CalendarDto();
                            var         protocolId   = Constants.Prot_Hospi_Adic;
                            _CalendarDto.v_PersonId         = objExam.PersonId;
                            _CalendarDto.d_DateTimeCalendar = DateTime.Now;
                            _CalendarDto.d_CircuitStartDate = DateTime.Now;
                            _CalendarDto.d_EntryTimeCM      = DateTime.Now;
                            _CalendarDto.i_ServiceTypeId    = (int)ServiceType.Particular;
                            _CalendarDto.i_ServiceId        = (int)MasterService.Hospitalizacion;

                            _CalendarDto.i_CalendarStatusId  = (int)CalendarStatus.Agendado;
                            _CalendarDto.i_LineStatusId      = (int)LineStatus.EnCircuito;
                            _CalendarDto.v_ProtocolId        = protocolId;
                            _CalendarDto.i_NewContinuationId = 1;
                            _CalendarDto.i_LineStatusId      = (int)LineStatus.EnCircuito;
                            _CalendarDto.i_IsVipId           = (int)SiNo.No;

                            var result = AddCalendar(_CalendarDto, nodeId, userId);

                            if (result)
                            {
                                ServiceDto _ServiceDto = new ServiceDto();

                                _ServiceDto = ctx.Service.Where(x => x.v_ServiceId == objExam.ServiceId).FirstOrDefault();
                                _ServiceDto.d_ServiceDate     = DateTime.Now;
                                _ServiceDto.i_ServiceStatusId = (int)ServiceStatus.Iniciado;
                                _ServiceDto.d_UpdateDate      = DateTime.Now;
                                _ServiceDto.i_UpdateUserId    = userId;
                                ctx.SaveChanges();

                                var servicesComponents = new ServiceComponentDal().GetServiceComponents(objExam.ServiceId);
                                if (servicesComponents != null)
                                {
                                    foreach (var servicesComponent in servicesComponents)
                                    {
                                        var oservicecomponentDto = ctx.ServiceComponent.Where(x => x.v_ServiceComponentId == servicesComponent.v_ServiceComponentId).FirstOrDefault();
                                        oservicecomponentDto.i_MedicoTratanteId   = 11;
                                        oservicecomponentDto.i_IsVisibleId        = 1;
                                        oservicecomponentDto.v_ServiceComponentId = servicesComponent.v_ServiceComponentId;
                                        oservicecomponentDto.i_UpdateUserId       = userId;
                                        oservicecomponentDto.d_UpdateDate         = DateTime.Now;
                                        ctx.SaveChanges();
                                    }

                                    var resultHospi = new HospitalizacionDal().AddHospitalizacionService(null, objExam.ServiceId, nodeId, userId);
                                    if (!resultHospi)
                                    {
                                        throw new Exception("");
                                    }
                                }
                                else
                                {
                                    throw new Exception("");
                                }
                            }
                            else
                            {
                                throw new Exception("");
                            }
                        }
                    }

                    var resultAdditional = new AdditionalExamDal().UpdateAdditionalExamByComponentIdAndServiceId(data, userId);
                    if (!resultAdditional)
                    {
                        throw new Exception("");
                    }
                    ts.Complete();
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }