private void submitButton_Click(object sender, EventArgs e) { newRoom = new Room(RoomListView.SelectedItems[0].SubItems[0].Text, Decimal.Parse(RoomListView.SelectedItems[0].SubItems[1].Text), DateTime.Parse(RoomListView.SelectedItems[0].SubItems[2].Text)); DBConnectionObject conn = DBConnectionObject.getInstance(); foreach (RADGSHALibrary.Room r in selectedVisit.getRoomList()) { conn.getRoomEntryExitDates(selectedPatient, selectedVisit, r, out DateTime entry, out DateTime roomExit, out bool stillInRoom); if (stillInRoom) { conn.closeStaysIn(selectedPatient, selectedVisit, r, DateTime.Now); } } conn.addStaysIn(newRoom, selectedPatient, selectedVisit, DateTime.Now); selectedVisit.addRoom(newRoom); Close(); }
public async void importPatientData(string url) { int numErrors = 0; int numberOfLines = getFileLineLength(url); int currentLineNumber = 0; int outputPercentTimer = 0; status.Imported = 0; status.Total = numberOfLines; string line; Char[] prohibitedChars = { ' ', '*', '.' }; System.IO.StreamReader file = new System.IO.StreamReader(url); while ((line = file.ReadLine()) != null) { // This "await Task.Delay(0);" line may look useless, but it allows the form to act asynchronous. await Task.Delay(1); string patientLastName = line.Substring(0, 50).Trim(prohibitedChars).Replace("'", "’"); string patientFirstName = line.Substring(50, 25).Trim(prohibitedChars).Replace("'", "’"); Char patientMiddleInitial = line.Substring(75, 1).Trim(prohibitedChars).Replace("'", "’").ToCharArray().First(); Char patientGender = line.Substring(76, 1).Trim(prohibitedChars).Replace("'", "’").ToCharArray().First(); string patientSSN = line.Substring(77, 9).Trim(prohibitedChars).Replace("'", "’"); int birthDate_month = Int32.Parse(line.Substring(86, 2).Trim(prohibitedChars).Replace("'", "’")); int birthDate_day = Int32.Parse(line.Substring(88, 2).Trim(prohibitedChars).Replace("'", "’")); int birthDate_year = Int32.Parse(line.Substring(90, 4).Trim(prohibitedChars).Replace("'", "’")); DateTime birthDate = new DateTime(birthDate_year, birthDate_month, birthDate_day); string patientZipcode = line.Substring(559, 5).Trim(prohibitedChars).Replace("'", "’"); string patientState = line.Substring(557, 2).Trim(prohibitedChars).Replace("'", "’"); string patientCity = line.Substring(532, 25).Trim(prohibitedChars).Replace("'", "’"); string patientAddressLine1 = line.Substring(462, 35).Trim(prohibitedChars).Replace("'", "’"); string patientAddressLine2 = line.Substring(497, 35).Trim(prohibitedChars).Replace("'", "’"); string patientInsurer = line.Substring(457, 5).Trim(prohibitedChars).Replace("'", "’"); string DnrStatusString = line.Substring(564, 1).Trim(prohibitedChars).Replace("'", "’"); Boolean patientDnrStatus = (DnrStatusString == "Y"); string OrganDonorString = line.Substring(565, 1).Trim(prohibitedChars).Replace("'", "’"); Boolean patientOrganDonor = (OrganDonorString == "Y"); Patient p = new Patient(patientSSN); p.setFirstName(patientFirstName); p.setMiddleInitial(patientMiddleInitial); p.setLastName(patientLastName); p.setGender(patientGender); p.setZipcode(patientZipcode); p.setState(patientState); p.setCity(patientCity); p.setAddressLine1(patientAddressLine1); p.setAddressLine2(patientAddressLine2); p.setBirthDate(birthDate); p.setInsurer(patientInsurer); p.setDoNotResuscitateStatus(patientDnrStatus); p.setOrganDonorStatus(patientOrganDonor); if (conn.queryPatient(patientSSN, "", "", "").Count >= 1) { conn.updatePatient(p); } else { conn.addPatient(p); } string[] symptom = new string[6]; symptom[0] = line.Substring(132, 25).Trim(); symptom[1] = line.Substring(157, 25).Trim(); symptom[2] = line.Substring(182, 25).Trim(); symptom[3] = line.Substring(207, 25).Trim(); symptom[4] = line.Substring(232, 25).Trim(); symptom[5] = line.Substring(257, 25).Trim(); string diagnosis = line.Substring(282, 75).Trim(); string attendingPhys = line.Substring(118, 5).Trim(prohibitedChars); string note = line.Substring(357, 100).Trim(); DateTime entryDate; string entryMonth = line.Substring(94, 2); string entryDay = line.Substring(96, 2); string entryYear = line.Substring(98, 4); string entryHour = line.Substring(102, 2); string entryMinute = line.Substring(104, 2); entryDate = DateTime.Parse(entryMonth + "/" + entryDay + "/" + entryYear + " " + entryHour + ":" + entryMinute); DateTime exitDate; string exitMonth = line.Substring(106, 2); string exitDay = line.Substring(108, 2); string exitYear = line.Substring(110, 4); string exitHour = line.Substring(114, 2); string exitMinute = line.Substring(116, 2); exitDate = DateTime.Parse(exitMonth + "/" + exitDay + "/" + exitYear + " " + exitHour + ":" + exitMinute); string roomNumber = line.Substring(123, 9); Visit v = new Visit(); v.setEntryDate(entryDate); v.setExitDate(exitDate); v.setAttendingPhysician(attendingPhys); v.setNote(note); v.changeDiagnosis(diagnosis); try { conn.addVisit(v, p); for (int i = 0; i < 6; i++) { List <string> l = conn.querySymptoms(p, v, symptom[i]); //Console.WriteLine("Matching symptoms for " + symptom[i] +" : " + l.Count()); if (l.Count == 0) { conn.addSymptom(p, v, symptom[i]); // if this patient doesn't have the symptom, add it } } conn.closeVisit(p, v); List <Room> rooms = conn.queryRoom(roomNumber); int bestIndex = -1; for (int i = 0; i < rooms.Count; i++) { if (v.getEntryDate() < rooms[i].getEffectiveDate()) { bestIndex = i; } } if (bestIndex != -1) { conn.addStaysIn(rooms[bestIndex], p, v); } conn.closeStaysIn(p, v, rooms[bestIndex], v.getExitDate()); } catch (Exception e) { numErrors++; } currentLineNumber++; outputPercentTimer++; status.Imported = currentLineNumber; if (outputPercentTimer > 1000) { outputPercentTimer = 0; Console.WriteLine(((currentLineNumber * 100) / (numberOfLines)).ToString() + "% complete"); // status.PercentDone = (currentLineNumber * 100) / (numberOfLines); } } //status.PercentDone = 100; status.Imported = status.Total; Console.WriteLine("Import Completed."); file.Close(); Console.WriteLine("Import Completed with " + numErrors + " errors. If errors occurred, it's possible user is already imported."); }