Пример #1
0
        public int AddEmrNote(XmlNode notePattern, XmlElement emrNote, NoteStatus status, bool sexOption, XmlNode wordXml)
        {
            int    series     = -1;
            string registryID = emrDoc.DocumentElement.GetAttribute(AttributeNames.RegistryID);
            string noteID     = notePattern.Attributes[AttributeNames.NoteID].Value;

            #region Set attributes for emr note
            string sequence = null;
            #region Treat attribute StartTime
            switch (notePattern.Attributes[AttributeNames.StartTime].Value)
            {
            case StartTime.Routine:
                if (Globals.offline)
                {
                    emrNote.SetAttribute(AttributeNames.Start, ThisAddIn.Today().ToString());
                }
                else
                {
                    emrNote.SetAttribute(AttributeNames.Start,
                                         ThisAddIn.LastDegreeOrderTime(registryID).ToString());
                }
                break;

            case StartTime.Operation:
                sequence = OperationSequence(registryID, noteID);
                if (sequence == null)
                {
                    return(series);
                }
                emrNote.SetAttribute(AttributeNames.Sequence, sequence);
                break;

            case StartTime.Rescued:
                sequence = RescueSequence(registryID, noteID);
                if (sequence == null)
                {
                    return(series);
                }
                emrNote.SetAttribute(AttributeNames.RescueSequence, sequence);
                break;

            case StartTime.TransferIn:
                sequence = TransferInSequence(registryID, noteID);
                if (sequence == null)
                {
                    return(series);
                }
                emrNote.SetAttribute(AttributeNames.TransferInSequence, sequence);
                break;

            case StartTime.TransferOut:
                sequence = TransferOutSequence(registryID, noteID);
                if (sequence == null)
                {
                    return(series);
                }
                emrNote.SetAttribute(AttributeNames.TransferOutSequence, sequence);
                break;

            case StartTime.TakeOver:
                sequence = TakeoverSequence(registryID, noteID);
                if (sequence == null)
                {
                    return(series);
                }
                emrNote.SetAttribute(AttributeNames.TakeOverSequence, sequence);
                break;

            case StartTime.Consult:
                sequence = ConsultSequence(registryID, noteID);
                if (sequence == null)
                {
                    //  MessageBox.Show("此次会诊记录已经书写完成!");
                    return(series);
                }
                emrNote.SetAttribute(AttributeNames.Sequence, sequence);
                break;
            }
            #endregion

            int sign = 0;
            //try
            //{
            //    foreach (Microsoft.Office.Interop.Word.XMLNode xn in ActiveDocumentManager.getDefaultAD().XMLNodes)
            //    {

            //        if (xn.BaseName == "电子病历")
            //        {
            //            for (int i = 1; i <= xn.ChildNodes.Count; i++)
            //            {

            //                if (xn.ChildNodes[i].Text == null) continue;
            //                if (xn.ChildNodes[i].BaseName == "医护签名")
            //                {
            //                    sign = xn.ChildNodes[i].ChildNodes.Count;
            //                    break;
            //                }
            //            }
            //        }
            //        else break;
            //    }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message, "EmrDocument 的317行");
            //}

            emrNote.SetAttribute(AttributeNames.NoteID, noteID);
            emrNote.SetAttribute(AttributeNames.NoteName, notePattern.Attributes[AttributeNames.NoteName].Value);
            emrNote.SetAttribute(AttributeNames.Header, notePattern.Attributes[AttributeNames.Header].Value);
            emrNote.SetAttribute(AttributeNames.Unique, notePattern.Attributes[AttributeNames.Unique].Value);
            emrNote.SetAttribute(AttributeNames.NoteStatus, status.ToString("d"));
            emrNote.SetAttribute(AttributeNames.WriterID, Globals.DoctorID);
            emrNote.SetAttribute(AttributeNames.Writer, Globals.DoctorName);


            DateTime now = ThisAddIn.Today();
            /* because allow the operator to choose commit time */
            emrNote.SetAttribute(AttributeNames.CheckerID, "");
            emrNote.SetAttribute(AttributeNames.Checker, "");
            emrNote.SetAttribute(AttributeNames.CheckedDate, "");
            emrNote.SetAttribute(AttributeNames.FinalCheckerID, "");
            emrNote.SetAttribute(AttributeNames.FinalChecker, "");
            emrNote.SetAttribute(AttributeNames.FinalCheckedDate, "");
            emrNote.SetAttribute("sign", sign.ToString());
            /* 2007-07-11 add sign lables */
            if (notePattern.Attributes[AttributeNames.Sign1] != null)
            {
                emrNote.SetAttribute(AttributeNames.Sign1, notePattern.Attributes[AttributeNames.Sign1].Value);
            }
            if (notePattern.Attributes[AttributeNames.Sign2] != null)
            {
                emrNote.SetAttribute(AttributeNames.Sign2, notePattern.Attributes[AttributeNames.Sign2].Value);
            }
            if (notePattern.Attributes[AttributeNames.Sign3] != null)
            {
                emrNote.SetAttribute(AttributeNames.Sign3, notePattern.Attributes[AttributeNames.Sign3].Value);
            }

            emrNote.SetAttribute(AttributeNames.LastWriteTime, now.ToFileTime().ToString());
            /*  add merge property */
            emrNote.SetAttribute(AttributeNames.Merge, notePattern.Attributes[AttributeNames.Merge].Value);
            emrNote.SetAttribute(AttributeNames.StartTime, notePattern.Attributes[AttributeNames.StartTime].Value);
            /* add sex feature for it to be as a template */
            if (sexOption)
            {
                emrNote.SetAttribute(AttributeNames.Sex, StringGeneral.Yes);
            }
            else
            {
                emrNote.SetAttribute(AttributeNames.Sex, StringGeneral.No);
            }

            if (emrNote.Attributes[AttributeNames.SingleContinue] == null)
            {
                XmlAttribute newAttribute = emrNote.OwnerDocument.CreateAttribute(AttributeNames.SingleContinue);
                emrNote.Attributes.Append(newAttribute);
            }
            if (notePattern.Attributes[AttributeNames.SingleContinue] != null)
            {
                emrNote.SetAttribute(AttributeNames.SingleContinue, notePattern.Attributes[AttributeNames.SingleContinue].Value);
            }
            else
            {
                emrNote.SetAttribute(AttributeNames.SingleContinue, "no");
            }
            /*----------------------------------------------------------------------------*/

            /* Make a new series as unique id for the EmrNote. */
            #endregion

            /* word window to word document */
            //string tmpfile = Path.GetFullPath("病程记录.dotx");
            string tmpfile = Path.Combine(Globals.currentDirectory, ResourceName.Mytmp);
            //udt.jj.SaveWordDoc(ThisAddIn.Application.ActiveDocument, tmpfile, false);

            #region Save document into database
            if (!Globals.offline)
            {
                XmlElement noteDoc = emrDoc.CreateElement(ElementNames.EmrNote);
                noteDoc.InnerText = udt.jj.WordDocumentToString(tmpfile);
                emrNote.SetAttribute(AttributeNames.Series, "0");
                series = ThisAddIn.NewOneEmrNote(registryID, archiveNum, emrNote, noteDoc, wordXml);
                if (series < 0)
                {
                    return(series);
                }
            }
            else
            {
                series = Convert.ToInt32(emrDoc.DocumentElement.GetAttribute(AttributeNames.Series)) + 1;
                return(-100);
            }

            #endregion

            #region Save document into local storage
            string wdDocName = udt.MakeWdDocumentFileName(registryID, noteID, series, Globals.workFolder);
            File.Copy(tmpfile, wdDocName, true);
            if (Globals.localDocumentEncode)
            {
                udt.jj.EncodeEmrDocument(wdDocName);
            }

            emrNote.SetAttribute(AttributeNames.Series, series.ToString("d"));
            emrDoc.DocumentElement.AppendChild(emrNote);
            emrDoc.DocumentElement.SetAttribute(AttributeNames.LastWriteTime, now.ToFileTime().ToString());
            emrDoc.DocumentElement.SetAttribute(AttributeNames.Series, series.ToString("d"));
            emrDoc.Save(emrDocFile);
            udt.jj.EncodeEmrDocument(emrDocFile);
            #endregion

            return(series);
        }