123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- import 'dart:convert';
- import 'package:fis_common/index.dart';
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/managers/interfaces/follow_up.dart';
- import 'package:vitalapp/managers/interfaces/prescription.dart';
- import 'package:vitalapp/managers/interfaces/template.dart';
- import 'package:vitalapp/pages/check/prescription/pediatric_prescription_collection.dart';
- import 'package:vitalapp/pages/form/form_info.dart';
- import 'package:vitalapp/store/store.dart';
- import 'forms/antenatal_visit.dart';
- import 'forms/checkup_42_days.dart';
- import 'forms/first_form.dart';
- import 'forms/postpartum_follow_up.dart';
- import 'state.dart';
- class MaternalHealthManagementController extends GetxController {
- MaternalHealthManagementController();
- //第 1 次产前检查
- final String firstFollowUpkey = "MaternalHealthManagement";
- //第 2~5 次产前随访
- final String prenatalFollowupKey = "PrenatalFollowupServiceRecord";
- //产后访视
- final String postnatalVisitKey = "PostnatalVisitRecord";
- //产后42天随访
- final String postpartumHealthCheckup42DaysKey =
- "PostpartumHealthCheckup42Days";
- final _followUpManager = Get.find<IFollowUpManager>();
- final _templateManager = Get.find<ITemplateManager>();
- final _prescriptionManager = Get.find<IPrescriptionManager>();
- final state = MaternalHealthManagementState();
- List<List> offlineSyncTemp = [];
- ///是否处于编辑模式
- bool isEdit = false;
- ///当前选中的记录Code
- String recordCode = "";
- ///当前使用的模板Code
- String templateCode = "";
- FollowUpModeEnum followUpMode = FollowUpModeEnum.Outpatient;
- @override
- void onReady() {
- super.onReady();
- _initData();
- }
- Future<bool> save(String key) async {
- List<String> followUpPhotos = [];
- DateTime followUpTime = DateTime.now();
- String? followUpData;
- // if (FormInfo.instance.formValue.isEmpty) {
- // PromptBox.toast('不能提交空数据');
- // return false;
- // }
- followUpData = jsonEncode(FormInfo.instance.formValue);
- if (FormInfo.instance.formValue.containsKey("Form_Date")) {
- followUpTime = DateTime.parse(FormInfo.instance.formValue["Form_Date"]);
- }
- DateTime? nextFollowUpTime;
- if (FormInfo.instance.formValue.containsKey("Next_Follow_Up_Date")) {
- nextFollowUpTime =
- DateTime.parse(FormInfo.instance.formValue["Next_Follow_Up_Date"]);
- }
- String patientCode = Store.user.currentSelectPatientInfo?.code ?? '';
- bool result = false;
- if (isEdit) {
- result = await _followUpManager.updateFollowUp(
- UpdateFollowUpRequest(
- key: key,
- followUpData: followUpData,
- followUpTime: followUpTime,
- nextFollowUpTime: nextFollowUpTime,
- followUpMode: followUpMode,
- followUpPhotos: followUpPhotos,
- code: recordCode,
- ),
- ) ??
- false;
- } else {
- String createResult = await _followUpManager.createFollowUp(
- CreateFollowUpRequest(
- key: key,
- patientCode: patientCode,
- templateCode: templateCode,
- followUpData: followUpData,
- followUpTime: followUpTime,
- nextFollowUpTime: nextFollowUpTime,
- followUpMode: followUpMode,
- followUpPhotos: followUpPhotos,
- ),
- );
- if (createResult.isNotEmpty) {
- recordCode = createResult;
- result = true;
- }
- }
- if (result) {
- getFollowUpRecordList();
- return true;
- }
- return false;
- }
- Future<void> getFollowUpRecordList() async {
- try {
- var patientCode = Store.user.currentSelectPatientInfo?.code ?? '';
- var result = await _followUpManager.getFollowUpRecordList(
- [
- firstFollowUpkey,
- prenatalFollowupKey,
- postnatalVisitKey,
- postpartumHealthCheckup42DaysKey,
- ],
- patientCode,
- );
- List<FollowUpRecordDTO> followUpDTOList = [];
- followUpDTOList.addAll(result ?? []);
- state.followUpDTOList = followUpDTOList;
- } catch (e) {
- return;
- }
- }
- String getFollowUpValueByKey(FollowUpRecordDataDTO dto) {
- var key = dto.key;
- if (key == firstFollowUpkey) {
- return "第 1 次产前检查";
- } else if (key == prenatalFollowupKey) {
- Map datas = jsonDecode(dto.followUpData ?? '');
- if (datas.containsKey("times")) {
- int times = datas["times"] ?? 2;
- return "第 ${times} 次产前随访";
- }
- return "第 2~5 次产前随访";
- } else if (key == postnatalVisitKey) {
- return "产后访视";
- } else if (key == postpartumHealthCheckup42DaysKey) {
- return "产后 42 天健康检查";
- }
- return "";
- }
- Future<List<String>> sharePrescription(
- FollowUpRecordDataDTO dataDTO,
- ) async {
- List<String> previewUrlList = [];
- List<PrescriptionDTO>? prescriptionList =
- await getPrescriptionList(dataDTO.code!);
- for (PrescriptionDTO prescription in prescriptionList ?? []) {
- previewUrlList.add(prescription.previewUrl ?? "");
- }
- return previewUrlList;
- }
- Future<List<PrescriptionDTO>?> getPrescriptionList(
- String followUpCode) async {
- // 获取处方列表
- var patientCode = Store.user.currentSelectPatientInfo?.code ?? '';
- List<PrescriptionDTO>? prescriptionList =
- await _prescriptionManager.getPrescriptionPage(
- patientCode: patientCode,
- followUpCode: followUpCode,
- );
- return prescriptionList;
- }
- ///跳转至随访页面
- void toCheckPage(FollowUpRecordDataDTO dataDto) {
- if (dataDto.followUpData.isNullOrEmpty) {
- return;
- }
- var datas = jsonDecode(dataDto.followUpData ?? '');
- if (datas is Map<String, dynamic>) {
- FormInfo.instance.formValue = datas;
- var key = dataDto.key;
- if (key == firstFollowUpkey) {
- Get.to(FirstMaternalHealthManagementForm(
- onClickPrescribe: () async {
- await Get.to(
- PrescriptionCollection(
- recordCode,
- isChild: false,
- ),
- );
- },
- ));
- } else if (key == prenatalFollowupKey) {
- int times = FormInfo.instance.formValue["times"] ?? 2;
- Get.to(AntenatalVisitForm(
- times,
- onClickPrescribe: () async {
- await Get.to(
- PrescriptionCollection(
- recordCode,
- isChild: false,
- ),
- );
- },
- ));
- } else if (key == postnatalVisitKey) {
- Get.to(PostpartumFormView(
- onClickPrescribe: () async {
- await Get.to(
- PrescriptionCollection(
- recordCode,
- isChild: false,
- ),
- );
- },
- ));
- } else if (key == postpartumHealthCheckup42DaysKey) {
- Get.to(PostpartumHealthCheckup42DaysForm(
- onClickPrescribe: () async {
- await Get.to(
- PrescriptionCollection(
- recordCode,
- isChild: false,
- ),
- );
- },
- ));
- }
- }
- }
- Future<String> getTemplate(String key) async {
- var templates =
- await _templateManager.readTemplateRelation('templateRelation');
- var templateRelation = jsonDecode(templates!);
- templateCode = templateRelation[key] ?? '';
- var template = await _templateManager.readTemplate(templateCode) ?? '';
- String templateContent =
- TemplateDTO.fromJson(jsonDecode(template)).templateContent!;
- return templateContent;
- }
- void _initData() {
- getFollowUpRecordList();
- }
- }
|