Esempio n. 1
0
        public ActionResult Edit([Bind(Include = "userId,firstName,lastName,hospitalId,roleId,dateCreated,dateUpdated,editedBy")] user user, FormCollection form)
        {
            user account = db.users.Find(UserAccount.GetUserID());

            if (account.role.title == "Database Adminstrator" || account.role.title == "Instructor")
            {
                if (ModelState.IsValid)
                {
                    user        u  = db.users.Find(user.userId);
                    userAccount uA = db.userAccounts.Where(p => p.userId == user.userId).First();
                    uA.userName = form["email"];
                    var password = form["password"];
                    if (form["password"] != "")
                    {
                        uA.passwordHash = UserAccount.HashSHA1(form["password"] + uA.userGuid);
                    }
                    db.Entry(u).CurrentValues.SetValues(user);
                    db.Entry(uA).State = EntityState.Modified;
                    db.SaveChanges();
                    logger.Info("User " + account.firstName + " " + account.lastName + " edited details of " + user.userId + "(" + user.firstName + " " + user.lastName + ")");
                    return(RedirectToAction("Index"));
                }
                ViewBag.hospitalId = new SelectList(db.hospitals, "hospitalId", "name", user.hospitalId);
                ViewBag.roleId     = new SelectList(db.roles, "roleId", "title", user.roleId);
                return(View(user));
            }
            else if (account.userId == user.userId)
            {
                if (ModelState.IsValid)
                {
                    user        u  = db.users.Find(user.userId);
                    userAccount uA = db.userAccounts.Where(p => p.userId == user.userId).First();
                    uA.userName = form["email"];
                    if (form["password"] != null || form["password"] != "")
                    {
                        uA.passwordHash = UserAccount.HashSHA1(form["password"] + uA.userGuid);
                    }
                    db.Entry(u).CurrentValues.SetValues(user);
                    db.Entry(uA).State = EntityState.Modified;
                    db.SaveChanges();
                    logger.Info("User " + account.firstName + " " + account.lastName + " edited details of " + user.userId + "(" + user.firstName + " " + user.lastName + ")");
                    return(RedirectToAction("Index"));
                }
                ViewBag.hospitalId = new SelectList(db.hospitals, "hospitalId", "name", user.hospitalId);
                ViewBag.roleId     = new SelectList(db.roles, "roleId", "title", user.roleId);
                return(View(user));
            }
            else
            {
                logger.Info("User " + account.firstName + " " + account.lastName + " attempted to edit the details of " + user.userId);
                return(RedirectToAction("tempError", "Home"));
            }
        }
Esempio n. 2
0
        public ActionResult Edit([Bind(Include = "roleId,title,dateCreated,dateUpdated,editedBy")] role role)
        {
            user account = db.users.Find(UserAccount.GetUserID());

            if (account.role.title == "Database Adminstrator" || account.role.title == "Instructor")
            {
                if (ModelState.IsValid)
                {
                    db.Entry(role).State = EntityState.Modified;
                    db.SaveChanges();
                    logger.Info("User " + account.firstName + " " + account.lastName + " edited role: " + role.title);
                    return(RedirectToAction("Index"));
                }
                return(View(role));
            }
            else
            {
                logger.Info("User " + account.firstName + " " + account.lastName + " tried to edit role: " + role.title);
                return(RedirectToAction("tempError", "Home"));
            }
        }
Esempio n. 3
0
        public ActionResult Create([Bind(Include = "birthRecordId,certiferName,certiferTitle,certiferDate,filedDate,paternityAck,ssnRequested,facilityId,birthFacility,homebirth,attendantName,attendantNpi,attendantTitle,motherTransferred,transferFacility,firstPrenatal,lastPrenatal,totalPrenatal,motherPreWeight,motherPostWeight,motherDeliveryWeight,hadWic,previousBirthLiving,previousBirthDead,lastLiveBirth,otherBirthOutcomes,lastOtherOutcome,cigThreeBefore,packThreeBefore,cigFirstThree,packFirstThree,cigSecondThree,packSecondThree,cigThirdTri,packThirdTri,paymentSource,dateLastMenses,diabetesPrepregnancy,diabetesGestational,hyperTensionPrepregnancy,hyperTensionGestational,hyperTensionEclampsia,prePreTerm,prePoorOutcome,resultInfertility,fertilityDrug,assistedTech,previousCesarean,previousCesareanAmount,gonorrhea,syphilis,chlamydia,hepB,hepC,cervicalCerclage,tocolysis,externalCephalic,preRuptureMembrane,preLabor,proLabor,inductionLabor,augmentationLabor,nonvertex,steroids,antibotics,chorioamnionitis,meconium,fetalIntolerance,epidural,unsuccessfulForceps,unsuccessfulVacuum,cephalic,breech,otherFetalPresentation,finalSpontaneous,finalForceps,finalVacuum,finalCesarean,finalTrialOfLabor,maternalTransfusion,perinealLaceration,rupturedUterus,hysterectomy,admitICU,unplannedOperating, birthWeight, fiveMinAgpar,tenMinAgpar,plurality,birthOrder,ventImmedite,ventSixHours,nicu,surfactant,neoNatalAntibotics,seizureDysfunction,birthInjury,anencephaly,meningomyelocele,cyanotic,cogenital,omphalocele,gastroschisis,limbReduction,cleftLip,cleftPalate,downConfirmed,downPending,suspectedConfirmed,suspectedPending,hypospadias,infantTransferred,infantLiving,breastFed,dateCreated,dateEdited,editedBy")] zz_birthRecord birthRecord, FormCollection form)
        {
            user account = newDB.users.Find(UserAccount.GetUserID());

            if (ModelState.IsValid)
            {
                //Create Child Info
                zz_patient child = new zz_patient();
                child.firstName     = form["childFirstName"];
                child.middleName    = form["childMiddleName"];
                child.lastName      = form["childLastName"];
                child.suffix        = form["childSuffix"];
                child.birthTime     = TimeSpan.Parse(form["timeOfBirth"]);
                child.gender        = form["genderList"];
                child.birthDate     = Convert.ToDateTime(form["childBirthDate"]);
                child.birthFacility = form["facilityName"];
                child.birthCity     = form["childBirthLocation"];
                child.birthCounty   = form["childBirthCounty"];
                child.birthWeight   = Convert.ToInt32(form["birthWeight"]);
                if (Request.Cookies["userId"] != null)
                {
                    HttpCookie aCookie = Request.Cookies["userId"];
                    child.editedBy = Convert.ToInt32(Server.HtmlEncode(aCookie.Value));
                }
                child.dateCreated = DateTime.Now;
                child.dateUpdated = DateTime.Now;

                Random random   = new Random();
                int    childMRN = random.Next(100000000, 999999999);

                using (HITProjectData_Fall17Entities1 newDB = new HITProjectData_Fall17Entities1())
                {
                    string            randomNumberString = Convert.ToString(childMRN);
                    List <zz_patient> patients           = newDB.zz_patient.Where(p => p.medicalRecordNumber == randomNumberString).ToList();
                    while (patients.Count > 0)
                    {
                        childMRN           = random.Next(100000000, 999999999);
                        randomNumberString = Convert.ToString(childMRN);
                        patients           = newDB.zz_patient.Where(p => p.medicalRecordNumber == randomNumberString).ToList();
                    }
                }
                child.medicalRecordNumber = Convert.ToString(childMRN);
                //Add and save child to Database
                newDB.zz_patient.Add(child);
                newDB.SaveChanges();

                //Mother info
                int        id     = Convert.ToInt32(form["motherId"]);
                zz_patient mother = newDB.zz_patient.Find(id);
                mother.firstName              = form["motherFirstName"];
                mother.middleName             = form["motherMiddleName"];
                mother.lastName               = form["motherLastName"];
                mother.suffix                 = form["motherSuffix"];
                mother.birthDate              = Convert.ToDateTime(form["motherDOB"]);
                mother.priorFirstName         = form["motherPriorFirstName"];
                mother.priorMiddleName        = form["motherPriorMiddleName"];
                mother.priorLastName          = form["motherPriorLastName"];
                mother.priorSuffix            = form["motherPriorSuffix"];
                mother.residenceState         = form["state"];
                mother.residenceCounty        = form["motherCountry"];
                mother.residenceCity          = form["motherCity"];
                mother.residenceStreetAddress = form["motherAddress"];
                mother.residenceAptNo         = form["motherAptNo"];
                mother.residenceZip           = form["motherZip"];
                mother.inCity                 = Convert.ToBoolean(form["inCity"].Split(',')[0]);
                newDB.Entry(mother).State     = EntityState.Modified;
                newDB.SaveChanges();

                //Add Mother address to child
                child.residenceState         = form["state"];
                child.residenceCounty        = form["motherCountry"];
                child.residenceCity          = form["motherCity"];
                child.residenceStreetAddress = form["motherAddress"];
                child.residenceAptNo         = form["motherAptNo"];
                child.residenceAptNo         = form["motherZip"];
                newDB.Entry(child).State     = EntityState.Modified;
                newDB.SaveChanges();

                //Father Information
                zz_patient father = new zz_patient();
                //If father information exists
                //TODO add logic for father lookup
                if (form["fatherFirstName"] != "")
                {
                    father.firstName  = form["fatherFirstName"];
                    father.middleName = form["fatherMiddleName"];
                    father.lastName   = form["fatherLastName"];
                    father.suffix     = form["fatherSuffix"];
                    father.birthDate  = Convert.ToDateTime(form["fatherDOB"]);
                    father.birthState = form["fatherBirthplace"];
                    int fatherMRN = random.Next(100000000, 999999999);

                    using (HITProjectData_Fall17Entities1 newDB = new HITProjectData_Fall17Entities1())
                    {
                        string            randomNumberString = Convert.ToString(fatherMRN);
                        List <zz_patient> patients           = newDB.zz_patient.Where(p => p.medicalRecordNumber == randomNumberString).ToList();
                        while (patients.Count > 0)
                        {
                            fatherMRN          = random.Next(100000000, 999999999);
                            randomNumberString = Convert.ToString(fatherMRN);
                            patients           = newDB.zz_patient.Where(p => p.medicalRecordNumber == randomNumberString).ToList();
                        }
                    }
                    father.medicalRecordNumber = Convert.ToString(fatherMRN);

                    //Add and save father to Database
                    newDB.zz_patient.Add(father);
                    newDB.SaveChanges();
                }

                //Certifier information
                birthRecord.certiferName  = form["certifierName"];
                birthRecord.certiferTitle = form["certifierTitleList"];
                if (birthRecord.certiferTitle == "Other")
                {
                    birthRecord.certiferTitle = form["certifierTitleOther"];
                }
                birthRecord.certiferDate = Convert.ToDateTime(form["dateCertified"]);
                birthRecord.filedDate    = Convert.ToDateTime(form["datedFiled"]);

                //Mother2 Info
                mother.mailingState         = form["stateList"];
                mother.mailingCity          = form["motherMailingCity"];
                mother.mailingStreetAddress = form["motherMailingAddress"];
                mother.mailingAptNo         = form["motherMailingAptNo"];
                mother.mailingZip           = form["motherMailingZip"];
                mother.isMarried            = Convert.ToBoolean(form["isMarried"].Split(',')[0]);
                //TODO null check
                mother.SSN      = form["motherSSN"];
                child.motherSSN = form["motherSSN"];
                //TODO null check
                if (form["fatherFirstName"] != "")
                {
                    father.SSN                = form["fatherSSN"];
                    child.fatherSSN           = form["fatherSSN"];
                    newDB.Entry(father).State = EntityState.Modified;
                }
                newDB.Entry(child).State  = EntityState.Modified;
                newDB.Entry(mother).State = EntityState.Modified;
                newDB.SaveChanges();

                //Mother3 Info
                mother.educationEarned = form["motherEducation"];
                mother.hispanic        = form["motherHispanic"];
                if (mother.hispanic == "Yes, other Spanish/Hispanic/Latina")
                {
                    mother.hispanic = "motherHispanicOther";
                }
                newDB.Entry(mother).State = EntityState.Modified;
                newDB.SaveChanges();

                zz_patientRace motherRace = new zz_patientRace();
                motherRace.patientId       = id;
                motherRace.white           = Convert.ToBoolean(form["motherWhite"].Split(',')[0]);
                motherRace.black           = Convert.ToBoolean(form["motherBlack"].Split(',')[0]);
                motherRace.tribe           = form["mothertribe"];
                motherRace.asianIndian     = Convert.ToBoolean(form["motherAsianIndian"].Split(',')[0]);
                motherRace.chinese         = Convert.ToBoolean(form["motherChinese"].Split(',')[0]);
                motherRace.flipino         = Convert.ToBoolean(form["motherFilipino"].Split(',')[0]);
                motherRace.japanese        = Convert.ToBoolean(form["motherJapanese"].Split(',')[0]);
                motherRace.korean          = Convert.ToBoolean(form["motherKorean"].Split(',')[0]);
                motherRace.vietnamese      = Convert.ToBoolean(form["motherVietnamese"].Split(',')[0]);
                motherRace.otherAsian      = form["motherOtherAsian"];
                motherRace.hawaiian        = Convert.ToBoolean(form["motherHawaiian"].Split(',')[0]);
                motherRace.guamanian       = Convert.ToBoolean(form["motherGuamanian"].Split(',')[0]);
                motherRace.samoan          = Convert.ToBoolean(form["motherSamoan"].Split(',')[0]);
                motherRace.pacificIslander = form["motherOtherIslander"];
                motherRace.other           = form["motherOtherRace"];
                newDB.zz_patientRace.Add(motherRace);
                newDB.SaveChanges();

                //Father 2 Information
                if (form["fatherFirstName"] != "")
                {
                    father.educationEarned = form["fatherEducation"];
                    father.hispanic        = form["fatherHispanic"];
                    if (father.hispanic == "Yes, other Spanish/Hispanic/Latina")
                    {
                        father.hispanic = "fatherHispanicOther";
                    }
                    newDB.Entry(father).State = EntityState.Modified;
                    newDB.SaveChanges();

                    List <zz_patient> patients   = newDB.zz_patient.Where(p => p.medicalRecordNumber == father.medicalRecordNumber).ToList();
                    zz_patientRace    fatherRace = new zz_patientRace();
                    fatherRace.patientId       = patients[0].patientId;
                    fatherRace.white           = Convert.ToBoolean(form["fatherWhite"].Split(',')[0]);
                    fatherRace.black           = Convert.ToBoolean(form["fatherBlack"].Split(',')[0]);
                    fatherRace.tribe           = form["fatherTribe"];
                    fatherRace.asianIndian     = Convert.ToBoolean(form["fatherAsianIndian"].Split(',')[0]);
                    fatherRace.chinese         = Convert.ToBoolean(form["fatherChinese"].Split(',')[0]);
                    fatherRace.flipino         = Convert.ToBoolean(form["fatherFilipino"].Split(',')[0]);
                    fatherRace.japanese        = Convert.ToBoolean(form["fatherJapanese"].Split(',')[0]);
                    fatherRace.korean          = Convert.ToBoolean(form["fatherKorean"].Split(',')[0]);
                    fatherRace.vietnamese      = Convert.ToBoolean(form["fatherVietnamese"].Split(',')[0]);
                    fatherRace.otherAsian      = form["fatherOtherAsian"];
                    fatherRace.hawaiian        = Convert.ToBoolean(form["fatherHawaiian"].Split(',')[0]);
                    fatherRace.guamanian       = Convert.ToBoolean(form["fatherGuamanian"].Split(',')[0]);
                    fatherRace.samoan          = Convert.ToBoolean(form["fatherSamoan"].Split(',')[0]);
                    fatherRace.pacificIslander = form["fatherOtherIslander"];
                    fatherRace.other           = form["fatherOtherRace"];
                    newDB.zz_patientRace.Add(fatherRace);
                    newDB.SaveChanges();
                }

                birthRecord.birthFacility = form["birthOccuredPlace"];
                if (birthRecord.birthFacility == "Other")
                {
                    birthRecord.birthFacility = form["birthOccuredPlaceOther"];
                }

                birthRecord.attendantTitle = form["attendantTitleList"];
                if (birthRecord.attendantTitle == "Other")
                {
                    birthRecord.attendantTitle = form["attendantNPIOther"];
                }
                birthRecord.noPrenatal = Convert.ToBoolean(form["noPrenatal"].Split(',')[0]);
                if (birthRecord.noPrenatal == false)
                {
                    birthRecord.firstPrenatal = Convert.ToDateTime(form["firstPrenatal"]);
                    birthRecord.lastPrenatal  = Convert.ToDateTime(form["lastPrenatal"]);
                }
                mother.height                = Convert.ToInt32(form["motherHeight"]);
                birthRecord.lastLiveBirth    = Convert.ToDateTime(form["lastLiveBirth"]);
                birthRecord.lastOtherOutcome = Convert.ToDateTime(form["lastOtherOutcome"]);
                birthRecord.paymentSource    = form["paymentList"];
                if (birthRecord.paymentSource == "Other")
                {
                    birthRecord.paymentSource = form["paymentOther"];
                }
                birthRecord.dateLastMenses = Convert.ToDateTime(form["dateLastMenses"]);
                birthRecord.infantLiving   = form["infantLiving"];

                newDB.Entry(mother).State = EntityState.Modified;
                newDB.zz_birthRecord.Add(birthRecord);
                newDB.SaveChanges();

                //TODO add record to bridging table
                //Add Mother
                zz_record   motherR = new zz_record();
                var         userId  = Convert.ToInt32(Request.Cookies["userId"].Value);
                List <user> users   = newDB.users.Where(u => u.userId == userId).ToList();
                motherR.hospitalId    = users[0].hospitalId;
                motherR.patientId     = mother.patientId;
                motherR.birthRecordId = birthRecord.birthRecordId;
                newDB.zz_record.Add(motherR);
                newDB.SaveChanges();

                //Add Father
                if (form["fatherFirstName"] != "")
                {
                    zz_record fatherR = new zz_record();
                    fatherR.hospitalId    = users[0].hospitalId;
                    fatherR.patientId     = father.patientId;
                    fatherR.birthRecordId = birthRecord.birthRecordId;
                    newDB.zz_record.Add(fatherR);
                    newDB.SaveChanges();
                }

                //Add Child
                zz_record childR = new zz_record();
                childR.hospitalId    = users[0].hospitalId;
                childR.patientId     = child.patientId;
                childR.birthRecordId = birthRecord.birthRecordId;
                newDB.zz_record.Add(childR);
                newDB.SaveChanges();
                logger.Info("User " + account.firstName + " " + account.lastName + " created birth record: " + birthRecord.birthRecordId);

                return(RedirectToAction("Index"));
            }

            return(View(birthRecord));
        }
Esempio n. 4
0
        public ActionResult DetailsUpdateAll(System.Web.Mvc.FormCollection form)
        {
            string  mrn     = Request.Form["mrn"];
            patient p       = db.patients.Where(r => r.medical_record_number == mrn).FirstOrDefault();
            user    account = db.users.Find(UserAccount.GetUserID());

            int patientID = p.patient_id;
            //Tables
            List <patient_name>       pn  = db.patient_name.Where(r => r.patient_id == patientID).ToList();
            List <patient_family>     pf  = db.patient_family.Where(r => r.patient_id == patientID).ToList();
            patient_birth_information pbi = db.patient_birth_information.Where(r => r.patient_id == patientID).FirstOrDefault();
            List <patient_address>    pa  = db.patient_address.Where(r => r.patient_id == patientID).ToList();
            List <patient_insurance>  pi  = db.patient_insurance.Where(r => r.patient_id == patientID).ToList();
            //Form inputs
            //PrimaryName
            string fName = Request.Form["firstName"];
            string mName = Request.Form["middleName"];
            string lName = Request.Form["lastName"];
            //NewAlias
            string AfName = Request.Form["AfirstName"];
            string AmName = Request.Form["AmiddleName"];
            string AlName = Request.Form["AlastName"];


            //Work out Patient Names
            if (pn.Any())
            {
                //Find Primary Name
                patient_name foundPrimary = db.patient_name.Where(r => r.patient_id == patientID && r.patient_name_type_id == 1).FirstOrDefault();
                if (foundPrimary != null)
                {                                              //if the patient has a primary name (Which they should)
                    if (foundPrimary.first_name != fName || foundPrimary.middle_name != mName || foundPrimary.last_name != lName)
                    {                                          //check if the primary name changed
                        foundPrimary.patient_name_type_id = 2; //change primary name to an alias.
                        foundPrimary.date_edited          = DateTime.Now;
                        foundPrimary.edited_by            = account.userId;
                        db.Entry(foundPrimary).State      = EntityState.Modified;
                        patient_name newPrimary = new patient_name();
                        newPrimary.patient_name_type_id = 1;
                        newPrimary.patient_id           = patientID;
                        newPrimary.first_name           = fName;
                        newPrimary.middle_name          = mName;
                        newPrimary.last_name            = lName;
                        newPrimary.date_added           = DateTime.Now;
                        db.patient_name.Add(newPrimary);
                        db.SaveChanges();
                    }
                    if (AfName.Length > 1 && AlName.Length > 1)
                    {//Add an Alias
                        patient_name newAlias = new patient_name();
                        newAlias.patient_name_type_id = 2;
                        newAlias.patient_id           = patientID;
                        newAlias.first_name           = AfName;
                        newAlias.middle_name          = AmName;
                        newAlias.last_name            = AlName;
                        newAlias.date_added           = DateTime.Now;
                        db.patient_name.Add(newAlias);
                        db.SaveChanges();
                    }
                }
            }
            //update any other General Info
            string motherMaidenName = Request.Form["mothersMaidenName"];
            string sex           = Request.Form["sex"];
            string gender        = Request.Form["gender"];
            int    maritalStatus = Convert.ToInt32(Request.Form["maritalStatus"]);
            int    race          = Convert.ToInt32(Request.Form["race"]);
            int    ethnicity     = Convert.ToInt32(Request.Form["ethnicity"]);
            int    changed       = 0;

            if (p.mother_maiden_name != motherMaidenName)
            {
                p.mother_maiden_name = motherMaidenName; changed++;
            }
            if (p.patient_ethnicity_id != ethnicity)
            {
                p.patient_ethnicity_id = ethnicity; changed++;
            }
            if (p.marital_status_id != maritalStatus)
            {
                p.marital_status_id = maritalStatus; changed++;
            }
            if (p.patient_race_id != race)
            {
                p.patient_race_id = race; changed++;
            }
            if (changed > 0)//if there were any changes, update patient record.
            {
                p.date_edited     = DateTime.Now;
                p.edited_by       = account.userId;
                db.Entry(p).State = EntityState.Modified;
            }
            string address  = Request.Form["address"];
            string address2 = Request.Form["address2"];
            string city     = Request.Form["city"];
            string state    = Request.Form["state"];
            string zip      = Request.Form["zip"];

            string addressBilling  = Request.Form["addressBilling"];
            string address2Billing = Request.Form["address2Billing"];
            string cityBilling     = Request.Form["cityBilling"];
            string stateBilling    = Request.Form["stateBilling"];
            string zipBilling      = Request.Form["zipBilling"];

            changed = 0;
            if (pa.Any())
            {
                patient_address primaryAddress = db.patient_address.Where(r => r.address_type_id == 1).FirstOrDefault();
                if (primaryAddress != null)
                {
                    if (primaryAddress.street_address_one != address || primaryAddress.street_address_two != address2)
                    {
                        changed++;
                        primaryAddress.address_type_id = 4;
                        primaryAddress.date_edited     = DateTime.Now;
                        primaryAddress.edited_by       = account.userId;
                        db.Entry(primaryAddress).State = EntityState.Modified;
                        patient_address newPrimary = new patient_address();
                        newPrimary.patient_id         = patientID;
                        newPrimary.street_address_one = address;
                        newPrimary.street_address_two = address2;
                        newPrimary.city            = city;
                        newPrimary.state           = state;
                        newPrimary.zip             = zip;
                        newPrimary.address_type_id = 1;
                        newPrimary.date_added      = DateTime.Now;
                        db.patient_address.Add(newPrimary);
                    }
                }
                else
                {
                    changed++;
                    patient_address newPrimary = new patient_address();
                    newPrimary.patient_id         = patientID;
                    newPrimary.street_address_one = address;
                    newPrimary.street_address_two = address2;
                    newPrimary.city            = city;
                    newPrimary.state           = state;
                    newPrimary.zip             = zip;
                    newPrimary.address_type_id = 1;
                    newPrimary.date_added      = DateTime.Now;
                    db.patient_address.Add(newPrimary);
                }
                patient_address primaryAddressBilling = db.patient_address.Where(r => r.address_type_id == 2).FirstOrDefault();
                if (primaryAddressBilling != null)
                {
                    if (primaryAddressBilling.street_address_one != addressBilling || primaryAddressBilling.street_address_two != address2Billing)
                    {
                        changed++;

                        patient_address newPrimaryBilling = new patient_address();
                        newPrimaryBilling.patient_id         = patientID;
                        newPrimaryBilling.street_address_one = addressBilling;
                        newPrimaryBilling.street_address_two = address2Billing;
                        newPrimaryBilling.city            = cityBilling;
                        newPrimaryBilling.state           = stateBilling;
                        newPrimaryBilling.zip             = zipBilling;
                        newPrimaryBilling.address_type_id = 2;
                        newPrimaryBilling.date_added      = DateTime.Now;
                        db.patient_address.Add(newPrimaryBilling);
                        primaryAddressBilling.address_type_id = 4;
                        primaryAddressBilling.date_edited     = DateTime.Now;
                        primaryAddressBilling.edited_by       = account.userId;
                        db.Entry(primaryAddressBilling).State = EntityState.Modified;
                    }
                }
                else
                {
                    changed++;
                    patient_address newPrimaryBilling = new patient_address();
                    newPrimaryBilling.patient_id         = patientID;
                    newPrimaryBilling.street_address_one = addressBilling;
                    newPrimaryBilling.street_address_two = address2Billing;
                    newPrimaryBilling.city            = cityBilling;
                    newPrimaryBilling.state           = stateBilling;
                    newPrimaryBilling.zip             = zipBilling;
                    newPrimaryBilling.address_type_id = 2;
                    newPrimaryBilling.date_added      = DateTime.Now;
                    db.patient_address.Add(newPrimaryBilling);
                }
            }
            else  //If no addresses exist add them
            {
                if (address.Length > 1 || address2.Length > 1 || city.Length > 1 || state.Length > 1 || zip.Length > 1)
                {
                    changed++;
                    patient_address newAddress = new patient_address();
                    newAddress.patient_id         = patientID;
                    newAddress.street_address_one = address;
                    newAddress.street_address_two = address2;
                    newAddress.city            = city;
                    newAddress.state           = state;
                    newAddress.zip             = zip;
                    newAddress.address_type_id = 1;
                    newAddress.date_added      = DateTime.Now;
                    db.patient_address.Add(newAddress);
                }
                if (addressBilling.Length > 1 || address2Billing.Length > 1 || cityBilling.Length > 1 || stateBilling.Length > 1 || zipBilling.Length > 1)
                {
                    changed++;
                    patient_address newAddressBilling = new patient_address();
                    newAddressBilling.patient_id         = patientID;
                    newAddressBilling.street_address_one = addressBilling;
                    newAddressBilling.street_address_two = address2Billing;
                    newAddressBilling.city            = cityBilling;
                    newAddressBilling.state           = stateBilling;
                    newAddressBilling.zip             = zipBilling;
                    newAddressBilling.address_type_id = 2;
                    newAddressBilling.date_added      = DateTime.Now;
                    db.patient_address.Add(newAddressBilling);
                }
            }
            if (changed > 0)
            {//If address is added or updated, save the changes.
                db.SaveChanges();
            }

            ViewBag.patientId = mrn;
            return(View("Details", new { id = mrn }));
        }