/**
* Project iLinkWorld
* File HistoricNanoSanteUserScreen
* Path screens/wallet/user
* Created by BRICE ZELE
* Date: 26/01/2022
*/
import React, {useEffect, useState} from 'react';
import {
ActivityIndicator,
Dimensions,
FlatList,
Platform,
ProgressBarAndroid,
ScrollView,
StyleSheet,
TouchableOpacity,
View,
} from 'react-native';
import isNil from 'lodash/isNil';
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,
fetchGetSubscription
} 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";
import Tag from "../../../components/Tag";
import FontAwesome5 from "react-native-vector-icons/FontAwesome5";
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
let moment = require('moment-timezone');
const {width, height} = Dimensions.get('window');
const HistoriqueNanoSanteUserScreen = ({
navigation,
fetchGetConsultation,
fetchGetSubscription,
fetchAcceptRejectConsultation,
getConsultation,
acceptRefuseConsultation
}) => {
const dispatch = useDispatch();
const [user, setUser] = useState(null);
const [displayModalHistory, setDisplayModalHistory] = useState(false);
const [historyItemDetail, setHistoryItemDetail] = useState({});
const [page, setPage] = useState(1);
const [loadMore, setLoadMore] = useState(false);
const [historyResult, setHistoryResult] = useState([]);
let dropDownAlertRef: any = null;
useEffect(() => {
dispatch(fetchGetConsultationReset());
dispatch(fetchAcceptRejectConsultationReset());
readUser().then((user) => {
setUser(user);
console.log("User", user);
fetchGetConsultation(user.id, 'UNTREATED', '', '&pagination=true&page=1');
});
}, []);
useEffect(() => {
if (getConsultation.result !== null) {
console.log("Page", page);
if (page < getConsultation.result.response.last_page)
setHistoryResult(historyResult.concat(getConsultation.result.response.data));
if (page === getConsultation.result.response.last_page) {
setPage(page + 1);
setHistoryResult(historyResult.concat(getConsultation.result.response.data));
}
}
if (getConsultation.error) {
dropDownAlertRef.alertWithType(
'error',
I18n.t('ERROR_LABEL'),
Utils.getErrorMsg(getConsultation),
);
dispatch(fetchGetConsultationReset());
}
}, [getConsultation]);
useEffect(() => {
console.log("historyResult", historyResult);
}, [historyResult]);
/* useEffect(() => {
if (acceptRefuseConsultation.result !== null) {
if(loadMore)
setHistoryResult(historyResult.concat(acceptRefuseConsultation.result.data.data.content));
}
if (acceptRefuseConsultation.error) {
dropDownAlertRef.alertWithType(
'error',
I18n.t('ERROR_LABEL'),
Utils.getErrorMsg(acceptRefuseConsultation),
);
dispatch(fetchAcceptRejectConsultationReset());
setDisplayModalHistory(false);
if (user !== null)
fetchGetConsultation(user.id, 'UNTREATED');
}
}, [acceptRefuseConsultation]);*/
const handleLoadMore = () => {
dispatch(fetchGetConsultationReset());
fetchGetConsultation(user.id, 'UNTREATED', '', `&pagination=true&page=${page + 1}`);
setPage(page + 1);
}
const renderLoader = () => (
{Platform.OS === 'android'
?
(
<>
{I18n.t('LOADING_DOTS')}
>
) :
<>
{I18n.t('LOADING_DOTS')}
>
}
);
const renderFooterLoader = () => {
return (
{Platform.OS === 'android'
?
(
<>
{I18n.t('LOADING_DOTS')}
>
) :
<>
{I18n.t('LOADING_DOTS')}
>
}
);
};
const renderModalHistoryDetail = () => (
{I18n.t('DETAIL')}
{historyItemDetail.hasOwnProperty('beneficiaries') ?
{I18n.t('STATE')}
{uppercaseFirstLetter(historyItemDetail.state.toLowerCase())}
{I18n.t('ASSURE')}
{`${user.firstname} ${user.lastname}`}
Date
{historyItemDetail.created_at}
{I18n.t('BONUS_AMOUNT')}
{historyItemDetail.bonus_amount}
{I18n.t('TOTAL_BONUS_AMOUNT')}
{historyItemDetail.total_bonus_amount}
{I18n.t('NUMBER_OF_MONTHS')}
{historyItemDetail.number_of_months}
{I18n.t('NETWORK')}
{historyItemDetail.network.name}
{I18n.t('AYANT_DROIT')}
{historyItemDetail.beneficiaries.map(beneficiary => (
{`${beneficiary.firstname} ${beneficiary.lastname}\n`}
))}
:
{I18n.t('PATIENT')}
{`${historyItemDetail.patient_lastname} ${historyItemDetail.patient_firstname}`}
Situation
{historyItemDetail.patient_situation.toLowerCase()}
{I18n.t('PRATICIEN')}
{`${historyItemDetail.practitioner_lastname} ${historyItemDetail.practitioner_firstname}`}
{I18n.t('MONTANT_ASSURANCE')}
{historyItemDetail.insurance_amount}
{I18n.t('MONTANT_ASSURE')}
{historyItemDetail.insured_amount}
{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('PRESTATION')}
{historyItemDetail.performances.map(performance => (
{`${performance.act.name} \n ${performance.amount_formatted} ${!isNil(performance.home_visit_fees_formatted) ? '\n' + I18n.t('FRAIS_DEPLACEMENT')+': ' + performance.home_visit_fees_formatted : ''} \n${!isNil(performance.unit_price_formatted) ? 'P.U: ' + performance.unit_price_formatted + '\n P.T: ' +performance.total_price : ''}`}
))}
{I18n.t('EXAMEN')}
{historyItemDetail.exams.map(exam => (
{`${exam.quantity} ${exam.description} \n ${exam.act.name} \n ${!isNil(exam.unit_price_formatted) ? 'P.U: ' + exam.unit_price_formatted + '\n P.T: ' + exam.total_price : ''}`}
))}
{I18n.t('MEDICAMENT')}
{historyItemDetail.prescriptions.map(prescription => (
{`${prescription.quantity} ${prescription.drug_or_device.name} \n ${prescription.dosage} \n ${!isNil(prescription.unit_price_formatted) ? 'P.U: ' + prescription.unit_price_formatted + '\n P.T: ' + prescription.total_price : ''}`}
))}
}
{
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) => (
item.hasOwnProperty('beneficiaries') ?
{
setDisplayModalHistory(true);
setHistoryItemDetail(item);
/*navigation.navigate('validateConsultationDetailScreen', {
item
});*/
}}>
{`${I18n.t('AMOUNT')}: ${item.bonus_amount}`}
{`${I18n.t('STATE')}: ${item.state.toLowerCase()}`}
{`${I18n.t('NETWORK')}: ${item.network.name}`}
{`${I18n.t('AYANT_DROIT')}: ${item.number_of_beneficiaries}`}
{`Type: ${item.insurance_action.toLowerCase()}`}
{`Date: ${moment(item.created_at).format('YYYY-MM-DD')}`}
:
{
setDisplayModalHistory(true);
setHistoryItemDetail(item);
/*navigation.navigate('validateConsultationDetailScreen', {
item
});*/
}}>
{`${I18n.t('PATIENT')}: ${item.patient_lastname} ${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)}/>
}
style={{
paddingRight: 10,
width: 120,
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
borderRightWidth: 1,
borderRightColor: Color.whiteColor
}}
onPress={() => {
dispatch(fetchGetConsultationReset());
setPage(1);
setLoadMore(false);
setHistoryResult([]);
fetchGetConsultation(user.id, 'ALL', '', '&pagination=true&page=1');
}}>
{I18n.t('SOINS')}
}
style={{width: 110, borderTopLeftRadius: 0, borderBottomLeftRadius: 0,}}
primary
onPress={() => {
dispatch(fetchGetConsultationReset());
setPage(1);
setLoadMore(false);
setHistoryResult([]);
fetchGetSubscription(user.id, 'ALL', '&pagination=true&page=1');
}}>
{I18n.t('SOUSCRIPTION')}
{getConsultation.loading && !loadMore
? renderLoader()
: (
{
return (
{I18n.t('NO_WALLET_HISTORY')}
)
}}
data={historyResult}
keyExtractor={(item, index) => item.id}
renderItem={({item, index}) => (
renderItem(item)
)}
onEndReached={() => {
if (getConsultation.result !== null) {
if (page < getConsultation.result.response.last_page) {
setLoadMore(true);
handleLoadMore();
}
}
}}
onEndReachedThreshold={0.5}
ListFooterComponent={getConsultation.result !== null ? page < getConsultation.result.response.last_page ? renderFooterLoader() : null : null}
/>
)}
{displayModalHistory && renderModalHistoryDetail()}
)
};
const mapStateToProps = createStructuredSelector({
subscriptionList: selectSubscriptionList,
activatePaySubscription: selectActivatePaySubscription,
getConsultation: selectGetConsultation,
acceptRefuseConsultation: selectAcceptRefuseConsultation
});
export default connect(mapStateToProps, {
fetchActivePaySubscription,
fetchGetConsultation,
fetchAcceptRejectConsultation,
fetchGetSubscription
})(
HistoriqueNanoSanteUserScreen,
);
const styles = StyleSheet.create({
textInput: {
height: 46,
backgroundColor: Color.fieldColor,
borderRadius: 5,
marginTop: 10,
padding: 10,
width: '100%',
},
contentService: {
paddingVertical: 10,
borderBottomWidth: 0.5,
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'space-between',
},
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,
},
});