protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state) { LoadAuthentication(context); templateName = TemplateName.Get(context); GetTemplateInfoDelegate = new Action(_GetTemplateInfo); return(GetTemplateInfoDelegate.BeginInvoke(callback, state)); }
//public bool AsTemplate(string doctorID, string departmentCode, int Flag) //{ // if (Globals.offline) // { // MessageBox.Show(ErrorMessage.NoNewTemplate, ErrorMessage.Warning); // return Return.Failed; // } // string templateType = StringGeneral.PersonTemplate; // string fullPath = null; // #region Create a xml doc. // XmlDocument doc = new XmlDocument(); // /* Load xml doc with local note template. */ // if (doctorID == EmrConstant.StringGeneral.NullCode) // { // /* As a department template */ // templateType = StringGeneral.DepartTemplate; // fullPath = emrTaskPane.NoteTemplate.MakeDepartNoteTemplateCategory(); // if (File.Exists(fullPath)) doc.Load(fullPath); // else doc.LoadXml("<NoteTemplates DepartmentCode=\"" + departmentCode + "\" />"); // } // if (doctorID == EmrConstant.StringGeneral.AllCode) // { // /* As a hospital department template */ // templateType = StringGeneral.HospitalTemplate; // fullPath = emrTaskPane.NoteTemplate.MakeHospitalNoteTemplateCategory(); // if (File.Exists(fullPath)) doc.Load(fullPath); // else doc.LoadXml("<NoteTemplates HospitalCode=\"" + StringGeneral.AllCode + "\" />"); // } // if (doctorID != EmrConstant.StringGeneral.NullCode && doctorID != EmrConstant.StringGeneral.AllCode) // { // /* As a person template */ // templateType = StringGeneral.PersonTemplate; // fullPath = emrTaskPane.NoteTemplate.MakePersonNoteTemplateCategory(doctorID); // if (File.Exists(fullPath)) doc.Load(fullPath); // else doc.LoadXml("<NoteTemplates DoctorID=\"" + doctorID + "\" />"); // } // #endregion // #region Get tempmate name from the operator // ArrayList names = new ArrayList(); // emrTaskPane.NoteTemplate.LoadTemplateNames(names, templateType); // string NodeID1 = ThisAddIn.GetNoteIDFromWordWindow(); // string defaultName = // Globals.emrPattern.GetNoteNameFromNoteID(NodeID1); // SaveTemplate tempName = new SaveTemplate(names, defaultName, Flag); // tempName.StartPosition = FormStartPosition.CenterScreen; // if (tempName.ShowDialog() == DialogResult.Cancel) return false; // string templateName = tempName.Get(); // string Creator = Globals.DoctorID; // string CreateDate = DateTime.Now.ToString(); // string IllType = tempName.GetIllType(); // string IllName = tempName.GetIllName(); // string Type = tempName.GetTypes(); // string TypeName = tempName.GetTypeName(); // string Sex = tempName.GetSex(); // string NoteName = Globals.emrPattern.GetNoteNameFromNoteID(NodeID1); // string TemplateName = tempName.GetTemplateName(); // if (noteInfo.GetEditMode() == NoteEditMode.Reading) // { // ThisAddIn.SetReadWrite(); // noteInfo.SetEditMode(NoteEditMode.Writing); // } // #endregion // #region Create attributs for the new template // XmlElement noteTemplate = doc.CreateElement(EmrConstant.ElementNames.NoteTemplate); // noteTemplate.SetAttribute(AttributeNames.Name, templateName); // noteTemplate.SetAttribute(AttributeNames.NoteID, NodeID1); // noteTemplate.SetAttribute(AttributeNames.NoteName, NoteName); // noteTemplate.SetAttribute(AttributeNames.Header, noteInfo.GetNoteHeaderType()); // noteTemplate.SetAttribute(AttributeNames.Unique, noteInfo.GetNoteUniqueFlag()); // if (author.finalCheckerLable != string.Empty) // noteTemplate.SetAttribute(AttributeNames.Sign1, author.finalCheckerLable); // if (author.checkerLable != string.Empty) // noteTemplate.SetAttribute(AttributeNames.Sign2, author.checkerLable); // noteTemplate.SetAttribute(AttributeNames.Sign3, author.writerLable); // noteTemplate.SetAttribute(AttributeNames.Merge, merge); // /// Special note treatment // noteTemplate.SetAttribute(AttributeNames.StartTime, startTime); // if (noteInfo.sexOption) // noteTemplate.SetAttribute(AttributeNames.Sex, emrTaskPane.GetPatientSex()); // else // noteTemplate.SetAttribute(AttributeNames.Sex, StringGeneral.Both); // noteTemplate.SetAttribute(AttributeNames.IllName, IllName); // noteTemplate.SetAttribute(AttributeNames.IllType, IllType); // noteTemplate.SetAttribute(AttributeNames.Type, Type); // noteTemplate.SetAttribute(AttributeNames.TypeName, TypeName); // if (noteInfo.GetNoteHeaderType() == StringGeneral.None) // { // XmlNode notePattern = Globals.emrPattern.GetEmrNote(noteInfo.GetNoteID()); // if (notePattern != null) // { // XmlElement header = doc.CreateElement(ElementNames.Header); // foreach (XmlNode subtitle in notePattern.SelectNodes(ElementNames.SubTitle)) // { // if (subtitle.Attributes[AttributeNames.Value] == null) continue; // XmlElement newSubtitle = doc.CreateElement(ElementNames.SubTitle); // foreach (XmlAttribute att in subtitle.Attributes) // { // newSubtitle.SetAttribute(att.Name, att.Value); // } // newSubtitle.InnerXml = subtitle.InnerXml; // header.AppendChild(newSubtitle); // } // noteTemplate.AppendChild(header); // } // } // #endregion // #region Save the new template into dadabase and add new template to the template tree. // if (emrTaskPane.NoteTemplate.AddNewTemplate(emrTaskPane, templateType, noteTemplate, IllType, IllName, Creator, CreateDate, Sex, Type, TypeName, NodeID1, NoteName, templateName) < 0) return Return.Failed; // #endregion // ActiveDocumentManager.getDefaultAD().Saved = true; // emrTaskPane.TemplateOperationEnable(true); // return Return.Successful; //} public bool AsTemplateOld(string doctorID, string departmentCode) { if (Globals.offline) { MessageBox.Show(ErrorMessage.NoNewTemplate, ErrorMessage.Warning); return(Return.Failed); } string templateType = StringGeneral.PersonTemplate; string fullPath = null; #region Create a xml doc. XmlDocument doc = new XmlDocument(); /* Load xml doc with local note template. */ if (doctorID == EmrConstant.StringGeneral.NullCode) { /* As a department template */ templateType = StringGeneral.DepartTemplate; fullPath = emrTaskPane.NoteTemplate.MakeDepartNoteTemplateCategory(); if (File.Exists(fullPath)) { doc.Load(fullPath); } else { doc.LoadXml("<NoteTemplates DepartmentCode=\"" + departmentCode + "\" />"); } } if (doctorID == EmrConstant.StringGeneral.AllCode) { /* As a hospital department template */ templateType = StringGeneral.HospitalTemplate; fullPath = emrTaskPane.NoteTemplate.MakeHospitalNoteTemplateCategory(); if (File.Exists(fullPath)) { doc.Load(fullPath); } else { doc.LoadXml("<NoteTemplates HospitalCode=\"" + StringGeneral.AllCode + "\" />"); } } if (doctorID != EmrConstant.StringGeneral.NullCode && doctorID != EmrConstant.StringGeneral.AllCode) { /* As a person template */ templateType = StringGeneral.PersonTemplate; fullPath = emrTaskPane.NoteTemplate.MakePersonNoteTemplateCategory(doctorID); if (File.Exists(fullPath)) { doc.Load(fullPath); } else { doc.LoadXml("<NoteTemplates DoctorID=\"" + doctorID + "\" />"); } } #endregion #region Get tempmate name from the operator ArrayList names = new ArrayList(); emrTaskPane.NoteTemplate.LoadTemplateNames(names, templateType); string childID = ""; string NodeID1 = emrTaskPane.GetNoteIDFromWordWindow(ref childID); if (NodeID1 == childID || childID == "") { childID = "0"; } string NoteName = Globals.emrPattern.GetNoteNameFromNoteID(NodeID1); string defaultName = ""; if (NodeID1 == "0") { defaultName = NoteName; } else { defaultName = Globals.childPattern.GetNoteNameFromNoteID(childID); if (defaultName == "" || defaultName == null) { defaultName = NoteName; } } TemplateName tempName = new TemplateName(names, defaultName); tempName.StartPosition = FormStartPosition.CenterScreen; if (tempName.ShowDialog() == DialogResult.Cancel) { return(false); } string templateName = tempName.Get(); //templateName += " *"; if (noteInfo.GetEditMode() == NoteEditMode.Reading) { emrTaskPane.SetReadWrite(); noteInfo.SetEditMode(NoteEditMode.Writing); } /* Remove revisions. */ // ActiveDocumentManager.getDefaultAD().AcceptAllRevisions(); #endregion #region Create attributs for the new template XmlElement noteTemplate = doc.CreateElement(EmrConstant.ElementNames.NoteTemplate); noteTemplate.SetAttribute(AttributeNames.Name, templateName); noteTemplate.SetAttribute(AttributeNames.NoteID, NodeID1); noteTemplate.SetAttribute(AttributeNames.NoteName, NoteName); noteTemplate.SetAttribute(AttributeNames.Header, noteInfo.GetNoteHeaderType()); noteTemplate.SetAttribute(AttributeNames.Unique, noteInfo.GetNoteUniqueFlag()); noteTemplate.SetAttribute(AttributeNames.ChildID, childID); if (author.finalCheckerLable != string.Empty) { noteTemplate.SetAttribute(AttributeNames.Sign1, author.finalCheckerLable); } if (author.checkerLable != string.Empty) { noteTemplate.SetAttribute(AttributeNames.Sign2, author.checkerLable); } noteTemplate.SetAttribute(AttributeNames.Sign3, author.writerLable); noteTemplate.SetAttribute(AttributeNames.Merge, merge); /// Special note treatment noteTemplate.SetAttribute(AttributeNames.StartTime, startTime); if (noteInfo.sexOption) { noteTemplate.SetAttribute(AttributeNames.Sex, emrTaskPane.GetPatientSex()); } else { noteTemplate.SetAttribute(AttributeNames.Sex, StringGeneral.Both); } if (noteInfo.GetNoteHeaderType() == StringGeneral.None) { XmlNode notePattern = Globals.emrPattern.GetEmrNote(noteInfo.GetNoteID()); if (notePattern != null) { XmlElement header = doc.CreateElement(ElementNames.Header); foreach (XmlNode subtitle in notePattern.SelectNodes(ElementNames.SubTitle)) { if (subtitle.Attributes[AttributeNames.Value] == null) { continue; } XmlElement newSubtitle = doc.CreateElement(ElementNames.SubTitle); foreach (XmlAttribute att in subtitle.Attributes) { newSubtitle.SetAttribute(att.Name, att.Value); } newSubtitle.InnerXml = subtitle.InnerXml; header.AppendChild(newSubtitle); } noteTemplate.AppendChild(header); } } #endregion #region Save the new template into dadabase and add new template to the template tree. if (emrTaskPane.NoteTemplate.AddNewTemplateOld(emrTaskPane, templateType, noteTemplate) < 0) { return(Return.Failed); } #endregion ActiveDocumentManager.getDefaultAD().Saved = true; //emrTaskPane.TemplateOperationEnable(true); return(Return.Successful); }