public void UpdateBiodata(VPatients patient)
        {
            using (_context = new PHCEntities())
            {
                var dbpatient = _context.Patients.Where(t => t.ID == patient.ID).FirstOrDefault();
                if (dbpatient != null)
                {
                    dbpatient.Title            = patient.Title;
                    dbpatient.Surname          = patient.Surname;
                    dbpatient.OtherNames       = patient.Othernames;
                    dbpatient.Gender           = patient.Gender;
                    dbpatient.DOB              = patient.DOB;
                    dbpatient.EnrollmentNumber = patient.Enrollmentnumber;
                    dbpatient.EnrollmentDate   = patient.Enrollmentdate;
                    dbpatient.OccupationID     = patient.Occupationid;

                    _context.SaveChanges();

                    base.Audittrail(new VAuditTrails()
                    {
                        Action      = "Update",
                        ActionBy    = 1,
                        ActionDate  = DateTime.Now,
                        RecordTable = "Patients",
                        RecordID    = dbpatient.ID,
                        Record      = JsonConvert.SerializeObject(patient)
                    });
                }
            }
        }
Example #2
0
        public JsonResult Create(VPatients patient)
        {
            try
            {
                //if (!ModelState.IsValid)
                //{
                //    return Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." });

                //}

                if (patient.Occupationid == 0 || patient.Occupationid == null)
                {
                    var addedoccupation = _occupation.Add(new VOccupations()
                    {
                        Occupation = patient.Occupation
                    });

                    patient.Occupationid = addedoccupation.ID;
                }

                if (patient.ID == 0)
                {
                    //Add patient biodata
                    patient = _patient.AddBiodata(patient);
                    return(Json(new { Result = "OK", Record = patient }));
                }
                else
                {
                    //Update patient biodata
                    _patient.UpdateBiodata(patient);
                    return(Json(new { Result = "OK" }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
        public VPatients AddBiodata(VPatients patient)
        {
            using (_context = new PHCEntities())
            {
                var newpatient = new Patients()
                {
                    Title            = patient.Title,
                    Surname          = patient.Surname,
                    OtherNames       = patient.Othernames,
                    Gender           = patient.Gender,
                    DOB              = patient.DOB,
                    EnrollmentNumber = patient.Enrollmentnumber,
                    EnrollmentDate   = patient.Enrollmentdate,
                    OccupationID     = patient.Occupationid,
                    Active           = true
                };

                _context.Patients.Add(newpatient);
                _context.SaveChanges();

                patient.ID = newpatient.ID;

                base.Audittrail(new VAuditTrails()
                {
                    Action      = "Insert",
                    ActionBy    = 1,
                    ActionDate  = DateTime.Now,
                    RecordTable = "Patients",
                    RecordID    = patient.ID,
                    Record      = JsonConvert.SerializeObject(patient)
                });


                patient.Occupation = newpatient.Occupations?.Occupation;
            }
            return(patient);
        }
 public VPatients Getpatient(int id)
 {
     using (_context = new PHCEntities())
     {
         VPatients patient   = new VPatients();
         var       dbpatient = _context.Patients.Where(t => t.ID == id).FirstOrDefault();
         if (dbpatient != null)
         {
             patient.ID         = dbpatient.ID;
             patient.Title      = dbpatient.Title;
             patient.Surname    = dbpatient.Surname;
             patient.Othernames = dbpatient.OtherNames;
             patient.Gender     = dbpatient.Gender;
             patient.DOB        = dbpatient.DOB;
             //patient.Cellphone = dbpatient.Cellphone;
             //patient.Cellphone2 = dbpatient.Cellphone2;
             //patient.Email = dbpatient.Email;
             patient.Occupationid     = dbpatient.OccupationID;
             patient.Enrollmentdate   = dbpatient.EnrollmentDate;
             patient.Enrollmentnumber = dbpatient.EnrollmentNumber;
         }
         return(patient);
     }
 }