import React, { ReactElement, useEffect } from 'react';
import Head from 'next/head'
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import dayjs from "dayjs";
import {useAppDispatch, useAppSelector} from "../../stores/hooks";
import {useRouter} from "next/router";
import { fetch } from '../../stores/healthcare_providers/healthcare_providersSlice'
import {saveFile} from "../../helpers/fileSaver";
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from "../../components/ImageField";
import LayoutAuthenticated from "../../layouts/Authenticated";
import {getPageTitle} from "../../config";
import SectionTitleLineWithButton from "../../components/SectionTitleLineWithButton";
import SectionMain from "../../components/SectionMain";
import CardBox from "../../components/CardBox";
import BaseButton from "../../components/BaseButton";
import BaseDivider from "../../components/BaseDivider";
import {mdiChartTimelineVariant} from "@mdi/js";
import {SwitchField} from "../../components/SwitchField";
import FormField from "../../components/FormField";


const Healthcare_providersView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { healthcare_providers } = useAppSelector((state) => state.healthcare_providers)
    

    const { id } = router.query;
    
    function removeLastCharacter(str) {
      console.log(str,`str`)
      return str.slice(0, -1);
    }

    useEffect(() => {
        dispatch(fetch({ id }));
    }, [dispatch, id]);


    return (
      <>
          <Head>
              <title>{getPageTitle('View healthcare_providers')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View healthcare_providers')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/healthcare_providers/healthcare_providers-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>User</p>
                    
                    
                        <p>{healthcare_providers?.user?.firstName ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ProviderType</p>
                    <p>{healthcare_providers?.provider_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ProviderName</p>
                    <p>{healthcare_providers?.provider_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ClinicorPractice</p>
                    <p>{healthcare_providers?.clinic_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Phone</p>
                    <p>{healthcare_providers?.phone}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Email</p>
                    <p>{healthcare_providers?.email}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              
                <FormField label='Multi Text' hasTextareaHeight>
                  <textarea className={'w-full'} disabled value={healthcare_providers?.address} />
                </FormField>
              

              

              

              

              

              

              

              

              

              

              

              
              

              

              
                <FormField label='Multi Text' hasTextareaHeight>
                  <textarea className={'w-full'} disabled value={healthcare_providers?.notes} />
                </FormField>
              

              

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Medications PrescribingProvider</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>MedicationName</th>
                                
                                
                                
                                <th>DoseAmount</th>
                                
                                
                                
                                <th>DoseUnit</th>
                                
                                
                                
                                <th>Frequency</th>
                                
                                
                                
                                <th>EveryXHours</th>
                                
                                
                                
                                <th>FrequencyNotes</th>
                                
                                
                                
                                <th>Route</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>ConditionTreated</th>
                                
                                
                                
                                <th>StartDate</th>
                                
                                
                                
                                <th>EndDate</th>
                                
                                
                                
                                <th>RefillReminderDate</th>
                                
                                
                                
                                <th>RemindMetoTakeIt</th>
                                
                                
                                
                                <th>ControlledSubstance</th>
                                
                                
                                
                                
                                
                                <th>Instructions</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {healthcare_providers.medications_prescribing_provider && Array.isArray(healthcare_providers.medications_prescribing_provider) &&
                              healthcare_providers.medications_prescribing_provider.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/medications/medications-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="medication_name">
                                        { item.medication_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="dose_amount">
                                        { item.dose_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="dose_unit">
                                        { item.dose_unit }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="frequency_type">
                                        { item.frequency_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="frequency_interval_hours">
                                        { item.frequency_interval_hours }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="frequency_notes">
                                        { item.frequency_notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="route">
                                        { item.route }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="condition_treated">
                                        { item.condition_treated }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="start_date">
                                        { dataFormatter.dateTimeFormatter(item.start_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_date">
                                        { dataFormatter.dateTimeFormatter(item.end_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="refill_reminder_date">
                                        { dataFormatter.dateTimeFormatter(item.refill_reminder_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reminders_enabled">
                                        { dataFormatter.booleanFormatter(item.reminders_enabled) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_controlled_substance">
                                        { dataFormatter.booleanFormatter(item.is_controlled_substance) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="instructions">
                                        { item.instructions }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!healthcare_providers?.medications_prescribing_provider?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Medical_appointments Provider</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>AppointmentStart</th>
                                
                                
                                
                                <th>AppointmentEnd</th>
                                
                                
                                
                                <th>AppointmentType</th>
                                
                                
                                
                                <th>ClinicLocation</th>
                                
                                
                                
                                <th>NotestoDiscuss</th>
                                
                                
                                
                                <th>DocumentstoBring</th>
                                
                                
                                
                                <th>PostAppointmentNotes</th>
                                
                                
                                
                                <th>FollowUpInstructions</th>
                                
                                
                                
                                <th>FollowUpReminderAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {healthcare_providers.medical_appointments_provider && Array.isArray(healthcare_providers.medical_appointments_provider) &&
                              healthcare_providers.medical_appointments_provider.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/medical_appointments/medical_appointments-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="appointment_start">
                                        { dataFormatter.dateTimeFormatter(item.appointment_start) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="appointment_end">
                                        { dataFormatter.dateTimeFormatter(item.appointment_end) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="appointment_type">
                                        { item.appointment_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="clinic_location">
                                        { item.clinic_location }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes_to_discuss">
                                        { item.notes_to_discuss }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="documents_to_bring">
                                        { item.documents_to_bring }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="post_appointment_notes">
                                        { item.post_appointment_notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="follow_up_instructions">
                                        { item.follow_up_instructions }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="follow_up_reminder_at">
                                        { dataFormatter.dateTimeFormatter(item.follow_up_reminder_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!healthcare_providers?.medical_appointments_provider?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Lab_documents OrderedByProvider</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>DocumentDate</th>
                                
                                
                                
                                <th>Category</th>
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>ReviewedwithDoctor</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {healthcare_providers.lab_documents_ordered_by_provider && Array.isArray(healthcare_providers.lab_documents_ordered_by_provider) &&
                              healthcare_providers.lab_documents_ordered_by_provider.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/lab_documents/lab_documents-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="document_date">
                                        { dataFormatter.dateTimeFormatter(item.document_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="category">
                                        { item.category }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reviewed_with_doctor">
                                        { dataFormatter.booleanFormatter(item.reviewed_with_doctor) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!healthcare_providers?.lab_documents_ordered_by_provider?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vaccinations Provider</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>VaccineName</th>
                                
                                
                                
                                <th>DateGiven</th>
                                
                                
                                
                                <th>DoseNumber</th>
                                
                                
                                
                                <th>BatchNumber</th>
                                
                                
                                
                                
                                
                                <th>BoosterDueDate</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {healthcare_providers.vaccinations_provider && Array.isArray(healthcare_providers.vaccinations_provider) &&
                              healthcare_providers.vaccinations_provider.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/vaccinations/vaccinations-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="vaccine_name">
                                        { item.vaccine_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="date_given">
                                        { dataFormatter.dateTimeFormatter(item.date_given) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="dose_number">
                                        { item.dose_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="batch_number">
                                        { item.batch_number }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="booster_due_date">
                                        { dataFormatter.dateTimeFormatter(item.booster_due_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!healthcare_providers?.vaccinations_provider?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Sti_tests ClinicProvider</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>TestDate</th>
                                
                                
                                
                                <th>TestsPerformed</th>
                                
                                
                                
                                <th>ResultStatus</th>
                                
                                
                                
                                <th>ResultsNotes</th>
                                
                                
                                
                                
                                
                                <th>NextRecommendedTestDate</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {healthcare_providers.sti_tests_clinic_provider && Array.isArray(healthcare_providers.sti_tests_clinic_provider) &&
                              healthcare_providers.sti_tests_clinic_provider.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/sti_tests/sti_tests-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="tested_at">
                                        { dataFormatter.dateTimeFormatter(item.tested_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tests_performed">
                                        { item.tests_performed }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="result_status">
                                        { item.result_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="results_notes">
                                        { item.results_notes }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="next_recommended_test_date">
                                        { dataFormatter.dateTimeFormatter(item.next_recommended_test_date) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!healthcare_providers?.sti_tests_clinic_provider?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vision_prescriptions Optometrist</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>PrescriptionDate</th>
                                
                                
                                
                                <th>RightSphere</th>
                                
                                
                                
                                <th>RightCylinder</th>
                                
                                
                                
                                <th>RightAxis</th>
                                
                                
                                
                                <th>LeftSphere</th>
                                
                                
                                
                                <th>LeftCylinder</th>
                                
                                
                                
                                <th>LeftAxis</th>
                                
                                
                                
                                <th>AddPower</th>
                                
                                
                                
                                <th>PupillaryDistance(mm)</th>
                                
                                
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {healthcare_providers.vision_prescriptions_optometrist && Array.isArray(healthcare_providers.vision_prescriptions_optometrist) &&
                              healthcare_providers.vision_prescriptions_optometrist.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/vision_prescriptions/vision_prescriptions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="prescription_date">
                                        { dataFormatter.dateTimeFormatter(item.prescription_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="right_sphere">
                                        { item.right_sphere }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="right_cylinder">
                                        { item.right_cylinder }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="right_axis">
                                        { item.right_axis }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="left_sphere">
                                        { item.left_sphere }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="left_cylinder">
                                        { item.left_cylinder }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="left_axis">
                                        { item.left_axis }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="add_power">
                                        { item.add_power }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="pupillary_distance_mm">
                                        { item.pupillary_distance_mm }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!healthcare_providers?.vision_prescriptions_optometrist?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Hearing_test_logs Provider</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>TestDate</th>
                                
                                
                                
                                <th>AudiogramJSON</th>
                                
                                
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {healthcare_providers.hearing_test_logs_provider && Array.isArray(healthcare_providers.hearing_test_logs_provider) &&
                              healthcare_providers.hearing_test_logs_provider.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/hearing_test_logs/hearing_test_logs-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="test_date">
                                        { dataFormatter.dateTimeFormatter(item.test_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="audiogram_json">
                                        { item.audiogram_json }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!healthcare_providers?.hearing_test_logs_provider?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

                <BaseButton
                    color='info'
                    label='Back'
                    onClick={() => router.push('/healthcare_providers/healthcare_providers-list')}
                />
              </CardBox>
          </SectionMain>
      </>
    );
};

Healthcare_providersView.getLayout = function getLayout(page: ReactElement) {
    return (
      <LayoutAuthenticated
        
        permission={'READ_HEALTHCARE_PROVIDERS'}
        
      >
          {page}
      </LayoutAuthenticated>
    )
}

export default Healthcare_providersView;