measure_page_test.dart 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. import 'dart:typed_data';
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:fis_measure/interfaces/enums/annotation.dart';
  4. import 'package:fis_measure/interfaces/process/items/item.dart';
  5. import 'package:fis_measure/interfaces/process/items/item_metas.dart';
  6. import 'package:fis_measure/interfaces/process/items/terms.dart';
  7. import 'package:fis_measure/interfaces/process/items/types.dart';
  8. import 'package:fis_measure/interfaces/process/player/play_controller.dart';
  9. import 'package:fis_measure/interfaces/process/standard_line/calibration.dart';
  10. import 'package:fis_measure/interfaces/process/visuals/visual_area.dart';
  11. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  12. import 'package:fis_measure/interfaces/process/workspace/exam_info.dart';
  13. import 'package:fis_measure/interfaces/process/workspace/measure_controller.dart';
  14. import 'package:fis_measure/process/items/item_meta_convert.dart';
  15. import 'package:fis_measure/process/workspace/measure_3d_view_controller.dart';
  16. import 'package:fis_measure/process/workspace/measure_controller.dart';
  17. import 'package:fis_measure/process/workspace/measure_data_controller.dart';
  18. import 'package:fis_measure/view/measure/measure_main_view.dart';
  19. import 'package:flutter/material.dart';
  20. import 'package:get/get.dart';
  21. import 'package:vid/us/vid_us_mode.dart';
  22. import 'item_create_test.dart';
  23. import 'process/workspace/measure_handler.dart';
  24. class MeasureDataTester {
  25. static Future<List<RemedicalItemList>> getRemedicalList(
  26. String patientCode,
  27. String recordCode,
  28. String token,
  29. ) async {
  30. return [];
  31. }
  32. static Future<RemedicalInfoDTO?> getImageInfo(
  33. String remedicalCode,
  34. String token,
  35. ) async {
  36. return null;
  37. }
  38. static Future<MeasureApplicationDTO?> getMeasureApplication(
  39. dynamic args) async {
  40. return null;
  41. }
  42. static Future<MeasureApplicationDTO?> saveUserDefinedMeasureApplicationAsync(
  43. dynamic args) async {
  44. return null;
  45. }
  46. static Future<bool?> saveImage(
  47. Uint8List imageBytes,
  48. String patientCode,
  49. String recordCode,
  50. String remedicalCode,
  51. String measuredData,
  52. ) async {
  53. return null;
  54. }
  55. static Future<void> saveMeasureSystemSettingAsync(
  56. MeasureSystemSettingDTO measureSystemSetting) async {
  57. return;
  58. }
  59. static Future<MeasureSystemSettingDTO?> getMeasureSystemSettingAsync() async {
  60. return null;
  61. }
  62. static Future<String> shareImage(String vid) async {
  63. return '';
  64. }
  65. static Future<CommentItemResultDTO?> getCommentsByApplicationAsync(
  66. String applicationName, String categoryName) async {
  67. return null;
  68. }
  69. static Future<bool?> saveUserDefinedCommentsAsync(String applicationName,
  70. String categoryName, List<CommentItemDTO> commentItems) async {
  71. return null;
  72. }
  73. }
  74. class MeasureTestPage extends StatefulWidget {
  75. const MeasureTestPage({Key? key}) : super(key: key);
  76. // ignore: non_constant_identifier_names
  77. static List<dynamic> MetaDTOList = [];
  78. @override
  79. State<StatefulWidget> createState() => _MeasureTestPageState();
  80. }
  81. class _MeasureTestPageState extends State<MeasureTestPage> {
  82. static const C_LINEAR_TISSUE =
  83. // "http://cdn-bj.fis.plus/9F066341FA874E21B48CDE247C13D495.vid"; //B TVI TD
  84. // "http://cdn-bj.fis.plus/974BABA5113640639FD749E06DD7DA5B.vid"; //B CF CW
  85. // "http://cdn-bj.fis.plus/0B344F48BA574ECD82B7FEDB8848421A.vid"; //单幅TM
  86. // "http://cdn-bj.fis.plus/3379F38302884C2991D90FBDFB0DEA7E.dat"; //单幅TM(2)
  87. "http://cdn-bj.fis.plus/6A99AD2530864616B64355A8EA9AE3EC.vid";
  88. // "http://cdn-bj.fis.plus/F26C6E5D57A7472A97E9EB543DF0D16C.vid"; // 单幅Convex
  89. // "http://cdn-bj.fis.plus/6B6E069659D14E7299EB9F6EFCDE9C8C.vid"; //双幅单TissueConvex
  90. // "http://cdn-bj.fis.plus/062643B82365437DB95F3811580AF3ED.vid"; //四幅单模式
  91. // "http://cdn-bj.fis.plus/EA90D146049D416E8E466B7446E00001.vid"; //四幅Doppler
  92. // "http://cdn-bj.fis.plus/3rd_linearTvTissue2.vid"; //魔盒
  93. // "http://cdn-bj.fis.plus/81FFF8E5E078473FA687FBE81C4869B1.vid"; // 魔盒TV
  94. // "http://cdn-bj.fis.plus/7B450708A2784B1490304C82787349BE.vid";// 胎儿Zoom
  95. static const C_CONVEX_TISSUE =
  96. "http://cdn-bj.fis.plus/FEB1AAE5D9C24839BEE31B16E8CB450A.vid";
  97. final _3dc = Get.put<Measure3DViewController>(Measure3DViewController());
  98. final datac = Get.put<MeasureDataController>(MeasureDataController(
  99. MeasureDataTester.getRemedicalList,
  100. MeasureDataTester.getImageInfo,
  101. MeasureDataTester.getMeasureApplication,
  102. MeasureDataTester.saveUserDefinedMeasureApplicationAsync,
  103. MeasureDataTester.saveImage,
  104. MeasureDataTester.saveMeasureSystemSettingAsync,
  105. MeasureDataTester.getMeasureSystemSettingAsync,
  106. MeasureDataTester.shareImage,
  107. MeasureDataTester.getCommentsByApplicationAsync,
  108. MeasureDataTester.saveUserDefinedCommentsAsync,
  109. ));
  110. final measureHandler = Get.put(MeasureHandler());
  111. final controller = Get.put<IMeasureController>(MeasureController(
  112. "12345",
  113. imagesFetchFunc: (code) async {
  114. return <ExamImageInfo>[
  115. ExamImageInfo(C_LINEAR_TISSUE, C_LINEAR_TISSUE),
  116. ExamImageInfo(C_CONVEX_TISSUE, C_CONVEX_TISSUE)
  117. ];
  118. },
  119. ));
  120. bool loaded = false;
  121. int opType = 0;
  122. bool useArrowAnnotation = false;
  123. @override
  124. void initState() {
  125. measureHandler.changeImageLoaded;
  126. controller.load().then((value) {
  127. // 加载指定图像
  128. controller.examInfo.selectedImageIndex = 0;
  129. });
  130. controller.imageLoaded.addListener(onImageLoaded);
  131. super.initState();
  132. }
  133. @override
  134. void dispose() {
  135. controller.imageLoaded.removeListener(onImageLoaded);
  136. controller.dispose();
  137. Get.delete<IMeasureController>();
  138. super.dispose();
  139. }
  140. void onImageLoaded(Object sender, ExamImageInfo? e) {
  141. if (!mounted) return;
  142. if (e != null) {
  143. Future.delayed(const Duration(milliseconds: 100), () {
  144. controller.playerController.play();
  145. });
  146. setState(() {
  147. loaded = true;
  148. });
  149. }
  150. }
  151. @override
  152. Widget build(BuildContext context) {
  153. Widget body;
  154. if (!loaded) {
  155. const loadingWidget = Center(child: CircularProgressIndicator());
  156. body = Row(
  157. children: const [
  158. SizedBox(
  159. width: 300,
  160. child: loadingWidget,
  161. ),
  162. VerticalDivider(),
  163. Expanded(child: loadingWidget),
  164. ],
  165. );
  166. } else {
  167. body = Row(
  168. key: ValueKey(controller.examInfo.selectedImageIndex),
  169. children: [
  170. opType == 1
  171. ? const _MeasureLeftAnnotation()
  172. : const _MeasureLeftBoard(),
  173. const VerticalDivider(),
  174. const Expanded(
  175. child: MeasureRightBoard(),
  176. ),
  177. ],
  178. );
  179. }
  180. return Scaffold(
  181. backgroundColor: const Color.fromARGB(255, 53, 55, 51),
  182. appBar: AppBar(
  183. actions: [
  184. TextButton(
  185. onPressed: () {
  186. Get.find<IApplication>().clearRecords();
  187. },
  188. child: const Text(
  189. "清空",
  190. style: TextStyle(
  191. color: Colors.white,
  192. ),
  193. ),
  194. ),
  195. TextButton(
  196. onPressed: () {
  197. Get.find<IApplication>().undoRecord();
  198. },
  199. child: const Text(
  200. "撤销",
  201. style: TextStyle(
  202. color: Colors.white,
  203. ),
  204. ),
  205. ),
  206. TextButton(
  207. onPressed: () {
  208. final c = Get.find<IStandardLineCalibrationController>();
  209. if (c.isEditing) {
  210. c.cancelEdit();
  211. } else {
  212. c.enterEditMode();
  213. }
  214. },
  215. child: const Text(
  216. "校准线",
  217. style: TextStyle(
  218. color: Colors.white,
  219. ),
  220. ),
  221. ),
  222. TextButton.icon(
  223. onPressed: () {
  224. setState(() {
  225. if (useArrowAnnotation) {
  226. useArrowAnnotation = false;
  227. controller.workingApplication.switchAnnotation();
  228. } else {
  229. useArrowAnnotation = true;
  230. controller.workingApplication
  231. .switchAnnotation(AnnotationType.arrow);
  232. }
  233. });
  234. },
  235. icon: const Icon(Icons.arrow_right_alt_sharp),
  236. label: Text(
  237. "箭头",
  238. style: TextStyle(
  239. color: useArrowAnnotation ? Colors.amber : Colors.white,
  240. ),
  241. ),
  242. ),
  243. TextButton(
  244. onPressed: () {
  245. setState(() {
  246. opType = opType == 1 ? 0 : 1;
  247. });
  248. },
  249. child: Text(
  250. opType == 1 ? "注释" : "测量",
  251. style: const TextStyle(
  252. color: Colors.white,
  253. ),
  254. ),
  255. ),
  256. TextButton(
  257. onPressed: () {
  258. if (controller.examInfo.selectedImageIndex == 0) return;
  259. controller.examInfo.selectedImageIndex = 0;
  260. },
  261. child: Text(
  262. '线阵',
  263. style: TextStyle(
  264. color: controller.examInfo.selectedImageIndex == 0
  265. ? Colors.amber
  266. : Colors.white,
  267. ),
  268. ),
  269. ),
  270. TextButton(
  271. onPressed: () {
  272. if (controller.examInfo.selectedImageIndex == 1) return;
  273. controller.examInfo.selectedImageIndex = 1;
  274. },
  275. child: Text(
  276. '扇阵',
  277. style: TextStyle(
  278. color: controller.examInfo.selectedImageIndex == 1
  279. ? Colors.amber
  280. : Colors.white,
  281. ),
  282. ),
  283. ),
  284. ],
  285. leading: IconButton(
  286. onPressed: () {
  287. Navigator.of(context).pop();
  288. },
  289. icon: const Icon(Icons.arrow_back),
  290. ),
  291. ),
  292. body: body,
  293. floatingActionButton: _ModeTips(),
  294. floatingActionButtonLocation: FloatingActionButtonLocation.startFloat,
  295. );
  296. }
  297. }
  298. class MeasureRightBoard extends StatefulWidget {
  299. const MeasureRightBoard({Key? key}) : super(key: key);
  300. @override
  301. State<StatefulWidget> createState() => _MeasureRightBoardState();
  302. }
  303. class _MeasureRightBoardState extends State<MeasureRightBoard> {
  304. final playerController = Get.find<IPlayerController>();
  305. @override
  306. Widget build(BuildContext context) {
  307. return Container(
  308. padding: const EdgeInsets.all(8).copyWith(left: 0),
  309. child: const MeasureMainView(),
  310. );
  311. }
  312. }
  313. class _MeasureLeftBoard extends StatefulWidget {
  314. const _MeasureLeftBoard({Key? key}) : super(key: key);
  315. @override
  316. State<StatefulWidget> createState() => _MeasureLeftBoardState();
  317. }
  318. class _MeasureLeftBoardState extends State<_MeasureLeftBoard> {
  319. // ignore: non_constant_identifier_names
  320. static final C_SUPPORTED_ITEMS = <String>[
  321. MeasureTerms.Distance,
  322. MeasureTerms.Perimeter,
  323. MeasureTerms.Area,
  324. MeasureTerms.Angle,
  325. MeasureTerms.Depth,
  326. MeasureTerms.Volume,
  327. MeasureTerms.Stenosis,
  328. MeasureTerms.AbRatio,
  329. MeasureTerms.RUV,
  330. //
  331. MeasureTypes.AreaPerimeterEllipse,
  332. MeasureTypes.AreaPerimeterPolyline,
  333. MeasureTypes.AreaPerimeterSpline,
  334. ];
  335. // ignore: non_constant_identifier_names
  336. static final C_SUPPORTED_M_ITEMS = <String>[
  337. MeasureTerms.VerticalDistance,
  338. MeasureTerms.Timespan,
  339. MeasureTerms.Depth,
  340. MeasureTerms.Stenosis,
  341. MeasureTerms.AbRatio,
  342. MeasureTerms.Slope,
  343. MeasureTerms.TAMAX,
  344. MeasureTerms.Velocity,
  345. MeasureTerms.Acceleration,
  346. MeasureTerms.PSED,
  347. MeasureTerms.RI,
  348. "Qp/Qs",
  349. ];
  350. late final List<String> passeItems;
  351. final scrollController = ScrollController();
  352. final application = Get.find<IApplication>();
  353. String modeType = 'Tissue';
  354. int activeIndex = 0;
  355. List<ItemMeta> workingItems = [];
  356. @override
  357. void initState() {
  358. // passeItems = C_SUPPORTED_ITEMS;
  359. // passeItems = TestItems.C_DISTANCE_ITEMS;
  360. passeItems = TestItems.C_TEST_ITEMS;
  361. loadItems();
  362. application.visualAreaChanged.addListener(_visualAreaChanged);
  363. super.initState();
  364. }
  365. @override
  366. dispose() {
  367. application.visualAreaChanged.removeListener(_visualAreaChanged);
  368. super.dispose();
  369. }
  370. void loadItems() {
  371. workingItems = [];
  372. var names = (modeType == "TissueTM" || modeType == "Doppler")
  373. ? C_SUPPORTED_M_ITEMS
  374. : passeItems;
  375. final workingItemDtos =
  376. MeasureTestPage.MetaDTOList.where((e) => names.contains(e['Name']));
  377. for (var map in workingItemDtos) {
  378. final dto = ItemMetaDTO.fromJson(map);
  379. final item = ItemMetaConverter(dto).output();
  380. workingItems.add(item);
  381. }
  382. print("workingItems: ${workingItems.length}");
  383. }
  384. void _visualAreaChanged(sender, IVisualArea e) {
  385. if (mounted) {
  386. _setAvailableModes(e.mode.modeType.toString().split('.')[1]);
  387. // changeItemByMeta(0); //暂时不要自动切测量项
  388. setState(() {});
  389. }
  390. }
  391. void _setAvailableModes(String name) {
  392. modeType = name;
  393. print("_setAvailableModes: $name");
  394. loadItems();
  395. }
  396. @override
  397. Widget build(BuildContext context) {
  398. return Container(
  399. width: 300,
  400. padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
  401. child: Scrollbar(
  402. controller: scrollController,
  403. isAlwaysShown: true,
  404. child: ListView.separated(
  405. controller: scrollController,
  406. itemCount: workingItems.length,
  407. itemBuilder: (BuildContext context, int index) {
  408. final meta = workingItems[index];
  409. final active = index == activeIndex;
  410. return active
  411. ? ElevatedButton(
  412. onPressed: () {
  413. changeItemByMeta(index);
  414. },
  415. child: Text(meta.name),
  416. style: ElevatedButton.styleFrom(
  417. fixedSize: const Size.fromHeight(50),
  418. ),
  419. )
  420. : OutlinedButton(
  421. onPressed: () => changeItemByMeta(index),
  422. child: Text(meta.name),
  423. style: OutlinedButton.styleFrom(
  424. fixedSize: const Size.fromHeight(50),
  425. ),
  426. );
  427. },
  428. separatorBuilder: (BuildContext context, int index) {
  429. return const SizedBox(height: 8);
  430. },
  431. ),
  432. ),
  433. );
  434. }
  435. void changeItemByMeta(int index) {
  436. setState(() {
  437. activeIndex = index;
  438. });
  439. final meta = workingItems[index];
  440. application.switchItem(meta);
  441. print(application.activeMeasureItem?.meta.name);
  442. // handle combo item
  443. if (application.activeMeasureItem != null) {
  444. final item = application.activeMeasureItem!;
  445. if (item is ITopMeasureItem) {
  446. item.switchChild(0);
  447. }
  448. }
  449. }
  450. }
  451. class _MeasureLeftAnnotation extends StatefulWidget {
  452. const _MeasureLeftAnnotation({Key? key}) : super(key: key);
  453. @override
  454. State<StatefulWidget> createState() => _MeasureLeftAnnotationState();
  455. }
  456. class _MeasureLeftAnnotationState extends State<_MeasureLeftAnnotation> {
  457. // ignore: non_constant_identifier_names
  458. static final C_SUPPORTED_TEXTS = <String>[
  459. "肝左叶",
  460. "胆囊",
  461. "脾脏",
  462. "结石",
  463. "积液",
  464. ];
  465. final scrollController = ScrollController();
  466. final application = Get.find<IApplication>();
  467. @override
  468. void initState() {
  469. // application.switchAnnotation(AnnotationType.label, C_SUPPORTED_TEXTS[0]);
  470. // application.switchAnnotation(AnnotationType.arrow);
  471. application.switchAnnotation(AnnotationType.input);
  472. super.initState();
  473. }
  474. @override
  475. Widget build(BuildContext context) {
  476. return Container(
  477. width: 300,
  478. padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
  479. child: Scrollbar(
  480. controller: scrollController,
  481. isAlwaysShown: true,
  482. child: ListView.separated(
  483. controller: scrollController,
  484. itemCount: C_SUPPORTED_TEXTS.length,
  485. itemBuilder: (BuildContext context, int index) {
  486. final name = C_SUPPORTED_TEXTS[index];
  487. const style = TextStyle(color: Colors.white, fontSize: 16);
  488. const dragStyle = TextStyle(color: Colors.amber, fontSize: 18);
  489. // TODO: melon - set drag cursor after version updated up then 3.0
  490. // https://github.com/flutter/flutter/pull/100475
  491. return Draggable<String>(
  492. data: name,
  493. dragAnchorStrategy: (data, context, offset) {
  494. // return offset - Offset(120, 14);
  495. return Offset.zero;
  496. },
  497. child: OutlinedButton(
  498. child: Text(name, style: style),
  499. onPressed: () {
  500. application.switchAnnotation(AnnotationType.label, name);
  501. },
  502. style: OutlinedButton.styleFrom(
  503. shape: RoundedRectangleBorder(
  504. borderRadius: BorderRadius.circular(4),
  505. ),
  506. side: BorderSide(color: Colors.grey.shade100),
  507. fixedSize: const Size.fromHeight(44),
  508. ),
  509. ),
  510. feedback: Material(
  511. color: Colors.transparent,
  512. child: Text(name, style: dragStyle),
  513. ),
  514. onDragStarted: () {
  515. application.switchAnnotation(AnnotationType.label, name);
  516. },
  517. );
  518. },
  519. separatorBuilder: (BuildContext context, int index) {
  520. return const SizedBox(height: 8);
  521. },
  522. ),
  523. ),
  524. );
  525. }
  526. }
  527. class _ModeTips extends StatefulWidget {
  528. @override
  529. State<StatefulWidget> createState() => _ModeTipsState();
  530. }
  531. class _ModeTipsState extends State<_ModeTips> {
  532. IApplication? application;
  533. @override
  534. void initState() {
  535. Future.delayed(const Duration(milliseconds: 100), () {
  536. application = Get.find<IApplication>();
  537. application!.visualsLoaded.addListener(_onVisualsLoaded);
  538. });
  539. super.initState();
  540. }
  541. @override
  542. void dispose() {
  543. application!.visualsLoaded.removeListener(_onVisualsLoaded);
  544. super.dispose();
  545. }
  546. void _onVisualsLoaded(Object sender, void e) {
  547. setState(() {});
  548. }
  549. @override
  550. Widget build(BuildContext context) {
  551. if (application == null) return const Text("Wait");
  552. return Material(
  553. child: Text(application!.avaliableModes.map((e) => e.name).join('/')),
  554. );
  555. }
  556. }