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 = 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) { throw new InvalidOperationException("Missing month selection on form"); } // Now we want to upload the data BirthDoseSubmission submission = new BirthDoseSubmission() { Month = (int)monthBubble.ValueAsFloat, FacilityId = facilityId, Data = new List <BirthDoseData>() }; // Iterate through the rows foreach (var dtl in page.Details.OfType <OmrRowData>()) { OmrBubbleData genderData = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "Gender"); OmrBubbleData[] birthDose = dtl.Details.OfType <OmrBubbleData>().Where(o => o.Key == "BirthDose").ToArray(), ttDose = dtl.Details.OfType <OmrBubbleData>().Where(o => o.Key == "TTDose").ToArray(); if (genderData == null) { Err += String.Format("Row {0} is missing gender group, skipping; ", dtl.Id); continue; } var data = new BirthDoseData() { Gender = genderData.Value, Doses = new List <string>() }; // Doses data.Doses.AddRange(birthDose.Select(o => o.Value)); data.Doses.AddRange(ttDose.Select(o => o.Value)); submission.Data.Add(data); } RestUtil restUtil = new RestUtil(new Uri(ConfigurationManager.AppSettings["GIIS_URL"])); restUtil.Post("AnonymousDataManagement.svc/PostBirthDose", submission); } 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 = 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 += "Form is missing month!; "; return; } // Now we want to upload the data WeighTallySubmission submission = new WeighTallySubmission() { Month = (int)monthBubble.ValueAsFloat, FacilityId = facilityId, Data = new List <WeighTallyData>() }; // Iterate through the rows foreach (var dtl in page.Details.OfType <OmrRowData>()) { OmrBubbleData ageData = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "Age"), genderData = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "Gender"), weightData = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "Weight"), ebfData = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "EBF"), rfData = dtl.Details.OfType <OmrBubbleData>().FirstOrDefault(o => o.Key == "RF"); if (ageData == null) { Err += String.Format("Row {0} is missing age group, skipping; ", dtl.Id); continue; } else if (weightData == null) { Err += String.Format("Row {0} is missing weight group, skipping; ", dtl.Id); continue; } else if (genderData == null) { Err += String.Format("Row {0} is missing gender group, skipping; ", dtl.Id); continue; } bool ebf = ebfData != null; bool rf = rfData != null; submission.Data.Add(new WeighTallyData() { AgeGroup = ageData.Value, Gender = genderData.Value, WeightGroup = weightData.Value, Ebf = ebf, Rf = rf }); } RestUtil restUtil = new RestUtil(new Uri(ConfigurationManager.AppSettings["GIIS_URL"])); restUtil.Post("AnonymousDataManagement.svc/PostWeighTally", submission); } catch (Exception e) { Trace.TraceError("Error:{0}", e); throw; } finally { dlg.Close(); } }