private async void StartAssessmentClicked() { _commonDataService.DOB = DOB; _commonDataService.IsAcademicForm = false; _commonDataService.IsScreenerForm = false; _commonDataService.IsCompleteForm = false; if (PopupNavigation.Instance.PopupStack != null && PopupNavigation.Instance.PopupStack.Count == 1) { await PopupNavigation.Instance.PopAsync(false); } UserDialogs.Instance.ShowLoading("Loading..."); await Task.Delay(300); var clinicalTestForm = new StudentTestFormOverview { LocalStudentId = OfflineStudentId, assessmentId = IsBattelleDevelopmentalCompleteChecked ? AssignmentTypes.BattelleDevelopmentalCompleteID : IsBattelleDevelopmentalScreenerChecked ? AssignmentTypes.BattelleDevelopmentalScreenerID : AssignmentTypes.BattelleDevelopmentalAcademicSurveyID }; int.TryParse(Application.Current.Properties["UserID"].ToString(), out var addedBy); clinicalTestForm.createdByUserId = addedBy; clinicalTestForm.createDate = DateTime.Now; var label = ProgramNote == "Select a program label" ? null : ProgramNote; var labelId = label != null?_commonDataService.ProgramNoteModels.FirstOrDefault(p => p.LabelName == ProgramNote)?.LabelId : null; clinicalTestForm.FormStatus = "Not started"; DateTime dateTime; DateTime.TryParse(TestDate, out dateTime); clinicalTestForm.formParameters = JsonConvert.SerializeObject( new FormParamterClass() { ProgramLabelId = labelId, TestDate = dateTime, }); clinicalTestFormService.InsertTestForm(clinicalTestForm); _commonDataService.StudentTestFormOverview = clinicalTestForm; LocalTestFormID = clinicalTestForm.LocalTestRecodId; var contentBaseCeiling = _commonDataService.ContentBasalCeilings; if (IsBattelleEarlyAcademicSurveyChecked) { var academicCategories = _commonDataService.AcademicCategories; if (academicCategories != null && academicCategories.Any()) { var lstStudentTestForms = new List <StudentTestForms>(); var parentCategories = _commonDataService.AcademicCategories.Where(p => p.parentContentCategoryId == 0).ToList(); foreach (var parentCategory in parentCategories) { var childCategory = _commonDataService.AcademicCategories.Where(p => p.parentContentCategoryId == parentCategory.contentCategoryId); if (childCategory != null && childCategory.Any()) { foreach (var item in childCategory) { var studentTestForms = new StudentTestForms { TSOStatus = "Not Started", LocalformInstanceId = LocalTestFormID, testDate = TestDate, examinerId = Convert.ToInt32(_commonDataService.SearchStaffResponseModel.FirstOrDefault(p => p.FirstNameLastName == Examiner)?.UserID), contentCategoryId = item.contentCategoryId, createDate = DateTime.Now, BaselCeilingReached = contentBaseCeiling.FirstOrDefault(p => p.contentCategoryId == item.contentCategoryId) == null, IsBaselCeilingApplied = contentBaseCeiling.FirstOrDefault(p => p.contentCategoryId == item.contentCategoryId) != null, }; var childchildCategory = _commonDataService.AcademicCategories.Where(p => p.parentContentCategoryId == item.contentCategoryId); if (childchildCategory != null && childchildCategory.Any()) { foreach (var childitem in childchildCategory) { var childitemstudentTestForms = new StudentTestForms { TSOStatus = "Not Started", LocalformInstanceId = LocalTestFormID, testDate = TestDate, examinerId = Convert.ToInt32(_commonDataService.SearchStaffResponseModel.FirstOrDefault(p => p.FirstNameLastName == Examiner)?.UserID), contentCategoryId = childitem.contentCategoryId, createDate = DateTime.Now, BaselCeilingReached = contentBaseCeiling.FirstOrDefault(p => p.contentCategoryId == childitem.contentCategoryId) == null, IsBaselCeilingApplied = contentBaseCeiling.FirstOrDefault(p => p.contentCategoryId == childitem.contentCategoryId) != null, }; lstStudentTestForms.Add(childitemstudentTestForms); } } else { lstStudentTestForms.Add(studentTestForms); } } } else { var studentTestForms = new StudentTestForms { TSOStatus = "Not Started", LocalformInstanceId = LocalTestFormID, testDate = TestDate, examinerId = Convert.ToInt32(_commonDataService.SearchStaffResponseModel.FirstOrDefault(p => p.FirstNameLastName == Examiner)?.UserID), contentCategoryId = parentCategory.contentCategoryId, createDate = DateTime.Now }; lstStudentTestForms.Add(studentTestForms); } } studentTestFormsService.DeleteAll(LocalTestFormID); studentTestFormsService.InsertAll(lstStudentTestForms); _commonDataService.LocaInstanceID = LocalTestFormID; _commonDataService.StudentTestForms = new List <StudentTestForms>(lstStudentTestForms); _commonDataService.IsAcademicForm = true; var navigationParams = new AdminstrationNavigationParams { LocalInstanceID = LocalTestFormID, DOB = DOB, TestDate = TestDate, FullName = FullName, OfflineStudentID = OfflineStudentId, IsDevelopmentCompleteForm = false }; await Application.Current.MainPage.Navigation.PushModalAsync(new AcademicformWithMatAndItems(navigationParams)); _commonDataService.ClearAddChildContent?.Invoke(); } } if ((IsBattelleDevelopmentalCompleteChecked && !string.IsNullOrEmpty(Examiner)) || (IsBattelleDevelopmentalScreenerChecked && !string.IsNullOrEmpty(Examiner))) { var totalCategories = IsBattelleDevelopmentalScreenerChecked ? _commonDataService.ScreenerCategories : _commonDataService.BattleCategories.Where(p => p.contentCategoryLevelId == 2).ToList(); if (totalCategories != null && totalCategories.Any()) { var lstStudentTestForms = new List <StudentTestForms>(); foreach (var item in totalCategories) { if (IsBattelleDevelopmentalScreenerChecked) { _commonDataService.IsScreenerForm = true; } else if (IsBattelleDevelopmentalCompleteChecked) { _commonDataService.IsCompleteForm = true; } var studentTestForms = new StudentTestForms { TSOStatus = "Not Started", LocalformInstanceId = LocalTestFormID, testDate = TestDate, examinerId = Convert.ToInt32(_commonDataService.SearchStaffResponseModel .FirstOrDefault(p => p.FirstNameLastName == Examiner)?.UserID), contentCategoryId = item.contentCategoryId, createDate = DateTime.Now, BaselCeilingReached = contentBaseCeiling.FirstOrDefault(p => p.contentCategoryId == item.contentCategoryId) == null, IsBaselCeilingApplied = true // contentBaseCeiling.FirstOrDefault(p => p.contentCategoryId == item.contentCategoryId) != null, }; lstStudentTestForms.Add(studentTestForms); } studentTestFormsService.DeleteAll(LocalTestFormID); studentTestFormsService.InsertAll(lstStudentTestForms); _commonDataService.LocaInstanceID = LocalTestFormID; _commonDataService.StudentTestForms = new List <StudentTestForms>(lstStudentTestForms); } var navigationParams = new AdminstrationNavigationParams { LocalInstanceID = LocalTestFormID, DOB = DOB, TestDate = TestDate, FullName = FullName, OfflineStudentID = OfflineStudentId, IsDevelopmentCompleteForm = IsBattelleDevelopmentalCompleteChecked }; _commonDataService.ClearAddChildContent?.Invoke(); await Application.Current.MainPage.Navigation.PushModalAsync(new AdministrationView(navigationParams)); } }
public async Task CommitTestRecord() { await PopupNavigation.Instance.PopAllAsync(); UserDialogs.Instance.ShowLoading("Loading..."); await Task.Delay(300); var username = Convert.ToString(Application.Current.Properties["UserName"]); var password = Convert.ToString(Application.Current.Properties["PassID"]); try { var response = await new BDIWebServices().LoginUser(new { username = username.Trim(), password = password.Trim() }); if (response != null) { if (!string.IsNullOrEmpty(response.StatusCode)) { UserDialogs.Instance.HideLoading(); await UserDialogs.Instance.AlertAsync("Sync Failed!"); return; } } } catch (Exception ex) { UserDialogs.Instance.HideLoading(); if (!string.IsNullOrEmpty(ex.Message) && ex.Message == "User Don't have BDI product") { await UserDialogs.Instance.AlertAsync("You Don't have BDI product access. Please contact Admin"); } else { await UserDialogs.Instance.AlertAsync("Sync Failed!"); } return; } UserDialogs.Instance.HideLoading(); UserDialogs.Instance.ShowLoading("Syncing Data to server..."); var lstStudents = new List <Students>(); var selectedRecords = new List <ChildInformationRecord>(); if (!isIndividual) { selectedRecords = ChildInformationRecords.Where(p => p.IsSelect).ToList(); } else { selectedRecords = new List <ChildInformationRecord>(); selectedRecords.Add(SelectedRecord); } if (selectedRecords != null && selectedRecords.Any()) { var groupedRecords = selectedRecords; if (groupedRecords != null && groupedRecords.Any()) { var lstSync = new List <SyncChild>(); var orgID = Convert.ToInt32(Application.Current.Properties["OrgnazationID"]); var researchCodes = productResearchCodesService.GetResearchCodesByOrg(orgID); var localStudent = _studentService.GetStudentById(OfflineStudentId); var researchCodesValues = productResearchCodeValuesService.GetProductResearchCodes(OfflineStudentId); var syncChild = new SyncChild(); int addedBy; var isSuccess = int.TryParse(Application.Current.Properties["UserID"].ToString(), out addedBy); if (localStudent != null) { lstStudents.Add(localStudent); localStudent.LocalTestFormIds = string.Join(",", selectedRecords.ToList().Select(p => p.LocalTestInstance)); var data = localStudent; var userRecord = userservice.GetUserByID(addedBy); syncChild.DeviceId = userRecord.DeviceId; lstSync.Add(syncChild); syncChild.SkipUpdate = localStudent.IsSynced; syncChild.LocalChildUserId = data.OfflineStudentID; syncChild.ChildId = data.ChildID; if (!string.IsNullOrEmpty(data.UserId)) { syncChild.UserId = Convert.ToInt32(data.UserId); } syncChild.OrganizationId = orgID; syncChild.DateOfBirth = data.Birthdate.Month + "/" + data.Birthdate.Day + "/" + data.Birthdate.Year; syncChild.EnrollmentDate = data.EnrollmentDate == DateTime.MinValue ? null : data.EnrollmentDate.Month + "/" + data.EnrollmentDate.Day + "/" + data.EnrollmentDate.Year; if (!string.IsNullOrEmpty(data.SelectedEthnictyIds)) { syncChild.EthnicityId = Convert.ToInt32(data.SelectedEthnictyIds); } syncChild.FirstName = data.FirstName; syncChild.LastName = data.LastName; syncChild.MiddleName = data.MiddleName; syncChild.ParentGuardianEmail1 = data.ParentEmailAddress1; syncChild.ParentGuardianEmail2 = data.ParentEmailAddress2; syncChild.ParentGuardianName1 = data.ParentGuardian1; syncChild.ParentGuardianName2 = data.ParentGuardian2; if (!string.IsNullOrEmpty(data.SelectedLanguageIds)) { syncChild.PrimaryLanguageId = Convert.ToInt32(data.SelectedLanguageIds); } if (!string.IsNullOrEmpty(data.SelectedRaceIds)) { syncChild.RaceIds = data.SelectedRaceIds.Split(',').Select(p => Convert.ToInt32(p)).ToList(); } syncChild.FreeLunch = Convert.ToBoolean(data.IsFreeLunch); if (!string.IsNullOrEmpty(data.SelectedFundingSourceIds)) { syncChild.FundingResourceIds = data.SelectedFundingSourceIds.Split(',').Select(p => Convert.ToInt32(p)).ToList(); } syncChild.GenderId = data.Gender; syncChild.Iep = Convert.ToBoolean(data.IsIEP); syncChild.Ifsp = Convert.ToBoolean(data.IsIFSP); syncChild.LocationId = data.SelectedLocationId.Value; syncChild.CreatedDate = data.updatedOn; syncChild.researchCodeNames = new List <SyncResearchCodeName>(); syncChild.ResearchCodeValues = new List <SyncResearchCodeValue>(); if (Convert.ToBoolean(data.IsIEP)) { syncChild.IepEligibilityDate = data.IEPEligibilityDate == DateTime.MinValue ? null : data.IEPEligibilityDate.Month + "/" + data.IEPEligibilityDate.Day + "/" + data.IEPEligibilityDate.Year; syncChild.IepExitDate = data.IEPExitDate == DateTime.MinValue ? null : data.IEPExitDate.Month + "/" + data.IEPExitDate.Day + "/" + data.IEPExitDate.Year; } if (Convert.ToBoolean(data.IsIFSP)) { syncChild.IfspEligibilityDate = data.IFSPEligibilityDate == DateTime.MinValue ? null : data.IFSPEligibilityDate.Month + "/" + data.IFSPEligibilityDate.Day + "/" + data.IFSPEligibilityDate.Year; syncChild.IfspExitDate = data.IFSPExitDate == DateTime.MinValue ? null : data.IFSPExitDate.Month + "/" + data.IFSPExitDate.Day + "/" + data.IFSPExitDate.Year; } if (Convert.ToBoolean(data.IsIEP) || Convert.ToBoolean(data.IsIFSP)) { if (!string.IsNullOrEmpty(data.SelectedPrimaryDiagnosesIds)) { syncChild.PrimaryDiagnosesId = Convert.ToInt32(data.SelectedPrimaryDiagnosesIds); } if (!string.IsNullOrEmpty(data.SelectedSecondaryDiagnosesIds)) { syncChild.SecondaryDiagnosesId = Convert.ToInt32(data.SelectedSecondaryDiagnosesIds); } } foreach (var codes in researchCodes) { syncChild.researchCodeNames.Add(new SyncResearchCodeName() { Name = codes.ValueName, ResearchCodeId = codes.ResearchCodeId }); } foreach (var codevalues in researchCodesValues) { syncChild.ResearchCodeValues.Add(new SyncResearchCodeValue() { ResearchCodeId = codevalues.ResearchCodeId, ResearchCodeValueId = codevalues.ResearchCodeValueId, Value = codevalues.value }); } } syncChild.TestRecords = new List <SyncTestRecord>(); foreach (var inneritem in selectedRecords) { var testRecord = clinicalTestFormService.GetStudentTestFormsByID(inneritem.LocalTestInstance); if (testRecord != null) { var newSyncTestRecord = new SyncTestRecord(); syncChild.TestRecords.Add(newSyncTestRecord); newSyncTestRecord.AdditionalNotes = testRecord.additionalNotes; newSyncTestRecord.Notes = testRecord.notes; newSyncTestRecord.AssessmentId = testRecord.assessmentId; newSyncTestRecord.CreateDate = Convert.ToString(testRecord.createDate.Value); newSyncTestRecord.CreatedByUserId = addedBy; newSyncTestRecord.FormParameters = testRecord.formParameters; newSyncTestRecord.LocalFormInstanceId = testRecord.LocalTestRecodId; newSyncTestRecord.ContentCategories = new List <SyncContentCategory>(); var records = studentTestFormsService.GetStudentTestForms(testRecord.LocalTestRecodId); if (records != null && records.Any()) { foreach (var record in records) { var newContentCatgory = new SyncContentCategory(); newContentCatgory.ContentCategoryId = record.contentCategoryId; newContentCatgory.CreateDate = Convert.ToString(record.createDate.Value); newContentCatgory.ExaminerId = record.examinerId.Value; newContentCatgory.Order = commonDataService.TotalCategories.FirstOrDefault(p => p.contentCategoryId == record.contentCategoryId).sequenceNo; newContentCatgory.Notes = record.Notes; newContentCatgory.TimeTaken = record.TimeTaken; newContentCatgory.RawScore = record.rawScore; newContentCatgory.ItemScore = record.rawScoreEnabled ? 0 : 1; newContentCatgory.Status = record.TSOStatus == "Saved" ? 1 : 0; newContentCatgory.AgeInMonths = CalculateAgeDiff(lstStudents.FirstOrDefault().Birthdate); newContentCatgory.TestDate = record.testDate; var testformResponse = studentTestFormResponsesService.GetStudentTestFormResponses(testRecord.LocalTestRecodId); var itemResponse = testformResponse.FirstOrDefault(p => p.ContentCategoryId == record.contentCategoryId); if (itemResponse != null) { newContentCatgory.ItemLevelResponse = new SyncItemLevelResponse(); newContentCatgory.ItemLevelResponse.CreatedBy = addedBy; newContentCatgory.ItemLevelResponse.SectionId = JsonConvert.DeserializeObject <FormJsonClass>(newSyncTestRecord.FormParameters).sectionId; newContentCatgory.ItemLevelResponse.Response = itemResponse.Response; newContentCatgory.ItemLevelResponse.CreatedOn = Convert.ToString(itemResponse.CreatedOn.Value); newSyncTestRecord.ContentCategories.Add(newContentCatgory); } } } } } if (lstSync != null && lstSync.Any()) { var response = await new BDIWebServices().SyncTestRecords(lstSync, ShowError); if (response != null && response.Any()) { foreach (var item in response) { if (item.StatusCode == SyncTestRecordStatusCode.Success) { clinicalTestFormService.DeleteTestFormByLocalID(item.LocalFormInstanceId); studentTestFormsService.DeleteAll(item.LocalFormInstanceId); studentTestFormResponsesService.DeleteAll(item.LocalFormInstanceId); if (lstStudents.Any(p => p.LocalTestFormIds.Split(',').Contains(item.LocalFormInstanceId + ""))) { var student = lstStudents.FirstOrDefault(p => p.LocalTestFormIds.Split(',').Contains(item.LocalFormInstanceId + "")); if (student != null && string.IsNullOrEmpty(student.UserId)) { student.UserId = item.ChildUserId.Value.ToString(); student.updatedOn = DateTime.Now.ToUniversalTime().ToString(); student.updatedOnUTC = DateTime.Now.ToUniversalTime().ToString(); _studentService.Update(student); } } if (item.ResearchCodeValues != null && item.ResearchCodeValues.Any()) { var student = lstStudents.FirstOrDefault(p => p.LocalTestFormIds.Split(',').Contains(item.LocalFormInstanceId + "")); var localCodeValues = productResearchCodeValuesService.GetProductResearchCodes(student.OfflineStudentID); var lstResearchCodeValues = new List <ProductResearchCodeValues>(); foreach (var innerItem in localCodeValues) { innerItem.ResearchCodeValueId = item.ResearchCodeValues.FirstOrDefault(p => p.ResearchCodeId == innerItem.ResearchCodeId).ResearchCodeValueId; } productResearchCodeValuesService.DeleteByStudentId(item.LocalChildUserId); productResearchCodeValuesService.InsertAll(localCodeValues); } } else { if (lstStudents.Any(p => p.LocalTestFormIds.Split(',').Contains(item.LocalFormInstanceId + ""))) { var student = lstStudents.FirstOrDefault(p => p.LocalTestFormIds.Split(',').Contains(item.LocalFormInstanceId + "")); if (item.ChildUserId.HasValue) { if (student != null && string.IsNullOrEmpty(student.UserId)) { student.UserId = item.ChildUserId.Value.ToString(); student.updatedOn = DateTime.Now.ToUniversalTime().ToString(); student.updatedOnUTC = DateTime.Now.ToUniversalTime().ToString(); _studentService.Update(student); } } } if (item.ResearchCodeValues != null && item.ResearchCodeValues.Any() && item.ChildUserId.HasValue) { var student = lstStudents.FirstOrDefault(p => p.LocalTestFormIds.Split(',').Contains(item.LocalFormInstanceId + "")); var localCodeValues = productResearchCodeValuesService.GetProductResearchCodes(student.OfflineStudentID); var lstResearchCodeValues = new List <ProductResearchCodeValues>(); foreach (var innerItem in localCodeValues) { innerItem.ResearchCodeValueId = item.ResearchCodeValues.FirstOrDefault(p => p.ResearchCodeId == innerItem.ResearchCodeId).ResearchCodeValueId; } productResearchCodeValuesService.DeleteByStudentId(item.LocalChildUserId); productResearchCodeValuesService.InsertAll(localCodeValues); } clinicalTestFormService.UpdateSyncStatus((int)item.StatusCode, item.LocalFormInstanceId); } } LoadTestRecordsFromDB(OfflineStudentId); UserDialogs.Instance.HideLoading(); } } } } }