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(); } }