/*
 * Create:      刘丹
 * CreateDate:  2023/10/19
 * Describe：   电子病历模板-视光验光单录入中转
 * */
import React from 'react';
// 自研电子病历
import CaseInformationNEW from './CaseInformation.jsx';
// 验光单电子病历
import OptometrySheetEntry from 'pages/optometry/component/OptometrySheetEntry.jsx';
import { Spin } from 'antd';
import { getEMRToken } from './utils/index.js';

class OptometryEmr extends React.Component {
  constructor(props) {
    super(props);
    const userData = React.$getSessionData(); // 登录用户数据
    const titleData = React.$getSessionData('titleData');
    this.state = {
      userData, // groupID 307 门诊医生
      loading: true,
      useNewEmr: false, // 是否使用新病历
      token: '', //emr Token
      titleData,
    }
  }
  componentDidMount () {
    this.setState({
      loading: true,
    }, () => {
      getEMRToken(this.state.titleData?.admDateTime).then(({ newEmrToken, useNewEmr }) => {
        this.setState({
          token: newEmrToken,
          useNewEmr,
          loading: false,
        });
      }).catch(() => {
        this.setState({
          loading: false,
        });
      });
    });
  }

  render () {
    return (
      <>
        {this.state.loading
          ? <Spin tip="加载中...">
            <div style={{ height: '400px' }}></div>
          </Spin >
          : this.state.useNewEmr
            ? <CaseInformationNEW {...this.props} token={this.state.token} hideQute={true} />
            : <OptometrySheetEntry {...this.props} />
        }
      </>
    )
  }
};
export default OptometryEmr;
