Beispiel #1
0
        public static List <Dose> GetDoseAsList(DataTable dt)
        {
            List <Dose> oList = new List <Dose>();

            foreach (DataRow row in dt.Rows)
            {
                try
                {
                    Dose o = new Dose();
                    o.Id = Helper.ConvertToInt(row["ID"]);
                    o.ScheduledVaccinationId = Helper.ConvertToInt(row["SCHEDULED_VACCINATION_ID"]);
                    o.DoseNumber             = Helper.ConvertToInt(row["DOSE_NUMBER"]);
                    o.AgeDefinitionId        = Helper.ConvertToInt(row["AGE_DEFINITION_ID"]);
                    o.Fullname            = row["FULLNAME"].ToString();
                    o.Notes               = row["NOTES"].ToString();
                    o.IsActive            = Helper.ConvertToBoolean(row["IS_ACTIVE"]);
                    o.ModifiedOn          = Helper.ConvertToDate(row["MODIFIED_ON"]);
                    o.ModifiedBy          = Helper.ConvertToInt(row["MODIFIED_BY"]);
                    o.FromAgeDefinitionId = Helper.ConvertToInt(row["FROM_AGE_DEFINITION_ID"]);
                    o.ToAgeDefinitionId   = Helper.ConvertToInt(row["TO_AGE_DEFINITION_ID"]);
                    oList.Add(o);
                }
                catch (Exception ex)
                {
                    Log.InsertEntity("Dose", "GetDoseAsList", 1, ex.StackTrace.Replace("'", ""), ex.Message.Replace("'", ""));
                    throw ex;
                }
            }
            return(oList);
        }
Beispiel #2
0
 public static int Insert(Dose o)
 {
     try
     {
         string query = @"INSERT INTO ""DOSE"" (""SCHEDULED_VACCINATION_ID"", ""DOSE_NUMBER"", ""AGE_DEFINITION_ID"", ""FULLNAME"", ""NOTES"", ""IS_ACTIVE"", ""MODIFIED_ON"", ""MODIFIED_BY"", ""FROM_AGE_DEFINITION_ID"", ""TO_AGE_DEFINITION_ID"") VALUES (@ScheduledVaccinationId, @DoseNumber, @AgeDefinitionId, @Fullname, @Notes, @IsActive, @ModifiedOn, @ModifiedBy, @FromAgeDefinitionId, @ToAgeDefinitionId) returning ""ID"" ";
         List <Npgsql.NpgsqlParameter> parameters = new List <NpgsqlParameter>()
         {
             new NpgsqlParameter("@ScheduledVaccinationId", DbType.Int32)
             {
                 Value = o.ScheduledVaccinationId
             },
             new NpgsqlParameter("@DoseNumber", DbType.Int32)
             {
                 Value = o.DoseNumber
             },
             new NpgsqlParameter("@AgeDefinitionId", DbType.Int32)
             {
                 Value = o.AgeDefinitionId
             },
             new NpgsqlParameter("@Fullname", DbType.String)
             {
                 Value = o.Fullname
             },
             new NpgsqlParameter("@Notes", DbType.String)
             {
                 Value = (object)o.Notes ?? DBNull.Value
             },
             new NpgsqlParameter("@IsActive", DbType.Boolean)
             {
                 Value = o.IsActive
             },
             new NpgsqlParameter("@ModifiedOn", DbType.DateTime)
             {
                 Value = (object)o.ModifiedOn ?? DBNull.Value
             },
             new NpgsqlParameter("@ModifiedBy", DbType.Int32)
             {
                 Value = (object)o.ModifiedBy ?? DBNull.Value
             },
             new NpgsqlParameter("@FromAgeDefinitionId", DbType.Int32)
             {
                 Value = (object)o.FromAgeDefinitionId ?? DBNull.Value
             },
             new NpgsqlParameter("@ToAgeDefinitionId", DbType.Int32)
             {
                 Value = (object)o.ToAgeDefinitionId ?? DBNull.Value
             }
         };
         object id = DBManager.ExecuteScalarCommand(query, CommandType.Text, parameters);
         AuditTable.InsertEntity("Dose", id.ToString(), 1, DateTime.Now, o.ModifiedBy);
         return(int.Parse(id.ToString()));
     }
     catch (Exception ex)
     {
         Log.InsertEntity("Dose", "Insert", 1, ex.StackTrace.Replace("'", ""), ex.Message.Replace("'", ""));
     }
     return(-1);
 }
        public static int InsertVaccinationsForChild(int childId, int userId)
        {
            try
            {
                Child child = Child.GetChildById(childId);

                List <Dose> vaccineDoseList = Dose.GetDosesByDates(child.Birthdate);

                foreach (Dose vaccineDose in vaccineDoseList)
                {
                    VaccinationAppointment o = new VaccinationAppointment();
                    o.ChildId             = childId;
                    o.ScheduledFacilityId = child.HealthcenterId;
                    o.ScheduledDate       = child.Birthdate.AddDays(vaccineDose.AgeDefinition.Days);
                    o.Notes      = String.Empty;
                    o.IsActive   = true;
                    o.ModifiedOn = DateTime.Now;
                    o.ModifiedBy = userId;

                    string where = string.Format(" \"CHILD_ID\" = {0} AND \"SCHEDULED_DATE\" = '{1}' ", child.Id, o.ScheduledDate.ToString("yyyy-MM-dd"));
                    List <VaccinationAppointment> list = GetVaccinationAppointmentForList(where);
                    int count = list.Count;

                    if (count == 0)
                    {
                        int lastApp = Insert(o);
                        if (lastApp > 0)
                        {
                            VaccinationEvent ve = new VaccinationEvent();

                            ve.AppointmentId     = lastApp;
                            ve.ChildId           = childId;
                            ve.DoseId            = vaccineDose.Id;
                            ve.HealthFacilityId  = child.HealthcenterId;
                            ve.ScheduledDate     = o.ScheduledDate;
                            ve.VaccinationDate   = o.ScheduledDate;
                            ve.Notes             = String.Empty;
                            ve.VaccinationStatus = false;
                            int dosenum = vaccineDose.DoseNumber - 1;

                            if (VaccinationEvent.OtherDose(vaccineDose.ScheduledVaccinationId, childId, dosenum) && dosenum > 0)
                            {
                                ve.IsActive = false;
                            }
                            else
                            {
                                ve.IsActive = true;
                            }
                            ve.ModifiedOn = DateTime.Now;
                            ve.ModifiedBy = userId;
                            int i = VaccinationEvent.Insert(ve);
                            if (!(i > 0))
                            {
                                VaccinationAppointment.DeleteByChild(childId);
                                Child.Delete(childId);
                                return(0);
                            }
                        }
                        else
                        {
                            Child.Delete(childId);
                            return(0);
                        }
                    }
                    else
                    {
                        VaccinationAppointment appointment = list[0];
                        VaccinationEvent       ve          = new VaccinationEvent();

                        ve.AppointmentId     = appointment.Id;
                        ve.ChildId           = childId;
                        ve.DoseId            = vaccineDose.Id;
                        ve.HealthFacilityId  = child.HealthcenterId;
                        ve.ScheduledDate     = o.ScheduledDate;
                        ve.VaccinationDate   = o.ScheduledDate;
                        ve.Notes             = String.Empty;
                        ve.VaccinationStatus = false;
                        int dosenum = vaccineDose.DoseNumber - 1;

                        if (VaccinationEvent.OtherDose(vaccineDose.ScheduledVaccinationId, childId, dosenum) && dosenum > 0)
                        {
                            ve.IsActive = false;
                        }
                        else
                        {
                            ve.IsActive = true;
                        }
                        ve.ModifiedOn = DateTime.Now;
                        ve.ModifiedBy = userId;
                        int i = VaccinationEvent.Insert(ve);
                        if (!(i > 0))
                        {
                            VaccinationAppointment.DeleteByChild(childId);
                            Child.Delete(childId);
                            return(0);
                        }
                    }
                }
                return(1);
            }
            catch (Exception ex)
            {
                Log.InsertEntity("VaccinationAppointment", "InsertVaccinationsForChild", 4, ex.StackTrace.Replace("'", ""), ex.Message.Replace("'", ""));
                throw ex;
            }

            // return 0;
        }
Beispiel #4
0
 public static int Update(Dose o)
 {
     try
     {
         string query = @"UPDATE ""DOSE"" SET ""ID"" = @Id, ""SCHEDULED_VACCINATION_ID"" = @ScheduledVaccinationId, ""DOSE_NUMBER"" = @DoseNumber, ""AGE_DEFINITION_ID"" = @AgeDefinitionId, ""FULLNAME"" = @Fullname, ""NOTES"" = @Notes, ""IS_ACTIVE"" = @IsActive, ""MODIFIED_ON"" = @ModifiedOn, ""MODIFIED_BY"" = @ModifiedBy, ""FROM_AGE_DEFINITION_ID"" = @FromAgeDefinitionId, ""TO_AGE_DEFINITION_ID"" = @ToAgeDefinitionId WHERE ""ID"" = @Id ";
         List <Npgsql.NpgsqlParameter> parameters = new List <NpgsqlParameter>()
         {
             new NpgsqlParameter("@ScheduledVaccinationId", DbType.Int32)
             {
                 Value = o.ScheduledVaccinationId
             },
             new NpgsqlParameter("@DoseNumber", DbType.Int32)
             {
                 Value = o.DoseNumber
             },
             new NpgsqlParameter("@AgeDefinitionId", DbType.Int32)
             {
                 Value = o.AgeDefinitionId
             },
             new NpgsqlParameter("@Fullname", DbType.String)
             {
                 Value = o.Fullname
             },
             new NpgsqlParameter("@Notes", DbType.String)
             {
                 Value = (object)o.Notes ?? DBNull.Value
             },
             new NpgsqlParameter("@IsActive", DbType.Boolean)
             {
                 Value = o.IsActive
             },
             new NpgsqlParameter("@ModifiedOn", DbType.DateTime)
             {
                 Value = (object)o.ModifiedOn ?? DBNull.Value
             },
             new NpgsqlParameter("@ModifiedBy", DbType.Int32)
             {
                 Value = (object)o.ModifiedBy ?? DBNull.Value
             },
             new NpgsqlParameter("@FromAgeDefinitionId", DbType.Int32)
             {
                 Value = (object)o.FromAgeDefinitionId ?? DBNull.Value
             },
             new NpgsqlParameter("@ToAgeDefinitionId", DbType.Int32)
             {
                 Value = (object)o.ToAgeDefinitionId ?? DBNull.Value
             },
             new NpgsqlParameter("@Id", DbType.Int32)
             {
                 Value = o.Id
             }
         };
         int rowAffected = DBManager.ExecuteNonQueryCommand(query, CommandType.Text, parameters);
         AuditTable.InsertEntity("Dose", o.Id.ToString(), 2, DateTime.Now, o.ModifiedBy);
         return(rowAffected);
     }
     catch (Exception ex)
     {
         Log.InsertEntity("Dose", "Update", 2, ex.StackTrace.Replace("'", ""), ex.Message.Replace("'", ""));
     }
     return(-1);
 }