Esempio n. 1
0
        private static void GetLiquidationAction(object sender, DoWorkEventArgs e)
        {
            var parameters = e.Argument as LiquidationParameters;

            if (parameters != null)
            {
                var paciente = parameters.CurrentPatient.OriginalObject as CRUD_TerceroSeleccionaExacto_Result
                               ?? new CRUD_TerceroSeleccionaExacto_Result();

                var detalle = new OscDataModel.OscDfLiquidaDataTable();

                foreach (CRUDEntity <Service> service in parameters.Services)
                {
                    var row = detalle.NewOscDfLiquidaRow();
                    row.Cant         = (decimal)service.BaseEntity.Quantity;
                    row.CodConvenio  = service.BaseEntity.ServiceAgreementCode;
                    row.CodPrestador = service.BaseEntity.ProviderCode;
                    row.CodigoFuente = service.BaseEntity.Code;
                    row.Nivel        = service.BaseEntity.Level;
                    row.VrItem       = (decimal)service.BaseEntity.Price;
                    decimal number;
                    if (Decimal.TryParse(service.BaseEntity.Level, out number))
                    {
                        row.VrAporteComple = decimal.Parse(service.BaseEntity.Level);
                    }

                    detalle.Rows.Add(row);
                }

                using (var context = new NeuronOscEntitites(NeuronOSCStorage.EntityConnectionString))
                {
                    var descuento = parameters.ValorDescuento;
                    var ta        = new PRO_OSCDFLiquidaPagoTableAdapter();
                    ta.Connection.ConnectionString = ((System.Data.EntityClient.EntityConnection)context.Connection).StoreConnection.ConnectionString;

                    var nud = string.IsNullOrWhiteSpace(paciente.NumeroUnicoDocumento)
                                  ? string.Empty
                                  : paciente.NumeroUnicoDocumento;
                    var result = ta.GetData(nud, detalle, (decimal)descuento);

                    e.Result = result.ToList();
                }
            }
        }
Esempio n. 2
0
        private static void SaveOscAction(object sender, DoWorkEventArgs e)
        {
            var parameters = e.Argument as SaveOSCParameters;

            if (Debugger.IsAttached)
            {
                Debugger.Break();
            }

            if (parameters != null)
            {
                var paciente = parameters.CurrentPatient.OriginalObject as CRUD_TerceroSeleccionaExacto_Result
                               ?? new CRUD_TerceroSeleccionaExacto_Result();

                ////var detalle = new DataTable();
                ////detalle.Columns.Add("Cant", typeof(decimal));
                //////// detalle.Columns.Add("CodigoManual");
                ////detalle.Columns.Add("CodigoFuente");
                ////detalle.Columns.Add("VrItem", typeof(decimal));

                var detalleServicios = new OscDataModel.OscDfLiquidaDataTable();

                foreach (CRUDEntity <Service> selectedService in parameters.SelectedServices)
                {
                    ////var row = detalle.NewRow();
                    ////row["VrItem"] = selectedService.BaseEntity.Price;
                    ////row["CodigoFuente"] = selectedService.BaseEntity.Code;
                    //////// row["CodigoManual"] = selectedService.BaseEntity.Plan;
                    ////row["Cant"] = selectedService.BaseEntity.Quantity;
                    ////detalle.Rows.Add(row);

                    var rowServicio = detalleServicios.NewOscDfLiquidaRow();

                    rowServicio.VrItem       = (decimal)selectedService.BaseEntity.Price;
                    rowServicio.CodigoFuente = selectedService.BaseEntity.Code;
                    rowServicio.Cant         = (decimal)selectedService.BaseEntity.Quantity;
                    rowServicio.CodConvenio  = selectedService.BaseEntity.ServiceAgreementCode;
                    rowServicio.CodPrestador = selectedService.BaseEntity.ProviderCode;
                    rowServicio.Nivel        = selectedService.BaseEntity.Level;
                    decimal number;
                    if (Decimal.TryParse(selectedService.BaseEntity.Level, out number))
                    {
                        rowServicio.VrAporteComple = decimal.Parse(selectedService.BaseEntity.Level);
                    }

                    detalleServicios.Rows.Add(rowServicio);
                }

                var detallePagos = new OscDataModel.OSCTipoPagoDataTable();
                foreach (ItemPago pago in parameters.Pagos)
                {
                    var rowPago = detallePagos.NewOSCTipoPagoRow();

                    rowPago.TipoPago    = pago.TipoPago;
                    rowPago.CodConvenio = pago.CodConvenio;
                    rowPago.VrTipoPago  = pago.VrTipoPago;
                    rowPago.NoDocumento = pago.NoDocumento;

                    detallePagos.Rows.Add(rowPago);
                }

                using (var context = new NeuronOscEntitites(NeuronOSCStorage.EntityConnectionString))
                {
                    var command = new SqlCommand
                    {
                        Connection  = new SqlConnection(((System.Data.EntityClient.EntityConnection)context.Connection).StoreConnection.ConnectionString),
                        CommandType = CommandType.StoredProcedure,
                        CommandText = "Caja.PRO_OSCInserta"
                    };

                    //var command = new SqlCommand
                    //{
                    //    Connection = new SqlConnection(((System.Data.EntityClient.EntityConnection)context.Connection).StoreConnection.ConnectionString),
                    //    CommandType = CommandType.StoredProcedure,
                    //    CommandText = "[CAJA].[PRO_OSCWEBInserta]"
                    //};

                    command.Parameters.Add(new SqlParameter("@PrefijoNoOSC", SqlDbType.VarChar)
                    {
                        Value = parameters.OSCPrefix
                    });
                    command.Parameters.Add(new SqlParameter("@Barrio", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(paciente.BarrioResidencia) ? string.Empty : paciente.BarrioResidencia
                    });
                    command.Parameters.Add(new SqlParameter("@CodDiag", SqlDbType.VarChar)
                    {
                        Value = parameters.CurrentDiagnosis.Code
                    });
                    command.Parameters.Add(new SqlParameter("@CodPersoAsisten", SqlDbType.VarChar)
                    {
                        Value = parameters.PersonalAsistencial == null ? string.Empty : parameters.PersonalAsistencial.Codigo
                    });
                    command.Parameters.Add(new SqlParameter("@CodRemitente", SqlDbType.VarChar)
                    {
                        Value = parameters.CurrentServiceRequester.Code
                    });
                    command.Parameters.Add(new SqlParameter("@VrDcto", SqlDbType.Decimal)
                    {
                        Value = string.IsNullOrWhiteSpace(parameters.VrDcto) ? string.Empty : parameters.VrDcto
                    });
                    command.Parameters.Add(new SqlParameter("@DireccionResidencia", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(paciente.DireccionResidencia) ? string.Empty : paciente.DireccionResidencia
                    });
                    command.Parameters.Add(new SqlParameter("@FechaUltimaRegla", SqlDbType.Date)
                    {
                        Value = parameters.FUR ?? default(DateTime)
                    });
                    command.Parameters.Add(new SqlParameter("@Fecha", SqlDbType.Date)
                    {
                        Value = DateTime.Now
                    });
                    command.Parameters.Add(new SqlParameter("@IdSistema", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(parameters.IdSistema) ? string.Empty : parameters.IdSistema
                    });
                    command.Parameters.Add(new SqlParameter("@NumeroAutorizacion", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(parameters.NumeroAutorizacion) ? string.Empty : parameters.NumeroAutorizacion
                    });
                    command.Parameters.Add(new SqlParameter("@NumeroUnicoDocumento", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(paciente.NumeroUnicoDocumento) ? string.Empty : paciente.NumeroUnicoDocumento
                    });
                    command.Parameters.Add(new SqlParameter("@Observaciones", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(parameters.Observaciones) ? string.Empty : parameters.Observaciones
                    });
                    command.Parameters.Add(new SqlParameter("@Telefono", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(paciente.TelefonoResidencia) ? string.Empty : paciente.TelefonoResidencia
                    });
                    command.Parameters.Add(new SqlParameter("@EnviarPDF", SqlDbType.Bit)
                    {
                        Value = parameters.EnviarResultadoPorCorreo
                    });
                    command.Parameters.Add(new SqlParameter("@CorreoElectronico", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(parameters.CorreoElectronico) ? string.Empty : parameters.CorreoElectronico
                    });
                    command.Parameters.Add(new SqlParameter("@IdProgramaAgenda", SqlDbType.VarChar)
                    {
                        Value = parameters.IdProgramaAgenda
                    });
                    command.Parameters.Add(new SqlParameter("@UsuarioRegistro", SqlDbType.VarChar)
                    {
                        Value = ConfiguracionGlobal.IPrincipalActual.Identity.Name
                    });
                    command.Parameters.Add(new SqlParameter("@VrPagar", SqlDbType.Decimal)
                    {
                        Value = parameters.Total
                    });
                    command.Parameters.Add(new SqlParameter("@NoOrdenMedica", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(parameters.NoOrdenMedica) ? string.Empty : parameters.NoOrdenMedica
                    });
                    command.Parameters.Add(new SqlParameter("@AsigNoMuestra", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(parameters.AsigNoMuestra.ToString()) ? string.Empty : parameters.AsigNoMuestra.ToString()
                    });
                    command.Parameters.Add(new SqlParameter("@IdMuestraCentroAsig", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(parameters.NumeroDeMuestraAsignado.NumeroAsignado) ? string.Empty : parameters.NumeroDeMuestraAsignado.NumeroAsignado
                    });
                    command.Parameters.Add(new SqlParameter("@PrefijoCentroToma", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(parameters.NumeroDeMuestraAsignado.CentroDeToma.Prefijo) ? string.Empty : parameters.NumeroDeMuestraAsignado.CentroDeToma.Prefijo
                    });
                    command.Parameters.Add(new SqlParameter("@ServicioUbicacion", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(parameters.ServicioUbicacion) ? string.Empty : parameters.ServicioUbicacion
                    });
                    command.Parameters.Add(new SqlParameter("@Cama", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(parameters.Cama) ? string.Empty : parameters.Cama
                    });
                    command.Parameters.Add(new SqlParameter("@SedeAtencion", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(parameters.Sede) ? string.Empty : parameters.Sede
                    });
                    command.Parameters.Add(new SqlParameter("@NoCita", SqlDbType.VarChar)
                    {
                        Value = string.IsNullOrWhiteSpace(parameters.BookingNumber) ? string.Empty : parameters.BookingNumber
                    });

                    ////command.Parameters.Add(new SqlParameter("@Edad", SqlDbType.VarChar) { Value = paciente.Edad });
                    ////command.Parameters.Add(new SqlParameter("@EdadDias", SqlDbType.Int) { Value = paciente.EdadDias });
                    ////command.Parameters.Add(new SqlParameter("@Genero", SqlDbType.VarChar) { Value = paciente.Genero });
                    ////command.Parameters.Add(new SqlParameter("@EstadoAfiliacion", SqlDbType.VarChar) { Value = parameters.CurrentServiceAgreement.EstadoAfiliacion });
                    ////command.Parameters.Add(new SqlParameter("@Nivel", SqlDbType.VarChar) { Value = parameters.Nivel });
                    ////command.Parameters.Add(new SqlParameter("@NomTarifario", SqlDbType.VarChar) { Value = "Testo" });
                    ////command.Parameters.Add(new SqlParameter("@NomPlanBeneficio", SqlDbType.VarChar) { Value = "Testo" });
                    ////command.Parameters.Add(new SqlParameter("@PrimerApellido", SqlDbType.VarChar) { Value = string.IsNullOrWhiteSpace(paciente.PrimerApellido) ? string.Empty : paciente.PrimerApellido });
                    ////command.Parameters.Add(new SqlParameter("@PrimerNombre", SqlDbType.VarChar) { Value = string.IsNullOrWhiteSpace(paciente.PrimerNombre) ? string.Empty : paciente.PrimerNombre });
                    ////command.Parameters.Add(new SqlParameter("@SegundoApellido", SqlDbType.VarChar) { Value = string.IsNullOrWhiteSpace(paciente.SegundoApellido) ? string.Empty : paciente.SegundoApellido });
                    ////command.Parameters.Add(new SqlParameter("@SegundoNombre", SqlDbType.VarChar) { Value = string.IsNullOrWhiteSpace(paciente.SegundoNombre) ? string.Empty : paciente.SegundoNombre });
                    ////command.Parameters.Add(new SqlParameter("@TipoAutorizacion", SqlDbType.VarChar) { Value = "Testo" });
                    ////command.Parameters.Add(new SqlParameter("@TipoUsuario", SqlDbType.VarChar) { Value = "Testo" });
                    ////command.Parameters.Add(new SqlParameter("@ZonaResidencia", SqlDbType.VarChar) { Value = paciente.Zona });
                    ////command.Parameters.Add(new SqlParameter("@CodConvenio", SqlDbType.VarChar) { Value = parameters.CurrentServiceAgreement.Code });
                    ////command.Parameters.Add(new SqlParameter("@CodMPio", SqlDbType.VarChar) { Value = paciente.CodMpioResidencia });
                    ////command.Parameters.Add(new SqlParameter("@CodPrestador", SqlDbType.VarChar) { Value = parameters.CurrentProvider.Code });

                    command.Parameters.Add(new SqlParameter("@OSCDet", SqlDbType.Structured)
                    {
                        Value = detalleServicios
                    });
                    command.Parameters.Add(new SqlParameter("@OSCTipoPago", SqlDbType.Structured)
                    {
                        Value = detallePagos
                    });

                    // Output Parameters:
                    ////command.Parameters.Add(new SqlParameter("@DocUnicoOSC", SqlDbType.VarChar, 10) { Direction = ParameterDirection.Output });
                    ////command.Parameters.Add(new SqlParameter("@NoMuestra", SqlDbType.VarChar, 50) { Direction = ParameterDirection.Output });

                    command.Parameters.Add(new SqlParameter("@Error", SqlDbType.VarChar, 200)
                    {
                        Direction = ParameterDirection.Output
                    });
                    command.Parameters.Add(new SqlParameter("@Token", SqlDbType.VarChar, 20)
                    {
                        Direction = ParameterDirection.Output
                    });
                    command.Parameters.Add(new SqlParameter("@IdNumMuestra", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    });
                    command.Parameters.Add(new SqlParameter("@IdMuestraCentro", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    });
                    command.Parameters.Add(new SqlParameter("@MensajeMuestra", SqlDbType.VarChar, 200)
                    {
                        Direction = ParameterDirection.Output
                    });
                    command.Parameters.Add(new SqlParameter("@ListaFactura", SqlDbType.VarChar, -1)
                    {
                        Direction = ParameterDirection.Output
                    });
                    command.Parameters.Add(new SqlParameter("@ListaOSC", SqlDbType.VarChar, -1)
                    {
                        Direction = ParameterDirection.Output
                    });

                    command.Connection.Open();
                    try
                    {
                        command.ExecuteNonQuery();
                    }
                    finally
                    {
                        command.Connection.Close();
                    }

                    //// e.Result = Tuple.Create(
                    //// command.Parameters["@DocUnicoOSC"].Value,
                    //// command.Parameters["@Token"].Value,
                    //// command.Parameters["@NoMuestra"].Value,
                    //// command.Parameters["@IdNumMuestra"].Value,
                    //// command.Parameters["@IdMuestraCentro"].Value);

                    e.Result = new OscInsertaResult
                    {
                        Error           = command.Parameters["@Error"].Value as string,
                        IdMuestraCentro = command.Parameters["@IdMuestraCentro"].Value as int?,
                        IdNumMuestra    = command.Parameters["@IdNumMuestra"].Value as int?,
                        ListaFactura    = command.Parameters["@ListaFactura"].Value as string,
                        ListaOsc        = command.Parameters["@ListaOSC"].Value as string,
                        MensajeMuestra  = command.Parameters["@MensajeMuestra"].Value as string,
                        Token           = command.Parameters["@Token"].Value as string
                    };
                }
            }
        }