public List <DepartmentListItem> GetDepartmentListForRuleSetId(long hospitalId, Guid ruleSetId, Guid SecurityToken) { if (ruleSetId == null || ruleSetId == Guid.Empty) { throw new UserInputValidationException("RuleSetId cant't be null or empty"); } var departmentList = m_orgService.GetDepartmentListByHospitalId(hospitalId, SecurityToken); var ruleSet = GetRuleSetById(ruleSetId); if (ruleSet.ExcludeOrgUnits?.Count == 0) { return(departmentList); } var newDepartmentList = new List <DepartmentListItem>(); foreach (var dep in departmentList) { bool isAvailable = false; foreach (var _ in ruleSet.ExcludeOrgUnits.Where(unit => dep.UnitGid == unit.UnitID).Select(unit => new { })) { isAvailable = true; } if (!isAvailable) { newDepartmentList.Add(dep); } } return(newDepartmentList); }
public ActionResult GetDepartmentsForHospital() { try { m_log.Info($"orgunit/departmentList endpoint called with hospital Id - {m_user.HospitalId}"); var deparmentResponse = m_orgUnitsService.GetDepartmentListByHospitalId(m_user.HospitalId, m_user.SecurityToken); return(Ok(deparmentResponse)); } catch (Exception e) { var ErrorMessage = " Exception thrown at GetDepartmentsForHospital for the hospital Id =" + m_user.HospitalId; m_log.ErrorException(ErrorMessage, e); throw; } }
public List <DepartmentNode> GenerateOverviewTree(bool getInactive, long hospitalId, Guid SecurityToken) { var isActive = !getInactive; var departments = m_orgService.GetDepartmentListByHospitalId(hospitalId, SecurityToken); var departmentNodes = new List <DepartmentNode>(); var textTemplates = m_textTemplateService.GetFullSMSTextTemplatesFor(isActive, hospitalId); // Global ---> Ruleset.Deptid is null AND Template.Deptid is null var templatesForGlobalSchedules = textTemplates.Where(t => (t.DepartmentId == null && t.TemplateDepartmentId == null)).ToList(); var globalRuleSetNodes = GroupByRSAndGetNodes(templatesForGlobalSchedules, true, hospitalId, SecurityToken); foreach (var department in departments) { //Department Schedules ---> Ruleset.DeptId = deptid OR Template.Deptid = deptid var deptTempalts = textTemplates.Where(t => (t.DepartmentId == department.DepartmentId || t.TemplateDepartmentId == department.DepartmentId)).ToList(); //var scheduleNodes = new List<RuleSetNode>(); var scheduleNodes = GroupByRSAndGetNodes(deptTempalts, false, hospitalId, SecurityToken); //Remove global ruleset if it has excluded the same department considering here. var filteredGlobalRuleSets = new List <RuleSetNode>(); foreach (var globalRuleSet in globalRuleSetNodes) { if (globalRuleSet.ExcludedOrgUnitNames != null && globalRuleSet.ExcludedOrgUnitNames.Any()) { if (!globalRuleSet.ExcludedOrgUnitNames.Any(c => c == department.UnitGid)) { filteredGlobalRuleSets.Add(globalRuleSet); } } else { filteredGlobalRuleSets.Add(globalRuleSet); } } //Add global schedules/templates into all the departments scheduleNodes.AddRange(filteredGlobalRuleSets); if (scheduleNodes.Count == scheduleNodes.Select(i => i.RuleSetId).Distinct().Count()) { var depNode = new DepartmentNode { Name = department.DepartmentName, Id = department.DepartmentId, Schedules = scheduleNodes }; departmentNodes.Add(depNode); } else { var depNode = new DepartmentNode { Name = department.DepartmentName, Id = department.DepartmentId, Schedules = GetDistinctRuleSetNode(scheduleNodes) }; departmentNodes.Add(depNode); } } return(departmentNodes); }