|
@@ -1,146 +1,59 @@
|
|
|
import 'package:fis_lib_report/converts/event_type.dart';
|
|
|
-import 'package:fis_lib_report/report/element_tag.dart';
|
|
|
import 'package:fis_lib_report/report/element_type.dart';
|
|
|
-import 'package:fis_lib_report/report/inputImageList.dart';
|
|
|
import 'package:fis_lib_report/report/interfaces/block_element.dart';
|
|
|
import 'package:fis_lib_report/report/interfaces/element.dart';
|
|
|
-import 'package:fis_lib_report/report/paragraph.dart';
|
|
|
-import 'package:fis_lib_report/report/report_template_document.dart';
|
|
|
-import 'package:fis_lib_report/report/rt_page_size.dart';
|
|
|
-import 'package:fis_lib_report/report/rt_table.dart';
|
|
|
import 'package:fis_lib_report/report_info/block_element_info_interface.dart';
|
|
|
import 'package:fis_lib_report/report_info/element_info.dart';
|
|
|
-import 'package:fis_lib_report/report_info/element_tag_names.dart';
|
|
|
import 'package:fis_lib_report/report_info/input_image_info.dart';
|
|
|
import 'package:fis_lib_report/report_info/input_image_list_info.dart';
|
|
|
import 'package:fis_lib_report/report_info/input_text_info.dart';
|
|
|
import 'package:fis_lib_report/report_info/paragraph_info.dart';
|
|
|
+import 'package:fis_lib_report/report_info/report_base_info.dart';
|
|
|
+import 'package:fis_lib_report/report_info/report_event_args.dart';
|
|
|
import 'package:fis_lib_report/report_info/rt_table_info.dart';
|
|
|
import 'package:fis_lib_report/report_info/single_selected_info.dart';
|
|
|
|
|
|
-class ReportInfo {
|
|
|
+class ReportInfo extends ReportBaseInfo {
|
|
|
static ReportInfo? _reportInfo;
|
|
|
- List<IBlockElementInfo> blocks = [];
|
|
|
- List<IBlockElementInfo> headers = [];
|
|
|
- List<IBlockElementInfo> footers = [];
|
|
|
-
|
|
|
- /// Gets the author of the report template.
|
|
|
- String? author;
|
|
|
-
|
|
|
- /// Gets or sets the value to indicate whether the report template is created by user.
|
|
|
- bool? isCustom;
|
|
|
-
|
|
|
- /// Gets the report template name.
|
|
|
- String? name;
|
|
|
-
|
|
|
- /// Gets the custom input element tags of the report template.
|
|
|
- Map<String, ElementTag>? tags;
|
|
|
-
|
|
|
- /// Gets or sets the update time.
|
|
|
- DateTime? updateTime;
|
|
|
-
|
|
|
- ///version
|
|
|
- String? version;
|
|
|
-
|
|
|
- /// Gets the id.
|
|
|
- String? id;
|
|
|
|
|
|
ReportInfo._internal();
|
|
|
|
|
|
- //报告页大小
|
|
|
- RTPageSize? pageSize;
|
|
|
-
|
|
|
-//报告者
|
|
|
- String? reporter;
|
|
|
-
|
|
|
- //报告病人名
|
|
|
- String? patientName;
|
|
|
-
|
|
|
- ///病人Id
|
|
|
- String? patinentId;
|
|
|
-
|
|
|
- ///病人年龄
|
|
|
- String? patientAge;
|
|
|
-
|
|
|
- ///病人性别
|
|
|
- String? patientSex;
|
|
|
-
|
|
|
- ///报告日期
|
|
|
- DateTime? reportDate;
|
|
|
-
|
|
|
- ///报告模板
|
|
|
- ReportTemplateDocument? reportTemplate;
|
|
|
-
|
|
|
- ///重载
|
|
|
- FEventHandler<ReportEventArgs> onReload = FEventHandler();
|
|
|
-
|
|
|
- ///重载完成时触发
|
|
|
- FEventHandler onReloadFinsh = FEventHandler();
|
|
|
-
|
|
|
- ///关闭页面,释放监听
|
|
|
- FEventHandler onClose = FEventHandler();
|
|
|
-
|
|
|
///ReportInfo全局单例
|
|
|
static ReportInfo get instance {
|
|
|
_reportInfo ??= ReportInfo._internal();
|
|
|
return _reportInfo!;
|
|
|
}
|
|
|
|
|
|
- ///初始化ReportInfo
|
|
|
- void init(
|
|
|
- ReportTemplateDocument reportTemplate,
|
|
|
- DateTime reportDate,
|
|
|
- String reporter, {
|
|
|
- String? patientName,
|
|
|
- String? patinentId,
|
|
|
- String? patientAge,
|
|
|
- String? patientSex,
|
|
|
- }) {
|
|
|
- try {
|
|
|
- this.reportTemplate = reportTemplate;
|
|
|
- this.reportDate = reportDate;
|
|
|
- this.reporter = reporter;
|
|
|
- isCustom = reportTemplate.isCustom;
|
|
|
- name = reportTemplate.name;
|
|
|
- updateTime = reportTemplate.updateTime;
|
|
|
- version = reportTemplate.version;
|
|
|
- id = reportTemplate.id;
|
|
|
- for (var element in reportTemplate.header!) {
|
|
|
- headers.add(_initBlockElement(element));
|
|
|
- }
|
|
|
- for (var element in reportTemplate.blocks!) {
|
|
|
- blocks.add(_initBlockElement(element));
|
|
|
- }
|
|
|
- for (var element in reportTemplate.footer!) {
|
|
|
- footers.add(_initBlockElement(element));
|
|
|
- }
|
|
|
- pageSize = reportTemplate.pageSize;
|
|
|
- final nameInputInfo = getElementInfoByTagName(TagNames.PATIENT_NAME_TAG);
|
|
|
- if (patientName != null &&
|
|
|
- patientName.isNotEmpty &&
|
|
|
- nameInputInfo != null) {
|
|
|
- final inputInfo = nameInputInfo as InputTextInfo;
|
|
|
- inputInfo.text = patientName;
|
|
|
- }
|
|
|
- final ageInputInfo = getElementInfoByTagName(TagNames.PATIENT_AGE_TAG);
|
|
|
- if (patientAge != null && patientAge.isNotEmpty && ageInputInfo != null) {
|
|
|
- final inputInfo = ageInputInfo as InputTextInfo;
|
|
|
- inputInfo.text = patientAge;
|
|
|
- }
|
|
|
- final idInputInfo = getElementInfoByTagName(TagNames.PATIENT_ID_TAG);
|
|
|
- if (patinentId != null && patinentId.isNotEmpty && idInputInfo != null) {
|
|
|
- final inputInfo = idInputInfo as InputTextInfo;
|
|
|
- inputInfo.text = patinentId;
|
|
|
- }
|
|
|
- final sexSelectedInfo = getElementInfoByTagName(TagNames.PATIENT_SEX_TAG);
|
|
|
- if (patientSex != null &&
|
|
|
- patientSex.isNotEmpty &&
|
|
|
- sexSelectedInfo != null) {
|
|
|
- final selectedInfo = sexSelectedInfo as SingleSelectedInfo;
|
|
|
- selectedInfo.selectedItem = patientSex;
|
|
|
+ ///从Json中加载数据
|
|
|
+ void fromJson(Map<String, dynamic> json) {
|
|
|
+ List<dynamic> jsonBlocks = json['BlockInfos'];
|
|
|
+ if (jsonBlocks.isNotEmpty) {
|
|
|
+ for (var block in jsonBlocks) {
|
|
|
+ final type = block['ElementType'];
|
|
|
+ final jsonType = ElementType.fromJson(type);
|
|
|
+ final name = jsonType.name;
|
|
|
+ if (name == ElementType.paragraph.name) {
|
|
|
+ final paragraphInfo = block as Map<String, dynamic>;
|
|
|
+ _paragraphInfoFromJson(paragraphInfo);
|
|
|
+ } else if (name == ElementType.rtTable.name) {
|
|
|
+ final tableInfo = block as Map<String, dynamic>;
|
|
|
+ List<dynamic> jsonElements = tableInfo['Cells'];
|
|
|
+ int index = 0;
|
|
|
+ for (var map in jsonElements) {
|
|
|
+ //TODO(Loki):此处可优化Json的结构,无需区分奇偶
|
|
|
+ if (index.isOdd) {
|
|
|
+ final jsonType = map['ElementType'];
|
|
|
+ final type = ElementType.fromJson(jsonType);
|
|
|
+ if (type.name == ElementType.rtCell.name) {
|
|
|
+ final cellMap = map as Map<String, dynamic>;
|
|
|
+ final jsonBlocks = cellMap['Blocks'] as Map<String, dynamic>;
|
|
|
+ _paragraphInfoFromJson(jsonBlocks);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- } catch (e) {
|
|
|
- print(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -216,42 +129,6 @@ class ReportInfo {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- ///跟据TagName获取Elementnt
|
|
|
- ElementInfo? getElementInfoByTagName(String tagName) {
|
|
|
- try {
|
|
|
- for (var e in headers) {
|
|
|
- if (e.tag != null && e.tag!.name == tagName) {
|
|
|
- return e;
|
|
|
- }
|
|
|
- final elementInfo = _getBaseElementInfoByTagName(e, tagName);
|
|
|
- if (elementInfo != null) {
|
|
|
- return elementInfo;
|
|
|
- }
|
|
|
- }
|
|
|
- for (var e in blocks) {
|
|
|
- if (e.tag != null && e.tag!.name == tagName) {
|
|
|
- return e;
|
|
|
- }
|
|
|
- final elementInfo = _getBaseElementInfoByTagName(e, tagName);
|
|
|
- if (elementInfo != null) {
|
|
|
- return elementInfo;
|
|
|
- }
|
|
|
- }
|
|
|
- for (var e in footers) {
|
|
|
- if (e.tag != null && e.tag!.name == tagName) {
|
|
|
- return e;
|
|
|
- }
|
|
|
- final elementInfo = _getBaseElementInfoByTagName(e, tagName);
|
|
|
- if (elementInfo != null) {
|
|
|
- return elementInfo;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (e) {
|
|
|
- print(e);
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
///跟据UI组件获取ReportInfo中的组件
|
|
|
ElementInfo? getElementInfo(IElement element) {
|
|
|
try {
|
|
@@ -279,17 +156,27 @@ class ReportInfo {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- IBlockElementInfo _initBlockElement(IBlockElement element) {
|
|
|
- final _type = element.elementType!;
|
|
|
- if (_type.name == ElementType.rtTable!.name) {
|
|
|
- final table = element as RTTable;
|
|
|
- return RTTableInfo.fromElement(table);
|
|
|
- } else if (_type.name == ElementType.paragraph!.name) {
|
|
|
- final paragraph = element as Paragraph;
|
|
|
- return ParagraphInfo.fromElement(paragraph);
|
|
|
- } else {
|
|
|
- final inputImageList = element as InputImageList;
|
|
|
- return InputImageListInfo.fromElement(inputImageList);
|
|
|
+ void _paragraphInfoFromJson(Map<String, dynamic> paragraphInfo) {
|
|
|
+ List<dynamic> jsonElements = paragraphInfo['ElementInfos'];
|
|
|
+ if (jsonElements.isEmpty) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (var map in jsonElements) {
|
|
|
+ final jsonType = ElementType.fromJson(map['ElementType']);
|
|
|
+ final id = map['Id'];
|
|
|
+ if (jsonType.name == ElementType.inputText.name) {
|
|
|
+ final info = getElementInfoById(id);
|
|
|
+ if (info != null) {
|
|
|
+ final inputInfo = info as InputTextInfo;
|
|
|
+ inputInfo.text = map['Text'];
|
|
|
+ }
|
|
|
+ } else if (jsonType.name == ElementType.singleSelected.name) {
|
|
|
+ final info = getElementInfoById(id);
|
|
|
+ if (info != null) {
|
|
|
+ final inputInfo = info as SingleSelectedInfo;
|
|
|
+ inputInfo.selectedItem = map['SelectedItem'];
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -318,7 +205,7 @@ class ReportInfo {
|
|
|
ElementInfo? _getBaseElementInfo(IBlockElementInfo block, IElement element) {
|
|
|
ElementInfo? result;
|
|
|
final type = block.elementType;
|
|
|
- if (type!.name == ElementType.paragraph!.name) {
|
|
|
+ if (type!.name == ElementType.paragraph.name) {
|
|
|
final paragraph = block as ParagraphInfo;
|
|
|
for (var el in paragraph.elementInfos!) {
|
|
|
if (el.id == element.id) {
|
|
@@ -328,7 +215,7 @@ class ReportInfo {
|
|
|
}
|
|
|
}
|
|
|
if (result == null) {
|
|
|
- if (type.name == ElementType.rtTable!.name) {
|
|
|
+ if (type.name == ElementType.rtTable.name) {
|
|
|
final table = block as RTTableInfo;
|
|
|
final cells = table.cells!;
|
|
|
for (var cell in cells.values) {
|
|
@@ -346,45 +233,12 @@ class ReportInfo {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- ///获取基础组件信息
|
|
|
- ElementInfo? _getBaseElementInfoByTagName(
|
|
|
- IBlockElementInfo block, String tagName) {
|
|
|
- ElementInfo? result;
|
|
|
- final type = block.elementType;
|
|
|
- if (type!.name == ElementType.paragraph!.name) {
|
|
|
- final paragraph = block as ParagraphInfo;
|
|
|
- for (var el in paragraph.elementInfos!) {
|
|
|
- if (el.tag != null && el.tag!.name == tagName) {
|
|
|
- result = el;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (result == null) {
|
|
|
- if (type.name == ElementType.rtTable!.name) {
|
|
|
- final table = block as RTTableInfo;
|
|
|
- final cells = table.cells!;
|
|
|
- for (var cell in cells.values) {
|
|
|
- for (var b in cell.blocks!) {
|
|
|
- final info = _getBaseElementInfoByTagName(b, tagName);
|
|
|
- if (info != null) {
|
|
|
- result = info;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
Map<String, dynamic> _getElementInfo(IBlockElementInfo element) {
|
|
|
final _type = element.elementType!;
|
|
|
- if (_type.name == ElementType.rtTable!.name) {
|
|
|
+ if (_type.name == ElementType.rtTable.name) {
|
|
|
final table = element as RTTableInfo;
|
|
|
return table.toJson();
|
|
|
- } else if (_type.name == ElementType.paragraph!.name) {
|
|
|
+ } else if (_type.name == ElementType.paragraph.name) {
|
|
|
final paragraph = element as ParagraphInfo;
|
|
|
return paragraph.toJson();
|
|
|
} else {
|
|
@@ -393,12 +247,3 @@ class ReportInfo {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-class ReportEventArgs {
|
|
|
- final FEventHandler<String> onSelect;
|
|
|
-
|
|
|
- final String jsonStr;
|
|
|
- final String reporter;
|
|
|
- final DateTime reportDate;
|
|
|
- ReportEventArgs(this.reportDate, this.reporter, this.jsonStr, this.onSelect);
|
|
|
-}
|