import 'antd/es/message/style';
import _message from 'antd/es/message';
import _set from 'lodash/set';
import _get from 'lodash/get';
import _find from 'lodash/find';
import _cloneDeep from 'lodash/cloneDeep';
import { s as styleInject, b as __awaiter, c as __generator, e as api, d as __assign, f as __rest, D as DoctorEnd_Diagnoses } from './index.js';
import { MyFormSectionForm, useMyEffectSafe, MyLazyComponent, OkButton, getBMI, EventEmitter_Old, CustomIcon, GestationalWeekProjectTree, formatTimeToDate } from '@lm_fe/components_m';
import { mchcUtils, mchcEvent, mchcEnv, mchcConfig } from '@lm_fe/env';
import { process_OutpatientDocument_physicalExam_remote, SLocal_Calculator, process_OutpatientDocument_physicalExam_local, SMchc_Doctor } from '@lm_fe/service';
import { expect_array, getFutureDate, request, copyText, getSearchParamsValue } from '@lm_fe/utils';
import React__default, { useState, useEffect, lazy, useCallback, useRef } from 'react';
import 'antd/es/card/style';
import _Card from 'antd/es/card';
import 'antd/es/space/style';
import _Space from 'antd/es/space';
import 'antd/es/button/style';
import _Button from 'antd/es/button';
import 'antd/es/form/style';
import _Form from 'antd/es/form';
import _size from 'lodash/size';
import { PlusOutlined, SyncOutlined, SettingOutlined } from '@ant-design/icons';
import { I as Index, a as Index$1, M as ManagementPlan, f as filter_diagnoses } from './index2.js';
import 'antd/es/modal/style';
import _Modal from 'antd/es/modal';
import 'antd/es/tabs/style';
import _Tabs from 'antd/es/tabs';
import _isEmpty from 'lodash/isEmpty';
import _forEach from 'lodash/forEach';
import { LazyAntd, MyLazyComponent as MyLazyComponent$1 } from '@lm_fe/components';
import { BF_Wrap2, mchcModal__, HighRiskTableEntry } from '@lm_fe/pages';
import { _ as _extends } from './extends.js';
import 'lodash/values';
import 'lodash/keyBy';
import classnames from 'classnames';
import 'antd/es/timeline/style';
import _Timeline from 'antd/es/timeline';
import 'antd/es/collapse/style';
import _Collapse from 'antd/es/collapse';
import _slice from 'lodash/slice';
import _map from 'lodash/map';
import _join from 'lodash/join';
import { u as useHistory } from './react-router.js';
var css_248z$5 = ".result-import-modal .ant-modal-body {\n  max-height: 650px;\n  overflow-y: auto;\n  padding: 12px 24px;\n}\n.result-import-modal .ant-modal-body .ant-tabs-bar {\n  margin-bottom: 0;\n  border-bottom: none;\n}\n.result-import-modal .ant-modal-body .ant-tabs-tab-active .list-btn {\n  color: #3d8bf7;\n  border: 1px solid #007aff;\n}\n.result-import-modal .ant-modal-body .ant-tabs-ink-bar {\n  display: none !important;\n}\n.result-import-modal .ant-modal-body .ant-tabs-nav .ant-tabs-tab {\n  margin-right: 0;\n}\n.result-import-modal .ant-modal-body .ant-tabs-top > .ant-tabs-nav {\n  margin-bottom: 6px;\n}\n.result-import-modal .ant-modal-body .ant-tabs-top > .ant-tabs-nav::before {\n  border: none;\n}\n.result-import-modal .ant-modal-body .list-btn {\n  height: 32px;\n  color: #535881;\n  font-weight: 600;\n  padding: 0 15px;\n  margin-right: 24px;\n  background-color: #fff;\n  border: 1px solid #d8dce6;\n}\n.result-import-modal .unusual-item .ant-tree-checkbox-inner {\n  background-color: #ff517d;\n}\n.result-import-modal .unusual-item .ant-tree-title {\n  color: #ff517d;\n}\n";
styleInject(css_248z$5);
var Tree = LazyAntd.Tree;
LazyAntd.TreeSelect;
LazyAntd.Select;
LazyAntd.Table;
LazyAntd.Dropdown;
LazyAntd.Pagination;
function ResultImport(props) {
  var _this = this;
  var headerInfo = props.headerInfo,
    closeModal = props.closeModal;
  var isShowResultImport = props.isShowResultImport,
    importTitle = props.importTitle;
  var _a = useState('1'),
    activeTabKey = _a[0],
    set_activeTabKey = _a[1];
  var _b = useState([]),
    examResult = _b[0],
    set_examResult = _b[1];
  var _c = useState(''),
    defaultExpandedKey = _c[0],
    set_defaultExpandedKey = _c[1];
  var _d = useState([]),
    checkedItems = _d[0],
    set_checkedItems = _d[1];
  useEffect(function () {
    (function () {
      return __awaiter(_this, void 0, void 0, function () {
        var examResult;
        return __generator(this, function (_a) {
          switch (_a.label) {
            case 0:
              return [4, api.components.getLabExamImportTree(_get(headerInfo, 'id'))];
            case 1:
              examResult = _a.sent();
              set_examResult(examResult);
              set_defaultExpandedKey(String(_get(examResult, '0.id')));
              return [2];
          }
        });
      });
    })();
    return function () {};
  }, []);
  function handleCancel() {
    closeModal('isShowResultImport');
  }
  function handleTabChange(key) {
    return __awaiter(this, void 0, void 0, function () {
      var headerInfo, examResult;
      return __generator(this, function (_a) {
        switch (_a.label) {
          case 0:
            headerInfo = props.headerInfo;
            examResult = [];
            if (!(key === '1')) return [3, 2];
            return [4, api.components.getLabExamImportTree(_get(headerInfo, 'id'))];
          case 1:
            examResult = _a.sent();
            return [3, 4];
          case 2:
            return [4, api.components.getImageExamImportTree(_get(headerInfo, 'id'))];
          case 3:
            examResult = _a.sent();
            _a.label = 4;
          case 4:
            set_activeTabKey(key);
            set_examResult(examResult);
            set_defaultExpandedKey(String(_get(examResult, '0.id')));
            return [2];
        }
      });
    });
  }
  function handleOk() {
    var nodeStr = '';
    if (checkedItems.length > 0) {
      _forEach(checkedItems, function (item) {
        nodeStr += item + '，';
      });
    }
    nodeStr = nodeStr.substr(0, nodeStr.length - 1);
    closeModal('isShowResultImport', nodeStr, 'inspection');
  }
  function handleCheck(keys, _a) {
    var checkedNodes = _a.checkedNodes;
    console.log({
      checkedNodes: checkedNodes
    });
    var checkedItems = [];
    _forEach(checkedNodes, function (item) {
      checkedItems.push(item.title);
    });
    set_checkedItems(checkedItems);
  }
  function transferTemplateData(data, pid) {
    if (pid === void 0) {
      pid = 0;
    }
    var treeData = [];
    var unusualArr = ['↑', '↓'];
    _forEach(data, function (item) {
      if (item.pid === pid) {
        item.key = String(item.id);
        item.className = item.unusual === '1' && 'unusual-item';
        item.title = unusualArr.includes(item.unusualDesc) ? "".concat(item.title, " ").concat(item.unusualDesc) : item.title;
        item.children = transferTemplateData(item.items, item.id);
        if (_isEmpty(item.children)) {
          item.isLeaf = true;
        } else {
          item.isLeaf = false;
        }
        treeData.push(item);
      }
    });
    return treeData;
  }
  var treeData = transferTemplateData(examResult);
  return /*#__PURE__*/React__default.createElement(_Modal, {
    className: "result-import-modal",
    title: importTitle,
    visible: isShowResultImport,
    width: 900,
    onCancel: handleCancel,
    onOk: handleOk
  }, /*#__PURE__*/React__default.createElement(_Tabs, {
    defaultActiveKey: activeTabKey,
    onChange: handleTabChange
  }, /*#__PURE__*/React__default.createElement(_Tabs.TabPane, {
    tab: /*#__PURE__*/React__default.createElement(_Button, {
      className: "list-btn"
    }, "\u68C0\u9A8C\u7ED3\u679C"),
    key: "1"
  }, !_isEmpty(examResult) && activeTabKey === '1' ? /*#__PURE__*/React__default.createElement(Tree, {
    checkable: true,
    defaultExpandedKeys: [defaultExpandedKey],
    onCheck: handleCheck,
    treeData: treeData
  }) : '暂无数据~'), /*#__PURE__*/React__default.createElement(_Tabs.TabPane, {
    tab: /*#__PURE__*/React__default.createElement(_Button, {
      className: "list-btn"
    }, "\u8D85\u58F0\u7ED3\u679C"),
    key: "2"
  }, !_isEmpty(examResult) && activeTabKey === '2' ? /*#__PURE__*/React__default.createElement(Tree, {
    checkable: true,
    defaultExpandedKeys: [defaultExpandedKey],
    onCheck: handleCheck,
    treeData: treeData
  }) : '暂无数据~')));
}
var diag_filter_map = {
  diabetes: {
    diagKeyword: ['糖尿病', 'GDM', 'gdm']
  },
  ultrasounds: {
    diagKeyword: ['双胎', '三胎', '多胎', '胎妊娠', '胎儿发育迟缓', '胎儿生长缓慢', '胎儿生长发育迟缓']
  },
  hypertension: {
    diagKeyword: ['高血压', '子痫', '肾炎', '肾脏', '肾病', '红斑狼疮', '免疫系统疾病', 'SLE', 'sle', '风湿性关节炎', '类风湿性关节炎', '硬皮病']
  },
  coronary: {
    diagKeyword: ['心脏', '心肌', '心包', '心血管', '血管', '冠心病', '心力衰竭']
  },
  ICP: {
    diagKeyword: ['ICP', 'icp', '肝内胆汁淤积']
  },
  hypothyroidism: {
    diagKeyword: ['甲减', '甲状腺机能减退', '甲状腺功能减退']
  },
  fetalGrowth: {
    diagKeyword: ['胎儿发育迟缓', '胎儿生长缓慢', '胎儿生长发育迟缓']
  }
};
var checkAssociatedForm = function checkAssociatedForm(list, searchObj) {
  var _a, _b;
  if (list === void 0) {
    list = [];
  }
  if (!(searchObj === null || searchObj === void 0 ? void 0 : searchObj.diagKeyword)) return false;
  var diagItem = (_b = (_a = list === null || list === void 0 ? void 0 : list.filter(function (l) {
    return l.diagnosis;
  })) === null || _a === void 0 ? void 0 : _a.map(function (l) {
    return l.diagnosis;
  })) !== null && _b !== void 0 ? _b : [];
  var is_coronary = searchObj.diagKeyword.includes('心脏');
  var refreshFrom = function refreshFrom() {
    var is_hidden = true;
    for (var _i = 0, diagItem_1 = diagItem; _i < diagItem_1.length; _i++) {
      var user_diag = diagItem_1[_i];
      for (var _a = 0, _b = searchObj['diagKeyword']; _a < _b.length; _a++) {
        var pre_diag = _b[_a];
        if (user_diag.includes(pre_diag)) {
          if (!is_coronary) {
            return false;
          }
          if (is_coronary && user_diag.includes('胎')) {
            return false;
          }
        }
      }
    }
    return is_hidden;
  };
  return refreshFrom();
};
var FormBlock = function FormBlock(props) {
  var _a;
  var diagnosesList = props.diagnosesList;
  var _b = BF_Wrap2({
      default_conf: {
        tableColumns: function tableColumns() {
          return import('./prenatal-visit.pregnancy.doctor-end15.js');
        },
        title: '复诊-产检信息'
      }
    }),
    config = _b.config,
    Wrap = _b.Wrap;
  var form_config = ((_a = config === null || config === void 0 ? void 0 : config.tableColumns) !== null && _a !== void 0 ? _a : []).map(function (f) {
    if (!(f === null || f === void 0 ? void 0 : f.usr1)) return f;
    return __assign(__assign({}, f), {
      isActive: !checkAssociatedForm(diagnosesList, f === null || f === void 0 ? void 0 : f.usr1)
    });
  });
  return /*#__PURE__*/React__default.createElement(Wrap, null, /*#__PURE__*/React__default.createElement(MyFormSectionForm, _extends({
    size: "small",
    style: {
      padding: '0 4px',
      overflow: 'hidden'
    },
    formDescriptions: form_config
  }, props, {
    onValuesChange: function onValuesChange(changedValues, values) {}
  })));
};
var css_248z$4 = ".index-module_return-btns__lEm9Z {\n  display: flex;\n  justify-content: flex-end;\n  padding: 12px;\n  text-align: right;\n}\n.index-module_return-btns__lEm9Z .ant-btn {\n  min-width: 128px;\n  border-radius: 4px;\n}\n.index-module_fixed__e7-UU {\n  position: fixed;\n  right: 24px;\n  bottom: 24px;\n}\n";
var styles$1 = {
  "return-btns": "index-module_return-btns__lEm9Z",
  "fixed": "index-module_fixed__e7-UU"
};
styleInject(css_248z$4);
function FurtherForm(props) {
  var _this = this;
  var getLastRecord = props.getLastRecord;
  var formChange = props.formChange;
  var addon_btns = props.addon_btns,
    before_submit = props.before_submit,
    diagnosesList = props.diagnosesList,
    formData = props.formData,
    visitsData = props.visitsData,
    getVisitsData = props.getVisitsData,
    isAllPregnancies = props.isAllPregnancies,
    headerInfo = props.headerInfo,
    changePreventPreeclampsia = props.changePreventPreeclampsia,
    onAddBtnClick = props.onAddBtnClick,
    isShowPreventPreeclampsia = props.isShowPreventPreeclampsia,
    canSave = props.canSave,
    handleSubmit = props.handleSubmit,
    loading = props.loading;
  var _a = useState(false),
    isShowMenzhen = _a[0],
    set_isShowMenzhen = _a[1];
  var _b = useState(false),
    isShowResultImport = _b[0],
    set_isShowResultImport = _b[1];
  var form = _Form.useForm()[0];
  var form_id = formData === null || formData === void 0 ? void 0 : formData.id;
  var preg_id = mchcUtils.getDoctorEndId(headerInfo);
  useEffect(function () {
    if (formData) {
      formData.physicalExam = process_OutpatientDocument_physicalExam_remote(formData.physicalExam);
      var fetusExam = expect_array(formData.fetusExam);
      formData.fetusExam = fetusExam.length ? fetusExam : [{}];
      form.setFieldsValue(formData);
    }
  }, [formData]);
  useMyEffectSafe(props)(function () {
    var rm = mchcEvent.on_rm('my_form', function (e) {
      return __awaiter(_this, void 0, void 0, function () {
        var values, value, key, a, physicalExam, bmi;
        var _a, _b;
        return __generator(this, function (_c) {
          switch (_c.label) {
            case 0:
              if (!(e.type === 'onChange')) return [3, 3];
              formChange(true);
              values = e.values;
              value = e.value;
              key = e.name;
              if (!(key === 'visitDate')) return [3, 2];
              return [4, SLocal_Calculator.calcGesWeek({
                date: value,
                id: preg_id
              })];
            case 1:
              a = _c.sent();
              (_a = e.setValue) === null || _a === void 0 ? void 0 : _a.call(e, 'gestationalWeek', a.gestationalWeek);
              _c.label = 2;
            case 2:
              if (key === 'appointmentCycle') {
                (_b = e.setValue) === null || _b === void 0 ? void 0 : _b.call(e, 'appointmentDate', getFutureDate(value));
              }
              if (key === 'physicalExam') {
                physicalExam = values === null || values === void 0 ? void 0 : values.physicalExam;
                bmi = getBMI(physicalExam === null || physicalExam === void 0 ? void 0 : physicalExam.weight, physicalExam === null || physicalExam === void 0 ? void 0 : physicalExam.height);
                form.setFieldsValue({
                  physicalExam: {
                    bmi: bmi
                  }
                });
              }
              _c.label = 3;
            case 3:
              if (e.type === 'onClick') {
                if (e.btnName === 'inspection') {
                  set_isShowResultImport(true);
                }
              }
              if (e.type === 'onFocus') {
                if (e.name === 'gestationalWeek') {
                  mchcModal__.open('modal_form', {
                    width: '20vw',
                    bodyStyle: {
                      height: '20vh'
                    },
                    modal_data: {
                      onSubmit: function onSubmit(v) {
                        return __awaiter(this, void 0, void 0, function () {
                          var values, visitDate, old_pre, params, gestationalWeek, prescription;
                          var _a;
                          return __generator(this, function (_b) {
                            switch (_b.label) {
                              case 0:
                                values = form.getFieldsValue();
                                visitDate = values.visitDate;
                                old_pre = (_a = values.prescription) !== null && _a !== void 0 ? _a : '';
                                params = {
                                  sureEdd: v.edd,
                                  date: visitDate,
                                  id: preg_id
                                };
                                return [4, SLocal_Calculator.calcGesWeek(params)];
                              case 1:
                                gestationalWeek = _b.sent().gestationalWeek;
                                mchcEvent.emit('outpatient', {
                                  type: '刷新头部',
                                  pregnancyId: preg_id
                                });
                                prescription = "".concat(old_pre, " ").concat(old_pre ? '/' : '', " \u9884\u4EA7\u671FB\u8D85\u4FEE\u8BA2\u4E3A ").concat(v.edd);
                                form.setFieldsValue({
                                  prescription: prescription,
                                  gestationalWeek: gestationalWeek
                                });
                                return [2, 1];
                            }
                          });
                        });
                      },
                      getInitialData: function getInitialData() {
                        return __awaiter(this, void 0, void 0, function () {
                          return __generator(this, function (_a) {
                            return [2, headerInfo];
                          });
                        });
                      },
                      formDescriptions: [{
                        label: '预产期-B超',
                        name: 'edd',
                        inputType: 'DatePicker'
                      }]
                    }
                  });
                }
              }
              return [2];
          }
        });
      });
    });
    return rm;
  }, []);
  function on_submit(sync) {
    if (sync === void 0) {
      sync = true;
    }
    if (before_submit) {
      return before_submit(handleSubmit, formData, form, sync);
    }
    form.validateFields().then(function (values) {
      values.physicalExam = process_OutpatientDocument_physicalExam_local(values.physicalExam);
      handleSubmit(values);
    })["catch"](function (error) {
      console.log('error', error);
      _message.error(_get(error, 'errorFields.0.errors.0'));
      form.scrollToField(_get(error, 'errorFields.0.name.0'));
    });
  }
  function closeModal(type, items, key) {
    if (_size(items) > 0) ;
    if (type === 'isShowMenzhen') {
      set_isShowMenzhen(false);
    }
    if (type === 'isShowResultImport') {
      set_isShowResultImport(false);
    }
  }
  function showpdf() {
    mchcModal__.open('print_modal', {
      modal_data: {
        requestData: {
          url: '/api/pdf-preview',
          resource: 'prenatalVisit1',
          id: form_id,
          template: '',
          version: '',
          note: ''
        }
      }
    });
  }
  function initial_preview() {
    mchcModal__.open('print_modal', {
      modal_data: {
        requestData: {
          url: '/api/pdf-preview',
          resource: 'prenatalVisit2',
          id: mchcUtils.getDoctorEndId(),
          template: '',
          version: '',
          note: ''
        }
      }
    });
  }
  function sign() {
    request.get('/api/doctor/updateRvisitRecordOfDoctorSign', {
      params: {
        id: form_id
      },
      successText: '签名成功'
    }).then(getVisitsData);
  }
  function copy() {
    if (mchcEnv["in"](['南医附属'])) {
      request.get('/api/doctor/getRvisitRecordCopied', {
        params: {
          id: form_id
        },
        successText: '复制成功'
      }).then(function (r) {
        copyText(r.data);
      });
    } else {
      _message.warning('暂未开发该功能，敬请期待');
    }
  }
  var saveBtnTxt = canSave ? "\u4FDD\u5B58".concat(mchcEnv.is('华医') ? '并关闭' : '') : '无权限保存';
  return /*#__PURE__*/React__default.createElement(_Card, {
    title: form_id ? "编辑产检记录" : "本次产检信息",
    bordered: false,
    size: "small",
    style: {
      overflowY: 'scroll'
    },
    extra: /*#__PURE__*/React__default.createElement("span", {
      id: "extra",
      style: {
        display: 'inline-block',
        minWidth: 75,
        height: 24,
        marginLeft: 98
      }
    }, form_id ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(_Button, {
      icon: /*#__PURE__*/React__default.createElement(PlusOutlined, null),
      type: "primary",
      size: "small",
      onClick: function onClick() {
        form.resetFields();
        onAddBtnClick();
      },
      style: {
        marginRight: 36
      }
    }, "\u65B0\u589E\u4EA7\u68C0\u8BB0\u5F55")) : null, /*#__PURE__*/React__default.createElement(_Button, {
      icon: /*#__PURE__*/React__default.createElement(SyncOutlined, null),
      type: "primary",
      size: "small",
      onClick: getLastRecord,
      style: {
        marginRight: 36
      }
    }, "\u540C\u6B65\u4E0A\u4E00\u6B21\u8BB0\u5F55"))
  }, /*#__PURE__*/React__default.createElement(MyLazyComponent, {
    size: "middle"
  }, /*#__PURE__*/React__default.createElement(FormBlock, {
    form: form,
    diagnosesList: diagnosesList !== null && diagnosesList !== void 0 ? diagnosesList : []
  }), /*#__PURE__*/React__default.createElement("div", {
    style: {
      marginLeft: '60px'
    }
  }, /*#__PURE__*/React__default.createElement(HighRiskTableEntry, {
    headerInfo: headerInfo,
    data: visitsData
  })), !isAllPregnancies && /*#__PURE__*/React__default.createElement(_Space, {
    className: classnames(styles$1['return-btns'], mchcConfig.get('医生端_复诊按钮浮动') ? styles$1['fixed'] : null)
  }, addon_btns === null || addon_btns === void 0 ? void 0 : addon_btns(formData), /*#__PURE__*/React__default.createElement(OkButton, {
    hidden: !mchcEnv.is('广州市八'),
    onClick: initial_preview
  }, "\u9996\u8BCA\u9884\u89C8"), /*#__PURE__*/React__default.createElement(OkButton, {
    hidden: !form_id,
    onClick: showpdf
  }, "\u6253\u5370"), /*#__PURE__*/React__default.createElement(OkButton, {
    hidden: !mchcEnv.is('南医附属') || !form_id,
    onClick: sign
  }, "\u7B7E\u540D"), /*#__PURE__*/React__default.createElement(OkButton, {
    hidden: !form_id,
    onClick: copy
  }, "\u590D\u5236"), /*#__PURE__*/React__default.createElement(OkButton, {
    hidden: !mchcEnv.is('郫都'),
    primary: true,
    loading: loading,
    disabled: !canSave,
    onClick: function onClick() {
      return on_submit(false);
    }
  }, "\u4EC5\u4FDD\u5B58"), /*#__PURE__*/React__default.createElement(OkButton, {
    primary: true,
    loading: loading,
    disabled: !canSave,
    onClick: function onClick() {
      return on_submit(true);
    }
  }, saveBtnTxt)), isShowMenzhen && /*#__PURE__*/React__default.createElement(Index, {
    isShowMenzhen: isShowMenzhen,
    closeModal: closeModal
  }), isShowResultImport && /*#__PURE__*/React__default.createElement(ResultImport, {
    isShowResultImport: isShowResultImport,
    closeModal: function closeModal(a, b, c) {
      var _a;
      set_isShowResultImport(false);
      if (b) form.setFieldsValue({
        inspection: "".concat((_a = form.getFieldValue('inspection')) !== null && _a !== void 0 ? _a : '', " / ").concat(b)
      });
    },
    headerInfo: headerInfo,
    importTitle: ''
  }), /*#__PURE__*/React__default.createElement(Index$1, {
    changePreventPreeclampsia: changePreventPreeclampsia,
    isShowPreventPreeclampsia: isShowPreventPreeclampsia,
    closeModal: closeModal
  })));
}
var Inner$1 = /*#__PURE__*/lazy(function () {
  return import('./prenatal-visit.pregnancy.doctor-end16.js');
});
function DiagTable(props) {
  return /*#__PURE__*/React__default.createElement(Inner$1, props);
}
var css_248z$3 = ".sider-container {\n  display: flex;\n  justify-content: space-between;\n  flex-direction: column;\n  width: 100%;\n  height: 100%;\n}\n.sider-container .tab-content {\n  display: flex;\n  height: 30px;\n  margin: 0px;\n  margin-top: 10px;\n}\n.sider-container .tab-content .tab-item {\n  cursor: pointer;\n  padding: 0 10px;\n  line-height: 30px;\n  border: 1px solid #ccc;\n  border-radius: 6px 6px 0 0;\n  background: #f9f9f9;\n  flex: 1;\n  text-align: center;\n}\n.sider-container .tab-content .active {\n  color: #3098ee;\n  background: #fff;\n}\n.sider-container .main-content {\n  flex: 1;\n  overflow: auto;\n}\n.prenatal-visit-main_return-sidebar .ant-collapse,\n.prenatal-tree-content .ant-collapse {\n  position: relative;\n}\n.prenatal-visit-main_return-sidebar .ant-collapse .diag-btn,\n.prenatal-tree-content .ant-collapse .diag-btn {\n  position: absolute;\n  top: 4px;\n  right: 4px;\n}\n.prenatal-visit-main_return-sidebar .ant-collapse .ant-collapse-header,\n.prenatal-tree-content .ant-collapse .ant-collapse-header {\n  display: flex;\n  align-items: center;\n  font-weight: bold;\n  padding-left: 0;\n  font-size: 15px;\n  background: #fff;\n  color: #3b3671;\n  padding-left: 20px;\n}\n.prenatal-visit-main_return-sidebar .ant-collapse .ant-collapse-header .header-btn,\n.prenatal-tree-content .ant-collapse .ant-collapse-header .header-btn {\n  position: absolute;\n  right: 4px;\n  top: 4px;\n}\n.prenatal-visit-main_return-sidebar .ant-collapse .ant-collapse-header .header-icon,\n.prenatal-tree-content .ant-collapse .ant-collapse-header .header-icon {\n  margin: 0 3px 0 8px;\n}\n.prenatal-visit-main_return-sidebar .ant-collapse .ant-collapse-header .isUnusual,\n.prenatal-tree-content .ant-collapse .ant-collapse-header .isUnusual {\n  color: #fff;\n  background-color: red !important;\n}\n.prenatal-visit-main_return-sidebar .ant-collapse .ant-collapse-content-box,\n.prenatal-tree-content .ant-collapse .ant-collapse-content-box {\n  padding: 5px;\n}\n.prenatal-visit-main_return-sidebar .ant-collapse .ant-collapse-content-box .diagWrapper,\n.prenatal-tree-content .ant-collapse .ant-collapse-content-box .diagWrapper {\n  padding: 0;\n  border: none;\n  overflow: hidden;\n}\n.prenatal-visit-main_return-sidebar .ant-collapse .ant-collapse-content-box .plan-timeline,\n.prenatal-tree-content .ant-collapse .ant-collapse-content-box .plan-timeline {\n  padding: 5px;\n}\n";
styleInject(css_248z$3);
var css_248z$2 = ".time-line-container {\n  padding: 10px;\n}\n.dot-content {\n  width: 20px;\n  height: 20px;\n  border-radius: 50%;\n  background-color: #1890ff;\n  color: #fff;\n  display: flex;\n  justify-content: center;\n  align-items: center;\n  position: relative;\n}\n.dot-content .dateGap {\n  position: absolute;\n  top: 23px;\n  left: -55%;\n  display: flex;\n  width: 40px;\n  justify-content: center;\n  color: #8c95a8;\n}\n.color1 {\n  color: #1890ff;\n  background-color: #fff;\n  border: 1px solid #1890ff;\n}\n.color2 {\n  color: #fff;\n  background-color: #1890ff;\n  border: 1px solid #1890ff;\n}\n.color3 {\n  color: #fff;\n  background-color: #f59a23;\n  border: 1px solid #f59a23;\n}\n.color4 {\n  color: #fff;\n  background-color: #015478;\n  border: 1px solid #015478;\n}\n.color5 {\n  color: #fff;\n  background-color: #ec808d;\n  border: 1px solid #ec808d;\n}\n.prenatal-info-content {\n  border: 1px solid #ccc;\n  overflow: auto;\n  padding: 6px 6px;\n}\n.prenatal-info-content div {\n  margin-bottom: 5px;\n}\n.prenatal-info-content .flex {\n  display: flex;\n  justify-content: space-between;\n}\n.prenatal-info-content .flex-start {\n  display: flex;\n  justify-content: flex-start;\n}\n.prenatal-info-content .hospital {\n  color: #480884;\n  border: 1px solid #480884;\n  margin-right: 10px;\n  cursor: pointer;\n}\n.prenatal-info-content .image {\n  color: #53a9a9;\n  border: 1px solid #53a9a9;\n  cursor: pointer;\n}\n.prenatal-info-content .checkout {\n  color: #088408;\n  border: 1px solid #088408;\n  margin-right: 10px;\n  cursor: pointer;\n}\n";
styleInject(css_248z$2);
function PrenatalTree(_a) {
  _a.id;
  var treeData = _a.treeData;
  __rest(_a, ["id", "treeData"]);
  var history = useHistory();
  var handleClick = useCallback(function (type, id) {
    if (id) {
      history.push('/deliver-management-v2/admission/deliver-edit?id=' + id);
    } else {
      EventEmitter_Old.dispatch('prenataltree', type);
    }
  }, []);
  return /*#__PURE__*/React__default.createElement(_Timeline, {
    style: {
      padding: 12
    }
  }, _map(treeData, function (item, index) {
    return /*#__PURE__*/React__default.createElement(_Timeline.Item, {
      dot: /*#__PURE__*/React__default.createElement(Dot, {
        type: _get(item, "type"),
        dateGap: _get(item, "dateGap")
      })
    }, /*#__PURE__*/React__default.createElement(PrenatalInfo, {
      handleClick: handleClick,
      item: item
    }));
  }));
}
function PrenatalInfo(_a) {
  var item = _a.item,
    props = __rest(_a, ["item"]);
  var handleClick = useCallback(function (type, id) {
    return function () {
      props && props.handleClick(type, id);
    };
  }, []);
  return /*#__PURE__*/React__default.createElement("div", {
    className: "prenatal-info-content"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "flex"
  }, /*#__PURE__*/React__default.createElement("span", null, _get(item, "date")), /*#__PURE__*/React__default.createElement("span", null, _get(item, "gesweek")), /*#__PURE__*/React__default.createElement("span", null, _get(item, "doctor"))), /*#__PURE__*/React__default.createElement("div", {
    className: "flex-start"
  }, _get(item, "inpatientEmrId") && /*#__PURE__*/React__default.createElement("span", {
    className: "hospital",
    onClick: handleClick('hospital', _get(item, "inpatientEmrId"))
  }, "\u4F4F\u9662\u75C5\u4F8B"), _get(item, "labExams") && /*#__PURE__*/React__default.createElement("span", {
    className: "checkout",
    onClick: handleClick('SurveyReport')
  }, "\u68C0\u9A8C\u62A5\u544A"), _get(item, "imageExams") && /*#__PURE__*/React__default.createElement("span", {
    className: "image",
    onClick: handleClick('ImageReport')
  }, "\u5F71\u50CF\u62A5\u544A")));
}
var Type = {
  0: {
    name: '首',
    "class": 'color1'
  },
  1: {
    name: '复',
    "class": 'color2'
  },
  4: {
    name: '胎',
    "class": 'color3'
  },
  5: {
    name: '住',
    "class": 'color4'
  },
  3: {
    name: '助',
    "class": 'color5'
  }
};
function Dot(props) {
  return /*#__PURE__*/React__default.createElement("div", {
    className: "dot-content ".concat(_get(Type, "[".concat(props.type, "].class"), 0))
  }, _get(Type, "[".concat(props.type, "].name")), " ", /*#__PURE__*/React__default.createElement("span", {
    className: "dateGap"
  }, _get(props, "dateGap")));
}
var Inner = /*#__PURE__*/lazy(function () {
  return import('./prenatal-visit.pregnancy.doctor-end17.js');
});
function SurveyList(props) {
  return /*#__PURE__*/React__default.createElement(Inner, props);
}
function FurtherSidebar(props) {
  var headerInfo = props.headerInfo,
    id = props.id,
    visitsData = props.visitsData,
    changeScreening = props.changeScreening,
    changeSyphilis = props.changeSyphilis,
    diagnosesList = props.diagnosesList,
    furtherRefresh = props.furtherRefresh,
    diagnosesWord = props.diagnosesWord,
    getHighriskDiagnosis = props.getHighriskDiagnosis,
    saveHeaderInfo = props.saveHeaderInfo,
    setDiagnosesList = props.setDiagnosesList,
    setDiagnosesWord = props.setDiagnosesWord,
    serialNo = props.serialNo;
  if (mchcConfig.get('医生端_复诊左侧隐藏')) return null;
  var _a = useState(false),
    isShowHisModal = _a[0],
    set_isShowHisModal = _a[1];
  var _b = useState(false),
    isShowListModal = _b[0],
    set_isShowListModal = _b[1];
  var _c = useState(false),
    isShowManageModal = _c[0],
    set_isShowManageModal = _c[1];
  var _d = useState(1),
    sidebarTab = _d[0],
    set_sidebarTab = _d[1];
  var _e = useState(null),
    prenatalTreeData = _e[0],
    set_prenatalTreeData = _e[1];
  var _f = useState(null),
    templateData = _f[0],
    set_templateData = _f[1];
  var _g = useState(''),
    lackReports = _g[0],
    set_lackReports = _g[1];
  var _h = useState([]),
    recentPlanData = _h[0],
    set_recentPlanData = _h[1];
  var _j = useState(['1', '2', '4']),
    collapseActiveKey = _j[0];
  _j[1];
  useEffect(function () {
    getLackReports();
    getPlanData();
    return function () {};
  }, []);
  function getPlanData() {
    return __awaiter(this, arguments, void 0, function (visitsData) {
      var planData;
      if (visitsData === void 0) {
        visitsData = props.visitsData;
      }
      return __generator(this, function (_a) {
        planData = _get(visitsData, "visitPlans", []);
        set_recentPlanData(_slice(planData, 0, 2));
        return [2];
      });
    });
  }
  function getLackReports() {
    return __awaiter(this, arguments, void 0, function (visitsData) {
      var lackReports;
      if (visitsData === void 0) {
        visitsData = props.visitsData;
      }
      return __generator(this, function (_a) {
        lackReports = _get(visitsData, "lackReports", []);
        set_lackReports(_join(lackReports || [], '，'));
        return [2];
      });
    });
  }
  function closeModal(type) {
    if (type === 'isShowHisModal') {
      set_isShowHisModal(false);
    }
    if (type === 'isShowManageModal') {
      set_isShowManageModal(false);
    }
  }
  function handleBtnClick(e, type) {
    e.stopPropagation();
    switch (type) {
      case 'hisBtn':
        set_isShowHisModal(true);
        break;
      case 'manageBtn':
        set_isShowManageModal(true);
        break;
    }
  }
  function getId() {
    return _get(headerInfo, 'id') || id;
  }
  function renderSiderBar() {
    return /*#__PURE__*/React__default.createElement("div", {
      className: "sider-container"
    }, /*#__PURE__*/React__default.createElement("div", {
      className: "main-content"
    }, sidebarTab == 1 && /*#__PURE__*/React__default.createElement("div", {
      className: "prenatal-visit-main_return-sidebar"
    }, /*#__PURE__*/React__default.createElement(_Collapse, {
      defaultActiveKey: collapseActiveKey
    }, /*#__PURE__*/React__default.createElement(_Collapse.Panel, {
      header: /*#__PURE__*/React__default.createElement("span", {
        style: {
          marginLeft: '10px'
        }
      }, "\u8BCA\u65AD"),
      key: "1",
      id: "further-diagnosis"
    }, /*#__PURE__*/React__default.createElement(DoctorEnd_Diagnoses, {
      serialNo: serialNo,
      diagnosesWord: diagnosesWord,
      getHighriskDiagnosis: getHighriskDiagnosis,
      changeScreening: changeScreening,
      changeSyphilis: changeSyphilis,
      saveHeaderInfo: saveHeaderInfo,
      setDiagnosesList: setDiagnosesList,
      setDiagnosesWord: setDiagnosesWord,
      headerInfo: headerInfo,
      diagnosesList: diagnosesList,
      isShowDiagnosesTemplate: false,
      noshowlist: false,
      isShowDiagnosesTemplatets: false,
      isAllPregnancies: false,
      getDiagnosesList: function getDiagnosesList() {},
      page: "return"
    })), /*#__PURE__*/React__default.createElement(_Collapse.Panel, {
      header: /*#__PURE__*/React__default.createElement("span", {
        style: {
          marginLeft: '10px'
        }
      }, !!lackReports ? '缺少检验报告' : '必查检验检查', /*#__PURE__*/React__default.createElement(_Button, {
        className: "header-btn",
        icon: /*#__PURE__*/React__default.createElement(CustomIcon, {
          type: 'icon-batch'
        }),
        onClick: function onClick(e) {
          set_isShowListModal(true);
        }
      }, "\u5FC5\u67E5\u6E05\u5355")),
      key: "2",
      id: "further-check-item"
    }, /*#__PURE__*/React__default.createElement(GestationalWeekProjectTree, {
      pregnancyId: mchcUtils.getDoctorEndId()
    })), mchcEnv.is('广三') || /*#__PURE__*/React__default.createElement(_Collapse.Panel, {
      header: /*#__PURE__*/React__default.createElement("span", {
        style: {
          marginLeft: '10px'
        }
      }, "\u4EA7\u68C0\u8BA1\u5212", /*#__PURE__*/React__default.createElement(_Button, {
        className: "header-btn",
        icon: /*#__PURE__*/React__default.createElement(SettingOutlined, null),
        onClick: function onClick(e) {
          return handleBtnClick(e, 'manageBtn');
        }
      }, "\u4EA7\u68C0\u7BA1\u7406")),
      key: "4"
    }, _size(recentPlanData) > 0 ? /*#__PURE__*/React__default.createElement(_Timeline, {
      className: "plan-timeline",
      mode: "left"
    }, _map(recentPlanData, function (item) {
      return /*#__PURE__*/React__default.createElement(_Timeline.Item, null, /*#__PURE__*/React__default.createElement("div", null, item.gestationalWeek, "\u5B55\u5468"), /*#__PURE__*/React__default.createElement("div", null, item.remind));
    })) : '暂无产检计划~'))), sidebarTab == 2 && /*#__PURE__*/React__default.createElement("div", {
      className: "prenatal-tree-content"
    }, /*#__PURE__*/React__default.createElement(PrenatalTree, {
      id: getId(),
      treeData: prenatalTreeData
    }))), /*#__PURE__*/React__default.createElement("div", {
      className: "tab-content"
    }, /*#__PURE__*/React__default.createElement("div", {
      className: classnames('tab-item', {
        active: sidebarTab == 1
      }),
      onClick: handleTabClick.bind(this, 1)
    }, "\u8BCA\u65AD"), /*#__PURE__*/React__default.createElement("div", {
      className: classnames('tab-item', {
        active: sidebarTab == 2
      }),
      onClick: handleTabClick.bind(this, 2)
    }, "\u4EA7\u68C0\u6811")));
  }
  function handleTabClick(value) {
    if (value == 2) {
      initTreeData();
    }
    if (value == 3) {
      initTemplateData();
    }
    set_sidebarTab(value);
  }
  function initTreeData() {
    return __awaiter(this, void 0, void 0, function () {
      var data;
      return __generator(this, function (_a) {
        switch (_a.label) {
          case 0:
            if (prenatalTreeData) return [2];
            return [4, request.get('/api/doctor/getExamTree?id=' + getId())];
          case 1:
            data = _a.sent().data;
            data = data.sort(function (a, b) {
              return a.date < b.date ? 1 : a.date > b.date ? -1 : 0;
            });
            set_prenatalTreeData(data);
            return [2];
        }
      });
    });
  }
  function transferTemplateData(data, pid) {
    if (pid === void 0) {
      pid = 0;
    }
    var treeData = [];
    _map(data, function (item) {
      if (item.pid === pid) {
        item.title = item.val;
        item.key = String(item.id);
        item.children = transferTemplateData(data, item.id);
        if (_isEmpty(item.children)) {
          item.isLeaf = true;
        } else {
          item.isLeaf = false;
        }
        treeData.push(item);
      }
    });
    return treeData;
  }
  function initTemplateData() {
    return __awaiter(this, void 0, void 0, function () {
      var res, res2, res3;
      return __generator(this, function (_a) {
        switch (_a.label) {
          case 0:
            if (templateData) return [2];
            if (!(_size(_get(templateData, "doctorTemplate", [])) == 0)) return [3, 2];
            return [4, request.get("/api/template-trees?type.equals=6&depid.equals=2&page=0&size=500")];
          case 1:
            res = _a.sent().data;
            _a.label = 2;
          case 2:
            if (!(_size(_get(templateData, "personalTemplate", [])) == 0)) return [3, 4];
            return [4, request.get("/api/template-trees?type.equals=7&userid.equals=".concat(_get(props, "basicInfo.id"), "&page=0&size=500"))];
          case 3:
            res2 = _a.sent().data;
            _a.label = 4;
          case 4:
            if (!(_size(_get(templateData, "adviseTemplate", [])) == 0)) return [3, 6];
            return [4, request.get("/api/template-trees?type.equals=10&depid.equals=2&pregnancyid.equals=".concat(getId(), "&page=0&size=500"))];
          case 5:
            res3 = _a.sent().data;
            _a.label = 6;
          case 6:
            set_templateData({
              adviseTemplate: transferTemplateData(res3),
              doctorTemplate: transferTemplateData(res),
              personalTemplate: transferTemplateData(res2)
            });
            return [2];
        }
      });
    });
  }
  return /*#__PURE__*/React__default.createElement("div", {
    style: {
      width: 280,
      height: '100%',
      padding: 4,
      marginRight: 8,
      background: '#fff'
    }
  }, /*#__PURE__*/React__default.createElement(MyLazyComponent, {
    size: "middle"
  }, renderSiderBar(), isShowHisModal && /*#__PURE__*/React__default.createElement(DiagTable, {
    isShowHisModal: isShowHisModal,
    closeModal: closeModal,
    visitsData: visitsData,
    headerInfo: headerInfo
  }), isShowListModal && /*#__PURE__*/React__default.createElement(SurveyList, {
    headerInfo: headerInfo,
    isAllPregnancies: false,
    furtherRefresh: furtherRefresh,
    isShowListModal: true,
    closeModal: function closeModal() {
      set_isShowListModal(false);
    }
  }), isShowManageModal && /*#__PURE__*/React__default.createElement(ManagementPlan, {
    isShowManageModal: isShowManageModal,
    headerInfo: headerInfo,
    closeModal: closeModal
  })));
}
var css_248z$1 = ".index-module_FurtherTable__JANN- {\n  margin-bottom: 8px !important;\n  padding: 2px;\n  position: relative;\n  background-color: #fff;\n}\n.index-module_FurtherTable__JANN- .index-module_selected-row__IJDaQ {\n  background: #8fb9f0 !important;\n}\n.index-module_FurtherTable__JANN- .ant-table-tbody > tr.ant-table-row:hover > td {\n  background: #c9d9ee !important;\n  cursor: pointer;\n}\n.index-module_FurtherTable__JANN- .ant-table .ant-table-thead th {\n  font-weight: bold;\n}\n.index-module_FurtherTable__JANN- em {\n  font-size: 8px;\n  color: #999;\n}\n.index-module_FurtherTable__JANN- .index-module_btn-wrap__ztmtr {\n  z-index: 9;\n  height: 26px;\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  padding: 0 12px;\n}\n";
var styles = {
  "FurtherTable": "index-module_FurtherTable__JANN-",
  "selected-row": "index-module_selected-row__IJDaQ",
  "btn-wrap": "index-module_btn-wrap__ztmtr"
};
styleInject(css_248z$1);
LazyAntd.Tree;
LazyAntd.TreeSelect;
LazyAntd.Select;
var Table = LazyAntd.Table;
LazyAntd.Dropdown;
LazyAntd.Pagination;
function FurtherTable(props) {
  var _a;
  var setFormData = props.setFormData,
    setDiagnosesList = props.setDiagnosesList,
    visitsData = props.visitsData;
  props.headerInfo;
  var formData = props.formData;
  var preg_id = mchcUtils.getDoctorEndId(visitsData);
  var _b = useState([]);
  _b[0];
  var set_selectKeys = _b[1];
  var _c = useState([]);
  _c[0];
  var set_selectRows = _c[1];
  useRef(null);
  var _d = BF_Wrap2({
      default_conf: {
        title: '复诊-产检记录表格',
        tableColumns: function tableColumns() {
          return import('./prenatal-visit.pregnancy.doctor-end14.js');
        }
      }
    }),
    config = _d.config,
    Wrap = _d.Wrap;
  useEffect(function () {}, []);
  var filtered_rvisits = ((_a = visitsData === null || visitsData === void 0 ? void 0 : visitsData.rvisits) !== null && _a !== void 0 ? _a : []).filter(function (_) {
    return _.id;
  });
  function handlePrint() {
    return __awaiter(this, void 0, void 0, function () {
      return __generator(this, function (_a) {
        mchcModal__.open('print_modal', {
          modal_data: {
            requestData: {
              url: '/api/pdf-preview',
              id: preg_id,
              resource: 'prenatalRVisit'
            }
          }
        });
        return [2];
      });
    });
  }
  var renderTable = function renderTable(isAll) {
    if (isAll === void 0) {
      isAll = false;
    }
    return /*#__PURE__*/React__default.createElement(Wrap, null, /*#__PURE__*/React__default.createElement(Table, {
      scroll: isAll ? undefined : {
        y: 160
      },
      bordered: true,
      pagination: false,
      size: isAll ? 'large' : 'small',
      onRow: function onRow(record) {
        return {
          onClick: function onClick(event) {
            set_selectKeys([record.id]);
            set_selectRows([record]);
          },
          onDoubleClick: function onDoubleClick() {
            setFormData(record);
            mchcModal__.pop();
            var __diagnoses = filter_diagnoses(visitsData === null || visitsData === void 0 ? void 0 : visitsData.diagnoses);
            setDiagnosesList === null || setDiagnosesList === void 0 ? void 0 : setDiagnosesList(__diagnoses);
          }
        };
      },
      rowClassName: function rowClassName(r) {
        return r.id === (formData === null || formData === void 0 ? void 0 : formData.id) ? styles['selected-row'] : '';
      },
      rowKey: 'id',
      dataSource: isAll ? filtered_rvisits : filtered_rvisits.slice(0, 5),
      columns: config === null || config === void 0 ? void 0 : config.tableColumns
    }));
  };
  return /*#__PURE__*/React__default.createElement("div", {
    className: styles['FurtherTable']
  }, /*#__PURE__*/React__default.createElement(MyLazyComponent$1, {
    size: "middle"
  }, renderTable(), /*#__PURE__*/React__default.createElement("div", {
    className: styles['btn-wrap']
  }, /*#__PURE__*/React__default.createElement("span", null, "\u5171 ", filtered_rvisits.length, " \u6761\u8BB0\u5F55"), /*#__PURE__*/React__default.createElement(_Space, null, /*#__PURE__*/React__default.createElement(OkButton, {
    type: "text",
    size: "small",
    onClick: props.furtherRefresh
  }, "\u5237\u65B0"), /*#__PURE__*/React__default.createElement(OkButton, {
    type: "text",
    size: "small",
    onClick: handlePrint
  }, "\u6253\u5370"), /*#__PURE__*/React__default.createElement(OkButton, {
    type: "text",
    size: "small",
    onClick: function onClick() {
      return mchcModal__.open('modal_page', {
        modal_data: {
          content: renderTable(true)
        }
      });
    }
  }, "\u66F4\u591A...")))));
}
var css_248z = ".further {\n  height: 100%;\n  display: flex;\n}\n.further-content {\n  display: flex;\n  flex-direction: column;\n  flex: 1;\n  height: 100%;\n  overflow: auto;\n}\n";
styleInject(css_248z);
var getDoctorEndId = mchcUtils.getDoctorEndId;
function DoctorEnd_Further(props) {
  var saveHeaderInfo = props.saveHeaderInfo,
    setDiagnosesWord = props.setDiagnosesWord,
    setDiagnosesList = props.setDiagnosesList,
    headerInfo = props.headerInfo,
    id = props.id,
    changePreventPreeclampsia = props.changePreventPreeclampsia,
    isShowPreventPreeclampsia = props.isShowPreventPreeclampsia,
    changeScreening = props.changeScreening,
    changeSyphilis = props.changeSyphilis,
    diagnosesList = props.diagnosesList,
    formChange = props.formChange,
    getHighriskDiagnosis = props.getHighriskDiagnosis,
    diagnosesWord = props.diagnosesWord;
  var serialNo_q = getSearchParamsValue('serialNo');
  var _a = useState(),
    visitsData = _a[0],
    _setVisitsData = _a[1];
  var _b = useState(),
    formData = _b[0],
    setFormData = _b[1];
  var _c = useState(false),
    canSave = _c[0],
    setCanSave = _c[1];
  var _d = useState(false),
    loading = _d[0],
    setLoading = _d[1];
  var visitsData_cache = useRef(visitsData);
  function setVisitsData(v) {
    _setVisitsData(v);
    visitsData_cache.current = v;
  }
  useEffect(function () {
    if (id) {
      getVisitsData();
    }
    return function () {};
  }, [id]);
  var get_default_value = function get_default_value() {
    return {
      gestationalWeek: headerInfo === null || headerInfo === void 0 ? void 0 : headerInfo.gesweek
    };
  };
  function fetchVisitData() {
    return __awaiter(this, void 0, void 0, function () {
      var visitInfo;
      return __generator(this, function (_a) {
        switch (_a.label) {
          case 0:
            return [4, SMchc_Doctor.getRvisitInfoOfOutpatient({
              id: getDoctorEndId(props),
              serialNo: mchcEnv.is('广三') ? serialNo_q : undefined
            })];
          case 1:
            visitInfo = _a.sent();
            return [2, visitInfo];
        }
      });
    });
  }
  function getVisitsData() {
    return __awaiter(this, void 0, void 0, function () {
      var visitInfo;
      return __generator(this, function (_a) {
        switch (_a.label) {
          case 0:
            return [4, fetchVisitData()];
          case 1:
            visitInfo = _a.sent();
            initDiagnoses(visitInfo);
            initVisitData(visitInfo);
            initFormData(visitInfo);
            return [2];
        }
      });
    });
  }
  function initDiagnoses(v) {
    return __awaiter(this, void 0, void 0, function () {
      var __diagnoses;
      return __generator(this, function (_a) {
        __diagnoses = filter_diagnoses(v.diagnoses);
        setDiagnosesList === null || setDiagnosesList === void 0 ? void 0 : setDiagnosesList(__diagnoses);
        return [2];
      });
    });
  }
  function initVisitData(v) {
    return __awaiter(this, void 0, void 0, function () {
      return __generator(this, function (_a) {
        setVisitsData(v);
        changeDoctorRecord(v);
        return [2];
      });
    });
  }
  function get_id_null_data(v) {
    var _a;
    var rvisits = (_a = v === null || v === void 0 ? void 0 : v.rvisits) !== null && _a !== void 0 ? _a : [];
    var idNullRvisit = rvisits.find(function (_) {
      return _.id === null;
    });
    return _cloneDeep(idNullRvisit);
  }
  function initFormData_toAdd(v) {
    if (!v) {
      setFormData(get_default_value());
      return;
    }
    var idNullRvisit = get_id_null_data(v);
    var first = idNullRvisit !== null && idNullRvisit !== void 0 ? idNullRvisit : get_default_value();
    console.log({
      first: first
    });
    setFormData(first);
    setCanSave(true);
  }
  function initFormData(v) {
    return __awaiter(this, void 0, void 0, function () {
      var rvisits, idNullRvisit, first, _formdata_q, _formdata;
      var _a;
      return __generator(this, function (_b) {
        if (!v) {
          setFormData(get_default_value());
          return [2];
        }
        rvisits = v.rvisits;
        idNullRvisit = get_id_null_data(v);
        first = (_a = idNullRvisit !== null && idNullRvisit !== void 0 ? idNullRvisit : rvisits[0]) !== null && _a !== void 0 ? _a : get_default_value();
        _formdata_q = mchcEnv.is('广三') ? v.rvisits.find(function (_) {
          return _.today;
        }) : null;
        _formdata = _formdata_q !== null && _formdata_q !== void 0 ? _formdata_q : first;
        setFormData(_formdata);
        if (mchcConfig.get('医生端_复诊编辑控制')) {
          if (idNullRvisit) {
            setCanSave(true);
          } else {
            SMchc_Doctor.getVisitEmrEditable(first.id).then(setCanSave);
          }
        } else {
          setCanSave(true);
        }
        return [2];
      });
    });
  }
  function handleSubmit(newData) {
    return __awaiter(this, void 0, void 0, function () {
      var outEmrId, __serialNo, serialNo, xxxa, redata, v;
      return __generator(this, function (_a) {
        switch (_a.label) {
          case 0:
            if (!canSave) return [2, Promise.resolve()];
            outEmrId = headerInfo === null || headerInfo === void 0 ? void 0 : headerInfo.id;
            __serialNo = mchcEnv.is('广三') ? serialNo_q : null;
            serialNo = __serialNo !== null && __serialNo !== void 0 ? __serialNo : formData === null || formData === void 0 ? void 0 : formData.serialNo;
            setLoading(true);
            if (mchcEnv.is('越秀妇幼')) {
              xxxa = diagnosesList.map(function (_) {
                return __assign(__assign({}, _), {
                  serialNo: serialNo,
                  outEmrId: outEmrId
                });
              });
              SMchc_Doctor.newOrSaveDiagnosisOfOutpatientList(xxxa).then(setDiagnosesList);
            }
            _set(newData, "outEmrId", outEmrId);
            _set(newData, "serialNo", serialNo);
            return [4, SMchc_Doctor.updateRvisitInfoOfOutpatient(newData)];
          case 1:
            redata = _a.sent();
            return [4, fetchVisitData()];
          case 2:
            v = _a.sent();
            initVisitData(v);
            setFormData(redata);
            HighRiskTableEntry.highRiskTablePopup(redata);
            mchcEvent.emit('outpatient', {
              type: '刷新头部',
              pregnancyId: outEmrId
            });
            setLoading(false);
            _message.success('信息保存成功');
            return [2];
        }
      });
    });
  }
  function onAddBtnClick() {
    setDiagnosesList((visitsData === null || visitsData === void 0 ? void 0 : visitsData.diagnoses) || []);
    initFormData_toAdd(visitsData_cache.current);
  }
  function changeDoctorRecord(v) {
    mchcUtils.getUserData();
    _get(v, "rvisits");
  }
  function getLastRecord() {
    return __awaiter(this, void 0, void 0, function () {
      var list, newFormData;
      return __generator(this, function (_a) {
        list = _get(visitsData_cache.current, "rvisits");
        newFormData = _cloneDeep(_find(list, function (item) {
          return item.id != null;
        }));
        console.log('newFormData', {
          newFormData: newFormData,
          list: list,
          visitsData: visitsData
        });
        if (!newFormData) return [2];
        delete newFormData['id'];
        _set(newFormData, "visitDate", formatTimeToDate(new Date()));
        _set(newFormData, "appointmentCycle", _get(formData, "appointmentCycle"));
        _set(newFormData, "appointmentDate", _get(formData, "appointmentDate"));
        _set(newFormData, "appointmentType", _get(formData, "appointmentType"));
        _set(newFormData, "appointmentPeriod", _get(formData, "appointmentPeriod"));
        _set(newFormData, "gestationalWeek", _get(formData, "gestationalWeek"));
        setFormData(newFormData);
        return [2];
      });
    });
  }
  function furtherRefresh() {
    var refreshData = props.refreshData;
    getVisitsData();
    refreshData === null || refreshData === void 0 ? void 0 : refreshData();
  }
  return /*#__PURE__*/React__default.createElement("div", {
    className: "further"
  }, /*#__PURE__*/React__default.createElement(FurtherSidebar, {
    serialNo: formData === null || formData === void 0 ? void 0 : formData.serialNo,
    saveHeaderInfo: saveHeaderInfo,
    setDiagnosesWord: setDiagnosesWord,
    setDiagnosesList: setDiagnosesList,
    diagnosesWord: diagnosesWord,
    getHighriskDiagnosis: getHighriskDiagnosis,
    changeScreening: changeScreening,
    changeSyphilis: changeSyphilis,
    diagnosesList: diagnosesList,
    headerInfo: headerInfo,
    id: id,
    visitsData: visitsData,
    furtherRefresh: furtherRefresh
  }), /*#__PURE__*/React__default.createElement("div", {
    className: "further-content"
  }, /*#__PURE__*/React__default.createElement(FurtherTable, {
    visitsData: visitsData,
    setFormData: setFormData,
    headerInfo: headerInfo,
    formData: formData,
    furtherRefresh: furtherRefresh
  }), /*#__PURE__*/React__default.createElement(FurtherForm, {
    addon_btns: props.addon_btns,
    before_submit: props.before_submit,
    loading: loading,
    handleSubmit: handleSubmit,
    onAddBtnClick: onAddBtnClick,
    visitsData: visitsData,
    formData: formData,
    getVisitsData: getVisitsData,
    getLastRecord: getLastRecord,
    headerInfo: headerInfo,
    diagnosesList: diagnosesList,
    isAllPregnancies: false,
    changePreventPreeclampsia: changePreventPreeclampsia,
    isShowPreventPreeclampsia: isShowPreventPreeclampsia,
    formChange: formChange,
    canSave: canSave
  })));
}
var DoctorEnd_FurtherPage = {
  __proto__: null,
  'default': DoctorEnd_Further
};
export { DoctorEnd_FurtherPage as D, diag_filter_map as d };
//# sourceMappingURL=DoctorEnd_FurtherPage.js.map
