public ActionResult Create([Bind(Include = "OtherId,PatientId,VisitDate,TCell,ViralLoad,WhiteBloodCell,Hemoglobin,PlasmaIronTurnover,OtherWeight,Triglycerides,TotalCholesterol,OtherDocuments")] OtherManagement otherManagement)
        {
            //   Logger.Log(LogLevel.Debug, "Starting OtherManagementsController Post Create.", "Patient Id = " + otherManagement.PatientId.ToString(), "", "");
            if (ModelState.IsValid)
            {
                db.OtherManagements.Add(otherManagement);
                db.SaveChanges();
                //       Logger.Log(LogLevel.Debug, "Returning OtherManagementsController Post Create.", "Patient Id = " + otherManagement.PatientId.ToString(), "", "Saved changes");
                return(RedirectToAction("OtherIndex", "OtherManagements", new { id = otherManagement.PatientId }));
            }

            //   Logger.Log(LogLevel.Debug, "Returning OtherManagementsController Post Create.", "Patient Id = " + otherManagement.PatientId.ToString(), "", "");
            return(View(otherManagement));
        }
 public IActionResult Create(Patient patient)
 {
     if (ModelState.IsValid)
     {
         patient.ModifiedDate = DateTime.Now;
         _context.Patients.Add(patient);
         _context.SaveChanges();
         return(CreatedAtRoute("GetPatient", new { id = patient.Id }, patient));
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
        public ActionResult Registration_Post(Patient patient)
        {
            string message = "";
            bool   status  = false;

            if (ModelState.IsValid)
            {
                if (isEmailExist(patient.EmailID))
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(patient));
                }
                else
                {
                    patient.Password = Crypto.Hash(patient.Password);
                    // patient.ConfirmPassword = Crypto.Hash(patient.ConfirmPassword);
                    using (PatientContext db = new PatientContext())
                    {
                        db.Patients.Add(patient);
                        db.SaveChanges();
                        status  = true;
                        message = "Registration successfully done.";
                    }
                }
            }
            else
            {
                message = "Invalid Request";
            }
            ViewBag.status  = status;
            ViewBag.message = message;

            return(View(patient));
        }
        public ActionResult Create([Bind(Include = "CommId,PatientId,CommDate,Notes")] Communication communication, HttpPostedFileBase file)
        {
            // Logger.Log(LogLevel.Debug, "Starting Patient CommunicationController Post Create.", "New Id", "", "");

            if (ModelState.IsValid)
            {
                db.Communication.Add(communication);
                string notes = communication.Notes.Replace("\r", "<br />");
                communication.Notes = notes;
                db.SaveChanges();
                return(RedirectToAction("CommIndex", "Communications", new { id = communication.PatientId }));
            }

            // Logger.Log(LogLevel.Debug, "Returning Patient CommunicationController Post Create.", "New Patient Id = " + communication.PatientId.ToString(), "", "");
            return(View(communication));
        }
示例#5
0
        private void SeedInMemoryDb()
        {
            var faker = new Faker <Patient>()
                        .Rules((f, o) =>
            {
                o.FamilyName  = f.Person.LastName;
                o.GivenName   = f.Person.FirstName;
                o.Gender      = f.PickRandom <Gender>();
                o.DateOfBirth = f.Person.DateOfBirth;
                o.HomeAddress =
                    $"{f.Person.Address.Street} - {f.Person.Address.City} - {f.Person.Address.State} - {f.Person.Address.ZipCode}";
                o.PhoneNumber = f.Person.Phone;
            });

            var patients = new[]
            {
                faker.Generate(),
                faker.Generate(),
                faker.Generate(),
                faker.Generate(),
                faker.Generate()
            };

            foreach (var patient in patients)
            {
                InMemoryContext.Patients.AddRange(patient);
            }

            InMemoryContext.SaveChanges();
        }
        public ActionResult EditPatient(Patient patient)
        {
            dbp.Entry(patient).State = System.Data.Entity.EntityState.Modified;
            dbp.SaveChanges();

            return(RedirectToAction("Index", new { id = Session["userID"] }));
        }
        public PatientController(PatientContext context)
        {
            _context = context;

            if (_context.Patients.Count() == 0)
            {
                _context.Patients.Add(new Patient {
                    FirstName = "John", LastName = "Smith", Age = 21
                });
                _context.Patients.Add(new Patient {
                    FirstName = "Mary", LastName = "Jane", Age = 28
                });
                _context.Patients.Add(new Patient {
                    FirstName = "Elizabeth", LastName = "Stone", Age = 22
                });
                _context.Patients.Add(new Patient {
                    FirstName = "Jimmy", LastName = "Brown", Age = 27
                });
                _context.Patients.Add(new Patient {
                    FirstName = "Rose", LastName = "Hamilton", Age = 23
                });
                _context.Patients.Add(new Patient {
                    FirstName = "Lewis", LastName = "Martin", Age = 26
                });
                _context.Patients.Add(new Patient {
                    FirstName = "Ian", LastName = "Wayne", Age = 24
                });
                _context.Patients.Add(new Patient {
                    FirstName = "Samantha", LastName = "Picoult", Age = 25
                });
                _context.SaveChanges();
            }
        }
示例#8
0
        public async Task <bool> DeletePatient(string Id)
        {
            try
            {
                var Patient = await _context.Patients.FindAsync(Guid.Parse(Id));

                _context.Patients.Remove(Patient);
                var result = _context.SaveChanges();
                return(result == 1);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw;
            }
        }
        public static void Initialize(PatientContext context)
        {
            context.Database.EnsureCreated();

            if (context.Patients.Any())
            {
                return;
            }

            var patients = new Patient[] {
                new Patient {
                    GivenName = "Ali", FamilyName = "Zaib", ContactNumber = "334512xxxx", DoB = new DateTime(1984, 3, 24), PasNumber = "1", SexCode = "M",
                    NextOfKin = new Kin {
                        Name = "Amir Zaib", RelationshopCode = "Brother", Address = "Full Address here"
                    }
                },
                new Patient {
                    GivenName = "Imran", FamilyName = "Zaib", ContactNumber = "334512xxxx", DoB = new DateTime(1992, 3, 24), PasNumber = "2", SexCode = "M",
                    NextOfKin = new Kin {
                        Name = "Jehan Zaib", RelationshopCode = "Brother", Address = "Full Address here"
                    }
                },
                new Patient {
                    GivenName = "Diya", FamilyName = "Ali", ContactNumber = "334512xxxx", DoB = new DateTime(1984, 3, 24), PasNumber = "1", SexCode = "F",
                    NextOfKin = new Kin {
                        Name = "Ali Zaib", RelationshopCode = "Husband", Address = "Full Address here"
                    }
                },
            };

            context.Patients.AddRange(patients);

            context.SaveChanges();
        }
示例#10
0
 public ActionResult Create(Patient patient)
 {
     if (ModelState.IsValid)
     {
         try
         {
             db.Patients.Add(patient);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         catch (Exception)
         {
             return(RedirectToRoute("Error"));
         }
     }
     return(View(patient));
 }
示例#11
0
 public void Add(Patient p)
 {
     using (PatientContext ctx = new PatientContext())
     {
         ctx.Patients.Add(p);
         ctx.SaveChanges();
     }
 }
示例#12
0
 public string Add(Patient item)
 {
     try
     {
         if (item == null)
         {
             throw new ArgumentNullException("item");
         }
         // TO DO : Code to save record into database
         _db.Patients.Add(item);
         _db.SaveChanges();
         return("Success");
     }
     catch (Exception ex)
     {
         return(ex.Message.ToString());
     }
 }
示例#13
0
 public void Delete(int id)
 {
     using (PatientContext ctx = new PatientContext())
     {
         var patient = ctx.Patients.First(p => p.id == id);
         ctx.Patients.Remove(patient);
         ctx.SaveChanges();
     }
 }
示例#14
0
        private void ProcessFiles(List <Upload> uploads)
        {
            foreach (Upload u in uploads)
            {
                // Base64 decode file
                byte[] base64Data    = System.Convert.FromBase64String(u.FileContent);
                string base64Decoded = System.Text.ASCIIEncoding.UTF8.GetString(base64Data);

                try
                {
                    // Deserialize and process JSON file, persisting entities to database
                    if (u.FileType.ToLower() == "patients")
                    {
                        List <Patient> patients = JsonSerializer.Deserialize <List <Patient> >(base64Decoded);
                        foreach (Patient p in patients)
                        {
                            p.ModifiedDate = DateTime.Now;
                            _patientContext.Patients.Add(p);
                        }
                        _patientContext.SaveChanges();
                    }

                    if (u.FileType.ToLower() == "organizations")
                    {
                        List <Organization> organizations = JsonSerializer.Deserialize <List <Organization> >(base64Decoded);
                        foreach (Organization o in organizations)
                        {
                            o.ModifiedDate = DateTime.Now;
                            _organizationContext.Organizations.Add(o);
                        }
                        _organizationContext.SaveChanges();
                    }

                    if (u.FileType.ToLower() == "claims")
                    {
                        List <Claim> claims = JsonSerializer.Deserialize <List <Claim> >(base64Decoded);
                        foreach (Claim c in claims)
                        {
                            c.ModifiedDate = DateTime.Now;
                            _claimContext.Claims.Add(c);
                        }
                        _claimContext.SaveChanges();
                    }
                }

                catch (Exception ex)
                {
                    _logger.LogInformation("Exception Type: " + ex.GetType());
                }

                // Update file processing status in the system
                u.ProcessedTimestamp = DateTime.Now;
                _logger.LogInformation("File Id: " + u.Id + " Name: " + u.FileType + " processed at " + DateTime.Now.ToString("dddd, MMMM dd, yyyy HH:mm:ss.fffK"));
            }
            _uploadContext.SaveChanges();
        }
示例#15
0
        public ActionResult Discharge(Patient patient1)
        {
            Patient patient = dbp.Patients.Find(patient1.Id);

            patient.discharged       = patient1.discharged;
            dbp.Entry(patient).State = System.Data.Entity.EntityState.Modified;
            dbp.SaveChanges();

            return(RedirectToAction("Index", new { id = Session["userID"] }));
        }
示例#16
0
        public ActionResult Create([Bind(Include = "DocFileId,DocDate,DocType,PatientId,Notes,FilePath, FileContent")] Documents documents, HttpPostedFileBase file)
        {
            // Logger.Log(LogLevel.Debug, "Starting DocumentsController Post Create.", "Patient id = " + documents.PatientId, "", documents.DocFileId.ToString());

            if (ModelState.IsValid)
            {
                try
                {
                    string FileExt = Path.GetExtension(file.FileName).ToUpper();

                    if (FileExt == ".PDF")
                    {
                        Stream       str     = file.InputStream;
                        BinaryReader Br      = new BinaryReader(str);
                        Byte[]       FileDet = Br.ReadBytes((Int32)str.Length);
                        documents.FilePath    = Path.GetFileName(file.FileName);
                        documents.FileContent = FileDet;
                    }
                    else
                    {
                        ViewBag.FileStatus = "Invalid file format.  Choose a pdf file.";
                        return(View());
                    }

                    db.Documents.Add(documents);
                    db.SaveChanges();
                    // Logger.Log(LogLevel.Debug, "Saving DocumentsController Post Create.", "Patient id = " + documents.PatientId, "", documents.DocFileId.ToString());
                    return(RedirectToAction("DocFileIndex", "Documents", new { id = documents.PatientId }));
                }
                catch (Exception ex)
                {
                }
            }

            //Logger.Log(LogLevel.Debug, "Returning DocumentsController Post Create model not valid.", "Patient id = " + documents.PatientId, "", "");
            return(View(documents));
        }
示例#17
0
        public void Put(int id, Patient value)
        {
            using (PatientContext ctx = new PatientContext())
            {
                var patient = ctx.Patients.First(p => p.id == id);;
                if (patient != null)
                {
                    patient.last_name  = value.last_name;
                    patient.first_name = value.first_name;
                    patient.phone_no   = value.phone_no;
                    patient.sex        = value.sex;

                    ctx.SaveChanges();
                }
            }
        }
示例#18
0
        public void Edit(int id, Patient PatientData)
        {
            Patient patient;

            using (var db = new PatientContext())
            {
                patient                = db.Patients.Find(id);
                patient.First_name     = PatientData.First_name;
                patient.Middle_initial = PatientData.Middle_initial;
                patient.Last_name      = patient.Last_name;
                patient.Email          = PatientData.Email;
                patient.Phone          = PatientData.Phone;
                patient.Address        = PatientData.Address;

                db.Entry(patient).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
示例#19
0
        public void Create(Patient PatientData)
        {
            Patient NewPatient;

            using (var db = new PatientContext())
            {
                NewPatient                = db.Patients.Create();
                NewPatient.First_name     = PatientData.First_name;
                NewPatient.Last_name      = PatientData.Last_name;
                NewPatient.Middle_initial = PatientData.Middle_initial;
                NewPatient.Phone          = PatientData.Phone;
                NewPatient.Address        = PatientData.Address;
                NewPatient.Email          = PatientData.Email;
                NewPatient.UserProfile    = db.UsersProfile.Find(WebSecurity.CurrentUserId);

                db.Patients.Add(NewPatient);
                db.SaveChanges();
            }
        }
        //Inserts the PatientDetail to the Database
        public bool PostPatientDetails(PatientDetail patientViewModel)
        {
            try
            {
                using (var ctx = new PatientContext())
                {
                    Patient patient = new Patient();
                    //Deserialize Object to XML
                    patient.PatientDetail = Serializer.Serialize <PatientDetail>(patientViewModel);;
                    ctx.Patients.Add(patient);
                    ctx.SaveChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#21
0
        public PatientsControllerTest()
        {
            var options = new DbContextOptionsBuilder<PatientContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            _context = new PatientContext(options);

            var patients = new[]
            {
                new Patient{Id = 1, Name = "John Smith" },
                new Patient{Id = 2, Name = "Alan White" },
                new Patient{Id = 3, Name = "Jack Black" },
                new Patient{Id = 4, Name = "Sean Patrick" }
            };

            _context.Patients.AddRange(patients);

            _context.SaveChanges();

            _relationshipMock = new Mock<IRelationshipService>();            
        }
示例#22
0
        private static void InsertData()
        {
            using (var context = new PatientContext())
            {
                // Creates the database if not exists
                context.Database.EnsureCreated();

                // Adds some Patient
                context.patient.Add(new Patient
                {
                    pat_sus_number     = 123456,
                    pat_blood_group    = "O",
                    pat_rh_factor      = "-",
                    pat_inclusion_date = new DateTime(),
                    pat_status         = 1,
                    per_id             = 1
                });

                // Saves changes
                context.SaveChanges();
            }
        }
示例#23
0
        public IActionResult Post([FromBody] AddPatientReq addPatientReq)
        {
            // Validate user
            var user = patientContext.User.Where(u => u.Name == addPatientReq.User).FirstOrDefault();

            if (user == null)
            {
                return(BadRequest(string.Format("Invalid user-{0}", addPatientReq.User)));
            }

            // Basic validations on request
            bool   basicValidationFlag = true;
            String basicErrors         = "";

            basicValidationFlag &= Validate.ForenameValid(addPatientReq.ForeName, ref basicErrors);
            basicValidationFlag &= Validate.SurnameValid(addPatientReq.Surname, ref basicErrors);
            basicValidationFlag &= Validate.PhoneValid(addPatientReq.PrimaryContactNumber, ref basicErrors);
            basicValidationFlag &= Validate.AddressLine1Valid(addPatientReq.PrimaryAddressLine1, ref basicErrors);
            basicValidationFlag &= Validate.PostcodeValid(addPatientReq.PostCode, ref basicErrors);
            if (basicValidationFlag == false)
            {
                return(BadRequest(basicErrors));
            }

            // Validate patient is not in the DB. For the purpose of the exercise assume that Forname, Surname and DateOfBirth is all that is needed to uniquely identify a patient.
            // Clearly not
            var checkPatient = patientContext.Patient.Where(p => p.Forename == addPatientReq.ForeName && p.Surname == addPatientReq.Surname && p.DateOfBirth == addPatientReq.DateOfBirth).FirstOrDefault();

            if (checkPatient != null)
            {
                return(BadRequest(string.Format("Patient already in database. Forename: {0}, Surname: {1}, DOB: {2:yyyy-MM-dd}", addPatientReq.ForeName, addPatientReq.Surname, addPatientReq.DateOfBirth)));
            }

            var  address    = patientContext.Address.Where(adr => adr.Line1 == addPatientReq.PrimaryAddressLine1 && adr.PostCode == addPatientReq.PostCode).FirstOrDefault();
            bool addAddress = false;

            if (address == null)
            {
                address = new Address
                {
                    Id       = Guid.NewGuid(),
                    Line1    = addPatientReq.PrimaryAddressLine1,
                    Line2    = addPatientReq.PrimaryAddressLine2,
                    Line3    = addPatientReq.PrimaryAddressLine3,
                    PostCode = addPatientReq.PostCode
                };
                addAddress = true;
            }

            var  phone    = patientContext.Phone.Where(ph => ph.Number == addPatientReq.PrimaryContactNumber).FirstOrDefault();
            bool addPhone = false;

            if (phone == null)
            {
                phone = new Phone
                {
                    Id     = Guid.NewGuid(),
                    Number = addPatientReq.PrimaryContactNumber
                };
                addPhone = true;
            }


            // Now add the database rows as required
            var newPatient = new Patient
            {
                Id                    = Guid.NewGuid(),
                Forename              = addPatientReq.ForeName,
                Surname               = addPatientReq.Surname,
                DateOfBirth           = addPatientReq.DateOfBirth,
                PrimaryContactPhoneID = phone.Id,
                PrimaryAddressId      = address.Id
            };

            patientContext.Add <Patient>(newPatient);


            if (addAddress == true)
            {
                patientContext.Add <Address>(address);
            }

            if (addPhone == true)
            {
                patientContext.Add <Phone>(phone);
            }

            // Audit Log record
            AuditLog auditRecord = new AuditLog
            {
                UserId    = user.Id,
                PatientID = newPatient.Id,
                DateTime  = DateTimeOffset.Now,
                Type      = "Add",
                Notes     = string.Format("Forename: {0}, Surname: {1}, DOB: {2:yyyy-MM-dd}", newPatient.Forename, newPatient.Surname, newPatient.DateOfBirth)
            };

            patientContext.Add <AuditLog>(auditRecord);

            // Finally commit the changes
            patientContext.SaveChanges();

            return(Ok(string.Format("Added - Forename: {0}, Surname: {1}, DOB: {2:yyyy-MM-dd}", newPatient.Forename, newPatient.Surname, newPatient.DateOfBirth)));
        }
示例#24
0
 public bool AddPatient(Patient patient)
 {
     service.Patient.Add(patient);
     service.SaveChanges();
     return(true);
 }