/// <summary>Makes one call to the database to retrieve the document of the patient for the given patNum, then uses that document and the pathPrepend to load and process the patient picture so it appears the same way it did in the image module(except for scaling and translation). Returns false if there is no patient picture, true otherwise. Sets the value of patientPict equal to a new instance of the patient's processed picture, but will be set to null on error. Assumes WithPat will always be same as patnum.</summary> public static bool GetPatPict(int patNum, string pathPrepend, out Bitmap patientPict) { patientPict = null; //first establish which category pat pics are in int defNumPicts = 0; for (int i = 0; i < DefB.Short[(int)DefCat.ImageCats].Length; i++) { if (DefB.Short[(int)DefCat.ImageCats][i].ItemValue == "P" || DefB.Short[(int)DefCat.ImageCats][i].ItemValue == "XP") { defNumPicts = DefB.Short[(int)DefCat.ImageCats][i].DefNum; break; } } if (defNumPicts == 0) //no category set for picts { return(false); } //then find string command = "SELECT document.* FROM document,docattach " + "WHERE document.DocNum=docattach.DocNum " + "AND docattach.PatNum=" + POut.PInt(patNum) + " AND document.DocCategory=" + POut.PInt(defNumPicts) + " ORDER BY DateCreated DESC "; //gets the most recent if (FormChooseDatabase.DBtype == DatabaseType.Oracle) { command = "SELECT * FROM (" + command + ") WHERE ROWNUM<=1"; } else //Assume MySQL { command += "LIMIT 1"; } Document[] pictureDocs = RefreshAndFill(command); if (pictureDocs == null || pictureDocs.Length < 1) //no pictures { return(false); } string shortFileName = pictureDocs[0].FileName; if (shortFileName.Length < 1) { return(false); } string fullName = pathPrepend + shortFileName; if (!File.Exists(fullName)) { return(true); } patientPict = ContrDocs.ApplyDocumentSettingsToImage(pictureDocs[0], new Bitmap(fullName), ContrDocs.ApplySettings.ALL); return(true); }
private void timer1_Tick(object sender, EventArgs e) { try{ backBuffGraph.Clear(Pens.White.Color); backBuffGraph.Transform = ContrDocs.GetScreenMatrix(displayedDoc, ImageCurrent.Width, ImageCurrent.Height, imageZoom * zoomFactor, imageTranslation); backBuffGraph.DrawImage(renderImage, 0, 0); Graphics pbg = PictureBox1.CreateGraphics(); pbg.DrawImage(backBuffer, 0, 0); pbg.Dispose(); }catch { //Not being able to render the image is non-fatal and probably due to a simple change in state //or rounding errors. } }
/// <summary>This form will get the necessary images off disk so that it can control layout.</summary> public void SetImage(Document thisDocument, string displayTitle) { //for now, the document is single. Later, it will get groups for composite images/mounts. Text = displayTitle; displayedDoc = thisDocument; ArrayList docNums = new ArrayList(); docNums.Add(thisDocument.DocNum); string fileName = (string)Documents.GetPaths(docNums)[0]; if (!File.Exists(fileName)) { MessageBox.Show(fileName + " could not be found."); return; } try{ ImageCurrent = new Bitmap(fileName); renderImage = ContrDocs.ApplyDocumentSettingsToImage(thisDocument, ImageCurrent, ApplySettings.CROP | ApplySettings.COLORFUNCTION); if (renderImage == null) { imageZoom = 1; imageTranslation = new PointF(0, 0); } else { float matchWidth = PictureBox1.Width - 16; matchWidth = (matchWidth <= 0?1:matchWidth); float matchHeight = PictureBox1.Height - 16; matchHeight = (matchHeight <= 0?1:matchHeight); imageZoom = (float)Math.Min(matchWidth / renderImage.Width, matchHeight / renderImage.Height); imageTranslation = new PointF(PictureBox1.Width / 2.0f, PictureBox1.Height / 2.0f); } zoomLevel = 0; zoomFactor = 1; }catch (System.Exception exception) { MessageBox.Show(Lan.g(this, exception.Message)); ImageCurrent = null; renderImage = null; } }
private void btnImportForms_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; XmlDocument x = new XmlDocument(); AddResults("Downloading new patient list..."); try { x.Load(sURL); } catch (Exception ex) { MessageBox.Show("Cannot access account.\r\n\r\nPlease make sure URL, username and password are correct.\r\n\r\nContact www.NewPatientForm.com for help.\r\n\r\n" + ex.Message); this.Close(); return; } if (x.DocumentElement.ChildNodes.Count == 0) { MessageBox.Show("No new patients."); this.Close(); return; } //Now that we have loaded all the new patient forms, loop through //each patient, import the xml and store the pdf file foreach (XmlNode ndeMessage in x.DocumentElement.ChildNodes) { string sPatientName = ""; try { sPatientName += ndeMessage.SelectSingleNode("PatientIdentification/NameLast").InnerText; } catch { AddResults("No lastname found."); } try { sPatientName += ", " + ndeMessage.SelectSingleNode("PatientIdentification/NameFirst").InnerText; } catch { AddResults("No firstname found."); } if (MessageBox.Show("Do you want to import information for " + sPatientName + " ?", "", MessageBoxButtons.OKCancel) == DialogResult.OK) { AddResults("Adding patient " + sPatientName); string sPDF = ""; try { sPDF = ndeMessage.SelectSingleNode("PatientIdentification/NewPatientForm").InnerText; } catch { AddResults("No pdf form found."); } //We have the encoded pdf in sPDF string so lets //delete that node and try to import the patient ndeMessage.SelectSingleNode("PatientIdentification").RemoveChild(ndeMessage.SelectSingleNode("PatientIdentification/NewPatientForm")); FormImportXML frmX = new FormImportXML(); frmX.textMain.Text = ndeMessage.OuterXml; frmX.butOK_Click(null, null); //The patient info is entered, let's save the pdf document to the images folder try { //We'll be working with a document //First make sure we have a directory and //everything is up to date ContrDocs cd = new ContrDocs(); cd.RefreshModuleData(frmX.existingPatOld.PatNum); Document DocCur = new Document(); OpenFileDialog openFileDialog = new OpenFileDialog(); DocCur.FileName = ".pdf"; DocCur.DateCreated = DateTime.Today; //Find the category, hopefully 'Patient Information' //otherwise, just default to first one int iCategory = iCategory = DefB.Short[(int)DefCat.ImageCats][0].DefNum;; for (int i = 0; i < DefB.Short[(int)DefCat.ImageCats].Length; i++) { if (DefB.Short[(int)DefCat.ImageCats][i].ItemName == "Patient Information") { iCategory = DefB.Short[(int)DefCat.ImageCats][i].DefNum; } } DocCur.DocCategory = iCategory; DocCur.ImgType = ImageType.Document; DocCur.Description = "New Patient Form"; DocCur.WithPat = cd.PatCur.PatNum; Documents.Insert(DocCur, cd.PatCur);//this assigns a filename and saves to db try { // Convert the Base64 UUEncoded input into binary output. byte[] binaryData = System.Convert.FromBase64String(sPDF); // Write out the decoded data. System.IO.FileStream outFile = new System.IO.FileStream(cd.patFolder + DocCur.FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write); outFile.Write(binaryData, 0, binaryData.Length); outFile.Close(); //Above is the code to save the file to a particular directory from NewPatientForm.com } catch { MessageBox.Show(Lan.g(this, "Unable to write pdf file to disk.")); Documents.Delete(DocCur); } } catch { AddResults("Could not save pdf file to patient's file."); } AddResults("Done writing pdf file to disk"); } else { AddResults("Cacelled import for " + sPatientName + "."); } } this.Cursor = Cursors.Default; MessageBox.Show("Import complete.\r\n\r\nIf any form imports were cancelled or unsuccessful\r\nthey will need to be imported manually."); btnImportForms.Enabled = false; //clear form instanciations }