public PromtVisitDateTime(ref Note aNote) { // // Required for Windows Form Designer support // InitializeComponent(); note = aNote; rbVisitNote.Checked = true; }
public Form3(Database aDatabase, ref Note aNote, ref Patient aPatient) { InitializeComponent(); database = aDatabase; note = aNote; patient = aPatient; dgDiagnosis.SetDataBinding(database.DsMaster, "Diagnosis"); SetupPatientChargeComboBox(); SetupVisitTypeComboBox(); SetupTreeView(); SetupDataGridDiagnosis(); }
public PatientNote(Patient aPatient, Note aNote, Charge aCharge) { patient = aPatient; note = aNote; charge = aCharge; }
private void btnNewNote_Click(object sender, System.EventArgs e) { if ((patient != null) && (database.IsAlreadyExsisting(patient)) && (database.IsPatientIdValid(patient.Id))) { bool bUpdateExistingNote = false; note = new Note(patient.Id); if (database.IsAlreadyExsisting(note)) { //Checks so that the user by mistake does not create two notes for the same patient, the same day DialogResult dialogResult = MessageBox.Show("Det har redan skapats en anteckning för den här patienten idag.\nVill du fortsätta att skapa en ny anteckning för patienten?\n\nOm du vill fortsätta med att skapa en ny anteckning tryck Ja.\nFör att öppna den redan skapade anteckningen tryck Nej.\nTryck Avbryt för att avbryta.", "Meddelande", MessageBoxButtons.YesNoCancel); switch (dialogResult) { case DialogResult.Cancel: return; case DialogResult.No: note = database.ReturnAlreadyExsisting(note); bUpdateExistingNote = true; break; } } if (note == null) throw new Exception("Något fel har inträffat, en anteckning som refererar till null försökte användas."); note.DiagnosisArray = database.FindLatestVisitNote(selectedPatientRow); Form3 dlgNewNote = new Form3(database, ref note, ref patient); if (dlgNewNote.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (!database.IsPatientIdValid(patient.Id)) throw new Exception("Något fel har inträffat, en anteckning som refererar till en patient som inte finns försökte skapas."); if (bUpdateExistingNote) database.Update(note); else { database.Add(note); //TODO: Select the note note = null; System.Windows.Forms.CurrencyManager cm = (CurrencyManager)BindingContext[dgNotes.DataSource, dgNotes.DataMember]; System.Data.DataView dv = (System.Data.DataView)cm.List; dv.Sort = "visitdatetime DESC"; } } dlgNewNote.Dispose(); } else MessageBox.Show("Välj en patient först", "Kunde inte skapa ny anteckning"); }
private void UpdateNote() { System.Windows.Forms.CurrencyManager cm = (CurrencyManager)BindingContext[dgNotes.DataSource,dgNotes.DataMember]; System.Data.DataView dv = (System.Data.DataView) cm.List; if (dv.Count > 0) { note = database.CreateNote(dv[dgNotes.CurrentRowIndex].Row); //Update controls if (note.Signed) btnSign.Enabled = false; else btnSign.Enabled = true; Debug.WriteLine("Current note: id=" + note.Id + ", " + note.JournalNote); } }
public void Update(Note[] noteArray) { //Setup a dataview in order to find the note that should be updated System.Data.DataView dv = new System.Data.DataView(); DataTable dt = dsMaster.Tables["Notes"]; dv.Table = dsMaster.Tables["Notes"]; dv.Sort = "noteid"; foreach (Note note in noteArray) { if (note != null) { int index = dv.Find(note.Id); System.Data.DataRow dr; try { dr = dv[index].Row; } catch(Exception exception) { throw new Exception(exception.Message + "\n\nAnteckningen kunde inte uppdateras eftersom dess id inte kunde hittas i databasen."); } //dr.BeginEdit(); //dr["noteid"] = note.Id; dt.Rows[index]["patientId"] = note.PatientId; dt.Rows[index]["createdatetime"] = note.CreateDateTime.ToString("g"); dt.Rows[index]["signed"] = note.Signed; dt.Rows[index]["signeddatetime"] = note.SignedDateTime.ToString("g"); dt.Rows[index]["newvisit"] = note.NewVisit; dt.Rows[index]["note"] = note.JournalNote; dt.Rows[index]["primula"] = note.Primula; dt.Rows[index]["visitdatetime"] = note.VisitDateTime.ToString("g"); dt.Rows[index]["chargeid"] = note.ChargeId; dt.Rows[index]["patientfee"] = note.PatientFee; dt.Rows[index]["diagnosis1"] = note.Diagnosis1; dt.Rows[index]["diagnosis2"] = note.Diagnosis2; dt.Rows[index]["diagnosis3"] = note.Diagnosis3; dt.Rows[index]["diagnosis4"] = note.Diagnosis4; dt.Rows[index]["diagnosis5"] = note.Diagnosis5; dt.Rows[index]["actioncode"] = note.ActionCode; dt.Rows[index]["visitnote"] = note.VisitNote; //dr.EndEdit(); } } daNotes.Update(dt); // Update the joined table dsMaster.Tables["Joined"].Clear(); daJoined.Fill(dsMaster, "Joined"); }
public Note ReturnAlreadyExsisting(Note note) { DataView dv = new DataView(); dv.Table = dsMaster.Tables["Notes"]; //dv.Sort = "createdatetime"; dv.RowFilter = "SUBSTRING(createdatetime, 1, 10)='" + note.CreateDateTime.ToShortDateString() + "'" + " AND patientid=" + note.PatientId; dv.Sort = "visitdatetime DESC"; if (dv.Count > 0) { //Return the latest created note return CreateNote(dv[0].Row); } else return null; }
public bool IsAlreadyExsisting(Note note) { DataView dv = new DataView(); dv.Table = dsMaster.Tables["Notes"]; //dv.Sort = "createdatetime"; dv.RowFilter = "SUBSTRING(createdatetime, 1, 10)='" + note.CreateDateTime.ToShortDateString() + "'" + " AND patientid=" + note.PatientId; if (dv.Count > 0) { return true; } else return false; }
public ArrayList FindDiagnosisNumbers(Note note) { ArrayList result = new ArrayList(); //TODO: link notes with diagnosis in a better way DataView dv = dsMaster.Tables["Diagnosis"].DefaultView; dv.Sort = "diagnosisid"; foreach (int diagnosisId in note.DiagnosisArray) { int i = dv.Find(diagnosisId); if (i > -1) { object o = dv[i]["diagnosisnumber"]; if (o != System.DBNull.Value) result.Add((string) o); } } return result; }
public bool Delete(Note aNote) { //Setup a dataview in order to find the note that should be updated System.Data.DataView dv = new System.Data.DataView(); dv.Table = dsMaster.Tables["Notes"]; dv.Sort = "noteid"; if (aNote != null) { int index = dv.Find(aNote.Id); System.Data.DataRow dr; try { dr = dv[index].Row; } catch(Exception exception) { throw new Exception(exception.Message + "\n\nAnteckningen kunde inte tas bort eftersom dess id inte kunde hittas i databasen."); } dsMaster.Tables["Notes"].Rows.Remove(dr); daNotes.Update(dsMaster, "Notes"); Debug.WriteLine("Anteckningen " + aNote.Id.ToString() + " " + aNote.VisitDateTime.ToShortDateString() + " " + aNote.JournalNote + " togs bort."); connection.Close(); return true; } return false; }
public Note CreateNote(System.Data.DataRow dr) { Note note = new Note(); if (!dr.HasErrors && dr != null) { if (dr["noteid"] != System.DBNull.Value) note.Id = (int) dr["noteid"]; else throw new Exception("Programmet försökte öppna en anteckning som saknar id."); if (dr["createdatetime"] != System.DBNull.Value) note.CreateDateTime = System.DateTime.Parse((string)dr["createdatetime"]); if (dr["signeddatetime"] != System.DBNull.Value) note.SignedDateTime = System.DateTime.Parse((string) dr["signedDateTime"]); if (dr["patientid"] != System.DBNull.Value) note.PatientId = (int) dr["patientid"]; if (dr["signed"] != System.DBNull.Value) note.Signed = (bool) dr["signed"]; if (dr["newvisit"] != System.DBNull.Value) note.NewVisit = (bool) dr["newvisit"]; if (dr["note"] != System.DBNull.Value) note.JournalNote = (string) dr["note"]; if (dr["chargeid"] != System.DBNull.Value) note.ChargeId = (int) dr["chargeid"]; if (dr["patientfee"] != System.DBNull.Value) note.PatientFee = (string) dr["patientfee"]; if (dr["diagnosis1"] != System.DBNull.Value) note.Diagnosis1 = (int) dr["diagnosis1"]; if (dr["diagnosis2"] != System.DBNull.Value) note.Diagnosis2 = (int) dr["diagnosis2"]; if (dr["diagnosis3"] != System.DBNull.Value) note.Diagnosis3 = (int) dr["diagnosis3"]; if (dr["diagnosis4"] != System.DBNull.Value) note.Diagnosis4 = (int) dr["diagnosis4"]; if (dr["diagnosis5"] != System.DBNull.Value) note.Diagnosis5 = (int) dr["diagnosis5"]; if (dr["actioncode"] != System.DBNull.Value) note.ActionCode = (string) dr["actioncode"]; if (dr["primula"] != System.DBNull.Value) note.Primula = (bool) dr["primula"]; if (dr["visitdatetime"] != System.DBNull.Value) note.VisitDateTime = System.DateTime.Parse((string) dr["visitdatetime"]); if (dr["visitnote"] != System.DBNull.Value) note.VisitNote = (bool) dr["visitnote"]; } return note; }
public void Add(Note note) { // Search for a note with the same date and patientid //TODO; Take care of the exception //Already existing notes with the same date is taken care of in functions calling this function /*if (IsAlreadyExsisting(note)) throw new Exception("En anteckning med samma datum finns redan");*/ System.Data.DataRow dr = dsMaster.Tables["Notes"].NewRow(); dr["patientid"] = note.PatientId; dr["createdatetime"] = note.CreateDateTime.ToString("g"); dr["signed"] = note.Signed; dr["signeddatetime"] = note.SignedDateTime.ToString("g"); dr["note"] = note.JournalNote; dr["newvisit"] = note.NewVisit; dr["primula"] = note.Primula; dr["visitdatetime"] = note.VisitDateTime.ToString("g"); dr["chargeid"] = note.ChargeId; dr["patientfee"] = note.PatientFee; dr["diagnosis1"] = note.Diagnosis1; dr["diagnosis2"] = note.Diagnosis2; dr["diagnosis3"] = note.Diagnosis3; dr["diagnosis4"] = note.Diagnosis4; dr["diagnosis5"] = note.Diagnosis5; dr["actioncode"] = note.ActionCode; dr["visitnote"] = note.VisitNote; dsMaster.Tables["Notes"].Rows.Add(dr); daNotes.Update(dsMaster, "Notes"); // Update the joined table dsMaster.Tables["Joined"].Clear(); daJoined.Fill(dsMaster, "Joined"); }
private bool WritePrimulaFile() { System.Data.DataView dv; bool success = false; ArrayList patientNotes = new ArrayList(); string filename = Settings.PrimulaFilename + "." + Settings.PrimulaFileNumber; System.Windows.Forms.CurrencyManager cm = (CurrencyManager)BindingContext[dgToPrimula.DataSource,dgToPrimula.DataMember]; dv = (System.Data.DataView) cm.List; //If rows were selected, create a dataset containing only those if (selectedRows.Count > 0) { System.Data.DataSet ds = Utils.SelectedRowsDataSet(dv, selectedRows); dv = ds.Tables[0].DefaultView; } foreach (System.Data.DataRowView drv in dv) { Note tmpNote = database.CreateNote(drv.Row); Patient tmpPatient = database.CreatePatient(drv.Row, null); Charge tmpCharge = database.CreateCharge(drv.Row); Utils.PatientNote patientNote = new Utils.PatientNote(tmpPatient, tmpNote, tmpCharge); patientNotes.Add(patientNote); } //Create an array with note objects in order to update all notes at the same time when the file has been written Note[] noteArray = new Note[patientNotes.Count]; int index = 0; try { using (StreamWriter writer = new StreamWriter(filename)) { foreach (object o in patientNotes.ToArray()) { Utils.PatientNote patientNote = (Utils.PatientNote) o; Note currentNote = patientNote.note; Patient currentPatient = patientNote.patient; Charge currentCharge = patientNote.charge; System.DateTime date = currentNote.VisitDateTime; //Field 1 - Personnummer writer.Write(currentPatient.Personnumber.Remove(8,1)); writer.Write(";"); //Field 2 writer.Write(";"); //Field 3 writer.Write(";"); //Field 4 writer.Write(";"); //Field 5 writer.Write(";"); //Field 6 writer.Write(";"); ////Field 7 - Avtalskod writer.Write("0164"); writer.Write(";"); //Field 8 writer.Write(";"); //Field 9 writer.Write(";"); //Field 10 writer.Write(";"); //Field 11 writer.Write(";"); //Field 12 - Kontaktdatum writer.Write(date.ToString("yyyyMMdd")); writer.Write(";"); //Field 13 - Kontakttid writer.Write(date.ToString("HHmm")); writer.Write(";"); //Field 14 writer.Write(";"); //Field 15 - Vårdgivarkategori writer.Write("07"); writer.Write(";"); //Field 16 writer.Write(";"); //Field 17 writer.Write(";"); //Field 18 writer.Write(";"); //Field 19 writer.Write(";"); //Field 20 writer.Write(";"); //Field 21 writer.Write(";"); //Field 22 writer.Write(";"); //Field 23 writer.Write(";"); //Field 24 writer.Write(";"); //Field 25 writer.Write(";"); //Field 26 writer.Write(";"); //Field 27 writer.Write(";"); //Field 28 writer.Write(";"); //Field 29 writer.Write(";"); //Field 30 writer.Write(";"); //Field 31 writer.Write(";"); //Field 32 writer.Write(";"); //Field 33 writer.Write(";"); //Field 34 writer.Write(";"); //Field 35 writer.Write(";"); //Field 36- Åtgärdskod writer.Write(currentNote.ActionCode); writer.Write(";"); //Field 37 writer.Write(";"); //Field 38 writer.Write(";"); //Field 39 writer.Write(";"); //Field 40 writer.Write(";"); //Field 41 writer.Write(";"); //Field 42 writer.Write(";"); //Field 43 writer.Write(";"); //Field 44 writer.Write(";"); //Field 45 - Patientavgift, kod writer.Write(currentCharge.PrimulaCharachter); writer.Write(";"); //Field 46 - Patientavgift, belopp writer.Write(currentNote.PatientFee); writer.Write(";"); //Field 47 writer.Write(";"); //Field 48 writer.Write(";"); //Field 49 writer.Write(";"); //Field 50 writer.Write(";"); //Field 51 writer.Write(";"); //Field 52 writer.Write(";"); //Field 53 writer.Write(";"); //Field 54 writer.Write(";"); //Field 55 - Vårdgivarspecialitet writer.Write("22"); writer.Write(";"); //Field 56 writer.Write(";"); //Field 57 writer.Write(";"); //Field 58 writer.Write(";"); //Field 59 writer.Write(";"); //Field 60 writer.Write(";"); //Field 61 writer.Write(";"); //Field 62 writer.Write(";"); //Field 63 writer.Write(";"); //Field 64 writer.Write(";"); //Field 65 writer.Write(";"); //Field 66 writer.Write(";"); //Field 67 writer.Write(";"); //Field 68 writer.WriteLine(";"); //This is the update currentNote.Primula = true; //Instead of invoking database update, store the note object in an array and call the update later //database.Update(currentNote); noteArray[index] = currentNote; index++; } } int nrofLines = 0; using (StreamReader reader = new StreamReader(filename)) { while (reader.ReadLine() != null) nrofLines++; } if (nrofLines != noteArray.Length) throw new Exception("Antalet besök i den skapta Primula-filen stämmer inte överens med antalet besök som ska registreras."); //TODO: Increase performance by calling the update function with an array of notes database.Update(noteArray); Settings.IncPrimulaFileNumber(); MessageBox.Show("Primulafilen " + filename + " skapades", "Skrivning av Primulafil lyckades"); //TODO: This should be done on exit Settings.SaveSettings(); success = true; selectedRows.Clear(); selectedNotes.Clear(); //Update the printed number of visits etc. CalculateVisits(); } catch(Exception exception) { MessageBox.Show("Det gick ej skapa Primulafilen, kontrollera att USB-minnet sitter i: \nFelmeddelande från programmet: " + exception.Message, "Kunde ej skapa Primulafil"); } return success; }
private void UpdateNote(DataGrid dataGrid) { System.Windows.Forms.CurrencyManager cm = (CurrencyManager)BindingContext[dataGrid.DataSource,dataGrid.DataMember]; System.Data.DataView dv = (System.Data.DataView) cm.List; if (dv.Count > 0) { note = new Note(); note.Id = (int) dv[dataGrid.CurrentRowIndex]["noteid"]; note.CreateDateTime = System.DateTime.Parse((string)dv[dataGrid.CurrentRowIndex]["createdatetime"]); note.SignedDateTime = System.DateTime.Parse((string) dv[dataGrid.CurrentRowIndex]["signedDateTime"]); note.PatientId = (int) dv[dataGrid.CurrentRowIndex]["patientid"]; note.Signed = (bool) dv[dataGrid.CurrentRowIndex]["signed"]; note.NewVisit = (bool) dv[dataGrid.CurrentRowIndex]["newvisit"]; //TODO: Check maximum nr of chars a string can hold note.JournalNote = (string) dv[dataGrid.CurrentRowIndex]["note"]; note.ChargeId = (int) dv[dataGrid.CurrentRowIndex]["chargeid"]; note.PatientFee = (string) dv[dataGrid.CurrentRowIndex]["patientfee"]; note.Diagnosis1 = (int) dv[dataGrid.CurrentRowIndex]["diagnosis1"]; note.Diagnosis2 = (int) dv[dataGrid.CurrentRowIndex]["diagnosis2"]; note.Diagnosis3 = (int) dv[dataGrid.CurrentRowIndex]["diagnosis3"]; note.Diagnosis4 = (int) dv[dataGrid.CurrentRowIndex]["diagnosis4"]; note.Diagnosis5 = (int) dv[dataGrid.CurrentRowIndex]["diagnosis5"]; note.ActionCode = (string) dv[dataGrid.CurrentRowIndex]["actioncode"]; note.Primula = (bool) dv[dataGrid.CurrentRowIndex]["primula"]; note.VisitDateTime = System.DateTime.Parse((string) dv[dataGrid.CurrentRowIndex]["visitdatetime"]); note.VisitNote = (bool)dv[dataGrid.CurrentRowIndex]["visitnote"]; Debug.WriteLine("noteid = " + note.Id + " patientid = " + note.PatientId + ", selected note at currentrowindex: " + dataGrid.CurrentRowIndex + ", primula = " + note.Primula.ToString()); } }
public Primula(Database aDatabase) { // // Required for Windows Form Designer support // InitializeComponent(); year = System.DateTime.Now.Year; database = aDatabase; dgToPrimula.SetDataBinding(database.DsMaster, "Joined"); dgInPrimula.SetDataBinding(database.DsMaster, "Joined"); SetupDataGridPrimula(dgToPrimula); SetupDataGridPrimula(dgInPrimula); dgToPrimula.CaptionText = "Besök som ska registreras i Primula"; dgInPrimula.CaptionText = "Besök registrerade i Primula"; cmToPrimula = (CurrencyManager)BindingContext[dgToPrimula.DataSource,dgToPrimula.DataMember]; cmInPrimula = (CurrencyManager)BindingContext[dgInPrimula.DataSource,dgInPrimula.DataMember]; dvToPrimula = (System.Data.DataView) cmToPrimula.List; dvInPrimula = (System.Data.DataView) cmInPrimula.List; //Select the current month as default dvToPrimula.RowFilter = "primula = false AND visitnote = true AND SUBSTRING(visitdatetime,1,4)=" + year.ToString() + " AND SUBSTRING(visitdatetime,6,2)=" + System.DateTime.Now.Month; dvToPrimula.Sort = "visitdatetime DESC"; //Select the current month as default dvInPrimula.RowFilter = "primula = true AND visitnote = true AND SUBSTRING(visitdatetime,1,4)=" + year.ToString() + " AND SUBSTRING(visitdatetime,6,2)=" + System.DateTime.Now.Month; dvInPrimula.Sort = "visitdatetime DESC"; monthsInPrimula = new ArrayList(); monthsToPrimula = new ArrayList(); selectedRows = new ArrayList(); selectedNotes = new ArrayList(); SetupComboBoxPickMonthInPrimula(); SetupComboBoxPickMonthToPrimula(); SetupPrinting(); note = new Note(); this.ttPrimulaRemove.SetToolTip(this.btnPrimulaRemove, "Ta bort ett eller flera besök från listan med besök som ska registreras i Primula.\nT.ex. om besöken av någon anledning inte ska skickas in till Landstinget.\nObeservera att dessa besök hamnar under den andra fliken"); this.ttWritePrimula.SetToolTip(this.btnWritePrimula, "Skriver en Primula-fil som ska skickas in till Landstinget."); this.ttPrimulaAdd.SetToolTip(this.btnPrimulaAdd, "Lägg till ett besök till listan med besök som ska registreras i Primula.\nT.ex. om besöket ska registreras om."); CalculateVisits(); }
private void btnPrimulaRemove_Click(object sender, System.EventArgs e) { if (selectedNotes.Count > 0) { Note[] noteArray = new Note[selectedNotes.Count]; for (int i = 0; i < selectedNotes.Count; i++) { Note n = (Note) selectedNotes[i]; n.Primula = true; noteArray[i] = n; } database.Update(noteArray); dgToPrimula.Refresh(); selectedRows.Clear(); selectedNotes.Clear(); CalculateVisits(); Utils.AutoSizeDataGrid(null, dgInPrimula, this.BindingContext, 0); } else MessageBox.Show("Välj ett besök eller fera besök att ta bort först", "Kunde ej ta bort besök från listan"); }