/** * Project iLinkWorld * File AcceptOrRejectConsultationScreen * Path screens/wallet/user * Created by BRICE ZELE * Date: 01/12/2021 */ import React, {useEffect, useState} from 'react'; import { ActivityIndicator, Alert, Dimensions, FlatList, Platform, ProgressBarAndroid, ScrollView, StyleSheet, TouchableOpacity, View, } from 'react-native'; import {connect, useDispatch} from 'react-redux'; import {Color} from "../../../config/Color"; import I18n from 'react-native-i18n'; import {ScreenComponent} from "../../../components/ScreenComponent"; import { fetchAcceptRejectConsultation, fetchAcceptRejectConsultationReset, fetchActivePaySubscription, fetchGetConsultation, fetchGetConsultationReset } from "../../../redux/insurance/insurance.actions"; import DropdownAlert from "react-native-dropdownalert"; import {createStructuredSelector} from "reselect"; import { selectAcceptRefuseConsultation, selectActivatePaySubscription, selectGetConsultation, selectSubscriptionList } from "../../../redux/insurance/insurance.selector"; import {readUser} from "../../../webservice/AuthApi"; import Text from '../../../components/Text'; import * as Utils from "../../../utils/UtilsFunction"; import {uppercaseFirstLetter} from "../../../utils/UtilsFunction"; import Dialog from "react-native-dialog"; import {Typography} from "../../../config/typography"; let moment = require('moment-timezone'); const {width, height} = Dimensions.get('window'); const ValidateConsultationScreen = ({ navigation, fetchGetConsultation, fetchAcceptRejectConsultation, getConsultation, acceptRefuseConsultation }) => { const dispatch = useDispatch(); const [user, setUser] = useState(null); const [displayModalHistory, setDisplayModalHistory] = useState(false); const [historyItemDetail, setHistoryItemDetail] = useState({}); let dropDownAlertRef: any = null; useEffect(() => { readUser().then((user) => { setUser(user); console.log("User", user); fetchGetConsultation(user.id, 'UNTREATED_ALL', ''); }); dispatch(fetchGetConsultationReset()); dispatch(fetchAcceptRejectConsultationReset()); }, []); useEffect(() => { if (getConsultation.error) { Alert.alert( I18n.t("ERROR_LABLE"), Utils.getErrorMsg(getConsultation), [ { text: I18n.t("OK"), onPress: () => { dispatch(fetchGetConsultationReset()); } } ], { cancelable: false } ); /* dropDownAlertRef.alertWithType( 'error', I18n.t('ERROR_LABEL'), Utils.getErrorMsg(getConsultation), ); dispatch(fetchGetConsultationReset());*/ } }, [getConsultation]); useEffect(() => { if (acceptRefuseConsultation.result !== null) { Alert.alert( I18n.t("SUCCESS"), acceptRefuseConsultation.result.response, [ { text: I18n.t("OK"), onPress: () => { dispatch(fetchAcceptRejectConsultationReset()); setDisplayModalHistory(false); if (user !== null) fetchGetConsultation(user.id, 'UNTREATED_ALL', ''); } } ], {cancelable: false} ); if (user !== null) fetchGetConsultation(user.id, 'UNTREATED_ALL', ''); } if (acceptRefuseConsultation.error) { Alert.alert( I18n.t("ERROR_LABLE"), Utils.getErrorMsg(acceptRefuseConsultation), [ { text: I18n.t("OK"), onPress: () => { dispatch(fetchAcceptRejectConsultationReset()); setDisplayModalHistory(false); if (user !== null) fetchGetConsultation(user.id, 'UNTREATED_ALL', ''); } } ], { cancelable: false } ); /* dropDownAlertRef.alertWithType( 'error', I18n.t('ERROR_LABEL'), Utils.getErrorMsg(acceptRefuseConsultation), ); dispatch(fetchAcceptRejectConsultationReset());*/ } }, [acceptRefuseConsultation]); const renderLoader = () => ( {Platform.OS === 'android' ? ( <> {I18n.t('LOADING_DOTS')} ) : <> {I18n.t('LOADING_DOTS')} } ); const renderModalHistoryDetail = () => ( {I18n.t('DETAIL')} {I18n.t('NETWORK')} {`${historyItemDetail.network.name}`} {I18n.t('PATIENT')} {`${historyItemDetail.patient_lastname !== null ? historyItemDetail.patient_lastname : ''} ${historyItemDetail.patient_firstname !== null ? historyItemDetail.patient_firstname : ''}`} Situation {historyItemDetail.patient_situation.toLowerCase()} {I18n.t('PRATICIEN')} {`${historyItemDetail.practitioner_lastname} ${historyItemDetail.practitioner_firstname}`} {I18n.t('CLASSE_PRESTATAIRE')} {uppercaseFirstLetter(historyItemDetail.practitioner_provider_class.toLowerCase())} {I18n.t('STATE')} {uppercaseFirstLetter(historyItemDetail.state.toLowerCase())} Type {uppercaseFirstLetter(historyItemDetail.type.toLowerCase())} {I18n.t('CONDITION_PRISE_CHARGE')} {uppercaseFirstLetter(historyItemDetail.care_condition.toLowerCase())} {I18n.t('INSTITUTE_NAME')} {uppercaseFirstLetter(historyItemDetail.institution_name.toLowerCase())} Date {moment(historyItemDetail.created_at).format('YYYY-MM-DD')} {I18n.t('EXAMEN')} {historyItemDetail.exams.map(exam => ( {`${exam.description} \n ${exam.act.name} \n`} ))} {I18n.t('MEDICAMENT')} {historyItemDetail.prescriptions.map(prescription => ( {`${prescription.drug_or_device.name} \n ${prescription.dosage} \n`} ))} {I18n.t('PRESTATION')} {historyItemDetail.performances.map(performance => ( {`${performance.act.name} \n ${performance.amount} \n`} ))} { setDisplayModalHistory(false); }}/> { fetchAcceptRejectConsultation({ health_care_sheet_id: historyItemDetail.id, user_id: user.id, action: "REJECT" }); }}/> { fetchAcceptRejectConsultation({ health_care_sheet_id: historyItemDetail.id, user_id: user.id, action: "ACCEPT" }); }}/> ) const renderItem = (item) => ( { setDisplayModalHistory(true); setHistoryItemDetail(item); /*navigation.navigate('validateConsultationDetailScreen', { item });*/ }}> {`${I18n.t('NETWORK')}: ${item.network.name}`} {`${I18n.t('PATIENT')}: ${item.patient_lastname !== null ? item.patient_lastname : ''} ${item.patient_firstname !== null ? item.patient_firstname : ''}`} {`${I18n.t('SITUATION')}: ${item.patient_situation.toLowerCase()}`} {`${I18n.t('PRATICIEN')}: ${item.practitioner_lastname} ${item.practitioner_firstname}`} {`${I18n.t('SITUATION')}: ${item.practitioner_provider_class}`} {`Type: ${item.type.toLowerCase()}`} {`Date: ${moment(item.created_at).format('YYYY-MM-DD')}`} ) return ( (dropDownAlertRef = ref)}/> {getConsultation.loading ? renderLoader() : getConsultation.result !== null ? ( { return ( {I18n.t('NO_CONSULTATION_DEMAND')} ) }} data={getConsultation.result.response} keyExtractor={(item, index) => item.id} renderItem={({item, index}) => ( renderItem(item) )} /> ) : null} {displayModalHistory && renderModalHistoryDetail()} ) }; const mapStateToProps = createStructuredSelector({ subscriptionList: selectSubscriptionList, activatePaySubscription: selectActivatePaySubscription, getConsultation: selectGetConsultation, acceptRefuseConsultation: selectAcceptRefuseConsultation }); export default connect(mapStateToProps, { fetchActivePaySubscription, fetchGetConsultation, fetchAcceptRejectConsultation, })( ValidateConsultationScreen, ); const styles = StyleSheet.create({ textInput: { height: 46, backgroundColor: Color.fieldColor, borderRadius: 5, marginTop: 10, padding: 10, width: '100%', }, lineRow: { flexDirection: 'row', justifyContent: 'space-between', paddingBottom: 20, }, contain: { marginTop: 20, paddingBottom: 20, paddingLeft: 10, paddingRight: 10, flex: 1, }, content: { padding: 10, marginBottom: 10, borderRadius: 8 }, contentTop: { flexDirection: "row", paddingBottom: 10, borderBottomWidth: 1 }, contentBottom: { flexDirection: "row", marginTop: 10, justifyContent: "space-between" }, bottomLeft: {flexDirection: "row", alignItems: "center"}, image: {width: 32, height: 32, marginRight: 10, borderRadius: 16}, blockView: { paddingVertical: 10, borderBottomWidth: 0.5, }, });