private static string GetFormattedResponse(def_ResponseVariables rv, XmlSchemaSimpleType type, IFormsRepository formsRepo) { string response = rv.rspValue; //for boolean items (typically representing checked checkboxes), check if there is a specific output value in lookup tables //negative responses to boolean items (rspValue "0") can be ignored in this step because they will be excluded from the output anyways if (rv.rspValue == "1") //this if-statement reduces the number of DB reads, doesn't effect output { def_ItemVariables iv = formsRepo.GetItemVariableById(rv.itemVariableId); if (iv.baseTypeId == 1) { def_LookupMaster lm = formsRepo.GetLookupMastersByLookupCode(iv.identifier); if (lm != null) { List <def_LookupDetail> ld = formsRepo.GetLookupDetailsByLookupMasterEnterprise(lm.lookupMasterId, SessionHelper.LoginStatus.EnterpriseID); if (ld.Count > 0) { response = ld[0].dataValue; } } } } try { return(Utilities.FormatDataByXmlDataType(response, type)); } catch (Exception excptn) { Debug.WriteLine("GetFormattedResponse Message: " + excptn.Message); return(GetDefaultValue(type)); // to pass validation } }
public ActionResult deleteMaster(int masterId) { List <def_LookupDetail> lookupDetails = new List <def_LookupDetail>(); lookupDetails.AddRange(formsRepo.GetLookupMasterById(masterId).def_LookupDetail); List <def_LookupText> lookupTexts = new List <def_LookupText>(); foreach (def_LookupDetail detail in lookupDetails) { lookupTexts.AddRange(formsRepo.GetLookupTextsByLookupDetail(detail.lookupDetailId)); } foreach (def_LookupText text in lookupTexts) { formsRepo.DeleteLookupText(text); } foreach (def_LookupDetail detail in lookupDetails) { formsRepo.DeleteLookupDetail(detail); } def_LookupMaster master = formsRepo.GetLookupMasterById(masterId); formsRepo.DeleteLookupMaster(master); lookupModel.LookupMasters = getMasters(); return(PartialView("_Masters", lookupModel)); }
/// <summary> /// Used to display responses to radiobuttons or dropdowns. /// /// Retrieve a numerical response for the given def_FormResult and deF_ItemVariable from the ResponseVariables table, /// Then lookup the display text associated with the numerical response, for the current UI language. /// </summary> /// <param name="formResultId"></param> /// <param name="itm"></param> /// <param name="iv"></param> /// <returns></returns> private string GetResponseThroughLookupTables(int formResultId, def_Items itm, def_ItemVariables iv) { string rsp = GetResponse(formResultId, itm, iv); def_LookupMaster lm = formsRepo.GetLookupMastersByLookupCode(iv.identifier); if (lm == null) { return(rsp); } def_LookupDetail ld = formsRepo.GetLookupDetailByEnterpriseMasterAndDataValue(SessionHelper.LoginStatus.EnterpriseID, lm.lookupMasterId, rsp); if (ld != null) { CultureInfo ci = Thread.CurrentThread.CurrentUICulture; string region = (ci == null) ? "en" : ci.TwoLetterISOLanguageName.ToLower(); int langId = formsRepo.GetLanguageByTwoLetterISOName(region).langId; def_LookupText lt = formsRepo.GetLookupTextsByLookupDetailLanguage(ld.lookupDetailId, langId).FirstOrDefault(); if (lt != null) { return(lt.displayText); } } return(rsp); }
public def_LookupMaster SetLookupMaster(string lkpCd, string title, int baseType, def_LookupMaster lkpMstr = null) { if (lkpMstr == null) { lkpMstr = new def_LookupMaster(); lkpMstr.lookupCode = lkpCd; lkpMstr.title = title; lkpMstr.baseTypeId = (short)baseType; db.def_LookupMaster.Add(lkpMstr); } else { lkpMstr.lookupCode = lkpCd; lkpMstr.title = title; lkpMstr.baseTypeId = (short)baseType; db.Entry(lkpMstr).State = EntityState.Modified; } db.SaveChanges(); return(lkpMstr); }
public ActionResult saveMaster(int lookupMasterId, string lookupCode, string title, int baseType) { def_LookupMaster master = formsRepo.GetLookupMasterById(lookupMasterId); formsRepo.SetLookupMaster(lookupCode, title, baseType, master); lookupModel.LookupMasters = getMasters(); return(PartialView("_Masters", lookupModel)); }
public ActionResult Upload(HttpPostedFileBase file) { AdapAdmin model = new AdapAdmin(); model.ActiveUserName = SessionHelper.LoginStatus.FirstName + " " + SessionHelper.LoginStatus.LastName; int enterpriseId = SessionHelper.LoginStatus.EnterpriseID; def_LookupMaster lookupMaster = mFormsRepository.GetLookupMastersByLookupCode("ADAP_CLINIC"); int lookupMasterId = 0; if (lookupMaster != null) { lookupMasterId = lookupMaster.lookupMasterId; } model.enterpriseId = enterpriseId; model.groupId = 0; model.lookupMasterId = lookupMasterId; model.statusFlag = true; if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName); file.SaveAs(path); LookupUploads lookupUploads = new LookupUploads(); model.Message = "Upload successful"; try { lookupUploads.UploadLookups(enterpriseId, SessionHelper.LoginStatus.UserID, mFormsRepository, path); } catch (Exception ex) { model.Message = "Upload error: " + ex.Message; return(View("~/Views/COADAP/UploadLookupData.cshtml", model)); } } else { model.Message = "Upload error: No file selected."; return(View("~/Views/COADAP/UploadLookupData.cshtml", model)); } return(RedirectToAction("Clinic", "ADAP")); }
/// <summary> /// This method is not in use and may be deprecated. /// </summary> /// <param name="clinicDataValue"></param> /// <param name="formResultId"></param> /// <param name="lookupCode"></param> public void UpdateTeam(string clinicDataValue, int formResultId, string lookupCode) { def_FormResults formResult = formsRepo.GetFormResultById(formResultId); int? enterpriseId = formResult.EnterpriseID; def_LookupMaster lookupMaster = formsRepo.GetLookupMastersByLookupCode(lookupCode); if (enterpriseId != null) { def_LookupDetail lookupDetail = formsRepo.GetLookupDetailByEnterpriseMasterAndDataValue(enterpriseId.Value, lookupMaster.lookupMasterId, clinicDataValue); if (lookupDetail != null && lookupDetail.GroupID != null) { formResult.GroupID = lookupDetail.GroupID; formsRepo.SaveFormResults(formResult); } } }
// GET: UploadLookupData public ActionResult Index() { AdapAdmin model = new AdapAdmin(); model.ActiveUserName = SessionHelper.LoginStatus.FirstName + " " + SessionHelper.LoginStatus.LastName; int enterpriseId = SessionHelper.LoginStatus.EnterpriseID; def_LookupMaster lookupMaster = mFormsRepository.GetLookupMastersByLookupCode("ADAP_CLINIC"); int lookupMasterId = 0; if (lookupMaster != null) { lookupMasterId = lookupMaster.lookupMasterId; } model.enterpriseId = enterpriseId; model.groupId = 0; model.lookupMasterId = lookupMasterId; model.statusFlag = true; return(View("~/Views/COADAP/UploadLookupData.cshtml", model)); }
public string GetLookup(string lkpCd) { Debug.WriteLine("GetLookup lkpCd: " + lkpCd); if (!SessionHelper.IsUserLoggedIn) { return("You are NOT logged in."); } int groupId = SessionHelper.LoginStatus.appGroupPermissions[0].authorizedGroups[0]; Debug.WriteLine("GetLookup lkpCd: " + lkpCd + " Enterprise: " + SessionHelper.LoginStatus.EnterpriseID + " GroupID:" + groupId); short lang = 1; // Make this use a session variable later!! def_LookupMaster master = null; try { using (var context = DataContext.GetDbContext()) { context.Configuration.LazyLoadingEnabled = false; /* var query = context.def_LookupMaster * .Where(m => m.lookupCode == lkpCd) * .Select(m => new { m, det = m.def_LookupDetail.Where(d => ) }) */ master = (from i in context.def_LookupMaster where lkpCd == i.lookupCode select i).FirstOrDefault(); var detailCount = context.Entry(master) .Collection(m => m.def_LookupDetail) .Query() .Where(m => m.EnterpriseID == SessionHelper.LoginStatus.EnterpriseID && m.GroupID == groupId) .Count(); // if the Enterprise and Group match, load the LookupDetail records if (detailCount > 0) { context.Entry(master) .Collection(m => m.def_LookupDetail) .Query() .Where(m => m.EnterpriseID == SessionHelper.LoginStatus.EnterpriseID && m.GroupID == groupId) .OrderBy(m => m.displayOrder) .Load(); } else { // Check for the Enterprise specific LookupDetail detailCount = context.Entry(master) .Collection(m => m.def_LookupDetail) .Query() .Where(m => m.EnterpriseID == SessionHelper.LoginStatus.EnterpriseID && m.GroupID == 0) .OrderBy(m => m.displayOrder) .Count(); // Load the Enterprise specific LookupDetail if (detailCount > 0) { context.Entry(master) .Collection(m => m.def_LookupDetail) .Query() .Where(m => m.EnterpriseID == SessionHelper.LoginStatus.EnterpriseID && m.GroupID == 0) .OrderBy(m => m.displayOrder) .Load(); } else { // Load the default LookupDetail context.Entry(master) .Collection(m => m.def_LookupDetail) .Query() .Where(m => m.EnterpriseID == 0 && m.GroupID == 0) .OrderBy(m => m.displayOrder) .Load(); } } // Load the associated LookupText for the selected LookupDetail records // Get a specific Language // If no records for a specific language, get English foreach (def_LookupDetail det in master.def_LookupDetail) { var textCount = context.Entry(det) .Collection(t => t.def_LookupText) .Query() .Where(t => t.langId == lang) .Count(); // If specific Language found, load the records // *** RRB 2/1/16 *** This doesn't look right. 2 different kinds of queries being used Entities and IQueryable // *** *** Also the last one appears to be pulling in almost anything other than specific language. if (textCount > 0) { context.Entry(det) .Collection(t => t.def_LookupText) .Query() .Where(t => t.langId == lang) .Load(); } else { context.Entry(det) .Collection(t => t.def_LookupText) .Load(); } } } } catch (SqlException sqlxcptn) { Debug.WriteLine("GetLookup Using SqlException: " + sqlxcptn.Message); } catch (Exception xcptn) { Debug.WriteLine("GetLookup Using Exception: " + xcptn.Message); } string jsonString = String.Empty; try { jsonString = fastJSON.JSON.ToJSON(master); } catch (Exception xcptn) { Debug.WriteLine("GetLookup fastJSON Exception: " + xcptn.Message); } Debug.WriteLine("GetLookup jsonString length: " + jsonString.Length); return(jsonString); }
/* * Returns a list of lookup details given the enterprise ID and Group ID. * These must be explicitly passed to ensure they have been intentionally set. * */ public List <def_LookupDetail> GetLookupDetails(string lkpCd, int ent, int grp) { def_LookupMaster lookupMaster = formsRepo.GetLookupMastersByLookupCode(lkpCd); return(formsRepo.GetLookupDetails(lookupMaster.lookupMasterId, ent, grp)); }
public string GetLookupADAP(string lkpCd) { Debug.WriteLine("GetLookup lkpCd: " + lkpCd); if (!SessionHelper.IsUserLoggedIn) { return("You are NOT logged in."); } Debug.WriteLine("GetLookup lkpCd: " + lkpCd + " Enterprise: " + SessionHelper.LoginStatus.EnterpriseID); // Get the Language for the User CultureInfo ci = Thread.CurrentThread.CurrentUICulture; string region = (ci == null) ? "en" : ci.TwoLetterISOLanguageName.ToLower(); int langId = DataContext.GetDbContext().def_Languages.Where(l => l.languageRegion.ToLower() == region).Select(l => l.langId).FirstOrDefault(); def_LookupMaster master = null; try { using (var context = DataContext.GetDbContext()) { context.Configuration.LazyLoadingEnabled = false; /* var query = context.def_LookupMaster * .Where(m => m.lookupCode == lkpCd) * .Select(m => new { m, det = m.def_LookupDetail.Where(d => ) }) */ master = (from i in context.def_LookupMaster where lkpCd == i.lookupCode select i).FirstOrDefault(); if (master != null) { //check if there are enterprise-specific lookups int entID = SessionHelper.LoginStatus.EnterpriseID; int detailCount = context.Entry(master) .Collection(m => m.def_LookupDetail) .Query() .Where(m => m.EnterpriseID == entID && m.StatusFlag == "A") .Count(); //if there are no enterprise-specific lookups, use ent 0 to retrieve defaults if (detailCount == 0) { entID = 0; detailCount = context.Entry(master) .Collection(m => m.def_LookupDetail) .Query() .Where(m => m.EnterpriseID == entID && m.StatusFlag == "A") .Count(); } if (detailCount > 0) { context.Entry(master) .Collection(m => m.def_LookupDetail) .Query() .Where(m => m.EnterpriseID == entID && m.StatusFlag == "A") .OrderBy(m => m.displayOrder) .Load(); } // Get the associated LookupText for each LookupDetail foreach (def_LookupDetail det in master.def_LookupDetail) { var textCount = context.Entry(det) .Collection(t => t.def_LookupText) .Query() .Where(t => t.langId == langId) .Count(); // *** RRB 2/1/16 *** // *** Like the SIS Lookup method above this is using 2 different types of query results // *** Figure out the correct one during Unit Testing // *** Since it is the final query, IQueryable isn't necessary if (textCount > 0) { context.Entry(det) .Collection(t => t.def_LookupText) .Query() .Where(t => t.langId == langId) .Load(); } else { context.Entry(det) .Collection(t => t.def_LookupText) .Load(); } } } } } catch (SqlException sqlxcptn) { Debug.WriteLine("GetLookup Using SqlException: " + sqlxcptn.Message); } catch (Exception xcptn) { Debug.WriteLine("GetLookup Using Exception: " + xcptn.Message); } string jsonString = String.Empty; if (master != null) { try { jsonString = fastJSON.JSON.ToJSON(master); } catch (Exception xcptn) { Debug.WriteLine("GetLookup fastJSON Exception: " + xcptn.Message); } } else { jsonString = "{\"def_BaseTypes\": null,\"def_LookupDetail\": [],\"lookupMasterId\": 0,\"lookupCode\": \"" + lkpCd + "\",\"title\": \"Duration of Power of Attorney (POA)\",\"baseTypeId\": 8}"; } Debug.WriteLine("GetLookup jsonString length: " + jsonString.Length); return(jsonString); }
/// <summary> /// Update lookup detail and lookup text records in the database (add them, update existing not currently supported --LK 11/4/2015) /// </summary> /// <param name="dataValues"></param> /// <param name="formsRepo"></param> private void UpdateLookups(int enterpriseId, string[] dataValues, IFormsRepository formsRepo) { int lookupDetailId; bool newDetail = false; def_LookupMaster lookupMaster = formsRepo.GetLookupMastersByLookupCode("ADAP_CLINIC"); if (lookupMaster == null) { throw new Exception("Cannot find lookup master: code ADAP_CLINIC"); } def_LookupDetail lookupDetail = null; // Display Choice (required) if (String.IsNullOrEmpty(dataValues[1])) { throw new Exception("Display Text is required field."); } // Display Order (required) if (String.IsNullOrEmpty(dataValues[0])) { throw new Exception("Display Order is required field. Missing for: " + dataValues[1]); } short langId = 0; // Check that language ID is valid (or empty) if (!Int16.TryParse(dataValues[2], out langId) || (langId != 1 && langId != 2)) { throw new Exception("Invalid language ID for: " + dataValues[1]); } // Try to find lookup detail by ID if (Int32.TryParse(dataValues[6], out lookupDetailId)) { lookupDetail = formsRepo.GetLookupDetailById(lookupDetailId); } if (lookupDetail == null && !String.IsNullOrEmpty(dataValues[5])) // find by data value { lookupDetail = formsRepo.GetLookupDetailByEnterpriseMasterAndDataValue(enterpriseId, lookupMaster.lookupMasterId, dataValues[5]); } if (lookupDetail == null && !String.IsNullOrEmpty(dataValues[1])) // find by display text and language { def_LookupText tempLookupText = formsRepo.GetLookupTextByDisplayTextEnterpriseIdMasterLang(dataValues[1], enterpriseId, lookupMaster.lookupMasterId, langId); if (tempLookupText != null) { lookupDetail = formsRepo.GetLookupDetailById(tempLookupText.lookupDetailId); } } if (lookupDetail == null) { lookupDetail = new def_LookupDetail(); newDetail = true; } lookupDetail.lookupMasterId = lookupMaster.lookupMasterId; // Set detail's display order int dispOrder = 0; if (!Int32.TryParse(dataValues[0], out dispOrder)) { throw new Exception("Display Order is not valid for: " + dataValues[1]); } else { lookupDetail.displayOrder = dispOrder; } // Set detail's status flag if (String.IsNullOrEmpty(dataValues[4])) { lookupDetail.StatusFlag = "A"; } else if (dataValues[4].ToUpper() == "A" || dataValues[4].ToLower() == "active") { lookupDetail.StatusFlag = "A"; } else if (dataValues[4].ToUpper() == "I" || dataValues[4].ToLower() == "inactive") { lookupDetail.StatusFlag = "I"; } else { throw new Exception("Invalid value in Status Flag field for " + dataValues[1]); } // Set detail's data value (if data value field in spread sheet is blank, use display choice field instead (which is required)) string dataValue = dataValues[5]; if (String.IsNullOrEmpty(dataValues[5])) { dataValue = dataValues[1]; } lookupDetail.dataValue = dataValue; lookupDetail.EnterpriseID = enterpriseId; int groupId = 0; if (Int32.TryParse(dataValues[3], out groupId)) { lookupDetail.GroupID = groupId; UASEntities uasEntities = new UASEntities(); uas_Group group = uasEntities.uas_Group.Where(g => g.GroupID == groupId && g.EnterpriseID == enterpriseId).FirstOrDefault(); if (group == null) { throw new Exception("Group with ID " + groupId + " does not exist for " + dataValues[1]); } } else { throw new Exception("Missing group ID for " + dataValues[1]); } if (newDetail) { // Add new lookup detail formsRepo.AddLookupDetail(lookupDetail); } else { // Update existing lookup detail formsRepo.SaveLookupDetail(lookupDetail); } def_LookupText lookupText = null; bool newLookupText = false; lookupText = formsRepo.GetLookupTextsByLookupDetailLanguage(lookupDetail.lookupDetailId, langId).FirstOrDefault(); if (lookupText == null) { lookupText = new def_LookupText(); newLookupText = true; } // Set Display Choice (required) lookupText.displayText = dataValues[1]; // Set Language if (String.IsNullOrEmpty(dataValues[2])) { throw new Exception("Language ID is a required field."); } else { // Language ID is either 1 (English) or 2 (Spanish), so use value lookupText.langId = langId; } // Set lookup detail ID to be for the associated lookup detail (either just saved/added) lookupText.lookupDetailId = lookupDetail.lookupDetailId; if (newLookupText) { // Add new lookup text formsRepo.AddLookupText(lookupText); } else { // Update the lookup text formsRepo.SaveLookupText(lookupText); } }
public bool UploadLookups(int enterpriseId, int userId, IFormsRepository formsRepo, string excelFileName) { def_LookupMaster lookupMaster = formsRepo.GetLookupMastersByLookupCode("ADAP_CLINIC"); if (lookupMaster == null) { throw new Exception("Cannot find lookup master: code ADAP_CLINIC"); } MarkAllLookupsInactive(lookupMaster.lookupMasterId, enterpriseId, formsRepo); int dataStartingRow = 7; Workbook workBook; SharedStringTable sharedStrings; IEnumerable <Sheet> workSheets; WorksheetPart recSheet; try { //Excel.Application xlApp; //Excel.Workbook xlWorkBook; //Excel.Worksheet xlWorkSheet; //Excel.Range range; //xlApp = new Excel.Application(); //xlWorkBook = xlApp.Workbooks.Open(excelFileName, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); //xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); //range = xlWorkSheet.UsedRange; //for (int rCnt = dataStartingRow; rCnt <= range.Rows.Count; rCnt++) //{ // // Create string array for row to pass to UpdateLookup function // string[] dataValues = new string[range.Columns.Count]; // int index = 0; // for (int cCnt = 1; cCnt <= range.Columns.Count; cCnt++) // { // string str = (range.Cells[rCnt, cCnt] as Excel.Range).Text.ToString(); // dataValues[index] = str; // index++; // } // if (arrayNotEmpty(dataValues)) // { // UpdateLookups(enterpriseId, dataValues, formsRepo); // } //} //xlWorkBook.Close(true, null, null); //xlApp.Quit(); //return true; //Declare helper variables. string recID; //Open the Excel workbook. using (SpreadsheetDocument document = SpreadsheetDocument.Open(excelFileName, true)) { //References to the workbook and Shared String Table. workBook = document.WorkbookPart.Workbook; workSheets = workBook.Descendants <Sheet>(); sharedStrings = document.WorkbookPart.SharedStringTablePart.SharedStringTable; //Reference to Excel Worksheet with Recipient data. //recID = workSheets.First(s => s.Name == strWorkSheetName).Id; recID = workSheets.First().Id; recSheet = (WorksheetPart)document.WorkbookPart.GetPartById(recID); //LINQ query to skip first row with column names. IEnumerable <Row> dataRows = from row in recSheet.Worksheet.Descendants <Row>() where row.RowIndex >= dataStartingRow select row; // Count the number of columns for headers. IEnumerable <Row> templateHeader = from row in recSheet.Worksheet.Descendants <Row>() where row.RowIndex == (dataStartingRow - 1) select row; int numCols = templateHeader.First().Count(); foreach (Row row in dataRows) { //If a column is missing from row, add an empty value IEnumerable <Cell> cells = from cell in row.Descendants <Cell>() select cell; int columnCounter = 0; List <string> dataValues = new List <string>(); foreach (var cell in cells) { string colReference = cell.CellReference; int colIndex = GetColumnIndexFromName(GetColumnName(colReference)); // if column index is higher than what it should be, add blank space to it until it matches up. if (columnCounter < colIndex) { for (int i = columnCounter; i < colIndex; i++) { dataValues.Add(""); } } string cellValue = string.Empty; if ((cell.DataType != null) && (cell.DataType == CellValues.SharedString)) { int id = -1; if (Int32.TryParse(cell.InnerText, out id)) { SharedStringItem item = GetSharedStringItemById(document.WorkbookPart, id); if (item.Text != null) { cellValue = item.Text.Text; } else if (item.InnerText != null) { cellValue = item.InnerText; } else if (item.InnerXml != null) { cellValue = item.InnerXml; } } } else if (cell.CellValue != null) { cellValue = cell.CellValue.InnerText; } dataValues.Add(cellValue); columnCounter = colIndex + 1; } if (dataValues.Count() < numCols) { for (int i = dataValues.Count(); i < numCols; i++) { dataValues.Add(""); } } else if (dataValues.Count() > numCols) { // if dataValues is more than number of column headers, delete the last data for (int i = dataValues.Count(); i > numCols; i--) { dataValues.RemoveAt(i - 1); } } if (arrayNotEmpty(dataValues.ToArray())) { UpdateLookups(enterpriseId, dataValues.ToArray(), formsRepo); } else { break; } } document.Close(); } return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex; return(false); } }
public void DeleteLookupMaster(def_LookupMaster lkpMstr) { db.def_LookupMaster.Remove(lkpMstr); db.SaveChanges(); }
/// <summary> /// Process a single node from an XML improted from Ramsell, modifying the specified formResult as applicable. /// Noramlly this will only be called from within a loop to iterate over xml nodes, however this function will recurse to handle Ramsell's "income" structures /// </summary> /// <param name="fromReader">XmlReader where Read() has already been called</param> /// <param name="checkedBoxes">this should ba appended to with itemVariable identifiers for each checked checkbox. Used to uncheck excluded boxes at the end of the import</param> /// <param name="specialCaseValuesByTagname">this will be used to run special-case transformations that may involve multiple ramsell tags</param> private void ImportXmlNodeFromRamsell( XmlReader fromReader, List <string> checkedBoxes, Dictionary <string, string> specialCaseValuesByTagname) { if (fromReader.NodeType != XmlNodeType.Element) { throw new Exception("Expecting NodeType \"" + XmlNodeType.Element + "\", found \"" + fromReader.NodeType + "\""); } string ramellTagName = fromReader.Name; //the "Income_Item" tag is a one-off structure with multiple occurances if (ramellTagName == "Income_Item") { ImportIncomeStructureFromRamsell(fromReader); return; } //get the nodes contents string ramsellVal = String.Empty; if (!fromReader.IsEmptyElement) { fromReader.Read(); if (fromReader.NodeType == XmlNodeType.EndElement) { return; } if (fromReader.NodeType != XmlNodeType.Text) { throw new Exception("Inside of node \"" + ramellTagName + "\", found NodeType \"" + fromReader.NodeType + "\", expecting NodeType \"" + XmlNodeType.Text + "\", or \"" + XmlNodeType.EndElement + "\""); } ramsellVal = fromReader.Value; } //based on tagName, check if this a simple case (no transformation necessary) List <string> ivIdentifiers = RamsellExport.GetItemVariableIdentifiersForRamsellTagName(ramellTagName); if (ivIdentifiers.Count == 1) { //one-to-one case: this ramsell tagName corresponds with exactly one itemVariable //so just save the text contents as a response to that itemVariable // RRB 4/18/16 Ramsell seems to be sending a default date of 1900-01-01 // This should be tested more. If doesn't fix, maybe our date converter is causing an empty DOB to be this date. if (ramellTagName.Equals("DOB") && (string.IsNullOrEmpty(ramsellVal) || ramsellVal.StartsWith("1900"))) { ; } else { UpdateResponse(ivIdentifiers[0], ramsellVal); } } else if (ivIdentifiers.Count > 1) { //checkbox case: this ramsell tagName corresponds to a set of itemVariables (representing checkboxes in the application) //so pick the checkbox based on this node's text contents, and save the response "1" for that checkbox #region checkbox case //based on lookups, pick the inidividual itemvariable (matchIv) that matches the node contents (ramsellVal) def_ItemVariables matchIv = null; foreach (string ivIdent in ivIdentifiers) { def_ItemVariables iv = formsRepo.GetItemVariableByIdentifier(ivIdent); if (iv.baseTypeId == 1) { def_LookupMaster lm = formsRepo.GetLookupMastersByLookupCode(iv.identifier); if (lm != null) { List <def_LookupDetail> ld = formsRepo.GetLookupDetailsByLookupMasterEnterprise(lm.lookupMasterId, SessionHelper.LoginStatus.EnterpriseID); if (ld.Where(ldt => ramsellVal == ldt.dataValue).Any()) { matchIv = iv; break; } } } } //save the respones "1" to the single matched itemVariable, and add it to the "checkedBoxes" list //at the end of the import, any grouped checkboxes that haven't been added to that list will be unchecked if (matchIv == null) { Debug.WriteLine("* * * RamsellImport: Could not find matching itemVariable for ramsell tag/value \"" + ramellTagName + "/" + ramsellVal + "\", skipping..."); } else { def_ItemResults ir = userData.SaveItemResult(toFormResultId, matchIv.itemId); userData.SaveResponseVariable(ir, matchIv, "1"); checkedBoxes.Add(matchIv.identifier); } #endregion } else { //this tagname must be either ignorable or handled by a special one-off transformation, //so just record the tagname/value pair to be handled later on. //the special-cases can involve multiple ramsell tags so there is no way to handle them one tag at a time. specialCaseValuesByTagname.Add(ramellTagName, ramsellVal); } }