// This helper is to populate the CreatedAt, CreatedAtDate, UpdatedAt, and UpdatedAtDate that seem to be hanging off many of the entities from the API private void UpdateAuditProperties(AuditObject auditObject, JToken dataEntity) { auditObject.CreatedAt = (long)dataEntity["created_at"]; auditObject.CreatedAtDate = Utils.ConvertUnixTime(auditObject.CreatedAt); auditObject.UpdatedAt = (long)dataEntity["updated_at"]; auditObject.UpdatedAtDate = Utils.ConvertUnixTime(auditObject.UpdatedAt); }
/// <summary> /// If T is new, inserts into collection, otherwise REPLACE item in collection with T /// </summary> /// <param name="entity"></param> /// <returns></returns> public T Update(T entity) { OnBeforeSave(entity); var audit = typeof(T).GetCustomAttributes(typeof(DocumentAuditAttr), false).SingleOrDefault(); if (audit != null && entity._id != null && ((audit as DocumentAuditAttr).AuditEnum & DocumentAuditEnum.Edit) == DocumentAuditEnum.Edit) { var editedObjRep = Repositories.Instance.Repository <AuditObject>(_mongoConfig); var auditObject = new AuditObject(); auditObject.OriginalId = entity._id; auditObject.Action = "UPD"; auditObject.Source = MongoUtil.GetCollectioNameFromInterface <T>(); T originalItem = FindOneById(entity._id); if (originalItem != null) { auditObject.Item = originalItem.ToBsonDocument(typeof(T)); editedObjRep.Add(auditObject); } } // if (typeof(IAuditFields).IsAssignableFrom(typeof(T))) // { // AuditAddEdit(entity); // } Collection.Save <T>(entity); OnAfterSave(entity); return(entity); }
public void Delete(T entity, bool saveCopyOfDeletedItem) { OnBeforeDelete(entity); //don't archive anything from the DeletedObjects collection. if (saveCopyOfDeletedItem && MongoUtil.GetCollectioNameFromInterface <T>() != "AuditObjects") { // var audit = // typeof (T).GetCustomAttributes(typeof (DocumentAuditAttr), false).SingleOrDefault(); // if (audit != null && ((audit as DocumentAuditAttr).AuditEnum & DocumentAuditEnum.Delete )== DocumentAuditEnum.Delete) { var deletedObjRepo = Repositories.Instance.Repository <AuditObject>(_mongoConfig); var deletedObject = new AuditObject(); deletedObject.OriginalId = entity._id; deletedObject.Action = "DEL"; deletedObject.Source = MongoUtil.GetCollectioNameFromInterface <T>(); deletedObject.Item = entity.ToBsonDocument(typeof(T)); deletedObjRepo.Add(deletedObject); } } //WriteConcernResult result; RemoveItemById(entity); OnAfterDelete(entity); }
public void Update(IEnumerable <T> entities) { var audit = typeof(T).GetCustomAttributes(typeof(DocumentAuditAttr), false).SingleOrDefault(); var mongoDocumentAuditAttr = audit as DocumentAuditAttr; if (mongoDocumentAuditAttr != null && ((mongoDocumentAuditAttr.AuditEnum & DocumentAuditEnum.Edit) == DocumentAuditEnum.Edit)) { List <AuditObject> auditObjects = new List <AuditObject>(); var editedObjRep = Repositories.Instance.Repository <AuditObject>(_mongoConfig); foreach (T item in entities) { if (item._id == null) { continue; } var auditObject = new AuditObject(); auditObject.OriginalId = item._id; auditObject.Action = "UPD"; auditObject.Source = typeof(T).UnderlyingSystemType.Name; auditObject.Item = item.ToBsonDocument(typeof(T)); auditObjects.Add(auditObject); } editedObjRep.Add(auditObjects); } // if (typeof(IAuditFields).IsAssignableFrom(typeof(T))) // { // if (entities != null) Parallel.ForEach(entities, AuditAddEdit); // } foreach (T entity in entities) { OnBeforeSave(entity); } foreach (T entity in entities) { Collection.Save <T>(entity); } foreach (T entity in entities) { OnAfterSave(entity); } }
// This helper is to populate the CreatedAt, CreatedAtDate, UpdatedAt, and UpdatedAtDate that seem to be hanging off many of the entities from the API private void UpdateAuditProperties(AuditObject auditObject, JToken dataEntity) { auditObject.CreatedAt = (long)dataEntity["created_at"]; auditObject.CreatedAtDate = Utils.ConvertUnixTime(auditObject.CreatedAt); auditObject.UpdatedAt = (long)dataEntity["updated_at"]; auditObject.UpdatedAtDate = Utils.ConvertUnixTime(auditObject.UpdatedAt); }
// 上傳血透品質統計資料 public bool UploadDQ(string Trdate) { bool bCheck = false; string sURL = ""; try { sURL = getSET("Dialysis_url") + getSET("Dialysis_Organization"); string[] OrganizationInfo = ReadFhirOrganization(sURL); if (OrganizationInfo[0] == "nodata") { return(false); } string orgId = OrganizationInfo[0]; string recipientId = OrganizationInfo[1]; sURL = getSET("Dialysis_url") + getSET("Dialysis_DQ") + "/" + Trdate; string[] modifier = GetDQ(sURL); if (modifier[0] == "nodata") { return(false); } UploadStatistic target = new UploadStatistic(); target.setFhirURI(getSET("FHIR_SERVER")); string sMdate = Trdate.Replace("-", ""); string commId = "DQ." + orgId + "." + sMdate; string commIdentifier = "DQ." + orgId + "." + sMdate; string commIdentifierSystem = "http://www.datacom.com.cn/DialysisStatistic"; string categoryCode = "DQ"; string categorySystem = "http://www.datacom.com.cn/DialysisStatisticCategory"; string categoryName = "血液透析品质"; string senderId = orgId; string sentDate = Trdate + "-" + DateTime.DaysInMonth(int.Parse(Trdate.Substring(0, 4)), int.Parse(Trdate.Substring(5, 2))).ToString(); string eventDateTime = DateTime.UtcNow.ToString("s"); Timing.UnitsOfTime durationUnit = Timing.UnitsOfTime.Mo; List <string[]> itemValue = new List <string[]>(); itemValue.Add(new string[] { "Hb_ED", "http://www.datacom.com.cn/DialysisStatisticDQ", "Hb 已检人数", null, modifier[0] }); itemValue.Add(new string[] { "Hb_PASS", "http://www.datacom.com.cn/DialysisStatisticDQ", "Hb 合格人数", null, modifier[1] }); itemValue.Add(new string[] { "ALB_ED", "http://www.datacom.com.cn/DialysisStatisticDQ", "ALB 已检人数", null, modifier[2] }); itemValue.Add(new string[] { "ALB_PASS", "http://www.datacom.com.cn/DialysisStatisticDQ", "ALB 合格人数", null, modifier[3] }); itemValue.Add(new string[] { "Ca_ED", "http://www.datacom.com.cn/DialysisStatisticDQ", "Ca 已检人数", null, modifier[4] }); itemValue.Add(new string[] { "Ca_PASS", "http://www.datacom.com.cn/DialysisStatisticDQ", "Ca 合格人数", null, modifier[5] }); itemValue.Add(new string[] { "P_ED", "http://www.datacom.com.cn/DialysisStatisticDQ", "P 已检人数", null, modifier[6] }); itemValue.Add(new string[] { "P_PASS", "http://www.datacom.com.cn/DialysisStatisticDQ", "P 合格人数", null, modifier[7] }); itemValue.Add(new string[] { "TS_ED", "http://www.datacom.com.cn/DialysisStatisticDQ", "TS 已检人数", null, modifier[8] }); itemValue.Add(new string[] { "TS_PASS", "http://www.datacom.com.cn/DialysisStatisticDQ", "TS 合格人数", null, modifier[9] }); itemValue.Add(new string[] { "SF_ED", "http://www.datacom.com.cn/DialysisStatisticDQ", "SF 已检人数", null, modifier[10] }); itemValue.Add(new string[] { "SF_PASS", "http://www.datacom.com.cn/DialysisStatisticDQ", "SF 合格人数", null, modifier[11] }); itemValue.Add(new string[] { "IPTH_ED", "http://www.datacom.com.cn/DialysisStatisticDQ", "IPTH 已检人数", null, modifier[12] }); itemValue.Add(new string[] { "IPTH_PASS", "http://www.datacom.com.cn/DialysisStatisticDQ", "IPTH 合格人数", null, modifier[13] }); itemValue.Add(new string[] { "KtV_ED", "http://www.datacom.com.cn/DialysisStatisticDQ", "KtV 已检人数", null, modifier[14] }); itemValue.Add(new string[] { "KtV_PASS", "http://www.datacom.com.cn/DialysisStatisticDQ", "KtV 合格人数", null, modifier[15] }); itemValue.Add(new string[] { "HBsAg_ED", "http://www.datacom.com.cn/DialysisStatisticDQ", "HBsAg 已检人数", null, modifier[16] }); itemValue.Add(new string[] { "HBsAg_POSI", "http://www.datacom.com.cn/DialysisStatisticDQ", "HBsAg 阳性人数", null, modifier[17] }); itemValue.Add(new string[] { "Anti-HCV_ED", "http://www.datacom.com.cn/DialysisStatisticDQ", "Anti-HCV 已检人数", null, modifier[18] }); itemValue.Add(new string[] { "Anti-HCV_POSI", "http://www.datacom.com.cn/DialysisStatisticDQ", "Anti-HCV 阳性人数", null, modifier[19] }); itemValue.Add(new string[] { "URR_ED", "http://www.datacom.com.cn/DialysisStatisticDQ", "URR 已检人数", null, modifier[20] }); itemValue.Add(new string[] { "URR_PASS", "http://www.datacom.com.cn/DialysisStatisticDQ", "URR 合格人数", null, modifier[21] }); itemValue.Add(new string[] { "FR", "http://www.datacom.com.cn/DialysisStatisticDQ", "瘘管重建人数", null, modifier[22] }); itemValue.Add(new string[] { "Out", "http://www.datacom.com.cn/DialysisStatisticDQ", "脱离人数", null, modifier[23] }); itemValue.Add(new string[] { "Population", "http://www.datacom.com.cn/DialysisStatisticDQ", "总人数", null, modifier[24] }); target.CommunicationCreateUpdate(commId, commIdentifier, commIdentifierSystem, categoryCode, categorySystem, categoryName, senderId, recipientId, sentDate, eventDateTime, durationUnit, itemValue); logger.Trace("DQ Event Date : " + eventDateTime); //Trace.WriteLine("DQ Event Date : " + eventDateTime); string ip = null; if (HttpContext.Current != null) { ip = HttpContext.Current.Request.UserHostAddress; } else { System.Net.IPAddress SvrIP = new System.Net.IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address); ip = SvrIP.ToString(); } AuditObject ao = new AuditObject() { Reference = "Communication/" + commId, Name = sMdate + categoryName, Success = true }; target.CommunicationAuditEventCreateUpdate("UL.DQ", "Statistic", categoryCode, AuditEvent.AuditEventOutcome.N0, ip, "", senderId, recipientId, "", ao); bCheck = true; } catch (Exception e) { logger.Error("UploadDQ error, error message: " + e.Message); return(false); } return(bCheck); }
// 上傳人口分布統計資料 public bool UploadPD(string Trdate) { bool bCheck = false; string sURL = ""; string ip = null; try { sURL = getSET("Dialysis_url") + getSET("Dialysis_Organization"); string[] OrganizationInfo = ReadFhirOrganization(sURL); if (OrganizationInfo[0] == "nodata") { return(false); } string orgId = OrganizationInfo[0]; string recipientId = OrganizationInfo[1]; string sentDate = Trdate + "-" + DateTime.DaysInMonth(int.Parse(Trdate.Substring(0, 4)), int.Parse(Trdate.Substring(5, 2))).ToString(); sURL = getSET("Dialysis_url") + getSET("Dialysis_PD") + "/" + sentDate; string[] modifier = GetPD(sURL); if (modifier[0] == "nodata") { return(false); } UploadStatistic target = new UploadStatistic(); target.setFhirURI(getSET("FHIR_SERVER")); string sMdate = Trdate.Replace("-", ""); string commId = "PD." + orgId + "." + sMdate; string commIdentifier = "PD." + orgId + "." + sMdate; string commIdentifierSystem = "http://www.datacom.com.cn/DialysisStatistic"; string categoryCode = "PD"; string categorySystem = "http://www.datacom.com.cn/DialysisStatisticCategory"; string categoryName = "人口分布"; string senderId = orgId; string eventDateTime = DateTime.UtcNow.ToString("s"); Timing.UnitsOfTime durationUnit = Timing.UnitsOfTime.Mo; List <string[]> itemValue = new List <string[]>(); itemValue.Add(new string[] { "-30", "http://www.datacom.com.cn/DialysisStatisticPD", "-30", "M", modifier[0] }); itemValue.Add(new string[] { "-30", "http://www.datacom.com.cn/DialysisStatisticPD", "-30", "F", modifier[1] }); itemValue.Add(new string[] { "30-39", "http://www.datacom.com.cn/DialysisStatisticPD", "30-39", "M", modifier[2] }); itemValue.Add(new string[] { "30-39", "http://www.datacom.com.cn/DialysisStatisticPD", "30-39", "F", modifier[3] }); itemValue.Add(new string[] { "40-49", "http://www.datacom.com.cn/DialysisStatisticPD", "40-49", "M", modifier[4] }); itemValue.Add(new string[] { "40-49", "http://www.datacom.com.cn/DialysisStatisticPD", "40-49", "F", modifier[5] }); itemValue.Add(new string[] { "50-59", "http://www.datacom.com.cn/DialysisStatisticPD", "50-59", "M", modifier[6] }); itemValue.Add(new string[] { "50-59", "http://www.datacom.com.cn/DialysisStatisticPD", "50-59", "F", modifier[7] }); itemValue.Add(new string[] { "60-69", "http://www.datacom.com.cn/DialysisStatisticPD", "60-69", "M", modifier[8] }); itemValue.Add(new string[] { "60-69", "http://www.datacom.com.cn/DialysisStatisticPD", "60-69", "F", modifier[9] }); itemValue.Add(new string[] { "70-79", "http://www.datacom.com.cn/DialysisStatisticPD", "70-79", "M", modifier[10] }); itemValue.Add(new string[] { "70-79", "http://www.datacom.com.cn/DialysisStatisticPD", "70-79", "F", modifier[11] }); itemValue.Add(new string[] { "80-89", "http://www.datacom.com.cn/DialysisStatisticPD", "80-89", "M", modifier[12] }); itemValue.Add(new string[] { "80-89", "http://www.datacom.com.cn/DialysisStatisticPD", "80-89", "F", modifier[13] }); itemValue.Add(new string[] { "90-", "http://www.datacom.com.cn/DialysisStatisticPD", "90-", "M", modifier[14] }); itemValue.Add(new string[] { "90-", "http://www.datacom.com.cn/DialysisStatisticPD", "90-", "F", modifier[15] }); itemValue.Add(new string[] { "SUM", "http://www.datacom.com.cn/DialysisStatisticPD", "SUM", "M", modifier[16] }); itemValue.Add(new string[] { "SUM", "http://www.datacom.com.cn/DialysisStatisticPD", "SUM", "F", modifier[17] }); itemValue.Add(new string[] { "Positive", "http://www.datacom.com.cn/DialysisStatisticPD", "Positive", "M", modifier[18] }); itemValue.Add(new string[] { "Positive", "http://www.datacom.com.cn/DialysisStatisticPD", "Positive", "F", modifier[19] }); itemValue.Add(new string[] { "Negitive", "http://www.datacom.com.cn/DialysisStatisticPD", "Negitive", "M", modifier[20] }); itemValue.Add(new string[] { "Negitive", "http://www.datacom.com.cn/DialysisStatisticPD", "Negitive", "F", modifier[21] }); logger.Trace("PD Event Date : " + eventDateTime); //Trace.WriteLine("PD Event Date : " + eventDateTime); target.CommunicationCreateUpdate(commId, commIdentifier, commIdentifierSystem, categoryCode, categorySystem, categoryName, senderId, recipientId, sentDate, eventDateTime, durationUnit, itemValue); if (HttpContext.Current != null) { ip = HttpContext.Current.Request.UserHostAddress; } else { System.Net.IPAddress SvrIP = new System.Net.IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address); ip = SvrIP.ToString(); } logger.Trace("PD IP Address : " + ip.ToString()); //Trace.WriteLine("PD IP Address : " + ip.ToString()); AuditObject ao = new AuditObject() { Reference = "Communication/" + commId, Name = sMdate + categoryName, Success = true }; target.CommunicationAuditEventCreateUpdate("UL.PD", "Statistic", categoryCode, AuditEvent.AuditEventOutcome.N0, ip, "", senderId, recipientId, "", ao); bCheck = true; } catch (Exception e) { logger.Error("UploadPD error, error message: " + e.Message); return(false); } return(bCheck); }
// 上傳死亡率統計資料 public bool UploadMR(string Trdate) { bool bCheck = false; string sURL = ""; string ip = null; try { sURL = getSET("Dialysis_url") + getSET("Dialysis_Organization"); string[] OrganizationInfo = ReadFhirOrganization(sURL); if (OrganizationInfo[0] == "nodata") { return(false); } string orgId = OrganizationInfo[0]; string recipientId = OrganizationInfo[1]; sURL = getSET("Dialysis_url") + getSET("Dialysis_MR") + "/" + Trdate; string[] modifier = GetMR(sURL); if (modifier[0] == "nodata") { return(false); } UploadStatistic target = new UploadStatistic(); target.setFhirURI(getSET("FHIR_SERVER")); string sMdate = Trdate.Replace("-", ""); string commId = "MR." + orgId + "." + sMdate; string commIdentifier = "MR." + orgId + "." + sMdate; string commIdentifierSystem = "http://www.datacom.com.cn/DialysisStatistic"; string categoryCode = "MR"; string categorySystem = "http://www.datacom.com.cn/DialysisStatisticCategory"; string categoryName = "死亡率"; string senderId = orgId; string sentDate = Trdate + "-" + DateTime.DaysInMonth(int.Parse(Trdate.Substring(0, 4)), int.Parse(Trdate.Substring(5, 2))).ToString(); string eventDateTime = DateTime.UtcNow.ToString("s"); Timing.UnitsOfTime durationUnit = Timing.UnitsOfTime.Mo; List <string[]> itemValue = new List <string[]>(); itemValue.Add(new string[] { "deaths", "http://www.datacom.com.cn/DialysisStatisticMR", "死亡人数", "M", modifier[0] }); itemValue.Add(new string[] { "deaths", "http://www.datacom.com.cn/DialysisStatisticMR", "死亡人数", "F", modifier[1] }); itemValue.Add(new string[] { "population", "http://www.datacom.com.cn/DialysisStatisticMR", "总人数", "M", modifier[2] }); itemValue.Add(new string[] { "population", "http://www.datacom.com.cn/DialysisStatisticMR", "总人数", "F", modifier[3] }); target.CommunicationCreateUpdate(commId, commIdentifier, commIdentifierSystem, categoryCode, categorySystem, categoryName, senderId, recipientId, sentDate, eventDateTime, durationUnit, itemValue); logger.Trace("MR Event Date : " + eventDateTime); //Trace.WriteLine("MR Event Date : " + eventDateTime); if (HttpContext.Current != null) { ip = HttpContext.Current.Request.UserHostAddress; } else { System.Net.IPAddress SvrIP = new System.Net.IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address); ip = SvrIP.ToString(); } AuditObject ao = new AuditObject() { Reference = "Communication/" + commId, Name = sMdate + categoryName, Success = true }; target.CommunicationAuditEventCreateUpdate("UL.MR", "Statistic", categoryCode, AuditEvent.AuditEventOutcome.N0, ip, "", senderId, recipientId, "", ao); bCheck = true; } catch (Exception e) { logger.Error("UploadMR error, error message: " + e.Message); return(false); } return(bCheck); }
public void UploadAdminTwo() { try { UploadAdmin uploadAdmin = new UploadAdmin(); try { uploadAdmin.OrganizationCreateUpdate(orgId); logger.Info("Organization Create/Update:" + orgId); } catch (Exception ex) { logger.Error(ex.Message); } //多筆醫師處置人員 //DBOracle db = new DBOracle(); DBMysql db = new DBMysql(); DataTable Mydt = new DataTable(); Mydt = db.Query("select acclv_stfcode, acclv_fname, acclv_type, acclv_active from access_level"); if (Mydt.Rows.Count > 0) { //orgId = "H57069000.8602"; //orgId = "H32000800.8066"; //orgName = "南京市大厂医院血液净化中心"; //orgName = "南京医科大学血液净化中心"; string acclv_stfcode = "Admin"; string acclv_fname = "Administrator"; string acclv_type = "Doctor"; Boolean acclv_active = true; string acclv_id = "1"; /*if (new TimeSpan(DateTime.Now.Ticks - newestSuccessListDateTime.Ticks).Days < 5) * { * DataTable MydtFilter = new DataTable(); * foreach (DataRow row in Mydt.Rows) * { * if (!newstSuccessIdList.Contains(row["acclv_stfcode"].ToString())) * MydtFilter.ImportRow(row); * } * Mydt = MydtFilter; * } * if (Mydt.Rows.Count == 0) * logger.Info("Practitioner Creaete/Update List is Empty"); */ ConcurrentBag <AuditObject> successList = new ConcurrentBag <AuditObject>(); ConcurrentBag <AuditObject> failList = new ConcurrentBag <AuditObject>(); int practitionerCounter = 1; Stopwatch sw = new Stopwatch(); sw.Start(); //foreach (DataRow row in Mydt.Rows) Parallel.ForEach(Mydt.AsEnumerable(), row => { lock (syncHandle) { acclv_stfcode = row["acclv_stfcode"].ToString(); acclv_fname = row["acclv_fname"].ToString(); acclv_type = row["acclv_type"].ToString(); //acclv_id = Mydt.Rows[i]["acclv_id"].ToString(); } logger.Info("Practitioner information@" + "acclv_stfcode=" + acclv_stfcode + ",acclv_fname=" + acclv_fname); try { // TODO: Create Practitioner //orgId, orgName, Stracclv_stfcode, Stracclv_fname, Stracclv_type, typeSystem, Bacclv_active, tel, email AuditObject resultAudit = uploadAdmin.PractitionerCreateUpdate(orgId, orgName, acclv_stfcode, acclv_fname, acclv_type, "", acclv_active, "", ""); logger.Info("Practitioner Create/Update:" + practitionerCounter + "/" + Mydt.Rows.Count); if (resultAudit.Success) { successList.Add(resultAudit); logger.Info("Practitioner Create Success@" + "acclv_stfcode=" + acclv_stfcode + ",acclv_fname=" + acclv_fname); } else { failList.Add(resultAudit); logger.Info("Practitioner Create Fail@" + "acclv_stfcode=" + acclv_stfcode + ",acclv_fname=" + acclv_fname); } practitionerCounter++; } catch (Exception ex) { failList.Add(new AuditObject { Success = false, Name = acclv_stfcode, Desc = acclv_fname }); logger.Error(ex.Message); logger.Error("Practitioner Create catch Fail@" + "acclv_stfcode=" + acclv_stfcode + ",acclv_fname=" + acclv_fname); } }); sw.Stop(); logger.Info("Practitioner Create/Update exec:" + practitionerCounter + "/" + Mydt.Rows.Count + " total cost " + (sw.ElapsedMilliseconds / 1000).ToString() + " seconds"); string ip = null; if (HttpContext.Current != null) { ip = HttpContext.Current.Request.UserHostAddress; } else { System.Net.IPAddress SvrIP = new System.Net.IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address); ip = SvrIP.ToString(); } try { if (successList.Count > 0) { uploadAdmin.AuditEventCreateUpdate("UL.Practitioner", "Organization", orgId, orgId, successList.ToList <AuditObject>(), Hl7.Fhir.Model.AuditEvent.AuditEventAction.U, Hl7.Fhir.Model.AuditEvent.AuditEventOutcome.N0, new Hl7.Fhir.Model.Coding("http://www.datacom.com.tw", "UL_PRACTITIONER"), ip); } if (failList.Count > 0) { uploadAdmin.AuditEventCreateUpdate("UL.Practitioner", "Organization", orgId, orgId, failList.ToList <AuditObject>(), Hl7.Fhir.Model.AuditEvent.AuditEventAction.U, Hl7.Fhir.Model.AuditEvent.AuditEventOutcome.N4, new Hl7.Fhir.Model.Coding("http://www.datacom.com.tw", "UL_PRACTITIONER"), ip); } } catch (Exception ex) { logger.Error(ex.Message); logger.Error("AuditEvent Create Fail@" + "UL_PRACTITIONER"); } } //病患上傳資料 Mydt = new DataTable(); Mydt = db.Query(" select pif_ic, pif_name, pif_pattyp, pif_mrn, pif_dob, pif_sex, pif_address, pif_contactperson, pif_contact, pif_imgloc, pif_insurance, pif_insid, pif_docname from pat_info group by pif_ic"); if (Mydt.Rows.Count > 0) { string pif_ic = ""; string pif_name = ""; string pif_pattyp = ""; string pif_mrn = ""; string pif_dob = ""; string pif_sex = ""; string pif_address = ""; string pif_contactperson = ""; string pif_contact = ""; //tel string pif_imgloc = ""; string pif_insurance = ""; string pif_insid = ""; string pif_docname = ""; ConcurrentBag <AuditObject> successList = new ConcurrentBag <AuditObject>(); ConcurrentBag <AuditObject> failList = new ConcurrentBag <AuditObject>(); int patientCounter = 1; Stopwatch sw1 = new Stopwatch(); sw1.Start(); //foreach (DataRow row in Mydt.Rows) Parallel.ForEach(Mydt.AsEnumerable(), row => { lock (syncHandle1) { pif_ic = row["pif_ic"].ToString(); pif_name = row["pif_name"].ToString(); pif_pattyp = row["pif_pattyp"].ToString(); pif_mrn = row["pif_mrn"].ToString(); pif_dob = row["pif_dob"].ToString(); pif_sex = row["pif_sex"].ToString(); pif_address = row["pif_address"].ToString(); pif_contactperson = row["pif_contactperson"].ToString(); pif_contact = row["pif_contact"].ToString(); pif_imgloc = row["pif_imgloc"].ToString(); pif_insurance = row["pif_insurance"].ToString(); pif_insid = row["pif_insid"].ToString(); pif_docname = row["pif_docname"].ToString(); //acclv_id = Mydt.Rows[i]["acclv_id"].ToString(); } logger.Info("Patient information@" + "pif_ic=" + pif_ic + ",pif_name=" + pif_name); try { // TODO: Create Patient //Str_pif_ic, Str_pif_name, Str_pif_dob, Str_pif_pattyp, Str_pif_mrn, Str_pif_sex, Str_pif_address, Str_pif_contactperson, Str_pif_contact, Str_pif_imgloc, Str_pif_insurance, Str_pif_insid, Str_pif_docname, email AuditObject resultAudit = uploadAdmin.PatientCreateUpdate(orgId, orgName, pif_ic, pif_name, pif_dob, pif_pattyp, pif_mrn, pif_sex, pif_address, pif_contactperson, pif_contact, pif_imgloc, pif_insurance, pif_insid, pif_docname, ""); logger.Info("Patient Create/Update:" + patientCounter + "/" + Mydt.Rows.Count); if (resultAudit.Success) { successList.Add(resultAudit); logger.Info("Patient Create Success@" + "pif_ic=" + pif_ic + ",pif_name=" + pif_name); } else { failList.Add(resultAudit); logger.Info("Patient Create Fail@" + "pif_ic=" + pif_ic + ",pif_name=" + pif_name); } patientCounter++; } catch (Exception ex) { failList.Add(new AuditObject { Success = false, Name = pif_ic, Desc = pif_name }); logger.Error(ex.Message); logger.Error("Patient Create catch Fail@" + "pif_ic=" + pif_ic + ",pif_name=" + pif_name); } }); sw1.Stop(); logger.Info("Patient Create/Update exec:" + patientCounter + "/" + Mydt.Rows.Count + " total cost " + (sw1.ElapsedMilliseconds / 1000).ToString() + " seconds"); sw1.Restart(); try { if (successList.Count > 0) { /*uploadAdmin.AuditEventCreateUpdate(null, "Organization", orgId, orgId, successList.ToList<AuditObject>(), * Hl7.Fhir.Model.SecurityEvent.SecurityEventAction.U, Hl7.Fhir.Model.SecurityEvent.SecurityEventOutcome.N0, * new Hl7.Fhir.Model.CodeableConcept("http://www.datacom.com.tw", "UL_PATIENT"), * HttpContext.Current.Request.UserHostAddress); */ List <AuditObject> ulClinicalList = successList.ToList <AuditObject>(); string auditDateTime = DateTime.Now.ToString("yyyyMMddHHmmss"); foreach (AuditObject obj in ulClinicalList) { obj.Name = auditDateTime; obj.Desc = ""; } uploadAdmin.AuditEventCreateUpdate("UL_CLINICAL", null, "Organization", orgId, orgId, ulClinicalList, Hl7.Fhir.Model.AuditEvent.AuditEventOutcome.N0, new Hl7.Fhir.Model.Coding("http://www.datacom.com.tw", "UL_CLINICAL"), HttpContext.Current.Request.UserHostAddress); } /*if (failList.Count > 0) * uploadAdmin.AuditEventCreateUpdate(null, "Organization", orgId, orgId, failList.ToList<AuditObject>(), * Hl7.Fhir.Model.AuditEvent.AuditEventAction.U, Hl7.Fhir.Model.SecurityEvent.AuditEventOutcome.N4, * new Hl7.Fhir.Model.Coding("http://www.datacom.com.tw", "UL_PATIENT"), * HttpContext.Current.Request.UserHostAddress); */ } catch (Exception ex) { logger.Error(ex.Message); logger.Error("Audit Create Fail@" + "UL_PATIENT"); } sw1.Stop(); logger.Info("PatientAudit Create/Update total cost " + (sw1.ElapsedMilliseconds / 1000).ToString() + " seconds"); } } catch (Exception uploadAdminException) { logger.Error(uploadAdminException.Message); logger.Error("UploadAdmin Error:" + uploadAdminException.Message); } finally { } }
public bool UploadPractitioner(string TrDate) { string[] OrganizationInfo; try { OrganizationInfo = DialysisToFhir.ReadFhirID01(); if (OrganizationInfo[0] == "nodata") { return(false); } orgId = OrganizationInfo[0]; orgName = OrganizationInfo[1]; } catch (Exception) { return(false); } UploadAdmin uploadAdmin = new UploadAdmin(); try { uploadAdmin.OrganizationCreateUpdate(orgId); logger.Info("Organization Create/Update:" + orgId); } catch (Exception ex) { logger.Error(ex.Message); } //多筆醫師處置人員 DBMysql db = new DBMysql(); DataTable Mydt = new DataTable(); string sSQL = "SELECT usrnm, name, type, active FROM access_level "; sSQL += "ORDER BY acclv_id"; Mydt = db.Query(sSQL); if (Mydt.Rows.Count > 0) { string acclv_stfcode = "Admin"; string acclv_fname = "Administrator"; string acclv_type = "Doctor"; Boolean acclv_active = true; DateTime lastUpdated; getAuditList(); try { lastUpdated = new DateTime(Convert.ToInt16(slastUpdated.Substring(0, 4)), Convert.ToInt16(slastUpdated.Substring(5, 2)), Convert.ToInt16(slastUpdated.Substring(8, 2))); } catch (Exception) { lastUpdated = DateTime.Now.AddMonths(-1); } ConcurrentBag <AuditObject> successList = new ConcurrentBag <AuditObject>(); ConcurrentBag <AuditObject> failList = new ConcurrentBag <AuditObject>(); int practitionerCounter = 0; AuditObject resultAudit = new AuditObject(); resultAudit.Success = false; Stopwatch sw = new Stopwatch(); sw.Start(); foreach (DataRow row in Mydt.Rows) //Parallel.ForEach(Mydt.AsEnumerable(), row => { lock (syncHandle) { acclv_stfcode = row["usrnm"].ToString(); acclv_fname = row["name"].ToString(); acclv_type = row["type"].ToString(); if (row["active"].ToString() == "A") { acclv_active = true; } else { acclv_active = false; } } practitionerCounter++; logger.Info("Practitioner Create " + practitionerCounter.ToString() + "/" + Mydt.Rows.Count.ToString() + " @" + "acclv_stfcode=" + acclv_stfcode + ",acclv_fname=" + acclv_fname); dvFhir.RowFilter = "C1='" + acclv_stfcode + "'"; if (dvFhir.Count > 0) { // 先拿掉要 5 天以上才能更新的門檻 - Remarked by Evan 20160906 //if (lastUpdated.CompareTo(DateTime.Now.AddDays(-5)) < 0) { if (dvFhir[0].Row["C3"].ToString() == acclv_fname.GetHashCode().ToString()) { continue; } } //else // continue; //------------------------------ } try { // TODO: Create Practitioner //orgId, orgName, Stracclv_stfcode, Stracclv_fname, Stracclv_type, typeSystem, Bacclv_active, tel, email // logger.Info("Practitioner Create/Update:" + practitionerCounter + "/" + Mydt.Rows.Count); resultAudit = uploadAdmin.PractitionerCreateUpdate(orgId, orgName, acclv_stfcode, acclv_fname, acclv_type, "", acclv_active, "", ""); if (resultAudit.Success) { successList.Add(resultAudit); } else { failList.Add(resultAudit); } } catch (Exception ex) { failList.Add(new AuditObject { Success = false, Name = acclv_stfcode, Desc = acclv_fname }); logger.Error(ex.Message); logger.Info(ex.Message); logger.Error("Practitioner Create catch Fail: " + practitionerCounter.ToString() + "/" + Mydt.Rows.Count.ToString() + " @" + "acclv_stfcode=" + acclv_stfcode + ",acclv_fname=" + acclv_fname); } //while (interval.CompareTo(DateTime.Now) > 0) { if (flag) { logger.Info("--------------"); flag = false; } }; } ; sw.Stop(); logger.Info("Practitioner Create/Update exec:" + practitionerCounter.ToString() + "/" + Mydt.Rows.Count.ToString() + " total cost " + (sw.ElapsedMilliseconds / 1000).ToString() + " seconds"); string ip = null; if (HttpContext.Current != null) { ip = HttpContext.Current.Request.UserHostAddress; } else { System.Net.IPAddress SvrIP = new System.Net.IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address); ip = SvrIP.ToString(); } try { if (successList.Count > 0) { uploadAdmin.AuditEventPracCreateUpdate("UL.PRACTITIONER", orgId, "Organization", orgId, orgId, successList.ToList <AuditObject>(), Hl7.Fhir.Model.AuditEvent.AuditEventOutcome.N0, new Hl7.Fhir.Model.Coding("http://www.datacom.com.tw", "UL.PRACTITIONER"), ip); } //if (successList.Count > 0) // uploadAdmin.AuditEventCreateUpdate("UL.Practitioner", "Organization", orgId, orgId, successList.ToList<AuditObject>(), // Hl7.Fhir.Model.AuditEvent.AuditEventAction.U, Hl7.Fhir.Model.AuditEvent.AuditEventOutcome.N0, // new Hl7.Fhir.Model.Coding("http://www.datacom.com.tw", "UL_PRACTITIONER"), ip); //if (failList.Count > 0) // uploadAdmin.AuditEventCreateUpdate("UL.Practitioner", "Organization", orgId, orgId, failList.ToList<AuditObject>(), // Hl7.Fhir.Model.AuditEvent.AuditEventAction.U, Hl7.Fhir.Model.AuditEvent.AuditEventOutcome.N4, // new Hl7.Fhir.Model.Coding("http://www.datacom.com.tw", "UL_PRACTITIONER"), ip); } catch (Exception ex) { logger.Error(ex.Message); logger.Error("AuditEvent Create catch Fail@" + "UL.PRACTITIONER"); } } return(true); }
public Task AuditLog(AuditObject obj, AuditAction act, AuditStatus status, int?id = null, Guid?uid = null) { return(Task.CompletedTask); }