measure_page_test.dart 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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. "Qp/Qs",
  345. ];
  346. late final List<String> passeItems;
  347. final scrollController = ScrollController();
  348. final application = Get.find<IApplication>();
  349. String modeType = 'Tissue';
  350. int activeIndex = 0;
  351. List<ItemMeta> workingItems = [];
  352. @override
  353. void initState() {
  354. // passeItems = C_SUPPORTED_ITEMS;
  355. // passeItems = TestItems.C_DISTANCE_ITEMS;
  356. passeItems = TestItems.C_TEST_ITEMS;
  357. loadItems();
  358. application.visualAreaChanged.addListener(_visualAreaChanged);
  359. super.initState();
  360. }
  361. @override
  362. dispose() {
  363. application.visualAreaChanged.removeListener(_visualAreaChanged);
  364. super.dispose();
  365. }
  366. void loadItems() {
  367. workingItems = [];
  368. var names = (modeType == "TissueTM" || modeType == "Doppler")
  369. ? C_SUPPORTED_M_ITEMS
  370. : passeItems;
  371. final workingItemDtos =
  372. MeasureTestPage.MetaDTOList.where((e) => names.contains(e['Name']));
  373. for (var map in workingItemDtos) {
  374. final dto = ItemMetaDTO.fromJson(map);
  375. final item = ItemMetaConverter(dto).output();
  376. workingItems.add(item);
  377. }
  378. print("workingItems: ${workingItems.length}");
  379. }
  380. void _visualAreaChanged(sender, IVisualArea e) {
  381. if (mounted) {
  382. _setAvailableModes(e.mode.modeType.toString().split('.')[1]);
  383. // changeItemByMeta(0); //暂时不要自动切测量项
  384. setState(() {});
  385. }
  386. }
  387. void _setAvailableModes(String name) {
  388. modeType = name;
  389. print("_setAvailableModes: $name");
  390. loadItems();
  391. }
  392. @override
  393. Widget build(BuildContext context) {
  394. return Container(
  395. width: 300,
  396. padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
  397. child: Scrollbar(
  398. controller: scrollController,
  399. isAlwaysShown: true,
  400. child: ListView.separated(
  401. controller: scrollController,
  402. itemCount: workingItems.length,
  403. itemBuilder: (BuildContext context, int index) {
  404. final meta = workingItems[index];
  405. final active = index == activeIndex;
  406. return active
  407. ? ElevatedButton(
  408. onPressed: () {
  409. changeItemByMeta(index);
  410. },
  411. child: Text(meta.name),
  412. style: ElevatedButton.styleFrom(
  413. fixedSize: const Size.fromHeight(50),
  414. ),
  415. )
  416. : OutlinedButton(
  417. onPressed: () => changeItemByMeta(index),
  418. child: Text(meta.name),
  419. style: OutlinedButton.styleFrom(
  420. fixedSize: const Size.fromHeight(50),
  421. ),
  422. );
  423. },
  424. separatorBuilder: (BuildContext context, int index) {
  425. return const SizedBox(height: 8);
  426. },
  427. ),
  428. ),
  429. );
  430. }
  431. void changeItemByMeta(int index) {
  432. setState(() {
  433. activeIndex = index;
  434. });
  435. final meta = workingItems[index];
  436. application.switchItem(meta);
  437. print(application.activeMeasureItem?.meta.name);
  438. // handle combo item
  439. if (application.activeMeasureItem != null) {
  440. final item = application.activeMeasureItem!;
  441. if (item is ITopMeasureItem) {
  442. item.switchChild(0);
  443. }
  444. }
  445. }
  446. }
  447. class _MeasureLeftAnnotation extends StatefulWidget {
  448. const _MeasureLeftAnnotation({Key? key}) : super(key: key);
  449. @override
  450. State<StatefulWidget> createState() => _MeasureLeftAnnotationState();
  451. }
  452. class _MeasureLeftAnnotationState extends State<_MeasureLeftAnnotation> {
  453. // ignore: non_constant_identifier_names
  454. static final C_SUPPORTED_TEXTS = <String>[
  455. "肝左叶",
  456. "胆囊",
  457. "脾脏",
  458. "结石",
  459. "积液",
  460. ];
  461. final scrollController = ScrollController();
  462. final application = Get.find<IApplication>();
  463. @override
  464. void initState() {
  465. // application.switchAnnotation(AnnotationType.label, C_SUPPORTED_TEXTS[0]);
  466. // application.switchAnnotation(AnnotationType.arrow);
  467. application.switchAnnotation(AnnotationType.input);
  468. super.initState();
  469. }
  470. @override
  471. Widget build(BuildContext context) {
  472. return Container(
  473. width: 300,
  474. padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
  475. child: Scrollbar(
  476. controller: scrollController,
  477. isAlwaysShown: true,
  478. child: ListView.separated(
  479. controller: scrollController,
  480. itemCount: C_SUPPORTED_TEXTS.length,
  481. itemBuilder: (BuildContext context, int index) {
  482. final name = C_SUPPORTED_TEXTS[index];
  483. const style = TextStyle(color: Colors.white, fontSize: 16);
  484. const dragStyle = TextStyle(color: Colors.amber, fontSize: 18);
  485. // TODO: melon - set drag cursor after version updated up then 3.0
  486. // https://github.com/flutter/flutter/pull/100475
  487. return Draggable<String>(
  488. data: name,
  489. dragAnchorStrategy: (data, context, offset) {
  490. // return offset - Offset(120, 14);
  491. return Offset.zero;
  492. },
  493. child: OutlinedButton(
  494. child: Text(name, style: style),
  495. onPressed: () {
  496. application.switchAnnotation(AnnotationType.label, name);
  497. },
  498. style: OutlinedButton.styleFrom(
  499. shape: RoundedRectangleBorder(
  500. borderRadius: BorderRadius.circular(4),
  501. ),
  502. side: BorderSide(color: Colors.grey.shade100),
  503. fixedSize: const Size.fromHeight(44),
  504. ),
  505. ),
  506. feedback: Material(
  507. color: Colors.transparent,
  508. child: Text(name, style: dragStyle),
  509. ),
  510. onDragStarted: () {
  511. application.switchAnnotation(AnnotationType.label, name);
  512. },
  513. );
  514. },
  515. separatorBuilder: (BuildContext context, int index) {
  516. return const SizedBox(height: 8);
  517. },
  518. ),
  519. ),
  520. );
  521. }
  522. }
  523. class _ModeTips extends StatefulWidget {
  524. @override
  525. State<StatefulWidget> createState() => _ModeTipsState();
  526. }
  527. class _ModeTipsState extends State<_ModeTips> {
  528. IApplication? application;
  529. @override
  530. void initState() {
  531. Future.delayed(const Duration(milliseconds: 100), () {
  532. application = Get.find<IApplication>();
  533. application!.visualsLoaded.addListener(_onVisualsLoaded);
  534. });
  535. super.initState();
  536. }
  537. @override
  538. void dispose() {
  539. application!.visualsLoaded.removeListener(_onVisualsLoaded);
  540. super.dispose();
  541. }
  542. void _onVisualsLoaded(Object sender, void e) {
  543. setState(() {});
  544. }
  545. @override
  546. Widget build(BuildContext context) {
  547. if (application == null) return const Text("Wait");
  548. return Material(
  549. child: Text(application!.avaliableModes.map((e) => e.name).join('/')),
  550. );
  551. }
  552. }