ai_resul_info.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. import 'dart:convert';
  2. import 'dart:math';
  3. import 'package:fis_common/index.dart';
  4. import 'package:fis_common/logger/logger.dart';
  5. import 'package:fis_i18n/i18n.dart';
  6. import 'package:fis_measure/interfaces/process/standard_line/calibration.dart';
  7. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  8. import 'package:fis_measure/process/language/measure_language.dart';
  9. import 'package:fis_measure/process/visual/visual.dart';
  10. import 'package:fis_measure/process/workspace/third_part/application.dart';
  11. import 'package:fis_measure/process/workspace/third_part/calibration_controller.dart';
  12. import 'package:fis_measure/process/workspace/visual_loader.dart';
  13. import 'package:fis_measure/values/unit_desc.dart';
  14. import 'package:fis_measure/view/paint/ai_patint_controller.dart';
  15. import 'package:fis_measure/view/paint/date_structure.dart';
  16. import 'package:flutter/material.dart';
  17. import 'package:get/get.dart';
  18. import 'package:vid/us/vid_us_unit.dart';
  19. /// AI诊断结果
  20. class ResultInfo extends StatefulWidget {
  21. const ResultInfo(this.aiDetectedObject, {Key? key}) : super(key: key);
  22. final List<AIDetectedObject>? aiDetectedObject;
  23. @override
  24. State<ResultInfo> createState() => _ResultInfoState();
  25. }
  26. class _ResultInfoState extends State<ResultInfo> {
  27. late final aiPatintController = Get.find<AiPatintController>();
  28. IStandardLineCalibrationController? standardLineCalibrationController;
  29. bool _isEmptyAITitle = false;
  30. /// 测量语言包
  31. final measureLanguage = MeasureLanguage();
  32. late AIDetectedObject aiDetectedObjectItem;
  33. double _unitsPhysicalPixels = 0;
  34. late final application = Get.find<IApplication>();
  35. // 图像的物理单位
  36. String _xUnit = '';
  37. @override
  38. void initState() {
  39. _updateImagePhysicalSize();
  40. try {
  41. if (application.isThirdPart) {
  42. final standradLine = (application as ThirdPartApplication).standardLine;
  43. standardLineCalibrationController =
  44. StandardLineCalibrationController(application, standradLine);
  45. Get.put<IStandardLineCalibrationController>(
  46. standardLineCalibrationController!);
  47. if (standardLineCalibrationController != null) {
  48. standardLineCalibrationController!.editStateChanged
  49. .addListener(onStandardLineUpdated);
  50. }
  51. }
  52. } catch (e) {
  53. logger.e('standardLineCalibrationController cannot find ', e);
  54. }
  55. super.initState();
  56. }
  57. @override
  58. void didUpdateWidget(ResultInfo oldWidget) {
  59. _updateImagePhysicalSize();
  60. super.didUpdateWidget(oldWidget);
  61. }
  62. @override
  63. void dispose() {
  64. if (standardLineCalibrationController != null) {
  65. standardLineCalibrationController!.editStateChanged
  66. .removeListener(onStandardLineUpdated);
  67. }
  68. super.dispose();
  69. }
  70. void onStandardLineUpdated(_, e) {
  71. _updateImagePhysicalSize();
  72. }
  73. @override
  74. Widget build(BuildContext context) {
  75. _isEmptyAITitle = ![
  76. DiagnosisOrganEnum.Breast,
  77. DiagnosisOrganEnum.Liver,
  78. DiagnosisOrganEnum.Thyroid,
  79. DiagnosisOrganEnum.CarotidArtery
  80. ].contains(aiPatintController.diagnosisOrgan);
  81. if (_isEmptyAITitle) {
  82. return const SizedBox();
  83. }
  84. if (_unitsPhysicalPixels <= 0) {
  85. _updateImagePhysicalSize();
  86. }
  87. final description = widget
  88. .aiDetectedObject?[aiPatintController.state.aiResultIndex].descriptions;
  89. var lesionSizeDescription = description?.firstWhereOrNull(
  90. (element) => element.type == DiagnosisDescriptionEnum.LesionSize);
  91. var lesionSize = lesionSizeDescription?.value ?? '';
  92. late final lesionSizeMap =
  93. (description?.length ?? 0) > 1 ? jsonDecode(lesionSize) : '';
  94. return Container(
  95. decoration: BoxDecoration(
  96. border: Border.all(
  97. color: Colors.grey,
  98. ),
  99. borderRadius: BorderRadius.circular(4),
  100. color: Colors.transparent,
  101. ),
  102. child: Column(
  103. children: [
  104. Row(
  105. mainAxisSize: MainAxisSize.max,
  106. children: [
  107. Expanded(
  108. child: Container(
  109. decoration: const BoxDecoration(
  110. borderRadius: BorderRadius.only(
  111. topLeft: Radius.circular(4),
  112. topRight: Radius.circular(4),
  113. ),
  114. color: Color.fromRGBO(54, 169, 206, 1),
  115. ),
  116. padding: const EdgeInsets.only(
  117. top: 4,
  118. bottom: 4,
  119. left: 8,
  120. right: 8,
  121. ),
  122. child: Text(
  123. i18nBook.measure.aiDiagnosticResults.t,
  124. style: const TextStyle(
  125. color: Colors.white,
  126. ),
  127. ),
  128. ),
  129. )
  130. ],
  131. ),
  132. Row(
  133. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  134. children: [
  135. Expanded(
  136. child: Container(
  137. padding: const EdgeInsets.only(
  138. left: 10,
  139. ),
  140. child: Column(
  141. crossAxisAlignment: CrossAxisAlignment.start,
  142. mainAxisAlignment: MainAxisAlignment.start,
  143. children: [
  144. _buildTitle(
  145. i18nBook.measure.analysisConclusion.t,
  146. _buildAITitle(),
  147. ),
  148. if (lesionSizeMap != '' && lesionSizeMap != null)
  149. _buildTitle(
  150. i18nBook.measure.isLesionSize.t,
  151. _buildLesionSize(
  152. lesionSizeMap?['HorizontalLengthInPixel'] ?? 0,
  153. lesionSizeMap?['VerticalLengthInPixel'] ?? 0,
  154. _unitsPhysicalPixels,
  155. ),
  156. )
  157. ],
  158. ),
  159. ),
  160. ),
  161. Container(
  162. margin: const EdgeInsets.symmetric(
  163. vertical: 5,
  164. ),
  165. padding: const EdgeInsets.only(right: 8),
  166. child: Column(
  167. children: [
  168. Text(
  169. i18nBook.measure.possibility.t,
  170. style: const TextStyle(
  171. color: Colors.grey,
  172. ),
  173. ),
  174. const SizedBox(
  175. height: 8,
  176. ),
  177. SizedBox(
  178. width: 70,
  179. height: 70,
  180. child: Stack(
  181. children: [
  182. SizedBox(
  183. width: 70,
  184. height: 70,
  185. child: Obx(() {
  186. final aiDetected = widget.aiDetectedObject?[
  187. aiPatintController.state.aiResultIndex];
  188. return CircularProgressIndicator(
  189. valueColor: AlwaysStoppedAnimation(
  190. _buildAITextColor(
  191. aiDetected?.label ?? 0,
  192. ),
  193. ),
  194. backgroundColor: Colors.grey,
  195. value: aiDetected?.confidence,
  196. );
  197. }),
  198. ),
  199. Center(
  200. child: SizedBox(
  201. width: 65,
  202. height: 45,
  203. child: Obx(
  204. () {
  205. final confidence = widget
  206. .aiDetectedObject?[aiPatintController
  207. .state.aiResultIndex]
  208. .confidence;
  209. return Center(
  210. child: Text(
  211. '${((confidence ?? 0) * 100).toStringAsFixed(1)}%',
  212. style: const TextStyle(
  213. color: Colors.white,
  214. fontSize: 18,
  215. fontWeight: FontWeight.bold,
  216. ),
  217. ),
  218. );
  219. },
  220. ),
  221. ),
  222. ),
  223. ],
  224. ),
  225. ),
  226. ],
  227. ),
  228. ),
  229. ],
  230. ),
  231. ],
  232. ),
  233. );
  234. }
  235. Widget _buildLesionSize(
  236. int horizontalLengthInPixel,
  237. int verticalLengthInPixel,
  238. double unitsPhysicalPixels,
  239. ) {
  240. return Text(
  241. (horizontalLengthInPixel * unitsPhysicalPixels)
  242. .toStringAsFixed(2)
  243. .toString() +
  244. '$_xUnit x' +
  245. (verticalLengthInPixel * unitsPhysicalPixels)
  246. .toStringAsFixed(2)
  247. .toString() +
  248. _xUnit,
  249. style: const TextStyle(color: Colors.white),
  250. );
  251. }
  252. /// 更新图像物理尺度信息
  253. void _updateImagePhysicalSize() {
  254. if (application.visuals.isEmpty) {
  255. return;
  256. }
  257. if (application.visuals[0].visualAreas.isEmpty) {
  258. return;
  259. }
  260. _unitsPhysicalPixels =
  261. (application.visuals[0].visualAreas[0].viewport?.region.width)! /
  262. (application.frameData!.width).toDouble();
  263. VidUsUnit targetUnit =
  264. application.visuals[0].visualAreas[0].viewport?.xUnit ?? VidUsUnit.cm;
  265. _xUnit = UnitDescriptionMap.getDesc(targetUnit);
  266. }
  267. Widget _buildTitle(String label, Widget value) {
  268. return Column(
  269. mainAxisSize: MainAxisSize.max,
  270. crossAxisAlignment: CrossAxisAlignment.start,
  271. children: [
  272. Text(
  273. label,
  274. style: const TextStyle(
  275. color: Color.fromRGBO(54, 169, 206, 1),
  276. ),
  277. ),
  278. value,
  279. const SizedBox(
  280. height: 5,
  281. ),
  282. ],
  283. );
  284. }
  285. Color _buildAITextColor(int label) {
  286. switch (aiPatintController.diagnosisOrgan) {
  287. /// 乳腺是0:未见异常; 1、2、3良性; 4、5、6、7恶性;
  288. case DiagnosisOrganEnum.Breast:
  289. switch (label) {
  290. case 0:
  291. return Colors.lightBlue;
  292. case 1:
  293. case 2:
  294. case 3:
  295. return Colors.greenAccent;
  296. case 4:
  297. case 5:
  298. case 6:
  299. case 7:
  300. return Colors.redAccent;
  301. default:
  302. return Colors.lightBlue;
  303. }
  304. /// 肝脏是0:未见异常; 1、2、3、4、5、6、7、8良性;
  305. case DiagnosisOrganEnum.Liver:
  306. switch (label) {
  307. case 0:
  308. return Colors.lightBlue;
  309. case 4:
  310. return Colors.redAccent;
  311. case 1:
  312. case 2:
  313. case 3:
  314. case 5:
  315. case 6:
  316. case 7:
  317. case 8:
  318. return Colors.greenAccent;
  319. default:
  320. return Colors.lightBlue;
  321. }
  322. /// 甲状腺是0:未见异常; 1、2、3、4、5、6、7、8良性;
  323. case DiagnosisOrganEnum.Thyroid:
  324. switch (label) {
  325. case 0:
  326. return Colors.lightBlue;
  327. case 1:
  328. case 2:
  329. case 7:
  330. return Colors.greenAccent;
  331. case 3:
  332. case 4:
  333. case 5:
  334. case 6:
  335. return Colors.redAccent;
  336. default:
  337. return Colors.lightBlue;
  338. }
  339. default:
  340. return Colors.lightBlue;
  341. }
  342. }
  343. Widget _buildAITitle() {
  344. switch (aiPatintController.diagnosisOrgan) {
  345. case DiagnosisOrganEnum.Breast:
  346. return Obx(() {
  347. aiDetectedObjectItem = widget
  348. .aiDetectedObject?[aiPatintController.state.aiResultIndex] ??
  349. AIDetectedObject();
  350. return _buildBreastDescription(aiDetectedObjectItem.label);
  351. });
  352. case DiagnosisOrganEnum.Liver:
  353. return Obx(() {
  354. aiDetectedObjectItem = widget
  355. .aiDetectedObject?[aiPatintController.state.aiResultIndex] ??
  356. AIDetectedObject();
  357. return _buildLiverDescription(aiDetectedObjectItem.label);
  358. });
  359. case DiagnosisOrganEnum.Thyroid:
  360. return Obx(() {
  361. aiDetectedObjectItem = widget
  362. .aiDetectedObject?[aiPatintController.state.aiResultIndex] ??
  363. AIDetectedObject();
  364. return _buildThyroidDescription(aiDetectedObjectItem.label);
  365. });
  366. case DiagnosisOrganEnum.CarotidArtery:
  367. return Obx(() {
  368. aiDetectedObjectItem = widget
  369. .aiDetectedObject?[aiPatintController.state.aiResultIndex] ??
  370. AIDetectedObject();
  371. return _buildCarotidArteryDescription(aiDetectedObjectItem.label);
  372. });
  373. default:
  374. return const SizedBox();
  375. }
  376. }
  377. Widget _buildBreastDescription(int label) {
  378. switch (label) {
  379. case 0:
  380. return _buildDescription(
  381. i18nBook.measure.noSignificantAbnormalitiesWereSeen.t);
  382. case 1:
  383. return _buildDescription(i18nBook.measure.lipoma.t);
  384. case 2:
  385. return _buildDescription('BI-RADS 2');
  386. case 3:
  387. return _buildDescription('BI-RADS 3');
  388. case 4:
  389. return _buildDescription('BI-RADS 4a');
  390. case 5:
  391. return _buildDescription('BI-RADS 4b');
  392. case 6:
  393. return _buildDescription('BI-RADS 4c');
  394. case 7:
  395. return _buildDescription('BI-RADS 5');
  396. case 8:
  397. return _buildDescription(
  398. i18nBook.measure.noSignificantAbnormalitiesWereSeen.t);
  399. default:
  400. return _buildDescription(null);
  401. }
  402. }
  403. Widget _buildLiverDescription(int label) {
  404. switch (label) {
  405. case 0:
  406. return _buildDescription(
  407. i18nBook.measure.noSignificantAbnormalitiesWereSeen.t);
  408. case 1:
  409. return _buildDescription(i18nBook.measure.intrahepaticStrongEchoFoci.t);
  410. case 2:
  411. return _buildDescription(i18nBook.measure.hepaticHemangioma.t);
  412. case 3:
  413. return _buildDescription(i18nBook.measure.liverCysts.t);
  414. case 4:
  415. return _buildDescription(i18nBook.measure.liverCancerMayOccur.t);
  416. case 5:
  417. return _buildDescription(i18nBook.measure.fattyLiver.t);
  418. case 6:
  419. return _buildDescription(
  420. i18nBook.measure.panisodicChangesLiverDiffuseLesions.t);
  421. case 7:
  422. return _buildDescription(i18nBook.measure.cirrhosis.t);
  423. case 8:
  424. return _buildDescription(i18nBook.measure.polycysticLiver.t);
  425. default:
  426. return _buildDescription(null);
  427. }
  428. }
  429. Widget _buildThyroidDescription(int label) {
  430. switch (label) {
  431. case 0:
  432. return _buildDescription(
  433. i18nBook.measure.noSignificantAbnormalitiesWereSeen.t);
  434. case 1:
  435. return _buildDescription(measureLanguage.t('ai', "TIRADS2"));
  436. case 2:
  437. return _buildDescription(measureLanguage.t('ai', "TIRADS3"));
  438. case 3:
  439. return _buildDescription(measureLanguage.t('ai', "TIRADS4a"));
  440. case 4:
  441. return _buildDescription(measureLanguage.t('ai', "TIRADS4b"));
  442. case 5:
  443. return _buildDescription(measureLanguage.t('ai', "TIRADS4c"));
  444. case 6:
  445. return _buildDescription(measureLanguage.t('ai', "TIRADS5"));
  446. case 7:
  447. return _buildDescription(i18nBook.measure.presenceDiffuseDisease.t);
  448. default:
  449. return _buildDescription(null);
  450. }
  451. }
  452. Widget _buildDescription(
  453. String? title,
  454. ) {
  455. return Column(
  456. crossAxisAlignment: CrossAxisAlignment.start,
  457. children: [
  458. if (title != null) ...[
  459. const SizedBox(
  460. height: 5,
  461. ),
  462. Text(
  463. title,
  464. style: const TextStyle(color: Colors.white),
  465. ),
  466. ],
  467. ],
  468. );
  469. }
  470. Widget _buildCarotidArteryDescription(int label) {
  471. switch (label) {
  472. case 0:
  473. return _buildDescription(
  474. i18nBook.measure.noSignificantAbnormalitiesWereSeen.t);
  475. case 1:
  476. return _buildDescription(i18nBook.measure.patch.t);
  477. default:
  478. return _buildDescription(null);
  479. }
  480. }
  481. }