/// <summary> /// Saves the current profile, existing or newly created. /// </summary> /// <param name="caller"></param> private void SaveCurrentProfile(string caller) { SecurityController sc = new SecurityController(); string user = sc.GetUserName(); if (!String.IsNullOrEmpty(this._ptProfileId.Value)) { ProfileId = Int32.Parse(this._ptProfileId.Value); } if (this._visitTypeStage.Value != "0") { VisitTypeId = Int32.Parse(this._visitTypeStage.Value); } PatientEducationDa da = new PatientEducationDa(); List <string> checkedPartsList = new List <string>(); foreach (TreeNode sectionNode in contentTV.Nodes) { foreach (TreeNode topicNode in sectionNode.ChildNodes) { foreach (TreeNode subTopicNode in topicNode.ChildNodes) { if (subTopicNode.Checked) { checkedPartsList.Add(subTopicNode.Value); } } } } if (ProfileId > 0) { DataTable dbProfilePartsDt = da.GetProfileDocPartsByProfileId(ProfileId); // Delete existing profile parts that have been deselected, // and update the list of actual new parts to be saved later on. foreach (DataRow dr in dbProfilePartsDt.Rows) { string stId = dr[PatientEdProfileDocPart.SubTopicId].ToString(); if (!checkedPartsList.Contains(stId)) { //delete this profile doc part from the db da.DeleteProfileDocPartByProfileIdAndSubTopicId(ProfileId, Int32.Parse(stId)); } else { //remove it from the list of checked parts, as we have confirmed it is already in the db checkedPartsList.Remove(stId); } } PatientEdProfile profileBiz = new PatientEdProfile(); profileBiz.Get(ProfileId); profileBiz[PatientEdProfile.UpdatedBy] = user; profileBiz[PatientEdProfile.UpdatedTime] = DateTime.Now.ToString(); if (caller == "print") { profileBiz[PatientEdProfile.LastPrintedBy] = user; profileBiz[PatientEdProfile.LastPrintedTime] = DateTime.Now.ToString(); } profileBiz.Save(); } else { // Saving a brand new profile. SessionHandler sh = new SessionHandler(Session); int ptId = sh.GetPatientId(); PatientEdProfile profile = new PatientEdProfile(); profile[PatientEdProfile.PatientId] = ptId.ToString(); if (this._visitTypeStage.Value != "0") { profile[PatientEdProfile.ProfileVisitTypeId] = VisitTypeId; } if (this.ddlDiseaseProfile.SelectedIndex > 0) { profile[PatientEdProfile.ProfileDiseaseId] = DiseaseId; } string profileDate = DateTime.Now.ToString(); profile[PatientEdProfile.ProfileCreateDate] = profileDate; profile[PatientEdProfile.EnteredBy] = user; profile[PatientEdProfile.EnteredTime] = profileDate; profile[PatientEdProfile.UpdatedBy] = user; profile[PatientEdProfile.UpdatedTime] = profileDate; if (caller == "print") { profile[PatientEdProfile.LastPrintedBy] = user; profile[PatientEdProfile.LastPrintedTime] = DateTime.Now.ToString(); } profile.Save(); ProfileId = Int32.Parse(profile[PatientEdProfile.ProfileId].ToString()); LoadListOfProfilesTable(ptId); ShowProfileLog(true); } // Add the new profile parts to this profile document foreach (string profilePart in checkedPartsList) { PatientEdProfileDocPart dp = new PatientEdProfileDocPart(); dp[PatientEdProfileDocPart.ProfileId] = ProfileId.ToString(); dp[PatientEdProfileDocPart.SubTopicId] = Int32.Parse(profilePart); dp[PatientEdProfileDocPart.ProfileDocPartVersionNumber] = "1.0"; dp[PatientEdProfileDocPart.ProfileDocPartOrderNumber] = "1"; dp.Save(); } LoadExistingProfile(); GetRootNodes(); this._callbackType.Value = String.Empty; }
protected void TreeNode_Populate(Object sender, TreeNodeEventArgs e) { int sectionId = Int32.Parse(e.Node.Value); PatientEducationDa da = new PatientEducationDa(); DataTable dt = da.GetTopicsBySection(sectionId); List <string> subTopicIds = new List <string>(); DataTable profilePartsDt = new DataTable(); DataTable subTopicTable = new DataTable(); string loadDocType = ""; // inside the loop we will want to check off boxes based on a profile or default doc if (ProfileId > 0) { profilePartsDt = da.GetProfileDocPartsByProfileId(ProfileId); loadDocType = "UserProfile"; } else if (PageUtil.IsInteger(_packetId.Value)) { // check off subtopics based on active packet subTopicTable = da.GetDiseaseVisitSubTopicByPacket(int.Parse(_packetId.Value)); loadDocType = "DefaultPacket"; PacketName.Text = _packetName.Value; } // get subtopics by topic foreach (DataRow row in dt.Rows) { string topicName = row[PatientEdTopic.TopicName].ToString(); TreeNode topicNode = new TreeNode("<span onclick='return false;' style='cursor:default;'>" + topicName + "</span>", row[PatientEdTopic.TopicId].ToString()); topicNode.Expanded = false; topicNode.ToolTip = topicName; topicNode.ImageToolTip = topicName; int topicId = Int32.Parse(row[PatientEdTopic.TopicId].ToString()); DataTable dtSubTopic = da.GetSubTopicsByTopic(topicId); foreach (DataRow dr in dtSubTopic.Rows) { string subTopicId = dr[PatientEdSubTopic.SubTopicId].ToString(); subTopicIds.Add(subTopicId); string subTopicName = dr[PatientEdSubTopic.SubTopicName].ToString(); TreeNode subTopicNode = new TreeNode("<span onclick='doNodeCheckboxClick(this);return false;' style='cursor:default;'>" + subTopicName + "</span>", dr[PatientEdSubTopic.SubTopicId].ToString()); subTopicNode.ToolTip = subTopicName; subTopicNode.ImageToolTip = subTopicName; subTopicNode.ShowCheckBox = true; //Loading an existing profile, so check off boxes if subtopic is part of the profile doc if (loadDocType.Equals("UserProfile")) { DataRow[] returnedRows = profilePartsDt.Select("SubTopicId = " + subTopicId + ""); if (returnedRows.Length > 0) { subTopicNode.Checked = true; topicNode.Expand(); } /* previous, less efficient way * foreach (DataRow pdr in profilePartsDt.Rows) * { * if (subTopicId == pdr[PatientEdProfileDocPart.SubTopicId].ToString()) * { * subTopicNode.Checked = true; * topicNode.Expand(); * } * } */ } else if (loadDocType.Equals("DefaultPacket")) //not for a particular patient { // if a the subtopic is part of the default packet, check it off DataRow[] foundRows = subTopicTable.Select("SubTopicId = " + subTopicId + ""); if (foundRows.Length > 0) { subTopicNode.Checked = true; topicNode.Expand(); } /*foreach (DataRow packetRow in subTopicTable.Rows) * { * if (subTopicId == packetRow[PatientEdDisease_VisitType_SubTopic.SubTopicId].ToString()) * { * subTopicNode.Checked = true; * topicNode.Expand(); * break; * } * }*/ /* Try to check off subtopics based on disease ddl and visit type * DataTable dST = da.GetDiseaseVisitSubTopicBySubTopic(Int32.Parse(subTopicId)); * foreach (DataRow r in dST.Rows) * { * string sVisitTypeId = ""; * //if (this._visitTypeId != 0) * if (VisitTypeId != 0) * { * sVisitTypeId = this._visitTypeId.ToString(); //this._visitTypeStage.Value * } * * if (r[PatientEdDisease_VisitType_SubTopic.DiseaseId].ToString() == this.ddlDiseaseProfile.SelectedValue * && r[PatientEdDisease_VisitType_SubTopic.VisitTypeId].ToString() == sVisitTypeId) * { * subTopicNode.Checked = true; * topicNode.Expand(); * break; * } * } */ } topicNode.ChildNodes.Add(subTopicNode); } topicNode.ShowCheckBox = false; e.Node.ChildNodes.Add(topicNode); } PatientEdUtil.RegisterStartupSubTopicIds(Page, sectionId, subTopicIds); }