All files / src/containers/PatientDetails PatientDetails.js

0% Statements 0/40
0% Branches 0/28
0% Functions 0/12
0% Lines 0/40
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170                                                                                                                                                                                                                                                                                                                                                   
//import i18next from 'i18next';
import i18next from '../../common/i18next';
import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import PatientDetailsTabs from './components/PatientDetailsTabs';
import PatientDetailsHeader from './components/PatientDetailsHeader';
import QRCodeGeneration from './components/QRCodeGeneration';
import { withRouter } from 'react-router-dom';
import DialogModal from '../../components/DialogModal/DialogModal';
import { questionnarieActions } from '../../redux/questionnarie';
import Button from '@material-ui/core/Button';
import { REGISTRY_UNIT_NAME } from '../../helper/constants';
 
class PatientDetails extends PureComponent {
    constructor(props) {
        super(props);
 
        this.state = {
            isQRCodeModal: false,
            // pageNumber: 0,
            // pageSize: 5,
            // patientUid:''
        };
    }
    componentDidMount() {
        // this.loadPatientProfileInfo(this.props.selectedAssignPro);
    };
 
    componentWillReceiveProps(nextProps) {
        if (nextProps.selectedAssignPro !== this.props.selectedAssignPro) {
            this.loadPatientProfileInfo(nextProps.selectedAssignPro);
            // this.setState({ patientUid:nextProps.selectedAssignPro.data.PatientUid})
        }
    }
 
    loadPatientProfileInfo = async (PatientData) => {
        const { patientProfileInfo: getPatientProfileInfo, selectedPractice } = this.props;
        const practiceId = (selectedPractice && selectedPractice.practiceId) ? selectedPractice.practiceId : '';
        const params = {
            input: {
                PracticeId: practiceId,
                Unit: REGISTRY_UNIT_NAME,
                IsLastVisit: true,
                PatientUid: PatientData ? PatientData.patientuid : '',
                PageNumber: 1,
                PageSize: 10,
                OutputColumn: "firstname,lastname,midname,mrn,practiceid,patientuid,visitdate,visituid,gender,emailid,dob"
            }
        };
    
        await getPatientProfileInfo(params);
    }
 
    // onPageChangeHandler = (page) => {
    //     // const{selectedAssignPro:data}= this.props;
    //      const{patientUid}=this.state;
    //      this.setState({
    //          pageNumber: page
    //      }, () => {
    //          this.loadQuestionnarieData(patientUid);
    //      });
    //  };
 
 
    // loadQuestionnarieData = (PatientUid) => {
    //     const { fetchQuestionnarie, questionnarieList, selectedAssignPro } = this.props;
    //     // const {
    //     //     pageNumber,
    //     //     pageSize
    //     // } = this.state;
        
    //     const requestJson = {
    //         input: {
    //             patientuid: PatientUid,
    //             unit: 'aao',              // TODO
    //             limit: pageSize,
    //             offset: pageNumber
    //         }
    //     };
    //     fetchQuestionnarie(requestJson);
    // }
 
    /**
     * Function used to generate QR Code
     */
    generateQRCode = () => {
        this.setState({ isQRCodeModal: true });
    };
 
    /**
     * Function used to get QR code modal template
     */
    getQRCodeModalTemplate = () => {
        const { isQRCodeModal } = this.state;
        const { headerData, selectedPractice } = this.props;
        const practiceId = (selectedPractice && selectedPractice.practiceId) ? selectedPractice.practiceId : '';
        const practiceName = (selectedPractice && selectedPractice.practiceName) ? selectedPractice.practiceName : '';
 
        const QRCodeValues = {
            registry_id: REGISTRY_UNIT_NAME,
            practice_id: practiceId,
            practice_name: practiceName,
            patient_id: headerData && headerData[0] && headerData[0].patientuid ? headerData[0].patientuid: '',
            patient_mrn: headerData && headerData[0] && headerData[0].mrn ? headerData[0].mrn : '',
            vendorType: i18next.t('patientDetails.modal.QRCode.vendorType'),
            vendorName: i18next.t('patientDetails.modal.QRCode.vendorName')
        };
        const fullWidth = true;
        return (
            <DialogModal
                isOpen={isQRCodeModal}
                fullWidth={fullWidth}
                maxWidth='xs'
                modalTitle={i18next.t('patientProfile.questionnarieHeader.QRCode.title')}
                modalContent={<QRCodeGeneration values={JSON.stringify(QRCodeValues)} />}
                modalContentAlignment='center'
                handleCloseEvent={this.closeQRCodeModal}
                handleCancelEvent={this.closeQRCodeModal}
                handleOkEvent={this.discardQRCodeModal}
            />
        );
    };
 
    /**
     * Function used to handle close event of QR code modal
     */
    closeQRCodeModal = () => {
        this.setState({ isQRCodeModal: false });
    };
 
    /**
     * Function used to handle ok event of QR code modal
     */
    discardQRCodeModal = () => {
        this.setState({ isQRCodeModal: false });
    };
    goBackToPatientBrowser = () => {
         const { history}=this.props
         history.goBack();
       
      }
 
    render() {
        const { isQRCodeModal } = this.state;
        return (
            <div className='patient-view'>
            {/* <Button onClick={this.goBackToPatientBrowser}> Go back</Button> */}
                {isQRCodeModal && this.getQRCodeModalTemplate()}
                <PatientDetailsHeader generateQRCode={() => this.generateQRCode()} handleButtonClick={this.goBackToPatientBrowser}/>
                <PatientDetailsTabs />
            </div>
        );
    }
}
 
const mapStateToProps = ({ questionnarieReducer, assignProList }) => {
    return {
        headerData: questionnarieReducer.patientProfileInfolist.data,
        selectedAssignPro: assignProList.selectedAssignPro.data,
        selectedPractice: assignProList.selectedPractice.data
    };
};
 
const mapDispatchToProps = {
    patientProfileInfo: questionnarieActions.patientProfileInfo,
    // fetchQuestionnarie: questionnarieActions.questionnarieData
}
 
export default withRouter(connect(mapStateToProps,mapDispatchToProps)(PatientDetails));