/// <summary> /// Populate the location node /// </summary> public void PopulateLocationNode(TreeNode parent) { RestUtil restUtil = new RestUtil(new Uri(ConfigurationManager.AppSettings["GIIS_URL"])); var parentId = 0; if (parent != null) { parentId = (int)parent.Tag; } else { if (String.IsNullOrEmpty(restUtil.GetCurrentUserName)) // Login { try { restUtil.Get <User>("UserManagement.svc/GetUser", new KeyValuePair <string, object>("username", ""), new KeyValuePair <String, Object>("password", "")); } catch { } } var userInfo = restUtil.Get <User>("UserManagement.svc/GetUserInfo", new KeyValuePair <string, object>("username", restUtil.GetCurrentUserName)); parentId = userInfo.HealthFacilityId; } var facilities = restUtil.Get <HealthFacility[]>("HealthFacilityManagement.svc/GetHealthFacilityByParentId", new KeyValuePair <string, object>("parentId", parentId)); if (parent == null) { foreach (var hf in facilities) { var tn = new TreeNode() { Tag = hf.Id, Text = hf.Name }; if (!hf.Leaf) { tn.Nodes.Add(String.Empty); } trvLocation.Nodes.Add(tn); } } else { parent.Nodes.Clear(); foreach (var hf in facilities) { var tn = new TreeNode() { Tag = hf.Id, Text = hf.Name }; if (!hf.Leaf) { tn.Nodes.Add(String.Empty); } parent.Nodes.Add(tn); } } }
private ReferenceData() { RestUtil restUtil = new RestUtil(new Uri(ConfigurationManager.AppSettings["GIIS_URL"])); if (this.Doses == null) { this.Doses = restUtil.Get <List <GIIS.DataLayer.Dose> >("DoseManagement.svc/GetDoseList"); } if (this.Vaccines == null) { this.Vaccines = restUtil.Get <List <GIIS.DataLayer.ScheduledVaccination> >("ScheduledVaccinationManagement.svc/GetScheduledVaccinationList"); } if (this.Items == null) { this.Items = restUtil.Get <List <GIIS.DataLayer.Item> >("ItemManagement.svc/GetItemList"); } if (this.ItemLots == null) { this.ItemLots = restUtil.Get <List <GIIS.DataLayer.ItemLot> >("StockManagement.svc/GetItemLots"); } if (this.Places == null) { this.Places = restUtil.Get <List <GIIS.DataLayer.Place> >("PlaceManagement.svc/GetLeafPlaces"); } }
private static Dictionary <string, ResourcePoolType> GetResourcePools( vCloudClient client, string url) { try { Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.GET_URL_MSG) + " - " + url); RestUtil.Get(client, url); ResourcePoolListType resourcePoolListType = SdkUtil.Get <ResourcePoolListType>(client, url, 200); Dictionary <string, ResourcePoolType> dictionary = new Dictionary <string, ResourcePoolType>(); if (resourcePoolListType != null && resourcePoolListType.ResourcePool != null) { foreach (ResourcePoolType resourcePoolType in resourcePoolListType.ResourcePool) { if (!dictionary.ContainsKey(resourcePoolType.name)) { dictionary.Add(resourcePoolType.name, resourcePoolType); } } } return(dictionary); } catch (Exception ex) { throw new VCloudException(ex.Message); } }
/// <summary> /// Update vaccination /// </summary> /// <param name="evt"></param> private void UpdateVaccination(VaccinationEvent evt) { RestUtil restUtil = new RestUtil(new Uri(ConfigurationManager.AppSettings["GIIS_URL"])); restUtil.Get <RestReturn>("VaccinationEvent.svc/UpdateVaccinationEventById", new KeyValuePair <string, object>("vaccinationEventId", evt.Id), new KeyValuePair <String, Object>("vaccinationDate", evt.ScheduledDate.ToString("yyyy-MM-dd HH:mm:ss")), new KeyValuePair <String, Object>("notes", "From form scanner"), new KeyValuePair <String, Object>("vaccinationStatus", true)); }
private static VappTemplate GetVappTemplate(vCloudClient client, string url) { try { Response response = RestUtil.Get(client, url); VappTemplate vappTemplate = (VappTemplate)null; if (response.IsExpected(200)) { VAppTemplateType resource = response.GetResource <VAppTemplateType>(); vappTemplate = new VappTemplate(client, resource); } else { response.HandleUnExpectedResponse(); } return(vappTemplate); } catch (Exception ex) { throw new VCloudException(ex.Message); } }
private static Dictionary <string, VmObjectRefType> GetVms( vCloudClient client, string url) { try { Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.GET_URL_MSG) + " - " + url); RestUtil.Get(client, url); VmObjectRefsListType objectRefsListType = SdkUtil.Get <VmObjectRefsListType>(client, url, 200); Dictionary <string, VmObjectRefType> dictionary = new Dictionary <string, VmObjectRefType>(); if (objectRefsListType != null && objectRefsListType.VmObjectRef != null) { foreach (VmObjectRefType vmObjectRefType in objectRefsListType.VmObjectRef) { dictionary.Add(vmObjectRefType.name, vmObjectRefType); } } return(dictionary); } catch (Exception ex) { throw new VCloudException(ex.Message); } }
public void UploadData(OmrPageOutput page) { if (!Connectivity.CheckForInternetConnection()) { MessageBox.Show( "Username is empty, This is usually caused by lack of internet connectivity. Please try again later"); Exception e = new Exception("No internet connection"); Trace.TraceError("Error:{0}", e); throw e; } StatusDialog dlg = new StatusDialog(); dlg.Show(); try { int facilityId = FacilitySelectionContext.FacilityId; // Non-remembered facility if (facilityId == 0) { LocationSelectionBox location = new LocationSelectionBox(); if (location.ShowDialog() != System.Windows.Forms.DialogResult.OK) { throw new InvalidOperationException("Cannot upload data without selecting a facility"); } if (location.Remember) { FacilitySelectionContext.FacilityId = location.FacilityId; } facilityId = location.FacilityId; } var monthBubble = page.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "month"); if (monthBubble == null) { Err += "Must select month!; "; return; } RestUtil restUtil = new RestUtil(new Uri(ConfigurationManager.AppSettings["GIIS_URL"])); var userInfo = restUtil.Get <User>("UserManagement.svc/GetUserInfo", new KeyValuePair <string, object>("username", restUtil.GetCurrentUserName)); var placeInfo = restUtil.Get <Place[]>("PlaceManagement.svc/GetPlaceByHealthFacilityId", new KeyValuePair <string, object>("hf_id", facilityId)); foreach (var dtl in page.Details.OfType <OmrRowData>()) { string rowNum = dtl.Id.Substring(dtl.Id.Length - 1, 1); if (dtl.Details.Count == 0) { continue; } // (string barcodeId, string firstname1, string firstname2, string lastname1, DateTime birthdate, bool gender, // int healthFacilityId, int birthplaceId, int domicileId, string address, string phone, string motherFirstname, // string motherLastname, string notes, int userId, DateTime modifiedOn) OmrBarcodeData omrBarcode = dtl.Details.OfType <OmrBarcodeData>().FirstOrDefault(); OmrBubbleData omrDobDay = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "dobDay"), omrDobDay10 = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "dobDay10"), omrDobMonth = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "dobMonth"), omrDobYear = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "dobYear"), omrGender = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "gender"), omrOutreach = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "Outreach"), omrVaccDay10 = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "vaccDay10"), omrVaccDay = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "vaccDay"), omrNew = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "newInfo"), omrUpdate = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "correct"), omrIgnore = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "moved"); OmrBubbleData[] omrBcg = dtl.Details.OfType <OmrBubbleData>().Where(o => o.Key == "BCG").ToArray(), omrOpv = dtl.Details.OfType <OmrBubbleData>().Where(o => o.Key == "OPV").ToArray(), omrPenta = dtl.Details.OfType <OmrBubbleData>().Where(o => o.Key == "PENTA").ToArray(), omrPcv = dtl.Details.OfType <OmrBubbleData>().Where(o => o.Key == "PCV").ToArray(), omrRota = dtl.Details.OfType <OmrBubbleData>().Where(o => o.Key == "ROTA").ToArray(), omrMr = dtl.Details.OfType <OmrBubbleData>().Where(o => o.Key == "MR").ToArray(), omrVaccine = dtl.Details.OfType <OmrBubbleData>().Where(o => o.Key == "vaccine").ToArray(); // From WCF Call // Create row data for the verification form OmrBarcodeField barcodeField = page.Template.FlatFields.Find(o => o.Id == String.Format("{0}Barcode", dtl.Id)) as OmrBarcodeField; OmrBubbleField outreachField = page.Template.FlatFields.OfType <OmrBubbleField>() .SingleOrDefault(o => o.AnswerRowGroup == dtl.Id && o.Question == "Outreach"), monthField = page.Template.FlatFields.OfType <OmrBubbleField>() .SingleOrDefault(o => o.AnswerRowGroup == dtl.Id && o.Question == "dobMonth" && o.Value == "12"); // Barcode bounds Tz02RowData rowData = new Tz02RowData() { RowBounds = new RectangleF() { Location = new PointF(barcodeField.TopLeft.X, monthField.TopLeft.Y - 20), Width = outreachField.TopLeft.X - barcodeField.TopLeft.X, Height = barcodeField.BottomLeft.Y - monthField.TopLeft.Y - 20 }, UserInfo = userInfo, Page = page, FacilityId = facilityId }; if (omrBarcode != null) { rowData.Barcode = omrBarcode.BarcodeData; } if (omrDobDay != null && omrDobDay10 != null && omrDobMonth != null && omrDobYear != null) { try { rowData.DateOfBirth = new DateTime((int)omrDobYear.ValueAsFloat, (int)omrDobMonth.ValueAsFloat, (int)omrDobDay10.ValueAsFloat + (int)omrDobDay.ValueAsFloat); } catch { } } if (omrGender != null) { rowData.Gender = omrGender.Value == "M" ? true : false; } if (omrOutreach != null) { rowData.Outreach = omrOutreach.Value == "T"; } // Doses rowData.Doses = new List <Dose>(); if (omrBcg != null && omrBcg.Length > 0) { rowData.Doses.Add(this.FindDoseOrThrow("BCG")); } if (omrOpv != null) { foreach (var bub in omrOpv) { VaccinationEvent opvEvent = null; rowData.Doses.Add(ReferenceData.Current.Doses .Single(d => (d.DoseNumber == Helper.ConvertToInt(bub.Value) && d.ScheduledVaccinationId == (ReferenceData.Current.Vaccines .Single(v => v.Name.ToLower().Contains("opv")).Id)))); } } if (omrPenta != null) { foreach (var bub in omrPenta) { rowData.Doses.Add(ReferenceData.Current.Doses .Single(d => (d.DoseNumber == Helper.ConvertToInt(bub.Value) && d.ScheduledVaccinationId == (ReferenceData.Current.Vaccines .Single(v => (v.Name.ToLower().Contains("dtp") || v.Name.ToLower().Contains("penta"))).Id)))); } } if (omrPcv != null) { foreach (var bub in omrPcv) { rowData.Doses.Add(ReferenceData.Current.Doses .Single(d => (d.DoseNumber == Helper.ConvertToInt(bub.Value) && d.ScheduledVaccinationId == (ReferenceData.Current.Vaccines .Single(v => v.Name.ToLower().Contains("pcv")).Id)))); } } if (omrRota != null) { foreach (var bub in omrRota) { rowData.Doses.Add(ReferenceData.Current.Doses .Single(d => (d.DoseNumber == Helper.ConvertToInt(bub.Value) && d.ScheduledVaccinationId == (ReferenceData.Current.Vaccines .Single(v => v.Name.ToLower().Contains("rota")).Id)))); } } if (omrMr != null) { foreach (var bub in omrMr) { rowData.Doses.Add(ReferenceData.Current.Doses .Single(d => (d.DoseNumber == Helper.ConvertToInt(bub.Value) && d.ScheduledVaccinationId == (ReferenceData.Current.Vaccines .Single(v => v.Name.ToLower().Contains("mr")) .Id)))); } } // Given vaccines rowData.VaccineGiven = new List <ScheduledVaccination>(); foreach (var vacc in omrVaccine) { string antigenName = vacc.Value; if (antigenName == "ROTA") { antigenName = ReferenceData.Current.Vaccines .Single(d => d.Name.ToLower().Contains("rota")).Name; } else if (antigenName == "PENTA") { antigenName = ReferenceData.Current.Vaccines.Single(d => (d.Name.ToLower().Contains("dtp") || d.Name.ToLower().Contains("penta"))).Name; } else if (antigenName == "MR") { antigenName = ReferenceData.Current.Vaccines .Single(d => (d.Name.ToLower().Contains("mr"))) .Name; } else if (antigenName == "PCV") { antigenName = ReferenceData.Current.Vaccines .Single(d => d.Name.ToLower().Contains("pcv")).Name; } else if (antigenName == "OPV") { antigenName = ReferenceData.Current.Vaccines .Single(d => d.Name.ToLower().Contains("opv")).Name; } var refData = ReferenceData.Current.Vaccines.FirstOrDefault(v => v.Name == antigenName); if (refData != null) { rowData.VaccineGiven.Add(refData); } else { MessageBox.Show(String.Format("The form expected a vaccination named {0} but the server did not respond with such a vaccine. Server vaccinations: [{1}]", antigenName, String.Join(",", ReferenceData.Current.Vaccines.Select(o => o.Name).ToArray()))); } } // Date of vaccination rowData.VaccineDate = DateTime.Now; if (omrVaccDay10 != null && omrVaccDay != null) { rowData.VaccineDate = new DateTime(DateTime.Now.Month < monthBubble.ValueAsFloat ? DateTime.Now.Year - 1 : DateTime.Now.Year, (int)monthBubble.ValueAsFloat, (int)omrVaccDay10.ValueAsFloat + (int)omrVaccDay.ValueAsFloat); } // Determine what to do if (omrUpdate?.Value == "T") { ChildSearch bc = new ChildSearch(rowData); if (bc.ShowDialog() == DialogResult.OK) { rowData.Barcode = bc.Child.BarcodeId; rowData.ChildId = bc.Child.Id; } else { continue; } } else if (omrIgnore?.Value == "T") { continue; } if (BarcodeUtil.HasData(page, barcodeField) || dtl.Details.Count > 2) { Registration registration = new Registration(rowData); registration.ShowDialog(); } } } catch (Exception e) { Trace.TraceError("Error:{0}", e); throw; } finally { dlg.Close(); } }
public void UploadData(OmrPageOutput page) { if (!Connectivity.CheckForInternetConnection()) { MessageBox.Show( "Username is empty, This is usually caused by lack of internet connectivity. Please try again later"); Exception e = new Exception("No internet connection"); Trace.TraceError("Error:{0}", e); throw e; } StatusDialog dlg = new StatusDialog(); dlg.Show(); try { int facilityId = Int32.Parse(page.Parameters[0]); int month = Int32.Parse(page.Parameters[1]); int year = Int32.Parse(page.Parameters[2]); this.Err = ""; Trace.TraceInformation("Reporting for facility {0} of {1}-{2}", facilityId, month, year); RestUtil restUtil = new RestUtil(new Uri(ConfigurationManager.AppSettings["GIIS_URL"])); User userInfo = null; try { userInfo = restUtil.Get <User>("UserManagement.svc/GetUserInfo", new KeyValuePair <string, object>("username", restUtil.GetCurrentUserName)); } catch { userInfo = restUtil.Get <User>("UserManagement.svc/GetUserInfo", new KeyValuePair <string, object>("username", restUtil.GetCurrentUserName)); } var placeInfo = restUtil.Get <Place[]>("PlaceManagement.svc/GetPlaceByHealthFacilityId", new KeyValuePair <string, object>("hf_id", facilityId)); foreach (var patientRow in page.Details.OfType <OmrRowData>().Where(o => !o.Id.Contains("-"))) { // Master patient row processing string rowNum = patientRow.Id.Substring(patientRow.Id.Length - 1, 1); if (patientRow.Details.Count == 0) { continue; } // Create row data for the verification form OmrBarcodeField barcodeField = page.Template.FlatFields.Find(o => o.Id == String.Format("{0}Barcode", patientRow.Id)) as OmrBarcodeField, omrStickerField = page.Template.FlatFields.Find(o => o.Id == String.Format("{0}Sticker", patientRow.Id)) as OmrBarcodeField; Tz01RowData rowData = new Tz01RowData() { RowBounds = new RectangleF() { Location = barcodeField.TopLeft, Width = page.BottomRight.X - barcodeField.TopLeft.X, Height = omrStickerField.BottomRight.Y - barcodeField.TopLeft.Y }, UserInfo = userInfo, Page = page }; // Barcodes only at this level OmrBarcodeData omrBarcode = patientRow.Details.OfType <OmrBarcodeData>().FirstOrDefault(o => o.Id == String.Format("{0}Barcode", patientRow.Id)), omrSticker = patientRow.Details.OfType <OmrBarcodeData>().FirstOrDefault(o => o.Id == String.Format("{0}Sticker", patientRow.Id)); if (omrBarcode == null) { rowData.Barcode = String.Empty; } else { rowData.Barcode = omrBarcode.BarcodeData; } rowData.StickerValue = omrSticker?.BarcodeData; // Try to lookup the poor chap if (rowData.Barcode.StartsWith("T")) // TEMP ID AUTH { rowData.StickerValue = omrSticker?.BarcodeData; var childDataList = restUtil.Get <List <ChildEntity> >("ChildManagement.svc/GetChildById", new KeyValuePair <string, object>("childId", rowData.Barcode.Replace("T", "")) ); if (childDataList == null) { throw new InvalidOperationException("Could not deserialize response"); } else if (childDataList.Count == 0) { throw new InvalidOperationException("Child with barcode " + rowData.Barcode + " not found!"); } rowData.Child = childDataList[0].childEntity; } else { var childDataList = restUtil.Get <List <ChildEntity> >("ChildManagement.svc/SearchByBarcode", new KeyValuePair <string, object>("barcodeId", rowData.Barcode)); if (childDataList == null) { throw new InvalidOperationException("Could not deserialize response"); } else if (childDataList.Count == 0) { if (!String.IsNullOrEmpty(rowData.StickerValue)) { childDataList = restUtil.Get <List <ChildEntity> >("ChildManagement.svc/SearchByBarcode", new KeyValuePair <string, object>("barcodeId", rowData.StickerValue)); } if (childDataList == null) { throw new InvalidOperationException("Could not deserialize response"); } else if (childDataList.Count == 0) { throw new InvalidOperationException("Child with barcode " + rowData.Barcode + " not found!"); } } rowData.Child = childDataList[0].childEntity; } // Get appointments and vaccinations for child VaccinationAppointment[] appts = restUtil.Get <VaccinationAppointment[]>("VaccinationAppointmentManagement.svc/GetVaccinationAppointmentsByChildId", new KeyValuePair <string, object>("childId", rowData.Child.Id)); VaccinationEvent[] vaccinationEvent = restUtil.Get <VaccinationEvent[]>("VaccinationEvent.svc/GetVaccinationEventListByChildId", new KeyValuePair <string, object>("childId", rowData.Child.Id)); rowData.Appointment = new List <Tz01Vaccination>(); // iterate over the sub-rows foreach (var aptRow in page.Details.OfType <OmrRowData>().Where(o => o.Id.StartsWith(String.Format("{0}-", patientRow.Id))).OrderBy(r => r.Id)) { OmrBarcodeData omrAptId = aptRow.Details.OfType <OmrBarcodeData>().FirstOrDefault(); OmrBubbleData omrDay10 = aptRow.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "day10"), omrDay = aptRow.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "day"), omrOutreach = aptRow.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "outreach"), omrVaccine = aptRow.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "vaccine"); // First, get the appointment data Tz01Vaccination vaccineData = new Tz01Vaccination(); if (omrAptId == null) { barcodeField = page.Template.Fields.FirstOrDefault(o => o.AnswerRowGroup == aptRow.Id) as OmrBarcodeField; // Show a correction form ... BarcodeCorrection bc = new BarcodeCorrection(page, barcodeField); if (BarcodeUtil.HasData(page, barcodeField) && bc.ShowDialog() == System.Windows.Forms.DialogResult.OK) { vaccineData.Appointment = appts.FirstOrDefault(o => o.ScheduledDate.Date.Equals(DateTime.ParseExact(bc.BarcodeId, "MM-dd-yyyy", CultureInfo.InvariantCulture))); } } else { vaccineData.Appointment = appts.FirstOrDefault(o => o.Id.ToString() == omrAptId.BarcodeData); } // Validate we got an appointment if (vaccineData.Appointment == null) { throw new InvalidOperationException(String.Format("Could not find appointment data for update on row {0}", rowNum)); } vaccineData.All = omrVaccine?.Value == "all"; vaccineData.Outreach = Boolean.Parse(omrOutreach?.Value ?? "false"); if (omrDay != null || omrDay10 != null) { try { vaccineData.Date = new DateTime(vaccineData.Appointment.ScheduledDate.Year, vaccineData.Appointment.ScheduledDate.Month, (int)(omrDay?.ValueAsFloat + omrDay10?.ValueAsFloat)); if (vaccineData.Date > DateTime.Now) { vaccineData.Date = new DateTime(year, month, (int)(omrDay.ValueAsFloat + omrDay10.ValueAsFloat)); } } catch (Exception e) { Trace.TraceError(e.ToString()); } } rowData.Appointment.Add(vaccineData); } if (rowData.Appointment[0].Date.HasValue || rowData.Appointment[1].Date.HasValue || rowData.Appointment[0].All || rowData.Appointment[1].All || BarcodeUtil.HasData(page, omrStickerField)) { VaccineCorrection vc = new VaccineCorrection(rowData, vaccinationEvent, ReferenceData.Current.Doses); vc.ShowDialog(); } } } catch (Exception e) { Trace.TraceError("Error:{0}", e); throw; } finally { dlg.Close(); } }
public void UploadData(OmrPageOutput page) { if (!Connectivity.CheckForInternetConnection()) { MessageBox.Show( "Username is empty, This is usually caused by lack of internet connectivity. Please try again later"); Exception e = new Exception("No internet connection"); Trace.TraceError("Error:{0}", e); throw e; } try { this.Err = ""; var restUtil = new RestUtil(new Uri(ConfigurationManager.AppSettings["GIIS_URL"])); Trace.TraceInformation("Need to sync {0} children with TIIS at {1}", page.Details.Count, ConfigurationManager.AppSettings["GIIS_URL"]); foreach (var dtl in page.Details.OfType <OmrRowData>()) { // Get the barcode information for this child var barcodes = dtl.Details.OfType <OmrBarcodeData>(); if (barcodes.Count() == 0) { throw new InvalidOperationException("No barcode found on row!"); } // Child code var childCode = barcodes.FirstOrDefault(o => o.Id == dtl.Id + "_TempId"); if (childCode == null) { throw new InvalidOperationException("No GIIS TempId Found on Row!"); } GIIS.DataLayer.Child childData = null; // Get the child by barcode id var childDataList = restUtil.Get <List <ChildEntity> >("ChildManagement.svc/GetChildById", new KeyValuePair <string, object>("childId", childCode.BarcodeData.Replace("T", "")) ); if (childDataList == null) { throw new InvalidOperationException("Could not deserialize response"); } else if (childDataList.Count == 0) { throw new InvalidOperationException("Child with id " + childCode.BarcodeData + " not found!"); } childData = childDataList[0].childEntity; var permCode = barcodes.FirstOrDefault(o => o.Id == dtl.Id + "_Barcode"); // Permcode == null = no association if (permCode == null) { Err += String.Format("{0}, {1} will not be associated with a barcode sticker; ", childData.Lastname1, childData.Firstname1); continue; } // Now to update the child Trace.TraceInformation("Will associated child id {0} with barcode {1}", childData.Id, permCode.BarcodeData); childData.BarcodeId = permCode.BarcodeData; // Send the update restUtil.Get <RestReturn>("ChildManagement.svc/UpdateChild", new KeyValuePair <string, object>("barcode", childData.BarcodeId), new KeyValuePair <string, object>("firstname1", childData.Firstname1), new KeyValuePair <string, object>("lastname1", childData.Lastname1), new KeyValuePair <string, object>("birthdate", childData.Birthdate.ToString("yyyy-MM-dd")), new KeyValuePair <string, object>("gender", childData.Gender), new KeyValuePair <string, object>("healthFacilityId", childData.HealthcenterId), new KeyValuePair <string, object>("birthplaceId", childData.BirthplaceId), new KeyValuePair <string, object>("domicileId", childData.DomicileId), new KeyValuePair <string, object>("statusId", childData.StatusId), new KeyValuePair <string, object>("address", childData.Address), new KeyValuePair <string, object>("phone", childData.Phone), new KeyValuePair <string, object>("motherFirstname", childData.MotherFirstname), new KeyValuePair <string, object>("motherLastname", childData.MotherLastname), new KeyValuePair <string, object>("notes", "Updated by form scanning application"), new KeyValuePair <string, object>("userId", 1), new KeyValuePair <string, object>("childId", childData.Id) ); } } catch (Exception ex) { Trace.TraceError(ex.ToString()); throw; } }
public void UploadData(OmrPageOutput page) { if (!Connectivity.CheckForInternetConnection()) { MessageBox.Show( "Username is empty, This is usually caused by lack of internet connectivity. Please try again later"); Exception e = new Exception("No internet connection"); Trace.TraceError("Error:{0}", e); throw e; } try { this.Err = ""; var restUtil = new RestUtil(new Uri(ConfigurationManager.AppSettings["GIIS_URL"])); Trace.TraceInformation("Need to sync {0} children with TIIS at {1}", page.Details.Count, ConfigurationManager.AppSettings["GIIS_URL"]); var refDoses = restUtil.Get <List <GIIS.DataLayer.Dose> >("DoseManagement.svc/GetDoseList"); var refVaccines = restUtil.Get <List <GIIS.DataLayer.ScheduledVaccination> >("ScheduledVaccinationManagement.svc/GetScheduledVaccinationList"); var refItems = restUtil.Get <List <GIIS.DataLayer.Item> >("ItemManagement.svc/GetItemList"); var refItemLots = restUtil.Get <List <GIIS.DataLayer.ItemLot> >("StockManagement.svc/GetItemLots"); foreach (var dtl in page.Details.OfType <OmrRowData>()) { // Get the barcode information for this child var barcodes = dtl.Details.OfType <OmrBarcodeData>(); if (barcodes.Count() > 1) { throw new InvalidOperationException("Only one barcode per row is supported by this template"); } else if (barcodes.Count() == 0) { throw new InvalidOperationException("No barcode found on row!"); } // Child code var childCode = barcodes.FirstOrDefault(); // Output sync Trace.TraceInformation("Syncing child {0} to GIIS - Step 1 - Resolve Barcode ID", childCode.BarcodeData); GIIS.DataLayer.Child childData = null; // Get the child by barcode id if (childCode.BarcodeData.StartsWith("T")) { var childDataList = restUtil.Get <List <ChildEntity> >("ChildManagement.svc/GetChildById", new KeyValuePair <string, object>("childId", childCode.BarcodeData.Replace("T", "")) ); if (childDataList == null) { throw new InvalidOperationException("Could not deserialize response"); } else if (childDataList.Count == 0) { throw new InvalidOperationException("Child with barcode " + childCode.BarcodeData + " not found!"); } childData = childDataList[0].childEntity; } else { var childDataList = restUtil.Get <List <ChildEntity> >("ChildManagement.svc/SearchByBarcode", new KeyValuePair <string, object>("barcodeId", childCode.BarcodeData)); if (childDataList == null) { throw new InvalidOperationException("Could not deserialize response"); } else if (childDataList.Count == 0) { throw new InvalidOperationException("Child with barcode " + childCode.BarcodeData + " not found!"); } childData = childDataList[0].childEntity; } int childId = childData.Id; // Is this child a non-vaccination? var bubbleData = dtl.Details.OfType <OmrBubbleData>(); // Load questions OmrBubbleData weight10 = bubbleData.FirstOrDefault(o => o.Key == "weight10"), weight1 = bubbleData.FirstOrDefault(o => o.Key == "weight"), weight10ths = bubbleData.FirstOrDefault(o => o.Key == "weightD"), date10 = bubbleData.FirstOrDefault(o => o.Key == "date10"), date = bubbleData.FirstOrDefault(o => o.Key == "date"), ebfr = bubbleData.FirstOrDefault(o => o.Key == "ebfr"), vaccines = bubbleData.FirstOrDefault(o => o.Key == "vaccines"), outreach = bubbleData.FirstOrDefault(o => o.Key == "outreach"); // No vaccinations? if (vaccines == null) { Trace.TraceInformation("No vaccines detected!"); continue; } // Weight float weight = 0.0f; if (weight10 != null) { weight = weight + weight10.ValueAsFloat; } if (weight1 != null) { weight = weight + weight1.ValueAsFloat; } if (weight10ths != null) { weight = weight + (weight10ths.ValueAsFloat * 0.1f); } // Date int day = 0; if (date10 != null) { day += (int)date10.ValueAsFloat; } if (date != null) { day += (int)date.ValueAsFloat; } int txYear = DateTime.Now.Year; int txMonth = Int32.Parse(page.Parameters[1]); if (txMonth > DateTime.Now.Month) // We got a form whose month (ex: 11) is greater than the current month (ex: 10), since we cannot scan in the future, it must be last year { txYear--; } Trace.TraceInformation("Using Date {0}-{1}-{2}", day, txMonth, txYear); DateTime dateOfTx = new DateTime(txYear, txMonth, day); // Register child weight restUtil.Get <object>("ChildManagement.svc/RegisterChildWeight", new KeyValuePair <string, object>("childId", childId), new KeyValuePair <string, object>("date", dateOfTx.ToString("yyyy-MM-dd HH:mm:ss")), new KeyValuePair <string, object>("weight", weight), new KeyValuePair <string, object>("modifiedOn", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), new KeyValuePair <string, object>("modifiedBy", 1) ); // Register child vaccinations if (vaccines == null || vaccines.Value == "none") { Trace.TraceInformation(string.Format("Child {0}, {1} was not vaccinated", childData.Lastname1, childData.Firstname1)); if (Err == null) { Err = String.Empty; } Err += String.Format("Child {0}, {1} requires manual reconciliation - Not all vaccinations given; ", childData.Lastname1, childData.Firstname1); continue; } else { // Get child's vaccination card var izCard = restUtil.Get <List <GIIS.DataLayer.VaccinationEvent> >("VaccinationEvent.svc/GetImmunizationCard", new KeyValuePair <string, object>("childId", childId), new KeyValuePair <string, object>("scheduledDate", dateOfTx.ToString("yyyy-MM-dd HH:MM:ss")) ); foreach (var vacc in izCard.Where(o => o.NonvaccinationReasonId == 0 && !o.VaccinationStatus && o.IsActive && (o.ScheduledDate.Month == txMonth || o.ScheduledDate.AddMonths(1).Month == txMonth) && o.ScheduledDate.Year == txYear)) { var dose = refDoses.Find(o => o.Id == vacc.DoseId); var vaccine = refVaccines.Find(o => o.Id == dose.ScheduledVaccinationId); var item = refItems.Find(o => o.Id == vaccine.ItemId); var itemLot = refItemLots.FindAll(o => o.ItemId == item.Id); var facilityBalance = restUtil.Get <List <GIIS.DataLayer.HealthFacilityBalance> >("StockManagement.svc/GetCurrentStockByLot", new KeyValuePair <String, Object>("hfId", page.Parameters[0])); var balance = facilityBalance.FindAll(o => itemLot.Exists(il => il.Gtin == o.Gtin && il.LotNumber == o.LotNumber)).OrderByDescending(p => p.Balance).FirstOrDefault(); if (balance == null) { Trace.TraceWarning("Facility has no balance for {0}! Can't determine vaccine lot / gtin", dose.Fullname); Err += String.Format("Child {0} cannot receive immunization {1} because facility has no {1} in stock. Please update stock and retry", childId, dose.Fullname); } Trace.TraceInformation("Giving child {0} immunization {1} (stock GTIN: {2} LN {3})", childId, dose.Fullname, balance.Gtin, balance.LotNumber); restUtil.Get <RestReturn>("VaccinationEvent.svc/UpdateVaccinationEvent", new KeyValuePair <String, Object>("vaccineLotId", itemLot.Find(o => o.Gtin == balance.Gtin && o.LotNumber == balance.LotNumber).Id), new KeyValuePair <String, Object>("healthFacilityId", page.Parameters[0]), new KeyValuePair <String, Object>("vaccinationDate", dateOfTx.ToString("yyyy-MM-dd HH:mm:ss")), new KeyValuePair <String, Object>("notes", "From Paper Register"), new KeyValuePair <String, Object>("vaccinationStatus", true), new KeyValuePair <String, Object>("userId", 1), new KeyValuePair <String, Object>("vaccinationEventId", vacc.Id), new KeyValuePair <String, Object>("outreach", outreach != null) ); if (outreach != null) { Trace.TraceInformation("Updating appointment {0} to be outreach", vacc.AppointmentId); restUtil.Get <RestReturn>("VaccinationAppointmentManagement.svc/UpdateVaccinationAppointment", new KeyValuePair <String, Object>("childId", childId), new KeyValuePair <String, Object>("vaccinationAppointmentId", vacc.AppointmentId), new KeyValuePair <String, Object>("outreach", true), new KeyValuePair <String, Object>("userId", 1), new KeyValuePair <String, Object>("scheduledFacilityId", page.Parameters[0]), new KeyValuePair <String, Object>("notes", "From Paper Form") ); } } } } } catch (Exception e) { Trace.TraceError(e.ToString()); Err = e.Message; } }