feat: add profile and defalt hospital

This commit is contained in:
2026-06-18 15:21:09 +08:00
parent d92efed6ae
commit e1a5ca2afa
5 changed files with 28 additions and 11 deletions
+3
View File
@@ -282,9 +282,12 @@ def hospital_overview(request):
profile = {
'institution_id': inst_id,
'code': inst.code if inst else '',
'name': inst.name if inst else '',
'logo': _build_banner_url(request, inst.banner_url) if inst else '', # 完整 URL(含 STATIC_PUBLIC_PREFIX
'level': inst.level if inst else '',
'province': inst.province if inst else '',
'city': inst.city if inst else '',
'cooperation_days': (now - inst.created_at).days if inst and inst.created_at else None,
}
+10 -1
View File
@@ -25,7 +25,16 @@ class CmsInstitutionSerializer(serializers.ModelSerializer):
'id', 'code', 'name', 'type', 'level',
'province', 'city', 'banner_url', 'created_at', 'updated_at',
]
read_only_fields = ['id', 'created_at', 'updated_at']
# type 不可编辑:新增/编辑均不接收,存库恒为 hospital(见 create/update
read_only_fields = ['id', 'type', 'created_at', 'updated_at']
def create(self, validated_data):
validated_data['type'] = 'hospital'
return super().create(validated_data)
def update(self, instance, validated_data):
validated_data['type'] = 'hospital' # 每次保存都归一为 hospital
return super().update(instance, validated_data)
def to_representation(self, instance):
data = super().to_representation(instance)
+3 -3
View File
@@ -18,7 +18,7 @@ from .serializers import CmsInstitutionSerializer, CmsDepartmentSerializer
ALLOWED_BANNER_EXT = ('.png', '.jpg', '.jpeg', '.webp')
MAX_BANNER_BYTES = 5 * 1024 * 1024 # 5MB
INST_IMPORT_HEADERS = ['机构编码', '名称', '类型', '等级', '', '']
INST_IMPORT_HEADERS = ['机构编码', '名称', '等级', '', '']
INST_EXPORT_HEADERS = ['ID', '机构编码', '名称', '类型', '等级', '', '']
DEPT_IMPORT_HEADERS = ['科室名称', '分类']
DEPT_EXPORT_HEADERS = ['ID', '科室名称', '分类']
@@ -135,7 +135,7 @@ class CmsInstitutionViewSet(viewsets.ModelViewSet):
@action(detail=False, methods=['post'], url_path='import',
parser_classes=[MultiPartParser, FormParser])
def import_institutions(self, request):
"""Excel 批量导入机构。列:机构编码 | 名称 | 类型 | 等级 | 省 | 市。"""
"""Excel 批量导入机构。列:机构编码 | 名称 | 等级 | 省 | 市(类型固定 hospital,不在表内)"""
file = request.FILES.get('file')
if not file:
raise AppError('CMS_IMPORT_FILE_REQUIRED', '请上传 .xlsx 文件(字段名 file)', status_code=400)
@@ -157,7 +157,7 @@ class CmsInstitutionViewSet(viewsets.ModelViewSet):
errors.append({'row': idx, 'reason': f'机构编码已存在:{code}'}); continue
Institution.objects.create(
code=code, name=name,
type=(row.get('类型') or 'hospital').strip() or 'hospital',
type='hospital', # 类型固定 hospital,不从 Excel 读取
level=(row.get('等级') or '').strip(),
province=(row.get('') or '').strip(),
city=(row.get('') or '').strip(),