/**
* Project iLinkWorld
* File SaisirFeuilleSoinScreen
* Path screens/wallet/agent
* Created by BRICE ZELE
* Date: 11/11/2021
*/
import React, {useEffect, useRef, useState} from 'react';
import {
ActivityIndicator,
Dimensions,
Keyboard,
KeyboardAvoidingView,
Platform,
ScrollView,
StyleSheet,
TouchableOpacity,
View,
} from 'react-native';
import {connect, useDispatch} from 'react-redux';
import Dialog from "react-native-dialog";
import {Formik, useFormik} from 'formik';
import * as Yup from 'yup';
import {Color} from "../../../config/Color";
import I18n from 'react-native-i18n';
import {ScreenComponent} from "../../../components/ScreenComponent";
import Button from "../../../components/Button";
import {responsiveWidth} from "react-native-responsive-dimensions";
import {
fetchActivePaySubscription,
fetchActivePaySubscriptionReset,
fetchGetSubscriptionList,
fetchGetSubscriptionListReset
} from "../../../redux/insurance/insurance.actions";
import DropdownAlert from "react-native-dropdownalert";
import {readUser} from "../../../webservice/AuthApi";
import TextInput from "../../../components/TextInput";
import {createStructuredSelector} from "reselect";
import {selectActivatePaySubscription, selectSubscriptionList} from "../../../redux/insurance/insurance.selector";
import StepHeader from "../../../components/StepHeaderComponent";
import Wizard from "react-native-wizard";
import Icon from "react-native-vector-icons/FontAwesome5";
import FontAwesome from "react-native-vector-icons/FontAwesome";
import Text from "../../../components/Text";
import SwitchSelector from "react-native-switch-selector";
import * as Animatable from "react-native-animatable";
import {Dropdown} from "react-native-material-dropdown";
import Modal from "react-native-modal";
import DateTimePicker from "@react-native-community/datetimepicker";
import QRCodeScanner from "react-native-qrcode-scanner";
import {RNCamera} from "react-native-camera";
let moment = require('moment-timezone');
const {width, height} = Dimensions.get('window');
const CIRCLE_SIZE = width * 0.5;
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: {
alignItems: 'center',
marginTop: 40,
paddingBottom: 20,
paddingLeft: 20,
paddingRight: 20,
flex: 1,
},
circle: {
width: CIRCLE_SIZE,
height: CIRCLE_SIZE,
borderRadius: CIRCLE_SIZE / 2,
position: 'absolute',
top: '15%',
},
circleContainer: {
alignItems: 'flex-end',
right: -(CIRCLE_SIZE / 3),
top: -(CIRCLE_SIZE / 1.5),
},
lineSeparator: {
borderWidth: 1,
width: '40%',
height: 1,
alignSelf: 'center',
},
line: {
width: 1,
height: 14,
backgroundColor: Color.grayColor,
marginLeft: 10,
},
contentModeView: {
width: 30,
height: '100%',
alignItems: 'flex-end',
justifyContent: 'center',
},
contentFilter: {
flexDirection: 'row',
alignItems: 'center',
marginLeft: 10,
},
bottomModal: {
justifyContent: 'flex-end',
margin: 0,
},
contentFilterBottom: {
width: "100%",
borderTopLeftRadius: 8,
borderTopRightRadius: 8,
paddingHorizontal: 20
},
contentSwipeDown: {
paddingTop: 10,
alignItems: 'center',
},
lineSwipeDown: {
width: 30,
height: 2.5,
backgroundColor: Color.dividerColor,
},
contentActionModalBottom: {
flexDirection: 'row',
paddingVertical: 15,
justifyContent: 'space-between',
borderBottomWidth: 1,
},
containModal: {
paddingVertical: 10,
paddingHorizontal: 20,
flexDirection: 'row',
justifyContent: 'space-between',
},
floatingButtonAdd: {
backgroundColor: Color.accentColor,
position: "absolute",
width: 25,
bottom: 0,
zIndex: 1000,
right: 20,
top: 35,
height: 25,
borderRadius: 12.5,
alignItems: 'center',
justifyContent: 'center',
},
contentSwitch: {
width: responsiveWidth(40),
},
switch: {},
choosePhotoBtn: {
marginTop: 10,
marginBottom: 10,
width: "auto",
height: "auto",
padding: 5,
alignItems: 'center',
borderColor: Color.borderColor,
marginRight: 10,
elevation: 2,
},
checkbox: {
alignSelf: "center",
color: "white"
},
itemAmountPerMonth: {
paddingLeft: 10,
marginTop: 10,
flexDirection: 'row',
},
dot: {
width: 12,
height: 12,
borderRadius: 6
},
blockView: {
paddingVertical: 10,
borderBottomWidth: 0.5,
},
iconNavigation: {
width: '100%',
flexDirection: 'row',
marginTop: 20,
justifyContent: 'space-between',
alignItems: 'center',
},
iconNavigationButton: {
borderWidth: 1,
borderRadius: 25,
width: 50,
height: 50,
alignItems: 'center',
justifyContent: 'center',
},
});
const SaisirFeuilleSoinScreen = ({
activatePaySubscription,
fetchGetSubscriptionList,
subscriptionList,
fetchActivePaySubscription,
navigation
}) => {
const [datePrestation, setDatePrestation] = useState('' + moment(new Date()).format('YYYY-MM-DD'));
const [showDatePrestation, setShowDatePrestation] = useState(false);
const [dateAccident, setDateAccident] = useState(null);
const [isAccident, setIsAccident] = useState(false);
const [showQRCodeScanner, setShowQRCodeScanner] = useState(false);
const [showDateAccidentPicker, setShowDateAccidentPicker] = useState(false);
const [dateDebutGrossesse, setDateDebutGrossesse] = useState(null);
const [dateFinGrossesse, setDateFinGrossesse] = useState(null);
const [isGrossesse, setIsGrossesse] = useState(false);
const [showDateDebutGrossessePicker, setShowDateDebutGrossessePicker] = useState(false);
const [showDateFinGrossessePicker, setShowDateFinGrossessePicker] = useState(false);
const [user, setUser] = useState(null);
const wizard = useRef();
const [isFirstStep, setIsFirstStep] = useState(true);
const [isLastStep, setIsLastStep] = useState(false);
const [currentStep, setCurrentStep] = useState(1);
const [modalPrestation, setModalPrestation] = useState(false);
const [modalPrescription, setModalPrescription] = useState(false);
const [statutPatientOption] = useState([
{label: I18n.t('AYANT_DROITS'), value: "M"},
{label: I18n.t('ASSURE'), value: "F"},
]);
const [accident] = useState([
{label: I18n.t('YES'), value: "YES"},
{label: I18n.t('NO'), value: "NO"},
]);
const [grossesse] = useState([
{label: I18n.t('YES'), value: "YES"},
{label: I18n.t('NO'), value: "NO"},
]);
const [visiteDomicile] = useState([
{label: I18n.t('YES'), value: "YES"},
{label: I18n.t('NO'), value: "NO"},
]);
const [conditionPriseEnChange] = useState([
{label: I18n.t('AFFECTION_COURANTE'), value: "AFFECTION_COURANTE"},
{label: I18n.t('AFFECTION_LONGUE'), value: "AFFECTION_LONGUE"},
{label: I18n.t('EXONERE'), value: "EXONERE"},
]);
const dispatch = useDispatch();
let dropDownAlertRef: any = null;
let classificationRef = null;
let codeActeRef = null;
useEffect(() => {
readUser().then((user) => {
setUser(user)
});
dispatch(fetchGetSubscriptionListReset());
dispatch(fetchActivePaySubscriptionReset());
}, []);
useEffect(() => {
if (user !== null) {
console.log("user", user.id);
}
}, [user]);
console.log("Date accident", dateAccident);
const SaisirFeuilleSoinSchema = Yup.object().shape({
numero_assure: Yup.string()
.required(I18n.t('THIS_FIELD_IS_REQUIRED')),
password: Yup.string()
.required(I18n.t('THIS_FIELD_IS_REQUIRED'))
});
const AddBeneficiarySchema = Yup.object().shape({
lastname: Yup.string().required(I18n.t('THIS_FIELD_IS_REQUIRED')),
firstname: Yup.string(),
});
const onChangeDatePrestation = (event, selectedDate) => {
const currentDate = selectedDate || '' + moment(new Date()).format('YYYY-MM-DD');
setShowDatePrestation(Platform.OS === 'ios');
setDatePrestation(currentDate);
};
const renderDatePrestationPicker = () => {
return (
);
}
const onChangeDateAccident = (event, selectedDate) => {
const currentDate = selectedDate || new Date();
setShowDateAccidentPicker(Platform.OS === 'ios');
setDateAccident(moment(currentDate).format('YYYY-MM-DD'));
};
const renderDateAccidentPicker = () => {
return (
);
}
const onChangeDateDebutGrossesse = (event, selectedDate) => {
const currentDate = selectedDate || new Date();
setShowDateDebutGrossessePicker(Platform.OS === 'ios');
setDateDebutGrossesse(moment(currentDate).format('YYYY-MM-DD'));
};
const renderDateDebutGrossessePicker = () => {
return (
);
}
const onChangeDateFinGrossesse = (event, selectedDate) => {
const currentDate = selectedDate || new Date();
setShowDateFinGrossessePicker(Platform.OS === 'ios');
setDateFinGrossesse(moment(currentDate).format('YYYY-MM-DD'));
};
const renderDateFinGrossessePicker = () => {
return (
);
}
const renderDialogQRCodeScanner = () => {
const {resultSearchUserByName, errorGetAvisImposition} = this.props;
console.log("resultGetAvisImposition", resultSearchUserByName);
return (
{I18n.t('SCAN')}
{I18n.t('BRING_YOUR_CAMERA_CLOSER_TO_SCAN_QR_CODE')}
{
setShowQRCodeScanner(false);
console.log("result", result.data);
}}
flashMode={RNCamera.Constants.FlashMode.off}
/>
{
setShowQRCodeScanner(false);
}}/>
)
}
const renderAddNewPrestation = () => (
{
}}>
{({
values,
errors,
touched,
handleChange,
handleBlur,
handleSubmit,
isSubmitting,
}) => (
{
setModalPrestation(false);
}}
swipeDirection={['down']}
style={styles.bottomModal}>
{I18n.t('ADD_PRESTATION')}
{
Keyboard.dismiss();
setShowDatePrestation(true);
}}
success={touched.birthdate && !errors.birthdate}
touched={touched.birthdate}
error={errors.birthdate}
/>
{
codeActeRef = comp
}}
style={{
width: responsiveWidth(90),
height: 60,
alignSelf: 'center',
borderRadius: 10,
paddingLeft: 20,
marginTop: 10,
paddingRight: 20,
backgroundColor: 'white'
}}>
{
console.log("Value", value);
}}
valueExtractor={(value) => {
return value
}}
labelExtractor={(value) => {
return value.name
}}
/>
{I18n.t('VISITE_DOMICILE')}
{
//setGender(value);
}}/>
)}
);
const renderAddNewPrescription = () => (
{
}}>
{({
values,
errors,
touched,
handleChange,
handleBlur,
handleSubmit,
isSubmitting,
}) => (
{
setModalPrescription(false);
}}
swipeDirection={['down']}
style={styles.bottomModal}>
{I18n.t('ADD_PRESCRIPTION')}
{
Keyboard.dismiss();
setShowDatePrestation(true);
}}
success={touched.birthdate && !errors.birthdate}
touched={touched.birthdate}
error={errors.birthdate}
/>
{
codeActeRef = comp
}}
style={{
width: responsiveWidth(90),
height: 60,
alignSelf: 'center',
borderRadius: 10,
paddingLeft: 20,
marginTop: 10,
paddingRight: 20,
backgroundColor: 'white'
}}>
{
console.log("Value", value);
}}
valueExtractor={(value) => {
return value
}}
labelExtractor={(value) => {
return value.name
}}
/>
{I18n.t('VISITE_DOMICILE')}
{
//setGender(value);
}}/>
)}
);
const {
handleChange,
handleSubmit,
handleBlur,
values,
errors,
touched,
setFieldValue,
setFieldTouched,
isValid,
} = useFormik({
validationSchema: SaisirFeuilleSoinSchema,
initialValues: {
numero_assure: '',
password: '',
firstname_patient: '',
lastname_patient: '',
firstname_praticien: '',
lastname_praticien: '',
agrement_praticien: ''
},
onSubmit: values => {
},
});
const onNext = () => {
switch (currentStep) {
case 1:
return (
errors.numero_assure
);
break;
default:
return false;
}
};
const stepList = [
{
title: I18n.t('ASSURE'),
content: (
}
/>
{
}}
/>
{
setShowQRCodeScanner(true);
}}
/>
),
},
{
title: I18n.t('PATIENT'),
content: (
{I18n.t('SITUATION')}
{
//setGender(value);
}}/>
),
},
{
title: I18n.t('PRATICIEN'),
content: (
{
classificationRef = comp
}}
style={{
width: responsiveWidth(90),
height: 60,
alignSelf: 'center',
borderRadius: 10,
paddingLeft: 20,
marginTop: 10,
paddingRight: 20,
backgroundColor: 'white'
}}>
{
console.log("Value", value);
}}
valueExtractor={(value) => {
return value
}}
labelExtractor={(value) => {
return value.name
}}
/>
{
classificationRef = comp
}}
style={{
width: responsiveWidth(90),
height: 60,
alignSelf: 'center',
borderRadius: 10,
paddingLeft: 20,
marginTop: 10,
paddingRight: 20,
backgroundColor: 'white'
}}>
{
console.log("Value", value);
}}
valueExtractor={(value) => {
return value
}}
labelExtractor={(value) => {
return value.label
}}
/>
{I18n.t('ACCIDENT')}
{
console.log(value);
setIsAccident(value === 'YES');
}}/>
{
isAccident && (
{
Keyboard.dismiss();
//setDateAccident('' + moment(new Date()).format('YYYY-MM-DD'));
setShowDateAccidentPicker(true);
}}
success={touched.date_accident && !errors.date_accident}
touched={touched.date_accident}
error={errors.date_accident}
/>
)
}
{I18n.t('GROSSESSE')}
{
setIsGrossesse(value === 'YES');
}}/>
{
isGrossesse && (
<>
{
Keyboard.dismiss();
//setDateAccident('' + moment(new Date()).format('YYYY-MM-DD'));
setShowDateDebutGrossessePicker(true);
}}
success={touched.date_debut_grossesse && !errors.date_debut_grossesse}
touched={touched.date_debut_grossesse}
error={errors.date_debut_grossesse}
/>
{
Keyboard.dismiss();
//setDateAccident('' + moment(new Date()).format('YYYY-MM-DD'));
setShowDateFinGrossessePicker(true);
}}
success={touched.date_fin_grossesse && !errors.date_fin_grossesse}
touched={touched.date_fin_grossesse}
error={errors.date_fin_grossesse}
/>
>
)
}
{
setModalPrestation(true);
}}>
{I18n.t('ADD_PRESTATION')}
{
setModalPrescription(true);
}}>
{I18n.t('ADD_PRESCRIPTION')}
),
},
];
return (
(dropDownAlertRef = ref)}/>
setIsFirstStep(val)
}
isLastStep={val =>
setIsLastStep(val)
}
onNext={() => {
onNext();
}}
onPrev={() => {
}}
currentStep={({
currentStep,
isLastStep,
isFirstStep,
}) => {
setCurrentStep(currentStep);
setIsFirstStep(isFirstStep);
setIsLastStep(isLastStep);
}}
/>
{!isFirstStep ? (
wizard.current.prev()
}>
) : (
)}
{currentStep === 3 ? (
) : (
{
handleSubmit(e);
wizard.current.next();
}}>
{subscriptionList.loading ?
: }
)}
{modalPrestation && renderAddNewPrestation()}
{modalPrescription && renderAddNewPrescription()}
{showDatePrestation && renderDatePrestationPicker()}
{showDateAccidentPicker && renderDateAccidentPicker()}
{showDateDebutGrossessePicker && renderDateDebutGrossessePicker()}
{showDateFinGrossessePicker && renderDateFinGrossessePicker()}
{showQRCodeScanner && renderDialogQRCodeScanner()}
);
};
const mapStateToProps = createStructuredSelector({
subscriptionList: selectSubscriptionList,
activatePaySubscription: selectActivatePaySubscription
});
export default connect(mapStateToProps, {
fetchActivePaySubscription,
fetchGetSubscriptionList,
})(
SaisirFeuilleSoinScreen,
);