measure_page_test.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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/measure_terms.dart';
  5. import 'package:fis_measure/interfaces/process/player/play_controller.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/interfaces/process/workspace/exam_info.dart';
  9. import 'package:fis_measure/interfaces/process/workspace/measure_controller.dart';
  10. import 'package:fis_measure/process/workspace/measure_3d_view_controller.dart';
  11. import 'package:fis_measure/process/workspace/measure_controller.dart';
  12. import 'package:fis_measure/process/workspace/measure_data_controller.dart';
  13. import 'package:fis_measure/view/measure/measure_main_view.dart';
  14. import 'package:flutter/material.dart';
  15. import 'package:get/get.dart';
  16. class MeasureDataTester {
  17. static Future<List<RemedicalItemList>> getRemedicalList(
  18. String patientCode,
  19. String recordCode,
  20. String token,
  21. ) async {
  22. return [];
  23. }
  24. static Future<RemedicalInfoDTO?> getImageInfo(
  25. String remedicalCode,
  26. String token,
  27. ) async {
  28. return null;
  29. }
  30. static Future<MeasureApplicationDTO?> getMeasureApplication(
  31. dynamic args) async {
  32. return null;
  33. }
  34. static Future<MeasureApplicationDTO?> saveUserDefinedMeasureApplicationAsync(
  35. dynamic args) async {
  36. return null;
  37. }
  38. static Future<bool?> saveImage(
  39. Uint8List imageBytes,
  40. String patientCode,
  41. String recordCode,
  42. String remedicalCode,
  43. String measuredData,
  44. ) async {
  45. return null;
  46. }
  47. static Future<void> saveMeasureSystemSettingAsync(
  48. MeasureSystemSettingDTO measureSystemSetting) async {
  49. return;
  50. }
  51. static Future<MeasureSystemSettingDTO?> getMeasureSystemSettingAsync() async {
  52. return null;
  53. }
  54. }
  55. class MeasureTestPage extends StatefulWidget {
  56. const MeasureTestPage({Key? key}) : super(key: key);
  57. @override
  58. State<StatefulWidget> createState() => _MeasureTestPageState();
  59. }
  60. class _MeasureTestPageState extends State<MeasureTestPage> {
  61. static const C_LINEAR_TISSUE =
  62. // "http://cdn-bj.fis.plus/0B344F48BA574ECD82B7FEDB8848421A.vid";//单幅TM
  63. "http://cdn-bj.fis.plus/F26C6E5D57A7472A97E9EB543DF0D16C.vid"; // 单幅Convex
  64. // "http://cdn-bj.fis.plus/6B6E069659D14E7299EB9F6EFCDE9C8C.vid"; //双幅单TissueConvex
  65. // "http://cdn-bj.fis.plus/062643B82365437DB95F3811580AF3ED.vid"; //四幅单模式
  66. // "http://cdn-bj.fis.plus/EA90D146049D416E8E466B7446E00001.vid"; //四幅Doppler
  67. // "http://cdn-bj.fis.plus/3rd_linearTvTissue2.vid"; //魔盒
  68. // "http://cdn-bj.fis.plus/81FFF8E5E078473FA687FBE81C4869B1.vid"; // 魔盒TV
  69. // "http://cdn-bj.fis.plus/7B450708A2784B1490304C82787349BE.vid";// 胎儿Zoom
  70. static const C_CONVEX_TISSUE =
  71. "http://cdn-bj.fis.plus/FEB1AAE5D9C24839BEE31B16E8CB450A.vid";
  72. final _3dc = Get.put<Measure3DViewController>(Measure3DViewController());
  73. final datac = Get.put<MeasureDataController>(MeasureDataController(
  74. MeasureDataTester.getRemedicalList,
  75. MeasureDataTester.getImageInfo,
  76. MeasureDataTester.getMeasureApplication,
  77. MeasureDataTester.saveUserDefinedMeasureApplicationAsync,
  78. MeasureDataTester.saveImage,
  79. MeasureDataTester.saveMeasureSystemSettingAsync,
  80. MeasureDataTester.getMeasureSystemSettingAsync,
  81. ));
  82. final controller = Get.put<IMeasureController>(MeasureController(
  83. "12345",
  84. imagesFetchFunc: (code) async {
  85. return <ExamImageInfo>[
  86. ExamImageInfo(C_LINEAR_TISSUE, C_LINEAR_TISSUE),
  87. ExamImageInfo(C_CONVEX_TISSUE, C_CONVEX_TISSUE)
  88. ];
  89. },
  90. ));
  91. bool loaded = false;
  92. int opType = 0;
  93. bool useArrowAnnotation = false;
  94. @override
  95. void initState() {
  96. controller.load().then((value) {
  97. // 加载指定图像
  98. controller.examInfo.selectedImageIndex = 0;
  99. });
  100. controller.imageLoaded.addListener(onImageLoaded);
  101. super.initState();
  102. }
  103. @override
  104. void dispose() {
  105. controller.imageLoaded.removeListener(onImageLoaded);
  106. controller.dispose();
  107. Get.delete<IMeasureController>();
  108. super.dispose();
  109. }
  110. void onImageLoaded(Object sender, ExamImageInfo? e) {
  111. if (!mounted) return;
  112. if (e != null) {
  113. Future.delayed(const Duration(milliseconds: 100), () {
  114. controller.playerController.play();
  115. });
  116. setState(() {
  117. loaded = true;
  118. });
  119. }
  120. }
  121. @override
  122. Widget build(BuildContext context) {
  123. Widget body;
  124. if (!loaded) {
  125. const loadingWidget = Center(child: CircularProgressIndicator());
  126. body = Row(
  127. children: const [
  128. SizedBox(
  129. width: 300,
  130. child: loadingWidget,
  131. ),
  132. VerticalDivider(),
  133. Expanded(child: loadingWidget),
  134. ],
  135. );
  136. } else {
  137. body = Row(
  138. key: ValueKey(controller.examInfo.selectedImageIndex),
  139. children: [
  140. opType == 1
  141. ? const _MeasureLeftAnnotation()
  142. : const _MeasureLeftBoard(),
  143. const VerticalDivider(),
  144. const Expanded(
  145. child: MeasureRightBoard(),
  146. ),
  147. ],
  148. );
  149. }
  150. return Scaffold(
  151. backgroundColor: const Color.fromARGB(255, 53, 55, 51),
  152. appBar: AppBar(
  153. actions: [
  154. TextButton(
  155. onPressed: () {
  156. Get.find<IApplication>().clearRecords();
  157. },
  158. child: const Text(
  159. "清空",
  160. style: TextStyle(
  161. color: Colors.white,
  162. ),
  163. ),
  164. ),
  165. TextButton(
  166. onPressed: () {
  167. Get.find<IApplication>().undoRecord();
  168. },
  169. child: const Text(
  170. "撤销",
  171. style: TextStyle(
  172. color: Colors.white,
  173. ),
  174. ),
  175. ),
  176. TextButton(
  177. onPressed: () {
  178. final c = Get.find<IStandardLineCalibrationController>();
  179. if (c.isEditing) {
  180. c.cancelEdit();
  181. } else {
  182. c.enterEditMode();
  183. }
  184. },
  185. child: const Text(
  186. "校准线",
  187. style: TextStyle(
  188. color: Colors.white,
  189. ),
  190. ),
  191. ),
  192. TextButton.icon(
  193. onPressed: () {
  194. setState(() {
  195. if (useArrowAnnotation) {
  196. useArrowAnnotation = false;
  197. controller.workingApplication.switchAnnotation();
  198. } else {
  199. useArrowAnnotation = true;
  200. controller.workingApplication
  201. .switchAnnotation(AnnotationType.arrow);
  202. }
  203. });
  204. },
  205. icon: const Icon(Icons.arrow_right_alt_sharp),
  206. label: Text(
  207. "箭头",
  208. style: TextStyle(
  209. color: useArrowAnnotation ? Colors.amber : Colors.white,
  210. ),
  211. ),
  212. ),
  213. TextButton(
  214. onPressed: () {
  215. setState(() {
  216. opType = opType == 1 ? 0 : 1;
  217. });
  218. },
  219. child: Text(
  220. opType == 1 ? "注释" : "测量",
  221. style: const TextStyle(
  222. color: Colors.white,
  223. ),
  224. ),
  225. ),
  226. TextButton(
  227. onPressed: () {
  228. if (controller.examInfo.selectedImageIndex == 0) return;
  229. controller.examInfo.selectedImageIndex = 0;
  230. },
  231. child: Text(
  232. '线阵',
  233. style: TextStyle(
  234. color: controller.examInfo.selectedImageIndex == 0
  235. ? Colors.amber
  236. : Colors.white,
  237. ),
  238. ),
  239. ),
  240. TextButton(
  241. onPressed: () {
  242. if (controller.examInfo.selectedImageIndex == 1) return;
  243. controller.examInfo.selectedImageIndex = 1;
  244. },
  245. child: Text(
  246. '扇阵',
  247. style: TextStyle(
  248. color: controller.examInfo.selectedImageIndex == 1
  249. ? Colors.amber
  250. : Colors.white,
  251. ),
  252. ),
  253. ),
  254. ],
  255. leading: IconButton(
  256. onPressed: () {
  257. Navigator.of(context).pop();
  258. },
  259. icon: const Icon(Icons.arrow_back),
  260. ),
  261. ),
  262. body: body,
  263. );
  264. }
  265. }
  266. class MeasureRightBoard extends StatefulWidget {
  267. const MeasureRightBoard({Key? key}) : super(key: key);
  268. @override
  269. State<StatefulWidget> createState() => _MeasureRightBoardState();
  270. }
  271. class _MeasureRightBoardState extends State<MeasureRightBoard> {
  272. final playerController = Get.find<IPlayerController>();
  273. @override
  274. Widget build(BuildContext context) {
  275. return Container(
  276. padding: const EdgeInsets.all(8).copyWith(left: 0),
  277. child: const MeasureMainView(),
  278. );
  279. }
  280. }
  281. class _MeasureLeftBoard extends StatefulWidget {
  282. const _MeasureLeftBoard({Key? key}) : super(key: key);
  283. @override
  284. State<StatefulWidget> createState() => _MeasureLeftBoardState();
  285. }
  286. class _MeasureLeftBoardState extends State<_MeasureLeftBoard> {
  287. // ignore: non_constant_identifier_names
  288. static final C_SUPPORTED_ITEMS = <String>[
  289. MeasureTerms.Distance,
  290. MeasureTerms.Perimeter,
  291. MeasureTerms.Area,
  292. MeasureTerms.Depth,
  293. ];
  294. final scrollController = ScrollController();
  295. final application = Get.find<IApplication>();
  296. int activeIndex = 0;
  297. @override
  298. void initState() {
  299. application.switchItemByName(C_SUPPORTED_ITEMS[0]);
  300. application.canMeasureChanged.addListener(_onCanMeasureChanged);
  301. super.initState();
  302. }
  303. @override
  304. dispose() {
  305. application.canMeasureChanged.removeListener(_onCanMeasureChanged);
  306. super.dispose();
  307. }
  308. _onCanMeasureChanged(Object sender, bool e) {
  309. if (e && mounted) {
  310. changeItem(0);
  311. }
  312. }
  313. @override
  314. Widget build(BuildContext context) {
  315. return Container(
  316. width: 300,
  317. padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
  318. child: Scrollbar(
  319. controller: scrollController,
  320. isAlwaysShown: true,
  321. child: ListView.separated(
  322. controller: scrollController,
  323. itemCount: C_SUPPORTED_ITEMS.length,
  324. itemBuilder: (BuildContext context, int index) {
  325. final name = C_SUPPORTED_ITEMS[index];
  326. final active = index == activeIndex;
  327. return active
  328. ? ElevatedButton(
  329. onPressed: () => changeItem(index),
  330. child: Text(name),
  331. style: ElevatedButton.styleFrom(
  332. fixedSize: const Size.fromHeight(50),
  333. ),
  334. )
  335. : OutlinedButton(
  336. onPressed: () => changeItem(index),
  337. child: Text(name),
  338. style: OutlinedButton.styleFrom(
  339. fixedSize: const Size.fromHeight(50),
  340. ),
  341. );
  342. },
  343. separatorBuilder: (BuildContext context, int index) {
  344. return const SizedBox(height: 8);
  345. },
  346. ),
  347. ),
  348. );
  349. }
  350. void changeItem(int index) {
  351. setState(() {
  352. activeIndex = index;
  353. });
  354. final name = C_SUPPORTED_ITEMS[index];
  355. application.switchItemByName(name);
  356. }
  357. }
  358. class _MeasureLeftAnnotation extends StatefulWidget {
  359. const _MeasureLeftAnnotation({Key? key}) : super(key: key);
  360. @override
  361. State<StatefulWidget> createState() => _MeasureLeftAnnotationState();
  362. }
  363. class _MeasureLeftAnnotationState extends State<_MeasureLeftAnnotation> {
  364. // ignore: non_constant_identifier_names
  365. static final C_SUPPORTED_TEXTS = <String>[
  366. "肝左叶",
  367. "胆囊",
  368. "脾脏",
  369. "结石",
  370. "积液",
  371. ];
  372. final scrollController = ScrollController();
  373. final application = Get.find<IApplication>();
  374. @override
  375. void initState() {
  376. // application.switchAnnotation(AnnotationType.label, C_SUPPORTED_TEXTS[0]);
  377. // application.switchAnnotation(AnnotationType.arrow);
  378. application.switchAnnotation(AnnotationType.input);
  379. super.initState();
  380. }
  381. @override
  382. Widget build(BuildContext context) {
  383. return Container(
  384. width: 300,
  385. padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
  386. child: Scrollbar(
  387. controller: scrollController,
  388. isAlwaysShown: true,
  389. child: ListView.separated(
  390. controller: scrollController,
  391. itemCount: C_SUPPORTED_TEXTS.length,
  392. itemBuilder: (BuildContext context, int index) {
  393. final name = C_SUPPORTED_TEXTS[index];
  394. const style = TextStyle(color: Colors.white, fontSize: 16);
  395. const dragStyle = TextStyle(color: Colors.amber, fontSize: 18);
  396. // TODO: melon - set drag cursor after version updated up then 3.0
  397. // https://github.com/flutter/flutter/pull/100475
  398. return Draggable<String>(
  399. data: name,
  400. dragAnchorStrategy: (data, context, offset) {
  401. // return offset - Offset(120, 14);
  402. return Offset.zero;
  403. },
  404. child: OutlinedButton(
  405. child: Text(name, style: style),
  406. onPressed: () {
  407. application.switchAnnotation(AnnotationType.label, name);
  408. },
  409. style: OutlinedButton.styleFrom(
  410. shape: RoundedRectangleBorder(
  411. borderRadius: BorderRadius.circular(4),
  412. ),
  413. side: BorderSide(color: Colors.grey.shade100),
  414. fixedSize: const Size.fromHeight(44),
  415. ),
  416. ),
  417. feedback: Material(
  418. color: Colors.transparent,
  419. child: Text(name, style: dragStyle),
  420. ),
  421. onDragStarted: () {
  422. application.switchAnnotation(AnnotationType.label, name);
  423. },
  424. );
  425. },
  426. separatorBuilder: (BuildContext context, int index) {
  427. return const SizedBox(height: 8);
  428. },
  429. ),
  430. ),
  431. );
  432. }
  433. }