public ActionResult Create([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) { role.dateCreated = DateTime.Now; role.dateUpdated = DateTime.Now; role.editedBy = 1; db.roles.Add(role); db.SaveChanges(); logger.Info("User " + account.firstName + " " + account.lastName + " created role: " + role.title); return(RedirectToAction("Index")); } return(View(role)); } else { logger.Info("User " + account.firstName + " " + account.lastName + " tried to created role: " + role.title); return(RedirectToAction("tempError", "Home")); } }
public ActionResult Create([Bind(Include = "hospitalId,name,dateCreated,dateUpdated,editedBy")] hospital hospital) { user account = db.users.Find(UserAccount.GetUserID()); if (account.role.title == "Database Adminstrator" || account.role.title == "Instructor") { if (ModelState.IsValid) { hospital.date_added = DateTime.Now; hospital.date_edited = DateTime.Now; hospital.edited_by = 1; db.hospitals.Add(hospital); db.SaveChanges(); logger.Info("User " + account.firstName + " " + account.lastName + " created hospital: " + hospital.name); return(RedirectToAction("Index")); } return(View(hospital)); } else { logger.Info("User " + account.firstName + " " + account.lastName + " tried to create hospital: " + hospital.name); return(RedirectToAction("tempError", "Home")); } }
public ActionResult Create([Bind(Include = "userId,firstName,lastName,hospitalId,roleId,dateCreated,dateUpdated,editedBy")] user user, FormCollection form) { if (ModelState.IsValid) { string email = form["email"].ToString(); if (db.userAccounts.Where(accounts => accounts.userName == email).Count() == 0) { //TODO make these two ID assignments db queries to find ID where hospital = "WCTC" and role = account with lowest permissions user.hospitalId = 1; user.roleId = 5; user.dateCreated = DateTime.Today; user.dateUpdated = DateTime.Today; user.editedBy = 1; db.users.Add(user); db.SaveChanges(); List <user> userList = db.users.Where(u => u.firstName == user.firstName && u.lastName == user.lastName && u.dateCreated == user.dateCreated).ToList(); userAccount uA = new userAccount(); uA.userId = userList[0].userId; uA.userName = email; uA.userGuid = System.Guid.NewGuid(); uA.passwordHash = UserAccount.HashSHA1(form["password"] + uA.userGuid); uA.dateCreated = DateTime.Now; uA.dateUpdated = DateTime.Now; uA.editedBy = 1; db.userAccounts.Add(uA); db.SaveChanges(); logger.Info("User " + uA.userName + " created"); //Get Signed in account try { user account = db.users.Find(UserAccount.GetUserID()); //If it's their account and they are lower-tier, they can't edit their hospital or role. if (account.role.title == "Database Adminstrator" || account.role.title == "Instructor") { return(RedirectToAction("Index")); } } catch (Exception e) { Console.WriteLine(e.Message); TempData["success"] = "Account " + uA.userName + " created! You may now sign in with limited access. Please see your instructor to have your account activated."; return(RedirectToAction("Index", "Home")); } } TempData["error"] = "Email already registered. Please sign in."; logger.Info("User tried to create an account with already registered email: " + email); return(RedirectToAction("Index", "Home")); } ViewBag.hospitalId = new SelectList(db.hospitals, "hospital_id", "name", user.hospitalId); ViewBag.roleId = new SelectList(db.roles, "roleId", "title", user.roleId); return(View(user)); }
public ActionResult Edit([Bind(Include = "wdl_ex, care_system_comment, date_care_system_added")] FormCollection form) { int ncsaID = int.Parse(form["care_system_assessment_id"]); nursing_care_system_assessment ncsa = db.nursing_care_system_assessment.FirstOrDefault(m => m.care_system_assessment_id == ncsaID); nursing_pca_record pca = db.nursing_pca_record.FirstOrDefault(m => m.pca_id == ncsa.pca_id); if (form["formButton"] == "Exit") { return(RedirectToAction("IndividualEncounter", "Encounter", new { id = pca.encounter_id })); } if (ModelState.IsValid) { nursing_care_system_assessment_history ncsahistory = new nursing_care_system_assessment_history(); ncsahistory.care_system_assessment_id = ncsa.care_system_assessment_id; ncsahistory.care_system_assessment_type_id = ncsa.care_system_assessment_type_id; ncsahistory.pca_id = ncsa.pca_id; ncsahistory.date_pca_record_added = pca.date_vitals_added; ncsahistory.wdl_ex = ncsa.wdl_ex; ncsahistory.care_system_comment = ncsa.care_system_comment; ncsahistory.date_care_system_added = ncsa.date_care_system_added; ncsahistory.date_care_system_modified = DateTime.Now; ncsa.wdl_ex = form["wdlRadios"] == "wdlEx" ? true : false; ncsa.care_system_comment = form["wdlExceptionInfo"]; db.SaveChanges(); switch (form["formButton"]) { case "SaveList": return(RedirectToAction("IndividualEncounter", "Encounter", new { id = pca.encounter_id })); case "SaveContinue": int typeID = (int)ncsa.care_system_assessment_type_id + 1; if (typeID <= db.nursing_care_system_assessment_type.Count()) { return(RedirectToAction("CreateOrEdit", "BodySystems", new { pcaID = ncsa.pca_id, typeID = typeID })); } else { return(RedirectToAction("CreateOrEdit", "Comments", new { pcaID = ncsa.pca_id, typeID = 2 })); } default: return(View(ncsa)); } } return(View(ncsa)); }
public ActionResult AddEncounter(System.Web.Mvc.FormCollection form) { string cc = Request.Form["chiefComplaint"]; int aType = Convert.ToInt32(Request.Form["aType"]); int doctor = Convert.ToInt32(Request.Form["doctor"]); string insurance = Request.Form["insurance"]; int facility = Convert.ToInt32(Request.Form["facility"]); encounter pat = db.encounters.OrderByDescending(r => r.encounter_data_id).First(); string encounterID = "0000000000000" + (pat.encounter_data_id + 1); encounterID = encounterID.Substring(encounterID.Length - 14, 14); encounter newEncounter = new encounter(); newEncounter.encounter_id = encounterID; newEncounter.admission_date = DateTime.Now; newEncounter.chief_complaint = cc; newEncounter.admission_type_id = aType; newEncounter.attending_doctor_id = doctor; if (insurance == "0") { patient_insurance pi = new patient_insurance(); pi.patient_id = Convert.ToInt32(Request.Form["patientid"]); pi.insurance_id = 3; pi.individual_insurance_id = "Out Of Pocket"; pi.date_added = DateTime.Now; db.patient_insurance.Add(pi); db.SaveChanges(); newEncounter.patient_insurance_id = pi.patient_insurance_id; } else { patient_insurance pi = db.patient_insurance.Where(r => r.individual_insurance_id == insurance).FirstOrDefault(); newEncounter.patient_insurance_id = pi.patient_insurance_id; } newEncounter.facility_id = facility; db.encounters.Add(newEncounter); db.SaveChanges(); return(Redirect("../IndividualEncounter/" + newEncounter.encounter_data_id)); }
public ActionResult Edit([Bind(Include = "commentData")] FormCollection form) { int npcacID = int.Parse(form["pca_comment_id"]); nursing_pca_comment npcac = db.nursing_pca_comment.FirstOrDefault(m => m.pca_comment_id == npcacID); nursing_pca_record pca = db.nursing_pca_record.FirstOrDefault(m => m.pca_id == npcac.pca_id); if (form["formButton"] == "Exit") { return(RedirectToAction("IndividualEncounter", "Encounter", new { id = pca.encounter_id })); } if (ModelState.IsValid) { nursing_pca_comment_history npcachistory = new nursing_pca_comment_history(); npcachistory.pca_comment_id = npcac.pca_comment_id; npcachistory.pca_comment_type_id = npcac.pca_comment_type_id; npcachistory.pca_id = npcac.pca_id; npcachistory.pca_comment = npcac.pca_comment; npcachistory.date_comment_original = npcac.date_comment_added; npcachistory.date_comment_modified = DateTime.Now; npcac.pca_comment = form["wdlExceptionInfo"]; db.SaveChanges(); switch (form["formButton"]) { case "SaveList": return(RedirectToAction("IndividualEncounter", "Encounter", new { id = pca.encounter_id })); case "SaveContinue": int typeID = (int)npcac.pca_comment_type_id + 1; if (typeID <= db.nursing_pca_comment_type.Count()) { return(RedirectToAction("CreateOrEdit", "Comments", new { pcaID = npcac.pca_id, typeID = typeID })); } else { return(RedirectToAction("Edit", "Comments", new { pcaID = npcac.pca_id, typeID = typeID })); } default: return(View(npcac)); } } return(View(npcac)); }
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)); }
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 })); }