Example #1
0
        public static Utils.PatientNote[] CreatePatientNotesArray(Database database, System.Data.DataView dv)
        {
            ArrayList patientNotes = new ArrayList();

            foreach (System.Data.DataRowView drv in dv)
            {
                Note tmpNote = database.CreateNote(drv.Row);
                Charge tmpCharge = database.CreateCharge(drv.Row);
                Patient tmpPatient = database.CreatePatient(drv.Row, null);
                Utils.PatientNote patientNote = new Utils.PatientNote(tmpPatient, tmpNote, tmpCharge);
                patientNotes.Add(patientNote);
            }

            Utils.PatientNote[] patientNotesArray;
            patientNotesArray = (Utils.PatientNote[]) patientNotes.ToArray((new Utils.PatientNote()).GetType());

            return patientNotesArray;
        }
Example #2
0
        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;
        }