Ejemplo n.º 1
0
        public IActionResult  OnPostMarkCompleted(int id, int stageID)
        {
            PatientLog patientStage = db.PatientLogs.FirstOrDefault(p => p.PatientID == id && p.StageID == stageID);
            Stage      currentstage = db.Stage.Find(stageID);

            if (patientStage == null)
            {
                return(NotFound());
            }
            patientStage.Completed = DateTime.Now;
            //get the next stage
            Stage nextStage = db.Stage.Where(s => s.OrderNumber > currentstage.OrderNumber).OrderBy(s => s.OrderNumber).First();

            if (nextStage != null)
            {
                PatientLog newLog = new PatientLog()
                {
                    PatientID = id,
                    StageID   = nextStage.Id,
                    EnteredIn = DateTime.Now,
                };
                db.Add(newLog);
            }
            db.Attach(patientStage);
            db.SaveChanges();
            return(RedirectToPage("/Patients/index", new { id = stageID }));
        }
Ejemplo n.º 2
0
        public ActionResult jsonSubmitPatient(PatientLog patientLog)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    PatientLog sourcePatient;
                    sourcePatient = (from p in db.PatientLogs
                                     where p.ID == patientLog.ID
                                     select p).Single();

                    sourcePatient.Notes           = patientLog.Notes;
                    sourcePatient.FaceSheet       = patientLog.FaceSheet;
                    db.Entry(sourcePatient).State = EntityState.Modified;
                    db.SaveChanges();
                    return(Content("Patient information has been saved successfully!"));
                }
                else
                {
                    return(Content("Model state is not valid."));
                }
            }
            catch (Exception ex) {
                return(Content(ex.Message));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            db.Patient.Add(newpatient);

            // get the initial stage id to add to patient log
            int initialState = GetInitialStageID();

            PatientLog newlog = new PatientLog()
            {
                EnteredIn = DateTime.Now,
                PatientID = newpatient.Id,
                StageID   = initialState
            };

            db.PatientLogs.Add(newlog);

            await db.SaveChangesAsync();

            return(RedirectToPage("Index", new { id = initialState }));
        }
Ejemplo n.º 4
0
        public static void DeletePatient(PatientLogModel db, int id)
        {
            PatientLog patient = db.PatientLogs.Find(id);

            db.PatientLogTmps.Add(CreateTmpPatient(patient));
            db.PatientLogs.Remove(patient);
            db.SaveChanges();
        }
Ejemplo n.º 5
0
        public static void DeletePatient(PatientLogModel db, string id)
        {
            PatientLog patient = db.PatientLogs.Find(Convert.ToInt32(id));

            db.PatientLogTmps.Add(CreateTmpPatient(patient));
            db.PatientLogs.Remove(patient);
            db.SaveChanges();
        }
Ejemplo n.º 6
0
        public async Task <ActionResult <PatientLog> > CreateEntry([FromBody] PatientLog log)
        {
            await context.PatientLogs.AddAsync(log);

            await context.SaveChangesAsync();

            return(log);
        }
Ejemplo n.º 7
0
        public ActionResult jsonGetPatient(string patientID)
        {
            int        patID = Convert.ToInt32(patientID);
            PatientLog query = (from p in db.PatientLogs
                                where p.ID == patID
                                select p).Single();

            return(Json(query, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 8
0
 public static void DeletePatients(PatientLogModel db, string[] id)
 {
     for (int i = 0; i < id.Length; i++)
     {
         PatientLog patient = db.PatientLogs.Find(Convert.ToInt32(id[i]));
         db.PatientLogTmps.Add(CreateTmpPatient(patient));
         db.PatientLogs.Remove(patient);
     }
     db.SaveChanges();
 }
Ejemplo n.º 9
0
        public static void CopyPatient(PatientLogModel db, PatientLog patient)
        {
            //Reset values for copied record
            patient.ServiceDate = DateTime.Parse(DateTime.Now.ToShortDateString());
            patient.DateCreated = DateTime.Now;
            patient.LastUpdated = null;
            patient.Notes       = null;

            db.PatientLogs.Add(patient);
            db.SaveChanges();
        }
Ejemplo n.º 10
0
 public static void DeletePatients(PatientLogModel db, string id)
 {
     string[] split = id.Split(',');
     for (int i = 0; i < split.Length; i++)
     {
         PatientLog patient = db.PatientLogs.Find(Convert.ToInt32(split[i]));
         db.PatientLogTmps.Add(CreateTmpPatient(patient));
         db.PatientLogs.Remove(patient);
     }
     db.SaveChanges();
 }
Ejemplo n.º 11
0
        public async Task <ActionResult> Edit([Bind(Include = "ID,Physician,Hospital,PCP_Practice,MRN_FIN,PatientName,DateCreated,ServiceType,Comments,LastUpdated,ServiceDate,RoomNo,AIMSComments,FaceSheet,Notes,AIMSBillingCodes,DOB,Gender,PatientClass")] PatientLog patientLog)
        {
            if (ModelState.IsValid)
            {
                patientLog.LastUpdated     = DateTime.Now;
                db.Entry(patientLog).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(patientLog));
        }
Ejemplo n.º 12
0
        // GET: PatientLog/Copy/5
        public async Task <ActionResult> Copy(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PatientLog patientLog = await db.PatientLogs.FindAsync(id);

            if (patientLog == null)
            {
                return(HttpNotFound());
            }
            return(View(patientLog));
        }
Ejemplo n.º 13
0
        public async Task <ActionResult> jsonSubmitPatient(PatientLog patientLog)
        {
            if (ModelState.IsValid)
            {
                patientLog.LastUpdated     = DateTime.Now;
                db.Entry(patientLog).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(Content("Patient information has been saved successfully!"));
            }
            else
            {
                return(Content("Something went wrong when saving this patient. Please notify IT"));
            }
        }
Ejemplo n.º 14
0
        public static void CopyPatients(PatientLogModel db, string[] id)
        {
            for (int i = 0; i < id.Length; i++)
            {
                PatientLog patient = db.PatientLogs.Find(Convert.ToInt32(id[i]));

                //Reset values for copied record
                patient.ServiceDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                patient.DateCreated = DateTime.Now;
                patient.LastUpdated = null;
                patient.Notes       = null;

                db.PatientLogs.Add(patient);
            }
            db.SaveChanges();
        }
Ejemplo n.º 15
0
        public static void SavePatient(PatientLogModel db, PatientLog patient)
        {
            patient.LastUpdated     = DateTime.Now;
            db.Entry(patient).State = EntityState.Modified;


            //db.Audits.Add(new Audit
            //{
            //    Action = "Update",
            //    FunctionUsed = "SavePatient(PatientLog)",
            //    UserID = HubSecurity.getLoggedInUserID(),
            //    TargetIDs = patient.ID.ToString(),
            //    Controller = getController(),
            //    Page = getPage(),
            //    TimeStamp = DateTime.Now
            //});

            db.SaveChanges();
        }
Ejemplo n.º 16
0
        public ActionResult jsonSaveNotes(string ID, string Notes, string Comments)
        {
            int        newID = Convert.ToInt32(ID);
            PatientLog pat   = db.PatientLogs.Find(newID);

            if (pat == null)
            {
                return(Json("Something went wrong, please notify IT immediately"));
            }
            else
            {
                pat.Notes    = Notes;
                pat.Comments = Comments;

                db.Entry(pat).State = EntityState.Modified;
                db.SaveChanges();
                return(Json("Success"));
            }
        }
Ejemplo n.º 17
0
        public static void CreatePatient(PatientLogModel db, PatientLog patient)
        {
            patient.DateCreated = DateTime.Now;
            //patientLog.LastUpdated = DateTime.Now;

            if (patient.Physician == "" || patient.Physician == null)
            {
                patient.Physician = "Unassigned";
            }
            if (patient.PCP_Practice == "" || patient.PCP_Practice == null)
            {
                patient.PCP_Practice = "No PCP";
            }
            if (patient.ServiceType == "" || patient.ServiceType == null)
            {
                patient.ServiceType = "Assigned";
            }
            db.PatientLogs.Add(patient);
            db.SaveChanges();
        }
Ejemplo n.º 18
0
        public async Task <ActionResult> jsonSubmitPatientAndFax(PatientLog patientLog)
        {
            if (ModelState.IsValid)
            {
                patientLog.LastUpdated     = DateTime.Now;
                db.Entry(patientLog).State = EntityState.Modified;
                await db.SaveChangesAsync();

                string commType = (from f in db.FaxServiceTypes
                                   where f.Service == patientLog.ServiceType
                                   select f.FaxType).Single().ToString();

                PCPCommunication comm = new PCPCommunication(patientLog.Physician, commType + "Notification", patientLog.Hospital, patientLog.PatientName, patientLog.ID, "313-867-5309", patientLog.DOB);
                db.Entry(comm).State = EntityState.Added;
                await db.SaveChangesAsync();

                return(Content("Patient information has been saved successfully!"));
            }
            else
            {
                return(Content("Something went wrong when saving this patient. Please notify IT"));
            }
        }
Ejemplo n.º 19
0
        public static void CopyPatient(PatientLogModel db, int id)
        {
            PatientLog patient = db.PatientLogs.Find(id);

            //Reset values for copied record
            patient.ServiceDate = DateTime.Parse(DateTime.Now.ToShortDateString());
            patient.DateCreated = DateTime.Now;
            patient.LastUpdated = null;
            patient.Notes       = null;

            //db.Audits.Add(new Audit
            //{
            //    Action = "Copy",
            //    FunctionUsed = "CopyPatient(int)",
            //    UserID = HubSecurity.getLoggedInUserID(),
            //    TargetIDs = id.ToString(),
            //    Controller = getController(),
            //    Page = getPage(),
            //    TimeStamp = DateTime.Now
            //});

            db.PatientLogs.Add(patient);
            db.SaveChanges();
        }
Ejemplo n.º 20
0
        private static PatientLogTmp CreateTmpPatient(PatientLog patient)
        {
            PatientLogTmp pt = new PatientLogTmp();

            pt.AIMSComments = patient.AIMSComments;
            pt.Comments     = patient.Comments;
            pt.DateCreated  = patient.DateCreated;
            pt.DOB          = patient.DOB;
            pt.FaceSheet    = patient.FaceSheet;
            pt.Gender       = patient.Gender;
            pt.Hospital     = patient.Hospital;
            pt.LastUpdated  = patient.LastUpdated;
            pt.MRN_FIN      = patient.MRN_FIN;
            pt.Notes        = patient.Notes;
            pt.PatientClass = patient.PatientClass;
            pt.PatientName  = patient.PatientName;
            pt.PCP_Practice = patient.PCP_Practice;
            pt.Physician    = patient.Physician;
            pt.PLRecord     = patient.ID;
            pt.RoomNo       = patient.RoomNo;
            pt.ServiceDate  = patient.ServiceDate;
            pt.ServiceType  = patient.ServiceType;
            return(pt);
        }
Ejemplo n.º 21
0
        // GET: PatientLog/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PatientLog patientLog = await db.PatientLogs.FindAsync(id);

            PatientLogEditViewModel viewM = new PatientLogEditViewModel();

            if (patientLog == null)
            {
                return(HttpNotFound());
            }
            viewM.Patient = patientLog;

            //Checks if service type is faxable
            bool foundType = db.FaxServiceTypes.AsEnumerable().Any(f => f.Service == patientLog.ServiceType);

            //If faxable, check that a notification was not sent already, and return the result
            if (foundType)
            {
                string faxType = (from f in db.FaxServiceTypes
                                  where f.Service == patientLog.ServiceType
                                  select f.FaxType).Single() + "Notification";

                bool commSent = db.PCPCommunications.AsEnumerable().Where(c => c.PLRecord == id && c.DocumentType == faxType).Any();
                viewM.isFaxable    = !commSent;
                viewM.alreadyFaxed = commSent;
            }
            else
            {
                viewM.isFaxable = false;
            }

            List <int> idList = (List <int>)Session["patientLogListOfID"];

            //Populates index variables that the view uses to set up previous/next logic
            for (int i = 0; i < idList.Count; i++)
            {
                if (id == idList[i])
                {
                    viewM.Indexer = i;
                    break;
                }
            }
            viewM.IndexerDisplay = viewM.Indexer + 1;
            if (idList.Count() == 1)
            {
                viewM.SafeIndexerPrev = 0;
                viewM.SafeIndexerNext = 0;
            }
            else
            {
                if (viewM.Indexer == 0)
                {
                    viewM.SafeIndexerPrev = 1;
                }
                else
                {
                    viewM.SafeIndexerPrev = viewM.Indexer - 1;
                }
                if (viewM.Indexer == (idList.Count() - 1))
                {
                    viewM.SafeIndexerNext = viewM.Indexer - 1;
                }
                else
                {
                    viewM.SafeIndexerNext = viewM.Indexer + 1;
                }
            }

            //Populates dropdownlists with selected value of current patient
            viewM.GenderList       = DataCollections.getGender(db, viewM.Patient.Gender);
            viewM.HospitalList     = DataCollections.getHospital(db, viewM.Patient.Hospital);
            viewM.PCPList          = DataCollections.getPCP(db, viewM.Patient.Hospital, viewM.Patient.PCP_Practice);
            viewM.ServiceTypeList  = DataCollections.getServiceType(db, viewM.Patient.ServiceType);
            viewM.PatientClassList = DataCollections.getPatientClass(db, viewM.Patient.PatientClass);
            viewM.PhysicianList    = DataCollections.getAIMSPhy(db, viewM.Patient.Hospital, viewM.Patient.Physician);
            return(View(viewM));
        }
Ejemplo n.º 22
0
 public static void DeletePatient(PatientLogModel db, PatientLog patient)
 {
     db.PatientLogTmps.Add(CreateTmpPatient(patient));
     db.PatientLogs.Remove(patient);
     db.SaveChanges();
 }
Ejemplo n.º 23
0
        private PatientLog MergePatient(PatientLog existing, PatientLog newData)
        {
            PatientLog returnPatient = new PatientLog();

            returnPatient.ID           = existing.ID;
            returnPatient.AIMSComments = existing.AIMSComments;
            returnPatient.MRN_FIN      = existing.MRN_FIN;
            returnPatient.ServiceDate  = existing.ServiceDate;
            returnPatient.PatientName  = existing.PatientName;
            returnPatient.DateCreated  = existing.DateCreated;
            returnPatient.LastUpdated  = existing.LastUpdated;
            returnPatient.FaceSheet    = existing.FaceSheet;
            returnPatient.Notes        = existing.Notes;

            if (newData.Comments != null && newData.Comments != "")
            {
                returnPatient.Comments = newData.Comments;
            }
            else
            {
                returnPatient.Comments = existing.Comments;
            }

            if (newData.DOB != null)
            {
                returnPatient.DOB = newData.DOB;
            }
            else
            {
                returnPatient.DOB = existing.DOB;
            }

            if (newData.Gender != null && newData.Gender != "")
            {
                returnPatient.Gender = newData.Gender;
            }
            else
            {
                returnPatient.Gender = existing.Gender;
            }

            if (newData.Hospital != null && newData.Hospital != "")
            {
                returnPatient.Hospital = newData.Hospital;
            }
            else
            {
                returnPatient.Hospital = existing.Hospital;
            }

            if (newData.PatientClass != null && newData.PatientClass != "")
            {
                returnPatient.PatientClass = newData.PatientClass;
            }
            else
            {
                returnPatient.PatientClass = existing.PatientClass;
            }

            if (newData.PCP_Practice != null && newData.PCP_Practice != "")
            {
                returnPatient.PCP_Practice = newData.PCP_Practice;
            }
            else
            {
                returnPatient.PCP_Practice = existing.PCP_Practice;
            }

            if (newData.Physician != null && newData.Physician != "")
            {
                returnPatient.Physician = newData.Physician;
            }
            else
            {
                returnPatient.Physician = existing.Physician;
            }

            if (newData.RoomNo != null && newData.RoomNo != "")
            {
                returnPatient.RoomNo = newData.RoomNo;
            }
            else
            {
                returnPatient.RoomNo = existing.RoomNo;
            }

            if (newData.ServiceType != null && newData.ServiceType != "")
            {
                returnPatient.ServiceType = newData.ServiceType;
            }
            else
            {
                returnPatient.ServiceType = existing.ServiceType;
            }

            return(returnPatient);
        }
Ejemplo n.º 24
0
        private void sendCommunications(string ids)
        {
            List <int> listofID = new List <int>();

            string[] splitList;
            splitList = ids.Split(new char[] { ',' });

            foreach (string i in splitList)
            {
                int theID = Convert.ToInt32(i);

                //Query patient record
                PatientLog pat = db.PatientLogs.Find(theID);

                //Determine fax type from table
                string faxType = (from f in db.FaxServiceTypes
                                  where f.Service == pat.ServiceType
                                  select f.FaxType).Single() + "Notice";

                //Break apart PCP name
                string[] splitName;
                splitName = pat.PCP_Practice.Split(new char[] { ',' });
                string pcpName   = splitName[1] + " " + splitName[0];
                string firstname = splitName[1].Trim(); //LINQ doesn't like arrays, throws error
                string lastname  = splitName[0].Trim();
                string pcpID     = (from u in db.Users where u.FirstName == firstname && u.LastName == lastname select u.UserID).Single();

                //Get practice info of PCP, default to AIMS otherwise
                ReferringPractice prac = new ReferringPractice();
                try
                {
                    prac = (from p in db.ReferringPractices
                            join r in db.RefPracUsers on p.PracID equals r.PracID
                            where r.UserID == pcpID
                            select p).Single();
                }
                catch
                {
                    prac.Fax             = "248-354-4807";
                    prac.FaxNotification = true;
                }

                //Create new reportviewer object and set parameters
                ReportViewer report = new ReportViewer();
                report.ProcessingMode         = ProcessingMode.Local;
                report.LocalReport.ReportPath = Server.MapPath("~") + "AdDisNotice\\" + faxType + pat.Hospital + ".rdlc";

                //Cannot perform ToShortDateString on pat.ServiceDate because of DateTime? type
                DateTime thed = new DateTime();
                thed = Convert.ToDateTime(pat.ServiceDate);
                DateTime birth = new DateTime();

                //Null values will cause the reportviewer control to error out
                try
                {
                    birth = Convert.ToDateTime(pat.DOB);
                }
                catch
                {
                    birth = DateTime.Parse("1/1/1900");
                }
                if (pat.PatientName == null)
                {
                    pat.PatientName = "";
                }
                if (pat.Comments == null)
                {
                    pat.Comments = "";
                }
                if (pat.MRN_FIN == null)
                {
                    pat.MRN_FIN = "";
                }

                ReportParameter dateparam      = new ReportParameter("Date", thed.ToShortDateString());
                ReportParameter faxparam       = new ReportParameter("Fax", prac.Fax);
                ReportParameter faxtoparam     = new ReportParameter("FaxTo", pcpName);
                ReportParameter dischargeparam = new ReportParameter("DischargeDate", thed.ToShortDateString());
                ReportParameter patientparam   = new ReportParameter("Patient", pat.PatientName);
                ReportParameter treatmentparam = new ReportParameter("Treatment", pat.Comments);
                ReportParameter mrnparam       = new ReportParameter("MRN", pat.MRN_FIN);
                ReportParameter physicianparam = new ReportParameter("Physician", HubSecurity.getLoggedInDisplayName());
                ReportParameter dobparam       = new ReportParameter("DOB", birth.ToShortDateString());

                ReportParameterCollection theparams = new ReportParameterCollection()
                {
                    dateparam, faxparam, faxtoparam, dischargeparam, patientparam, treatmentparam, mrnparam, physicianparam, dobparam
                };
                report.LocalReport.SetParameters(theparams);
                report.LocalReport.Refresh();

                string notificationTypes = "";
                if (prac.FaxNotification == true)
                {
                    notificationTypes += "Fax;";
                }
                if (prac.EmailNotification == true)
                {
                    notificationTypes += "Email;";
                }

                GenerateComms gcomm = new GenerateComms();
                gcomm.SendFax(faxType, report, FAX_FOLDER, prac.Fax, pat.Hospital, HubSecurity.getLoggedInUserID(), pcpID, pcpName,
                              pat.ID, pat.PatientName, pat.Comments, "", notificationTypes, birth.ToShortDateString(),
                              prac.PDFPassword, pat.Hospital + faxType, prac.Email, "");
            }
        }
Ejemplo n.º 25
0
        public JsonResult jsonImportFileCommit(HttpPostedFileBase file, string columns, bool copyDayBefore, bool sourceListFinal, string hospital)
        {
            file.SaveAs("C:\\Data\\PatientAssignment\\" + file.FileName);
            FileInfo     savedFile = new FileInfo("C:\\Data\\PatientAssignment\\" + file.FileName);
            DataTable    result    = new DataTable();
            ExcelPackage pack      = new ExcelPackage(savedFile);

            result = ToDataTable(pack);
            DateTime srvDate = DateTime.Now.Date + new TimeSpan(00, 00, 00);

            string[]      splitColumns = columns.Split(new char[] { ',' });
            List <string> listMRNs     = new List <string>(); //List of imported MRN's used to evaluate whether the record should be deleted if sourceListFinal is true

            string[] dcs = new string[] { "DC - STD", "DC - EXT" };

            //Copies from day before if selected to do so
            if (copyDayBefore)
            {
                DateTime dayBefore = srvDate.AddDays(-1);
                var      query     = from p in db.PatientLogs
                                     where p.ServiceDate == dayBefore && p.Hospital == hospital && !dcs.Contains(p.ServiceType)
                                     select p;

                foreach (PatientLog pat in query)
                {
                    pat.ServiceDate = srvDate;
                    pat.ServiceType = "Assigned";
                    db.PatientLogs.Add(pat);
                }
                db.SaveChanges();
            }
            DataValidations validate = new DataValidations();

            //Parses the Excel spreadsheet to create a Patient object
            for (int i = 0; i < result.Rows.Count; i++)
            {
                PatientLog patient = new PatientLog();

                for (int j = 0; j < splitColumns.Length; j++)
                {
                    switch (splitColumns[j])
                    {
                    case "Comments":
                        patient.Comments = result.Rows[i][j].ToString();
                        break;

                    case "DOB":
                        try
                        {
                            patient.DOB = DateTime.Parse(result.Rows[i][j].ToString());
                        }
                        catch
                        {
                            patient.DOB = DateTime.Parse("1/1/1900");
                        }
                        break;

                    case "Gender":
                        patient.Gender = validate.checkGender(db, result.Rows[i][j].ToString());
                        break;

                    case "Hospital":
                        patient.Hospital = result.Rows[i][j].ToString();
                        break;

                    case "MRN_FIN":
                        patient.MRN_FIN = result.Rows[i][j].ToString();
                        listMRNs.Add(patient.MRN_FIN);
                        break;

                    case "PatientClass":
                        patient.PatientClass = result.Rows[i][j].ToString();
                        break;

                    case "PatientName":
                        patient.PatientName = result.Rows[i][j].ToString();
                        break;

                    case "PCP_Practice":
                        patient.PCP_Practice = validate.checkPCPandHosp(db, result.Rows[i][j].ToString(), hospital);
                        break;

                    case "Physician":
                        patient.Physician = validate.checkAIMSPhyAndHosp(db, result.Rows[i][j].ToString(), hospital);
                        break;

                    case "RoomNo":
                        patient.RoomNo = result.Rows[i][j].ToString();
                        break;

                    case "ServiceDate":
                        try
                        {
                            patient.ServiceDate = DateTime.Parse(result.Rows[i][j].ToString());
                        }
                        catch
                        {
                            patient.ServiceDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                        }
                        break;

                    case "ServiceType":
                        patient.ServiceType = result.Rows[i][j].ToString();
                        break;
                    }
                }
                patient.Hospital = hospital;
                if (patient.ServiceDate == null)
                {
                    patient.ServiceDate = srvDate;
                }


                //Set default service type if none exists
                if (patient.ServiceType == null || patient.ServiceType == "")
                {
                    patient.ServiceType = "Assigned";
                }

                //Detect if patient already exists
                bool alreadyExists = (from p in db.PatientLogs
                                      where p.PatientName == patient.PatientName && p.MRN_FIN == patient.MRN_FIN && p.ServiceDate == patient.ServiceDate
                                      select p).Any();

                //If does not exist, add, otherwise check if sourceFinalList is true and evaluate eligibility
                if (!alreadyExists)
                {
                    //Set physician to unassigned if none exists
                    if (patient.Physician == null || patient.Physician == "")
                    {
                        patient.Physician = "Unassigned";
                    }
                    patient.DateCreated = DateTime.Now;
                    db.PatientLogs.Add(patient);
                }
                else
                {
                    PatientLog oldData = (from p in db.PatientLogs
                                          where p.PatientName == patient.PatientName && p.MRN_FIN == patient.MRN_FIN && p.ServiceDate == patient.ServiceDate
                                          select p).First();

                    if (patient.Comments != null && patient.Comments != "")
                    {
                        oldData.Comments = patient.Comments;
                    }

                    if (patient.DOB != null)
                    {
                        oldData.DOB = patient.DOB;
                    }

                    if (patient.Gender != null && patient.Gender != "")
                    {
                        oldData.Gender = patient.Gender;
                    }

                    if (patient.Hospital != null && patient.Hospital != "")
                    {
                        oldData.Hospital = patient.Hospital;
                    }

                    if (patient.PatientClass != null && patient.PatientClass != "")
                    {
                        oldData.PatientClass = patient.PatientClass;
                    }

                    if (patient.PCP_Practice != null && patient.PCP_Practice != "")
                    {
                        oldData.PCP_Practice = patient.PCP_Practice;
                    }

                    if (patient.Physician != null && patient.Physician != "")
                    {
                        oldData.Physician = patient.Physician;
                    }

                    if (patient.RoomNo != null && patient.RoomNo != "")
                    {
                        oldData.RoomNo = patient.RoomNo;
                    }

                    if (patient.ServiceType != null && patient.ServiceType != "")
                    {
                        oldData.ServiceType = patient.ServiceType;
                    }

                    db.Entry(oldData).State = EntityState.Modified;
                    //oldData = MergePatient(oldData, patient);
                    //db.SaveChanges();
                }

                //patient.Hospital = hospital;
                //importList.Add(patient);
            }
            db.SaveChanges();


            //If sourceListFinal is true and this MRN is not found, it is deleted
            if (sourceListFinal)
            {
                var todaysPatients = from p in db.PatientLogs
                                     where p.ServiceDate == srvDate && p.Hospital == hospital && !dcs.Contains(p.ServiceType)
                                     select p;
                foreach (PatientLog pat in todaysPatients)
                {
                    if (!listMRNs.Contains(pat.MRN_FIN))
                    {
                        db.PatientLogs.Remove(pat);
                    }
                }
            }

            db.SaveChanges();
            return(Json("Success", JsonRequestBehavior.AllowGet));
        }