remedical_Manager.dart 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. import 'package:fis_common/helpers/encrypt.dart';
  2. import 'package:fis_i18n/i18n.dart';
  3. import 'package:fis_jsonrpc/rpc.dart';
  4. import 'package:get/get.dart';
  5. import 'package:fis_common/logger/logger.dart';
  6. import 'package:vitalapp/helper/utc_dateTime_converter.dart';
  7. import 'package:vitalapp/managers/interfaces/remedical.dart';
  8. import 'package:vitalapp/pages/patient/create/widgets/patient_info.dart';
  9. import 'package:vitalapp/rpc.dart';
  10. import 'interfaces/base_manager.dart';
  11. import 'interfaces/models/process_arg.dart';
  12. import 'package:fis_common/event/event_type.dart';
  13. import 'simple_Info.dart';
  14. class RemedicalManager extends BaseManager implements IRemedicalManager {
  15. final processChange = FEventHandler<ProcessArg>();
  16. @override
  17. Future<PageResult<ClientPatientInfoBaseDTO>> findPatients({
  18. int pageIndex = 1,
  19. int pageSize = 20,
  20. String keyWord = '',
  21. DateTime? startDateTime,
  22. DateTime? endDateTime,
  23. PatientValidStatusEnum isValid = PatientValidStatusEnum.All,
  24. }) async {
  25. final patients = await rpc.patient.findPatientsAsync(
  26. FindPatientsPageRequest(
  27. token: token,
  28. pageIndex: pageIndex,
  29. pageSize: pageSize,
  30. keyWord: keyWord,
  31. startTime: startDateTime,
  32. endTime: endDateTime,
  33. isValid: isValid,
  34. ),
  35. );
  36. return patients;
  37. }
  38. @override
  39. Future<bool> createPatientByUnregisteredAsync(String patientName,
  40. {String? code}) async {
  41. final name = FEncryptHelper.encodeBase64(patientName);
  42. final result = await rpc.patient.createPatientByUnregisteredAsync(
  43. CreatePatientByUnregisteredRequest(
  44. token: token,
  45. patientName: name,
  46. unregisteredPatientCode: code,
  47. ),
  48. );
  49. return result;
  50. }
  51. @override
  52. Future<String> createUnregisteredPatient(String patientName,
  53. {String? code}) async {
  54. final name = FEncryptHelper.encodeBase64(patientName);
  55. final result = await rpc.patient.createUnregisteredPatientAsync(
  56. CreatePatientByUnregisteredRequest(
  57. token: token,
  58. patientName: name,
  59. unregisteredPatientCode: code,
  60. ),
  61. );
  62. return result;
  63. }
  64. @override
  65. Future<List<SimpleInfoItem>> findSimpleInfoPatients({
  66. int pageIndex = 1,
  67. int pageSize = 20,
  68. String keyWord = '',
  69. DateTime? startDateTime,
  70. DateTime? endDateTime,
  71. PatientValidStatusEnum isValid = PatientValidStatusEnum.All,
  72. bool isCounsultationPatient = false,
  73. }) async {
  74. PageResult<ClientPatientInfoBaseDTO> patients;
  75. if (isCounsultationPatient) {
  76. patients = await rpc.liveConsultation.findConsultationPatientAsync(
  77. FindConsultationPatientPageRequest(
  78. token: token,
  79. keyword: keyWord,
  80. pageIndex: pageIndex,
  81. pageSize: pageSize,
  82. ),
  83. );
  84. } else {
  85. patients = await findPatients(
  86. keyWord: keyWord,
  87. pageIndex: pageIndex,
  88. pageSize: pageSize,
  89. startDateTime: startDateTime,
  90. endDateTime: endDateTime,
  91. );
  92. }
  93. List<SimpleInfoItem> items = [];
  94. for (ClientPatientInfoBaseDTO p in patients.pageData ?? []) {
  95. List<DataItemDTO> patientData = p.patientData ?? [];
  96. var identityCard = patientData
  97. .firstWhereOrNull((element) => element.key == 'IdentityCard');
  98. items.add(
  99. SimpleInfoItem(
  100. itemCode: p.patientCode ?? '',
  101. name: _getPatientName(patientData),
  102. image: patientData
  103. .firstWhereOrNull((element) => element.key == 'HeadImgUrl')
  104. ?.value,
  105. role: patientData
  106. .firstWhereOrNull((element) => element.key == 'Phone')
  107. ?.value,
  108. des: [
  109. identityCard == null ? '' : identityCard.value,
  110. ],
  111. ),
  112. );
  113. }
  114. return items;
  115. }
  116. String? _getPatientName(List<DataItemDTO> patientData) {
  117. var name =
  118. patientData.firstWhereOrNull((element) => element.key == 'Name')?.value;
  119. if (name == null || name.isEmpty) {
  120. name = patientData
  121. .firstWhereOrNull((element) => element.key == 'AnimalInfoName')
  122. ?.value;
  123. }
  124. return name;
  125. }
  126. @override
  127. List<DataItemDTO>? convertPatientInfoToPatientDatas(
  128. PatientInfo? patientInfo) {
  129. if (patientInfo == null) {
  130. return [];
  131. }
  132. return [];
  133. }
  134. /// 根据后端接口的key值取到对应的value
  135. ///
  136. /// [patientData] 后端数据
  137. ///
  138. /// [keys] 对应的Key值
  139. @override
  140. String getKeyValue(
  141. List<DataItemDTO> patientData,
  142. List<String> keys,
  143. ) {
  144. return patientData.firstWhereOrNull((element) {
  145. return keys.contains(element.key);
  146. })?.value ??
  147. '';
  148. }
  149. @override
  150. Future<ClientPatientInfoDTO> findPatientByCode(
  151. String patientCode,
  152. ) async {
  153. return await rpc.remoteUltrasound.vitalFindPatientByCodeAsync(
  154. FindPatientByCodeRequest(
  155. code: patientCode,
  156. token: token,
  157. ),
  158. );
  159. }
  160. // @override
  161. // Future<List<FSelectModel>> findScanPositions() async {
  162. // List<FSelectModel> scanPositionsList = [];
  163. // return scanPositionsList;
  164. // }
  165. /// 获取测量图像
  166. @override
  167. Future<List<RemedicalMeasuredInfoDTO>> findRemedicalMeasuredInfoAsync(
  168. String recordCode,
  169. {BusinessTypeEnum businessType =
  170. BusinessTypeEnum.RemoteDiagnosis}) async {
  171. List<RemedicalMeasuredInfoDTO> result = [];
  172. try {
  173. result = await rpc.remoteUltrasound.vitalFindRemedicalMeasuredInfoAsync(
  174. FindRemedicalMeasuredInfoRequest(
  175. token: token,
  176. recordCode: recordCode,
  177. businessType: businessType,
  178. ),
  179. );
  180. return result;
  181. } catch (e) {
  182. logger.i("findRemedicalMeasuredInfoAsync exception:" + e.toString());
  183. }
  184. return result;
  185. }
  186. @override
  187. Future<List<ReportDTO>> findExamReports(String recordCode) async {
  188. try {
  189. var result = await rpc.ultrasoundReport.vitalFindReportsAsync(
  190. FindReportsRequest(
  191. token: token,
  192. recordCode: recordCode,
  193. ),
  194. );
  195. return result;
  196. } catch (e) {
  197. logger.e('RemedicalManager findExamReports ex:$e');
  198. return [];
  199. }
  200. }
  201. ///查询检查详情
  202. @override
  203. Future<QueryRecordResult?> queryRecordInfoAsync(String recordCode) async {
  204. try {
  205. return await rpc.remoteUltrasound.vitalQueryRecordInfoAsync(
  206. QueryRecordRequest(
  207. token: token,
  208. recordCode: recordCode,
  209. ),
  210. );
  211. } catch (e) {
  212. print('error:$recordCode');
  213. logger.i('queryRecordInfoAsync recordCode:$recordCode');
  214. logger.e('RemedicalManager queryRecordInfoAsync ex:', e);
  215. return null;
  216. }
  217. }
  218. @override
  219. Future<List<RemedicalAISelectedInfoDTO>> findAIImages(
  220. String recordCode, String patientId) async {
  221. final result = await rpc.remedical.getPatientAISelectedInfosAsync(
  222. GetPatientAISelectedInfosRequest(
  223. token: token,
  224. recordCode: recordCode,
  225. patientCode: patientId,
  226. ),
  227. );
  228. return result;
  229. }
  230. @override
  231. bool checkCarotidList(
  232. RemedicalItemList remedicalItem, CarotidScanTypeEnum scanTypeEnum) {
  233. return (remedicalItem.remedicalList
  234. ?.where(
  235. (element) =>
  236. element.carotidResult != null &&
  237. element.carotidResult?.carotidScanType == scanTypeEnum,
  238. )
  239. .toList() ??
  240. [])
  241. .isNotEmpty;
  242. }
  243. @override
  244. Future<RemedicalInfoDTO> findRemedicalByCode(String remedicalCode) async {
  245. return rpc.remoteUltrasound.vitalFindRemedicalByCodeAsync(
  246. FindRemedicalByCodeRequest(
  247. remedicalCode: remedicalCode,
  248. token: token,
  249. ),
  250. );
  251. }
  252. @override
  253. Future<PageResult<SimpleRecordInfoDTO>> findRecordPages({
  254. List<String>? organizationCodes,
  255. List<String>? deviceCodes,
  256. RecordQueryStateEnum recordQueryState = RecordQueryStateEnum.All,
  257. RecordProcessStateEnum recordProcessState = RecordProcessStateEnum.All,
  258. String? keyWord,
  259. DateTime? startTime,
  260. DateTime? endTime,
  261. String? patientCode,
  262. int pageIndex = 1,
  263. int pageSize = 20,
  264. }) async {
  265. try {
  266. return await rpc.remoteUltrasound.vitalFindRecordPagesAsync(
  267. FindRecordPagesRequest(
  268. token: token,
  269. pageIndex: pageIndex,
  270. pageSize: pageSize,
  271. organizationCodes: organizationCodes,
  272. deviceCodes: deviceCodes,
  273. keyWord: keyWord,
  274. recordQueryState: recordQueryState,
  275. language: i18nBook.locale.toCodeString('-'),
  276. recordProcessState: recordProcessState,
  277. patientCode: patientCode,
  278. startTime: UtcDateConverter.getDayStartOrEndUTCTime(startTime),
  279. endTime:
  280. UtcDateConverter.getDayStartOrEndUTCTime(endTime, isEnd: true),
  281. ),
  282. );
  283. } catch (e) {
  284. logger.e('RemedicalManager findRecordPages ex:$e');
  285. return PageResult<SimpleRecordInfoDTO>();
  286. }
  287. }
  288. @override
  289. void openImageMeasurePage(
  290. String imageUrl,
  291. int imageindex,
  292. String remedicalCode,
  293. String recordCode,
  294. String? remedicalAISelectedInfoCode,
  295. String patientCode) {}
  296. }