/**
* Project iLinkWorld
* File HistoricNanoSanteUserScreen
* Path screens/wallet/user
* Created by BRICE ZELE
* Date: 26/01/2022
*/
import React, {useEffect, useState} from 'react';
import {
ActivityIndicator, Alert,
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, fetchDemaneAutorisationSoinReset,
fetchGetConsultation,
fetchGetConsultationReset, fetchGetDemandeAutorisationSoin,
fetchGetSubscription
} from "../../../redux/insurance/insurance.actions";
import DropdownAlert from "react-native-dropdownalert";
import {createStructuredSelector} from "reselect";
import {
selectAcceptRefuseConsultation,
selectActivatePaySubscription, selectDemandeAutorisationSoin,
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,
fetchGetDemandeAutorisationSoin,
fetchAcceptRejectConsultation,
acceptRefuseConsultation,
getConsultation
}) => {
const dispatch = useDispatch();
const [user, setUser] = useState(null);
const [displayModalHistory, setDisplayModalHistory] = useState(false);
const [historyItemDetail, setHistoryItemDetail] = useState({});
const [page, setPage] = useState(1);
const [historiqueDetailLabel, setHistoriqueDetailLabel] = useState(I18n.t('SOINS'));
const [loadMore, setLoadMore] = useState(false);
const [historyResult, setHistoryResult] = useState([]);
let dropDownAlertRef: any = null;
function useForceUpdate() {
const [value, setValue] = useState(0); // integer state
return () => setValue(value => value + 1); // update the state to force render
}
const forceUpdate = useForceUpdate();
useEffect(() => {
dispatch(fetchGetConsultationReset());
dispatch(fetchAcceptRejectConsultationReset());
readUser().then((user) => {
setUser(user);
console.log("User", user);
fetchGetConsultation(user.id, 'ALL', '', '&pagination=true&page=1');
});
}, []);
useEffect(() => {
if (getConsultation.result !== null) {
if (page < getConsultation.result.response.last_page)
setHistoryResult(historyResult.concat(getConsultation.result.response.data));
if (page === getConsultation.result.response.last_page) {
console.log("Page", page === getConsultation.result.response.last_page);
setPage(page + 1);
console.log("historyResult.concat", historyResult.concat(getConsultation.result.response.data));
setHistoryResult(historyResult.concat(getConsultation.result.response.data));
}
}
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());*/
}
//forceUpdate();
}, [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') + ' ' + historiqueDetailLabel}
{historyItemDetail.hasOwnProperty('beneficiaries') ?
{I18n.t('STATE')}
{uppercaseFirstLetter(historyItemDetail.state.toLowerCase())}
{I18n.t('ASSURE')}
{`${user.firstname !== null ? 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`}
))}
: historyItemDetail.hasOwnProperty('act_name') ?
ID
{historyItemDetail.request_id}
Date
{historyItemDetail.created_at}
{I18n.t('STATE')}
{uppercaseFirstLetter(historyItemDetail.state.toLowerCase())}
{I18n.t('USER')}
{`${historyItemDetail.user_firstname !== null ? historyItemDetail.user_firstname : ''} ${historyItemDetail.user_lastname !== null ? historyItemDetail.user_lastname : ''} \n (${historyItemDetail.to.toLowerCase()})`}
{I18n.t('EMAIL')}
{`${historyItemDetail.user_email}`}
{I18n.t('PHONE')}
{`${historyItemDetail.user_phone}`}
{historyItemDetail.validating_agent_lastname !== null &&
(
{I18n.t('AGENT_VALIDEUR')}
{`${historyItemDetail.validating_agent_firstname !== null ? historyItemDetail.validating_agent_lastname : ''} ${historyItemDetail.validating_agent_lastname !== null ? historyItemDetail.validating_agent_lastname : ''}`}
)
}
{I18n.t('EMAIL')}
{historyItemDetail.validating_agent_email}
{I18n.t('PHONE')}
{historyItemDetail.validating_agent_phone}
{I18n.t('NETWORK')}
{historyItemDetail.network.name}
:
{I18n.t('NETWORK')}
{historyItemDetail.network.name}
{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')}`}
: item.hasOwnProperty('act_name') ?
{
setDisplayModalHistory(true);
setHistoryItemDetail(item);
/*navigation.navigate('validateConsultationDetailScreen', {
item
});*/
}}>
{`${I18n.t('ACTE')}: ${item.act_name}`}
{`${I18n.t('USER')}: ${item.user_firstname} ${item.user_lastname}`}
{`${I18n.t('NETWORK')}: ${item.network.name}`}
{item.validating_agent_lastname !== null &&
(
{`${I18n.t('AGENT_VALIDEUR')}: ${item.validating_agent_firstname} ${item.validating_agent_lastname}`}
)
}
{`${I18n.t('STATE')}: ${item.state.toLowerCase()}`}
{`Date: ${moment(item.created_at).format('YYYY-MM-DD')}`}
:
{
setDisplayModalHistory(true);
setHistoryItemDetail(item);
/*navigation.navigate('validateConsultationDetailScreen', {
item
});*/
}}>
{`${I18n.t('NETWORK')}: ${item.network.name}`}
{`${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([]);
setHistoriqueDetailLabel(I18n.t('SOINS'));
fetchGetConsultation(user.id, 'ALL', '', '&pagination=true&page=1');
}}>
{` ${I18n.t('SOINS')}`}
}
style={{
paddingRight: 10,
width: 120,
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
borderRightWidth: 1,
borderRightColor: Color.whiteColor,
borderLeftWidth: 1,
borderLeftColor: Color.whiteColor
}}
onPress={() => {
dispatch(fetchGetConsultationReset());
setPage(1);
setLoadMore(false);
setHistoryResult([]);
setHistoriqueDetailLabel(I18n.t('DEMANDES'));
fetchGetDemandeAutorisationSoin('?pagination=true&page=1&user_id=' + user.id);
}}>
{` ${I18n.t('DEMANDES')}`}
}
style={{width: 110, borderTopLeftRadius: 0, borderBottomLeftRadius: 0,}}
primary
onPress={() => {
dispatch(fetchGetConsultationReset());
setPage(1);
setLoadMore(false);
setHistoryResult([]);
setHistoriqueDetailLabel(I18n.t('SOUSCRIPTION'));
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,
fetchGetDemandeAutorisationSoin
})(
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,
},
});