Exemplo n.º 1
0
        public void Save(string directory)
        {
            if (template == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(this.template.htmlText))
            {
                this.template.htmlText = ""; //return; ????
            }
            FileInfo fInfo = template.CalculateFileName(SessionManager.Instance.GetActivePatient().name,
                                                        SessionManager.Instance.GetActivePatient().apptdatetime.ToShortDateString().Replace("/", "-"),
                                                        SessionManager.Instance.GetActivePatient().apptid,
                                                        SessionManager.Instance.GetActivePatient().unitnum,
                                                        "htm", directory);


            System.IO.File.WriteAllText(fInfo.FullName, this.template.htmlText);
        }
Exemplo n.º 2
0
        private void CreateDocument(bool print)
        {
            bool   bInterface        = false;
            bool   bPacsFound        = false;
            bool   bPowerscribeFound = false;
            int    interfaceId       = -1;
            string interfaceType     = "";
            string ipAddress         = "";
            string port          = "";
            string aeTitleRemote = "";
            string aeTitleLocal  = "";
            string DCMTKpath     = "";
            int    pacsSubType   = 1;

            ObjectListView olv = null;

            if (objectListView2.SelectedObject != null)
            {
                olv = objectListView2;
            }
            else if (objectListView1.SelectedObject != null)
            {
                olv = objectListView1;
            }

            if (olv != null)
            {
                DocumentTemplate dt = (DocumentTemplate)olv.SelectedObject;

                if (string.IsNullOrEmpty(dt.htmlPath))
                {
                    if (!string.IsNullOrEmpty(dt.documentFileName))
                    {
                        RiskAppCore.Globals.setApptID(SessionManager.Instance.GetActivePatient().apptid);
                        RiskAppCore.Globals.setUnitNum(SessionManager.Instance.GetActivePatient().unitnum);
                        FileInfo fInfo = dt.CalculateFileName(SessionManager.Instance.GetActivePatient().name,
                                                              SessionManager.Instance.GetActivePatient().apptdatetime.ToShortDateString().Replace("/", "-"),
                                                              SessionManager.Instance.GetActivePatient().apptid,
                                                              SessionManager.Instance.GetActivePatient().unitnum,
                                                              "doc", "");

                        LetterGenerator.Letter.generateDocFromTemplate(dt.documentFileName, dt.documentName, print);

                        RiskAppCore.Globals.setApptID(-1);
                        RiskAppCore.Globals.setUnitNum("");
                        return;
                    }
                }

                if (SessionManager.Instance.GetActivePatient() != null)
                {
                    FileInfo fInfo = dt.CalculateFileName(SessionManager.Instance.GetActivePatient().name,
                                                          SessionManager.Instance.GetActivePatient().apptdatetime.ToShortDateString().Replace("/", "-"),
                                                          SessionManager.Instance.GetActivePatient().apptid,
                                                          SessionManager.Instance.GetActivePatient().unitnum,
                                                          "html", "");

                    System.IO.File.WriteAllText(fInfo.FullName, dt.htmlText);

                    // Check to see if there's an interface we should send to... ONE PER DOCUMENT TEMPLATE!  If you want multiple interfaces, create multiple templates.
                    ParameterCollection pacsArgs = new ParameterCollection();
                    pacsArgs.Add("documentTemplateID", dt.documentTemplateID);
                    SqlDataReader reader = BCDB2.Instance.ExecuteReaderSPWithParams("sp_getInterfaceDefinitionFromTemplateID", pacsArgs);
                    while (reader.Read())       // loop thru these rows and see what interfaces there are for this document
                    {
                        if (reader.IsDBNull(0) == false)
                        {
                            bInterface  = true;
                            interfaceId = reader.GetInt32(0);
                        }
                        if (reader.IsDBNull(1) == false)
                        {
                            interfaceType = reader.GetString(1);        // used in message below, this should be refactored, as multiple rows can be returned
                            if (interfaceType.ToUpper() == "PACS")
                            {
                                bPacsFound = true;
                            }
                            if (interfaceType.ToUpper() == "POWERSCRIBE")
                            {
                                bPowerscribeFound = true;
                            }
                        }
                        if (reader.IsDBNull(2) == false)
                        {
                            ipAddress = reader.GetString(2);    // these are mostly deprecated now, except the booleans, as this query now can return multiple rows, we don't need this stuff here.  jdg 8/21/15
                        }
                        if (reader.IsDBNull(3) == false)
                        {
                            port = reader.GetString(3);
                        }
                        if (reader.IsDBNull(4) == false)
                        {
                            aeTitleRemote = reader.GetString(4);
                        }
                        if (reader.IsDBNull(5) == false)
                        {
                            aeTitleLocal = reader.GetString(5);
                        }
                        if (reader.IsDBNull(6) == false)
                        {
                            DCMTKpath = reader.GetString(6);
                        }
                        if (reader.IsDBNull(7) == false)
                        {
                            pacsSubType = reader.GetInt32(7);
                        }
                    }

                    if ((print) || (bInterface))        // not mutually exclusive
                    {
                        try
                        {
                            if (print)
                            {
                                PrinterSettings settings = new PrinterSettings();
                                DocumentTemplate.Print(dt.htmlText, settings.PrinterName);
                            }

                            // Prompt to actually execute interfaces...
                            if (bInterface && (MessageBox.Show("Would you like to send this document to " + interfaceType + "?\n\nThis will take a few moments.", "Send Document to External System?", MessageBoxButtons.YesNo) == DialogResult.Yes))
                            {
                                if (bPacsFound)
                                {
                                    try
                                    {
                                        // jdg 8/21/15 let send2Pacs figure out what interfaces and file formats to send this thing to
                                        DocumentTemplate.ConvertToPdf(dt.htmlText, fInfo.FullName + ".pdf");
                                        RiskApps3.Utilities.InterfaceUtils.send2PACS(dt, SessionManager.Instance.GetActivePatient(), fInfo.FullName + ".pdf", SessionManager.Instance.GetActivePatient().apptid);
                                    }
                                    catch (Exception e)
                                    {
                                        Logger.Instance.WriteToLog("Failed to send PDF file to interface for appointment " + SessionManager.Instance.GetActivePatient().apptid + ", document template: " + dt.documentTemplateID + ".  Underlying error was: " + e.Message);
                                    }
                                }

                                //if (interfaceType.ToUpper() == "POWERSCRIBE")
                                if (bPowerscribeFound)
                                {
                                    InterfaceUtils.sendPowerscribe(dt);
                                }

                                // TODO:  Add future interfaces here
                            }
                            // end jdg 8/5/15
                        }
                        catch (Exception e)
                        {
                            Logger.Instance.WriteToLog(e.ToString());
                        }
                    }

                    ParameterCollection pc = new ParameterCollection();
                    pc.Add("apptid", SessionManager.Instance.GetActivePatient().apptid);
                    pc.Add("templateID", dt.documentTemplateID);
                    pc.Add("dateTime", DateTime.Now);
                    pc.Add("userlogin", SessionManager.Instance.ActiveUser.userLogin);

                    string sqlStr = "INSERT INTO tblDocuments([apptID],[documentTemplateID],[created],[createdBy]) VALUES(@apptid, @templateID, @dateTime, @userlogin);";
                    BCDB2.Instance.ExecuteNonQueryWithParams(sqlStr, pc);
                }
            }
        }