appointmentmanager.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. import 'package:fis_common/helpers/encrypt.dart';
  2. import 'package:fis_common/index.dart';
  3. import 'package:fis_i18n/i18n.dart';
  4. import 'package:fis_jsonrpc/rpc.dart';
  5. import 'package:flyinsonolite/jsonrpc/fisLib/services/log.m.dart';
  6. import 'package:flyinsonolite/jsonrpc/jsonrpcclient.dart';
  7. import 'package:flyinsonolite/infrastructure/logger.dart';
  8. import 'package:flyinsonolite/managers/basemanager.dart';
  9. import 'package:flyinsonolite/managers/interfaces/iappointmentmanager.dart';
  10. import 'package:flyinsonolite/consultation/records/models/appointmentinformation.dart';
  11. import 'package:flyinsonolite/infrastructure/storage.dart';
  12. class AppointmentManager extends BaseManager implements IAppointmentManager {
  13. @override
  14. Future<PageResult<ConsultationPageDTO>> findConsultationsByPageAsync(
  15. ConsultationQueryTypeEnum consultationQueryType,
  16. int pageIndex,
  17. int pageSize,
  18. {String? keyword,
  19. DateTime? startDate,
  20. DateTime? endDate,
  21. QueryConsultationStatusEnum? consultationStatus,
  22. QueryEvaluateGradeEnum? evaluateGrade,
  23. String? language,
  24. List<String>? expertCodes,
  25. List<String>? applyOrganizationCodes,
  26. List<String>? expertOrganizationCodes,
  27. String? patientSex,
  28. String? patientDiseases,
  29. String? patientPrimaryDiagnosis,
  30. QueryPatientAgeLimitDTO? patientAgeLimit}) async {
  31. return await jsonRpcProxy.liveConsultation.findConsultationsByPageAsync(
  32. FindConsultationByPageRequest(
  33. token: token,
  34. pageIndex: pageIndex,
  35. pageSize: pageSize,
  36. consultationQueryType: consultationQueryType,
  37. keyword: keyword,
  38. startDate: startDate,
  39. endDate: endDate,
  40. language: language,
  41. expertCodes: expertCodes,
  42. patientSex: patientSex,
  43. patientAgeLimit: patientAgeLimit,
  44. patientDiseases: patientDiseases,
  45. patientPrimaryDiagnosis: patientPrimaryDiagnosis,
  46. applyOrganizationCodes: applyOrganizationCodes,
  47. expertOrganizationCodes: expertOrganizationCodes,
  48. consultationStatus:
  49. consultationStatus ?? QueryConsultationStatusEnum.All,
  50. evaluateGrade: evaluateGrade ?? QueryEvaluateGradeEnum.All,
  51. ),
  52. );
  53. }
  54. /// 查询会诊详情
  55. @override
  56. Future<ConsultationDetailDTO?> findConsultationDetailAsync(
  57. String consultationCode) async {
  58. try {
  59. final result =
  60. await jsonRpcProxy.liveConsultation.findConsultationDetailAsync(
  61. FindConsultationDetailRequest(
  62. token: token,
  63. consultationCode: consultationCode,
  64. ),
  65. );
  66. result.consultationTime =
  67. result.consultationTime?.toLocal() ?? DateTime.now();
  68. return result;
  69. } catch (e) {
  70. await loggerAsyn(FISDeviceLogCategory.Error,
  71. "AppointmentManager findConsultationDetailAsync exception: $e");
  72. return null;
  73. }
  74. }
  75. ///获取会诊随访信息
  76. @override
  77. Future<List<FollowUpVisitDTO>> getFollowUpVisitInfo(
  78. String currentConsultationCode) async {
  79. try {
  80. var result =
  81. await jsonRpcProxy.liveConsultation.getFollowUpVisitInfoAsync(
  82. GetFollowUpVisitInfoRequest(
  83. token: token,
  84. consultationRecordCode: currentConsultationCode,
  85. ),
  86. );
  87. return result;
  88. } catch (e) {
  89. await loggerAsyn(FISDeviceLogCategory.Error,
  90. 'AppointmentManager getFollowUpVisitInfo ex:$e');
  91. return [];
  92. }
  93. }
  94. ///获取病人列表
  95. @override
  96. Future<PageResult<ClientPatientInfoBaseDTO>> findConsultationPatientAsync(
  97. String? keyword, int pageIndex, int pageSize) async {
  98. return await jsonRpcProxy.liveConsultation.findConsultationPatientAsync(
  99. FindConsultationPatientPageRequest(
  100. token: token,
  101. keyword: keyword,
  102. pageIndex: pageIndex,
  103. pageSize: pageSize,
  104. ),
  105. );
  106. }
  107. ///创建病人
  108. @override
  109. Future<ClientPatientInfoBaseDTO?> createPatientByUnregisteredAsync(
  110. String patientName) async {
  111. final name = FEncryptHelper.encodeBase64(patientName);
  112. var result = await jsonRpcProxy.patient.createUnregisteredPatientAsync(
  113. CreatePatientByUnregisteredRequest(
  114. token: token,
  115. patientName: name,
  116. ),
  117. );
  118. if (result.isNotEmpty) {
  119. return await jsonRpcProxy.patient.findPatientByCodeAsync(
  120. FindPatientByCodeRequest(code: result, token: token));
  121. }
  122. return null;
  123. }
  124. ///获取用户名下所有设备
  125. @override
  126. Future<PageCollection<DeviceInfoDTO>> getDeviceListByPersonRoleAsync() async {
  127. try {
  128. return await jsonRpcProxy.device.getDeviceListByPersonRoleAsync(
  129. GetPersonRoleDeviceRequest(
  130. token: token, pageIndex: 1, pageSize: 1000));
  131. } catch (e) {
  132. await loggerAsyn(FISDeviceLogCategory.Error,
  133. 'AppointmentManager getDeviceListByPersonRoleAsync ex:$e');
  134. }
  135. return PageCollection();
  136. }
  137. ///获取扫查医生
  138. @override
  139. Future<List<UserExtendDTO>> getScanDoctorsAsync() async {
  140. try {
  141. return await jsonRpcProxy.user.getUserListAsync(
  142. GetUserListRequest(
  143. token: token,
  144. organizationCode: Storage.user.organizationCode,
  145. organizationQueryType: OrganizationQueryTypeEnum.All,
  146. roleCodes: [RoleType.certifiedExpert, RoleType.certifiedPhysician]),
  147. );
  148. } catch (e) {
  149. await loggerAsyn(FISDeviceLogCategory.Error,
  150. 'AppointmentManager getScanDoctorsAsync ex:$e');
  151. }
  152. return [];
  153. }
  154. ///获取扫查部位
  155. @override
  156. Future<List<String>> getScanPositionsAsync() async {
  157. try {
  158. return await jsonRpcProxy.liveConsultation.findScanPositionsAsync(
  159. TokenRequest(
  160. token: token,
  161. ),
  162. );
  163. } catch (e) {
  164. await loggerAsyn(FISDeviceLogCategory.Error,
  165. 'AppointmentManager getScanPositionsAsync ex:$e');
  166. }
  167. return [];
  168. }
  169. /// 获取会诊机构
  170. @override
  171. Future<List<OrganizationBaseDTO>> findParentOrganizationsAsync() async {
  172. try {
  173. return await jsonRpcProxy.liveConsultation.findParentOrganizationsAsync(
  174. FindHigherOrganizationsRequest(
  175. token: token,
  176. ),
  177. );
  178. } catch (e) {
  179. await loggerAsyn(FISDeviceLogCategory.Error,
  180. 'AppointmentManager findParentOrganizationsAsync ex:$e');
  181. }
  182. return [];
  183. }
  184. ///获取会诊专家
  185. @override
  186. Future<PageResult<OrganizationExpertDTO>> findOrganizationExpertsAsync(
  187. String organizationCode) async {
  188. try {
  189. return await jsonRpcProxy.liveConsultation.findOrganizationExpertsAsync(
  190. FindOrganizationExpertsRequest(
  191. token: token,
  192. organizationCode: organizationCode,
  193. pageIndex: 1,
  194. pageSize: 1000));
  195. } catch (ex) {
  196. await loggerAsyn(FISDeviceLogCategory.Error,
  197. 'AppointmentManager findOrganizationExpertsAsync ex:$ex');
  198. }
  199. return PageResult();
  200. }
  201. ///获取申请人列表
  202. @override
  203. Future<List<OrganizationExpertDTO>> findAssistantExpertsAsync() async {
  204. try {
  205. return await jsonRpcProxy.liveConsultation.findAssistantExpertsAsync(
  206. FindAssistantExpertsRequest(
  207. token: token,
  208. ),
  209. );
  210. } catch (ex) {
  211. await loggerAsyn(FISDeviceLogCategory.Error,
  212. 'AppointmentManager findAssistantExpertsAsync ex:$ex');
  213. }
  214. return [];
  215. }
  216. //创建会诊
  217. @override
  218. Future<String> applyConsultationAsync(
  219. String? patientCode,
  220. AppointmentInformation appointmentInformation,
  221. List<DataItemDTO>? patientDatas) async {
  222. return await jsonRpcProxy.liveConsultation
  223. .applyConsultationAsync(ApplyConsultationRequest(
  224. token: token,
  225. expertUserCode: appointmentInformation.appointmentCompetentExperts,
  226. deviceCode: appointmentInformation.appointmentDevice,
  227. scanPositions: appointmentInformation.appointmentScanningPosition,
  228. consultationTime: appointmentInformation.appointmentTime!.toUtc(),
  229. patientCode: patientCode,
  230. diseases: appointmentInformation.appointmentDiseaseName,
  231. scanUserCode: appointmentInformation.appointmentScanDoctor,
  232. expertOrganizationCode:
  233. appointmentInformation.appointmentConsultationInstitution,
  234. applyUserCode: appointmentInformation.appointmentApplicant,
  235. primaryDiagnosis: appointmentInformation.preliminaryDiagnosis,
  236. patientDatas: patientDatas, // 申请预约单的病人数据
  237. ));
  238. }
  239. //修改会诊
  240. @override
  241. Future<bool> updateConsultationAsync(String? consultationCode,
  242. AppointmentInformation appointmentInformation) async {
  243. return await jsonRpcProxy.liveConsultation.updateConsultationAsync(
  244. UpdateConsultationRequest(
  245. token: token,
  246. expertUserCode: appointmentInformation.appointmentCompetentExperts,
  247. deviceCode: appointmentInformation.appointmentDevice,
  248. scanPositions: appointmentInformation.appointmentScanningPosition,
  249. consultationTime: appointmentInformation.appointmentTime!.toUtc(),
  250. diseases: appointmentInformation.appointmentDiseaseName,
  251. scanUserCode: appointmentInformation.appointmentScanDoctor,
  252. expertOrganizationCode:
  253. appointmentInformation.appointmentConsultationInstitution,
  254. applyUserCode: appointmentInformation.appointmentApplicant,
  255. primaryDiagnosis: appointmentInformation.preliminaryDiagnosis,
  256. consultationCode: consultationCode,
  257. ),
  258. );
  259. }
  260. //完善会诊, 急诊创建的会诊单需要完善,其他不需要
  261. @override
  262. Future<bool> improveConsultationInfoAsync(
  263. String? patientCode,
  264. String? consultationCode,
  265. AppointmentInformation appointmentInformation,
  266. List<DataItemDTO>? patientDatas) async {
  267. return await jsonRpcProxy.liveConsultation
  268. .improveConsultationInfoAsync(ImproveConsultationInfoRequest(
  269. consultationCode: consultationCode,
  270. patientCode: patientCode,
  271. scanPositions: appointmentInformation.appointmentScanningPosition,
  272. diseases: appointmentInformation.appointmentDiseaseName,
  273. primaryDiagnosis: appointmentInformation.preliminaryDiagnosis,
  274. patientDatas: patientDatas,
  275. token: token,
  276. ));
  277. }
  278. //撤回会诊
  279. @override
  280. Future<bool> withdrawConsultationAsync(String? consultationCode) async {
  281. return await jsonRpcProxy.liveConsultation.revokeConsultationAsync(
  282. RevokeConsultationRequest(
  283. token: token,
  284. consultationCode: consultationCode,
  285. ),
  286. );
  287. }
  288. //拒绝会诊
  289. @override
  290. Future<bool> refuseConsultationAsync(
  291. String? consultationCode, String? reason) async {
  292. return await jsonRpcProxy.liveConsultation.rejectApplyConsultationAsync(
  293. RejectApplyConsultationRequest(
  294. token: token, consultationCode: consultationCode, reason: reason),
  295. );
  296. }
  297. //接收/拒绝加入会诊
  298. @override
  299. Future<bool> acceptInvitationAsync(
  300. String? consultationCode, bool isAgree, String? reason) async {
  301. return await jsonRpcProxy.liveConsultation.acceptInvitationAsync(
  302. AcceptInvitationRequest(
  303. token: token,
  304. consultationRecordCode: consultationCode,
  305. refusalCause: reason,
  306. isAgree: isAgree,
  307. ),
  308. );
  309. }
  310. ///获取用户信息,用于获取助理医师信息
  311. @override
  312. Future<UserInfoByCodeDTO> getUserByCodeAsync(String? userCode) async {
  313. return await jsonRpcProxy.user.getUserByCodeAsync(
  314. GetUserByCodeRequest(token: token, userCode: userCode));
  315. }
  316. ///审批同意会诊申请
  317. @override
  318. Future<bool> approveConsultationAsync(
  319. ApproveConsultationInfo approveConsultationInfo) async {
  320. return await jsonRpcProxy.liveConsultation.approvalConsultationAsync(
  321. ApprovalConsultationRequest(
  322. token: token,
  323. consultationCode: approveConsultationInfo.consultationCode,
  324. expertUserCode: approveConsultationInfo.competentExperts,
  325. consultationTime: approveConsultationInfo.startTime!.toUtc(),
  326. consultationTimeEnd: approveConsultationInfo.endTime!.toUtc(),
  327. consultationMemberCodes: approveConsultationInfo.participants,
  328. description: approveConsultationInfo.description,
  329. consultationReminders: approveConsultationInfo.consultationReminders,
  330. location: "",
  331. ),
  332. );
  333. }
  334. //会诊中添加时排除已存在的用户
  335. @override
  336. Future<List<UserExtendDTO>> getInviteableUserListAsyn(
  337. String consultationCode, String organizationCode) async {
  338. return await jsonRpcProxy.liveConsultation.getInviteableUserListAsync(
  339. GetInviteableUserListRequest(
  340. token: token,
  341. language: i18nBook.locale.toCodeString('-'),
  342. consultationCode: consultationCode,
  343. organizationCode: organizationCode,
  344. ),
  345. );
  346. }
  347. @override
  348. Future<List<ConsultationImagesDTO>> getConsultationImagesAsync(
  349. String consultationCode) async {
  350. try {
  351. if (consultationCode.isEmpty) {
  352. return [];
  353. }
  354. var realTimeConsultationImageList =
  355. await jsonRpcProxy.liveConsultation.getConsultationFilesAsync(
  356. FindConsultationDetailRequest(
  357. consultationCode: consultationCode, token: token),
  358. );
  359. return realTimeConsultationImageList;
  360. } catch (e) {
  361. await loggerAsyn(FISDeviceLogCategory.Error,
  362. 'AppointmentManager getConsultationImagesAsync ex:$e');
  363. }
  364. return [];
  365. }
  366. @override
  367. List<DataItemDTO> getPatientDatas(Map<String, String> patient) {
  368. List<DataItemDTO> patientDatas = [];
  369. patient.forEach((key, value) {
  370. if (key == 'Phone' ||
  371. key == 'Name' ||
  372. key == 'IdentityCard' ||
  373. key == 'InsuranceCode' ||
  374. key == 'AnimalInfoName' ||
  375. key == 'AnimalInfoPhone' ||
  376. key == 'AnimalInfoIdentityCard') {
  377. value = FEncryptHelper.encodeBase64(value);
  378. }
  379. if (value.isNotNullOrWhiteSpace) {
  380. patientDatas.add(DataItemDTO(
  381. key: key,
  382. value: value,
  383. ));
  384. }
  385. });
  386. return patientDatas;
  387. }
  388. }
  389. ///角色类型
  390. class RoleType {
  391. static String generalUser = "Role_GeneralUser"; //普通用户
  392. static String internshipDoctor = "Role_InternshipDoctor"; //实习医生
  393. static String expertAssistant = "Role_ExpertAssistant"; //专家助理
  394. static String certifiedPhysician = "Role_CertifiedPhysician"; //认证医师
  395. static String certifiedExpert = "Role_CertifiedExpert"; //认证专家
  396. }