feat: cms users institution department manager

This commit is contained in:
2026-06-11 10:37:29 +08:00
parent 1dc9141856
commit 32915bc6b4
39 changed files with 2403 additions and 75 deletions
+21 -21
View File
@@ -69,16 +69,13 @@ class InstitutionInfoTest(CacheTestCase):
class MyDepartmentsTest(CacheTestCase):
"""所属机构科室列表接口(不分页)。"""
def test_returns_all_departments_no_pagination(self):
"""返回本机构全部科室,且不分页(直接为列表)。"""
inst = ensure_institution(name='测试医院', code='TEST-HOSP-001')
Department.objects.create(institution=inst, name='', category='临床')
Department.objects.create(institution=inst, name='', category='临床')
# 另一机构的科室不应出现
other = ensure_institution(name='其他医院', code='TEST-HOSP-OTHER')
Department.objects.create(institution=other, name='儿科', category='临床')
def test_returns_all_global_departments_no_pagination(self):
"""返回全部全局科室(与机构无关),不分页(直接为列表)。"""
Department.objects.create(name='内科', category='临床')
Department.objects.create(name='', category='临床')
Department.objects.create(name='', category='临床')
user = create_test_user(phone='13900200010', institution=inst)
user = create_test_user(phone='13900200010')
client = get_auth_client(user)
resp = client.get(USER_MY_DEPARTMENTS_URL)
self.assertEqual(resp.status_code, 200, resp.content)
@@ -86,13 +83,16 @@ class MyDepartmentsTest(CacheTestCase):
data = resp.json()
self.assertIsInstance(data, list) # 不分页:顶层是列表
names = {d['name'] for d in data}
self.assertEqual(names, {'内科', '外科'})
self.assertEqual(names, {'内科', '外科', '儿科'})
def test_user_without_institution_404(self):
def test_no_institution_still_returns_departments(self):
"""科室全局,用户没机构也能拿到全部科室。"""
Department.objects.create(name='内科', category='临床')
user = create_test_user(phone='13900200011', institution=None)
client = get_auth_client(user)
resp = client.get(USER_MY_DEPARTMENTS_URL)
self.assertEqual(resp.status_code, 404, resp.content)
self.assertEqual(resp.status_code, 200, resp.content)
self.assertEqual({d['name'] for d in resp.json()}, {'内科'})
class ProfileConfigTest(CacheTestCase):
@@ -101,7 +101,7 @@ class ProfileConfigTest(CacheTestCase):
def test_config_success(self):
"""录入 科室/职称/执业年限 → 落库成功。"""
inst = ensure_institution(name='测试医院', code='TEST-HOSP-001')
dept = Department.objects.create(institution=inst, name='内科', category='临床')
dept = Department.objects.create(name='内科', category='临床')
user = create_test_user(phone='13900200020', institution=inst)
client = get_auth_client(user)
@@ -118,20 +118,20 @@ class ProfileConfigTest(CacheTestCase):
self.assertEqual(user.practice_years, '1-3年')
self.assertEqual(resp.json()['user']['practice_years'], '1-3年')
def test_department_from_other_institution_rejected(self):
"""所选科室不属于本机构 → 校验失败 400"""
inst = ensure_institution(name='测试医院', code='TEST-HOSP-001')
other = ensure_institution(name='其他医院', code='TEST-HOSP-OTHER')
other_dept = Department.objects.create(institution=other, name='外科', category='临床')
user = create_test_user(phone='13900200021', institution=inst)
def test_any_global_department_accepted(self):
"""科室全局:可选择任意科室(不再校验机构归属)"""
dept = Department.objects.create(name='外科', category='临床')
user = create_test_user(phone='13900200021', institution=None)
client = get_auth_client(user)
resp = client.post(USER_PROFILE_CONFIG_URL, {
'department': other_dept.id,
'department': dept.id,
'title_name': '住院医师',
'practice_years': '1-3年',
})
self.assertEqual(resp.status_code, 400, resp.content)
self.assertEqual(resp.status_code, 200, resp.content)
user.refresh_from_db()
self.assertEqual(user.department_id, dept.id)
def test_missing_fields_rejected(self):
"""缺少必填字段 → 400。"""