Guest User

Untitled

a guest
Jun 18th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.12 KB | None | 0 0
  1. public void StartService(object e)
  2. {
  3. try {
  4. //ExtractorEventLog("0", null);
  5. List<PracticeInformation> getServiceTime = GetpracticeInformationList();
  6. var gettime = (from t in getServiceTime
  7. select new PracticeInformation
  8. {
  9. extractor_start_time = t.extractor_start_time
  10. }).OrderByDescending(x => x.id).ToList().FirstOrDefault();
  11.  
  12. DateTime SetdateTime = DateTime.Parse(ConfigurationManager.AppSettings["ScheduledTime"]);
  13. if (gettime != null)
  14. {
  15. SetdateTime = DateTime.Parse(gettime.extractor_start_time.ToString());
  16. }
  17. try
  18. {
  19. if (SetdateTime.ToString("HH:mm") == DateTime.Now.ToString("HH:mm"))
  20. {
  21. ExtractorEventLog(SetdateTime.ToString("HH:mm") + " " + DateTime.Now.ToString("HH:mm"), null);
  22. string strFile = @"C:requiredFilesForDDPTemp" + DateTime.Now.Ticks.ToString() + ".csv";
  23. if (connm == "")
  24. {
  25. GetConnectionString();
  26. }
  27. using (OdbcConnection conn = new OdbcConnection(connm))
  28. {
  29. //ExtractorEventLog(connm, null);
  30. conn.Open();
  31. #region Get Hospital data
  32. var id = 0;
  33. try
  34. {
  35. List<PracticeInformation> practiceList = getServiceTime;
  36. var practiceName = practiceList[0].name;
  37. id = practiceList[0].id;
  38. List<PracticeInformationModel> HospitalAll = new List<PracticeInformationModel>();
  39. using (OdbcCommand com = new OdbcCommand(Common.cmdGetHospital, conn))
  40. {
  41. using (OdbcDataReader readerHospital = com.ExecuteReader())
  42. {
  43. HospitalAll = DataReaderMapToList<PracticeInformationModel>(readerHospital);
  44. List<PracticeInformationModel> objPracticeInformationmodel = (from pi in HospitalAll
  45. select new PracticeInformationModel
  46. {
  47. practice_name = pi.practice_name,
  48. phone = pi.phone
  49. }
  50. ).ToList();
  51.  
  52. var getPracticeName = practiceList.Select(x => new { x.name }).ToList();
  53. List<PracticeInformationModel> objpracticelist = objPracticeInformationmodel.Where(x => !getPracticeName.Any(y => y.name == x.practice_name)).ToList();
  54. DataTable PracticeInformationDT = ToDataTable(objpracticelist); // To save PracticeInformation table
  55. using (MySqlConnection sqConn = new MySqlConnection(Common.connectionStringDB))
  56. {
  57. using (SqlBulkCopy blkcopyPi = new SqlBulkCopy(sqConn.ConnectionString, SqlBulkCopyOptions.KeepNulls))
  58. {
  59. CreateCSVfile(PracticeInformationDT, strFile);
  60. if (!File.Exists(strFile))
  61. {
  62. FileStream fs = new FileStream(strFile, FileMode.Create, FileAccess.Write);
  63. fs.Close();
  64. fs.Dispose();
  65. }
  66. if (sqConn.State == ConnectionState.Open)
  67. {
  68. sqConn.Close();
  69. }
  70. sqConn.Open();
  71. MySqlBulkLoader bcp1 = new MySqlBulkLoader(sqConn);
  72. bcp1.TableName = "PracticeInformation"; //Create PracticeInformation table into MYSQL database...
  73. bcp1.FieldTerminator = ",";
  74. bcp1.LineTerminator = "rn";
  75. bcp1.FileName = strFile;
  76. bcp1.NumberOfLinesToSkip = 0;
  77. bcp1.Load();
  78. try
  79. {
  80. File.Delete(strFile);
  81. }
  82. catch (Exception ex)
  83. {
  84. ExceptionLog(ex.Message, ex.GetType().Name.ToString(), ex.StackTrace, id);
  85. }
  86. }
  87. readerHospital.Close();
  88. }
  89. }
  90. }
  91. #endregion
  92. #region Get Provider Data From Dentrix
  93. List<Provider> ProviderAll = new List<Provider>();
  94. using (OdbcCommand com = new OdbcCommand(Common.cmdGetProvider, conn))
  95. {
  96. using (OdbcDataReader readerProvider = com.ExecuteReader())
  97. {
  98. ProviderAll = DataReaderMapToList<Provider>(readerProvider);
  99. List<Provider> objProvider = (from pro in ProviderAll
  100. select new Provider
  101. {
  102. provider_id = pro.provider_id,
  103. first_name = pro.first_name,
  104. last_name = pro.last_name,
  105. work_phone = pro.work_phone
  106. }).ToList();
  107. }
  108. }
  109. #endregion
  110. #region Add Appointment
  111. using (OdbcCommand com = new OdbcCommand(Common.cmdText, conn))
  112. {
  113. using (OdbcDataReader reader = com.ExecuteReader())
  114. {
  115. List<AllModalFromApplointment> AppointmentListAll = new List<AllModalFromApplointment>();
  116. AppointmentListAll = DataReaderMapToList<AllModalFromApplointment>(reader);
  117. List<Alert> patientalert_id = new List<Alert>();
  118. #region Get alert data
  119. MySqlConnection connection = null;
  120. List<string> target = new List<string>();
  121. EventLog(Common.Get_Pre_Med_Alerts);
  122. ExtractorEventLog(Common.Get_Pre_Med_Alerts, id.ToString());
  123. int add = 0;
  124. int alert_count = 0;
  125. //string connectionStringDB = "server=192.168.0.1;user=dentrix;database=db_dentrix;password=dentrix";
  126. connection = new MySqlConnection(Common.connectionStringDB);
  127. foreach (var i in AppointmentListAll.Select(x => x.patient_id).ToList())
  128. {
  129. if (i != 0)
  130. {
  131. OdbcCommand ODBCCommand = new OdbcCommand("{call admin.sp_getpatientmedalerts (?)}", conn);
  132. ODBCCommand.CommandType = CommandType.StoredProcedure;
  133. ODBCCommand.Parameters.AddWithValue("@patient_guid", i); //4898-11738
  134. ODBCCommand.ExecuteNonQuery();
  135. OdbcDataReader a = ODBCCommand.ExecuteReader();
  136. DataTable getAlert = new DataTable();
  137. if (a.HasRows)
  138. {
  139. target.Add(i.ToString());
  140. alert_count = add + 1;
  141. getAlert.Load(a);
  142. a.Close();
  143. }
  144. }
  145. }
  146. ExtractorEventLog(target.Count() + " " + Common.No_Of_Pre_Med_Alert, null);
  147. #endregion
  148.  
  149. #region
  150. List<AppointmentDetail> objAppointment = (from app in AppointmentListAll
  151. join pro in ProviderAll on app.provider_id equals pro.provider_id
  152. select new AppointmentDetail
  153. {
  154. patient_id = Convert.ToInt64(app.patient_guid),
  155. appointment_id = Convert.ToInt64(app.appointment_id),
  156. appointment_timestamp = Convert.ToString(app.appointment_date.AddHours(app.start_hour).AddMinutes(app.start_minute)),
  157. patient_first_name = app.patient_name.Split(',')[0],
  158. patient_last_name = app.patient_name.Split(',')[1],
  159. patient_phone_number = app.patient_phone,
  160. red_cross_flag = target.Any(x => x.ToString().Contains(app.patient_id.ToString())) ? "Y" : "N",
  161. dr_name = pro.first_name.Trim() + ' ' + pro.last_name.Trim(),
  162. dr_phone = HospitalAll[0].phone,
  163. hospital_name = HospitalAll[0].practice_name,
  164. appointment_type = null,
  165. fees = 0,
  166. status = null
  167. //createdDate = DateTime.UtcNow
  168. }).ToList();
  169.  
  170. //Ristrict duplicate records
  171. ExtractorEventLog(Common.Data_Inserting, id.ToString());
  172. List<AppointmentDetail> usethe = GetAppointmentList();
  173. var query = usethe.Select(x => new { x.appointment_id }).ToList();
  174. List<AppointmentDetail> xyz = objAppointment.Where(x => !query.Any(y => y.appointment_id == x.appointment_id)).ToList();
  175. if (xyz != null && xyz.Count != 0)
  176. {
  177. var from = xyz.First().appointment_timestamp;
  178. var to = xyz.Last().appointment_timestamp;
  179. ExtractorEventLog(Common.Get_Appointment_Date + from + "and" + to, id.ToString());
  180. }
  181. else
  182. {
  183. EventLog("No appointmet present");
  184. }
  185. int appointment_count = xyz.Count();
  186. DataTable appointmentDT = ToDataTable(xyz); // To save appointment table
  187. using (MySqlConnection sqConn = new MySqlConnection(Common.connectionStringDB))
  188. {
  189. using (SqlBulkCopy blkcopy = new SqlBulkCopy(sqConn.ConnectionString, SqlBulkCopyOptions.KeepNulls))
  190. {
  191. CreateCSVfile(appointmentDT, strFile);
  192. if (!File.Exists(strFile))
  193. {
  194. FileStream fs = new FileStream(strFile, FileMode.Create, FileAccess.Write);
  195. fs.Close();
  196. fs.Dispose();
  197. }
  198. if (sqConn.State == ConnectionState.Open)
  199. {
  200. sqConn.Close();
  201. }
  202. sqConn.Open();
  203. MySqlBulkLoader bcp1 = new MySqlBulkLoader(sqConn);
  204. bcp1.TableName = "appointment";
  205. //bcp1.TableName = "Appointment"; //Create Appointment table into MYSQL database.
  206. bcp1.FieldTerminator = ",";
  207. bcp1.LineTerminator = "rn";
  208. bcp1.FileName = strFile;
  209. bcp1.NumberOfLinesToSkip = 0;
  210. bcp1.Load();
  211. try
  212. {
  213. File.Delete(strFile);
  214. }
  215. catch (Exception ex)
  216. {
  217. ExtractorEventLog("appointment-ex", null);
  218. ExceptionLog(ex.Message, ex.GetType().Name.ToString(), ex.StackTrace, id);
  219. }
  220. ExtractorEventLog(appointment_count + " " + Common.No_Of_Appointment_Retrive, id.ToString());
  221. }
  222. ExtractorEventLog(Common.Done, id.ToString());
  223. this.ScheduleService();
  224. }
  225. #endregion
  226. }
  227. }
  228. }
  229. catch (Exception ex)
  230. {
  231. ExtractorEventLog("a-ex", null);
  232. ExceptionLog(ex.Message, ex.GetType().Name.ToString(), ex.StackTrace, id);
  233. }
  234. }
  235.  
  236. }
  237. else{
  238. this.ScheduleService();
  239. }
  240. }
  241. catch (Exception ex)
  242. {
  243. ExtractorEventLog(ex.Message +"b-ex", null);
  244. //ExceptionLog(ex.Message, ex.GetType().Name.ToString(), ex.StackTrace, id);
  245. }
  246.  
  247. //EventLog("this ScheduleService()");
  248. // this.ScheduleService();m
  249. }
  250. catch(Exception ex)
  251. {
  252. ExtractorEventLog("zz-ex", null);
  253. }
  254. }
Add Comment
Please, Sign In to add comment