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/organizations/organizationsSlice'
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";

import {hasPermission} from "../../helpers/userPermissions";


const OrganizationsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { organizations } = useAppSelector((state) => state.organizations)
    
    const { currentUser } = useAppSelector((state) => state.auth);
    

    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 organizations')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View organizations')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/organizations/organizations-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Name</p>
                    <p>{organizations?.name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

                
                <>
                    <p className={'block font-bold mb-2'}>Users Organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>First Name</th>
                                
                                
                                
                                <th>Last Name</th>
                                
                                
                                
                                <th>Phone Number</th>
                                
                                
                                
                                <th>E-Mail</th>
                                
                                
                                
                                <th>Disabled</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.users_organizations && Array.isArray(organizations.users_organizations) &&
                              organizations.users_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/users/users-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="firstName">
                                        { item.firstName }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="lastName">
                                        { item.lastName }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="phoneNumber">
                                        { item.phoneNumber }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="email">
                                        { item.email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="disabled">
                                        { dataFormatter.booleanFormatter(item.disabled) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.users_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Doctor_profiles Organization</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>DoctorType</th>
                                
                                
                                
                                
                                
                                <th>MedicalLicenseNumber</th>
                                
                                
                                
                                <th>Specialization</th>
                                
                                
                                
                                <th>Qualification</th>
                                
                                
                                
                                <th>YearsOfExperience</th>
                                
                                
                                
                                <th>AvailabilityStatus</th>
                                
                                
                                
                                <th>ConsultationFeeNote</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.doctor_profiles_organization && Array.isArray(organizations.doctor_profiles_organization) &&
                              organizations.doctor_profiles_organization.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/doctor_profiles/doctor_profiles-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="doctor_type">
                                        { item.doctor_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="medical_license_number">
                                        { item.medical_license_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="specialization">
                                        { item.specialization }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="qualification">
                                        { item.qualification }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="years_of_experience">
                                        { item.years_of_experience }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="availability_status">
                                        { item.availability_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="consultation_fee_note">
                                        { item.consultation_fee_note }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.doctor_profiles_organization?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Patient_profiles organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>PatientIdentifier</th>
                                
                                
                                
                                <th>Gender</th>
                                
                                
                                
                                <th>DateOfBirth</th>
                                
                                
                                
                                <th>BloodGroup</th>
                                
                                
                                
                                <th>Address</th>
                                
                                
                                
                                <th>Village</th>
                                
                                
                                
                                <th>District</th>
                                
                                
                                
                                <th>State</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>ConsentForTelemedicine</th>
                                
                                
                                
                                <th>ConsentForNotifications</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.patient_profiles_organizations && Array.isArray(organizations.patient_profiles_organizations) &&
                              organizations.patient_profiles_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/patient_profiles/patient_profiles-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="patient_identifier">
                                        { item.patient_identifier }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gender">
                                        { item.gender }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="date_of_birth">
                                        { dataFormatter.dateTimeFormatter(item.date_of_birth) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="blood_group">
                                        { item.blood_group }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address_line">
                                        { item.address_line }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="village">
                                        { item.village }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="district">
                                        { item.district }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="state">
                                        { item.state }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="consent_for_telemedicine">
                                        { dataFormatter.booleanFormatter(item.consent_for_telemedicine) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="consent_for_notifications">
                                        { dataFormatter.booleanFormatter(item.consent_for_notifications) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.patient_profiles_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Medical_camps OrganizerOrganization</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>CampName</th>
                                
                                
                                
                                <th>CampType</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>StartAt</th>
                                
                                
                                
                                <th>EndAt</th>
                                
                                
                                
                                <th>LocationLabel</th>
                                
                                
                                
                                <th>Address</th>
                                
                                
                                
                                <th>Latitude</th>
                                
                                
                                
                                <th>Longitude</th>
                                
                                
                                
                                <th>CampStatus</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.medical_camps_organizer_organization && Array.isArray(organizations.medical_camps_organizer_organization) &&
                              organizations.medical_camps_organizer_organization.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/medical_camps/medical_camps-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="camp_name">
                                        { item.camp_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="camp_type">
                                        { item.camp_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="start_at">
                                        { dataFormatter.dateTimeFormatter(item.start_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_at">
                                        { dataFormatter.dateTimeFormatter(item.end_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="location_label">
                                        { item.location_label }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address_line">
                                        { item.address_line }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="latitude">
                                        { item.latitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="longitude">
                                        { item.longitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="camp_status">
                                        { item.camp_status }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.medical_camps_organizer_organization?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Appointments organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ScheduledStartAt</th>
                                
                                
                                
                                <th>ScheduledEndAt</th>
                                
                                
                                
                                <th>AppointmentType</th>
                                
                                
                                
                                <th>AppointmentStatus</th>
                                
                                
                                
                                <th>Reason</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.appointments_organizations && Array.isArray(organizations.appointments_organizations) &&
                              organizations.appointments_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/appointments/appointments-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="scheduled_start_at">
                                        { dataFormatter.dateTimeFormatter(item.scheduled_start_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="scheduled_end_at">
                                        { dataFormatter.dateTimeFormatter(item.scheduled_end_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="appointment_type">
                                        { item.appointment_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="appointment_status">
                                        { item.appointment_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reason">
                                        { item.reason }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.appointments_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Consultations organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>StartedAt</th>
                                
                                
                                
                                <th>EndedAt</th>
                                
                                
                                
                                <th>Channel</th>
                                
                                
                                
                                <th>ConsultationStatus</th>
                                
                                
                                
                                <th>ChiefComplaint</th>
                                
                                
                                
                                
                                
                                <th>DiagnosisSummary</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.consultations_organizations && Array.isArray(organizations.consultations_organizations) &&
                              organizations.consultations_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/consultations/consultations-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="started_at">
                                        { dataFormatter.dateTimeFormatter(item.started_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ended_at">
                                        { dataFormatter.dateTimeFormatter(item.ended_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="channel">
                                        { item.channel }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="consultation_status">
                                        { item.consultation_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="chief_complaint">
                                        { item.chief_complaint }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="diagnosis_summary">
                                        { item.diagnosis_summary }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.consultations_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Medical_reports organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ReportType</th>
                                
                                
                                
                                <th>ReportDate</th>
                                
                                
                                
                                <th>ReportTitle</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>QRPayload</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.medical_reports_organizations && Array.isArray(organizations.medical_reports_organizations) &&
                              organizations.medical_reports_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/medical_reports/medical_reports-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="report_type">
                                        { item.report_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="report_date">
                                        { dataFormatter.dateTimeFormatter(item.report_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="report_title">
                                        { item.report_title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="qr_payload">
                                        { item.qr_payload }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.medical_reports_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Medicines organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>MedicineName</th>
                                
                                
                                
                                <th>GenericName</th>
                                
                                
                                
                                <th>Strength</th>
                                
                                
                                
                                <th>DosageForm</th>
                                
                                
                                
                                <th>Manufacturer</th>
                                
                                
                                
                                <th>RequiresPrescription</th>
                                
                                
                                
                                <th>StorageInstructions</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.medicines_organizations && Array.isArray(organizations.medicines_organizations) &&
                              organizations.medicines_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/medicines/medicines-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="medicine_name">
                                        { item.medicine_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="generic_name">
                                        { item.generic_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="strength">
                                        { item.strength }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="dosage_form">
                                        { item.dosage_form }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="manufacturer">
                                        { item.manufacturer }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="requires_prescription">
                                        { dataFormatter.booleanFormatter(item.requires_prescription) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="storage_instructions">
                                        { item.storage_instructions }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.medicines_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Inventory_items Organization</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>BatchCode</th>
                                
                                
                                
                                <th>ExpiryDate</th>
                                
                                
                                
                                <th>QuantityOnHand</th>
                                
                                
                                
                                <th>ReorderLevel</th>
                                
                                
                                
                                <th>UnitCost</th>
                                
                                
                                
                                <th>StockStatus</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.inventory_items_organization && Array.isArray(organizations.inventory_items_organization) &&
                              organizations.inventory_items_organization.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/inventory_items/inventory_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="batch_code">
                                        { item.batch_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expiry_date">
                                        { dataFormatter.dateTimeFormatter(item.expiry_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity_on_hand">
                                        { item.quantity_on_hand }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reorder_level">
                                        { item.reorder_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_cost">
                                        { item.unit_cost }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="stock_status">
                                        { item.stock_status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.inventory_items_organization?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Prescriptions organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>PrescribedAt</th>
                                
                                
                                
                                <th>PrescriptionStatus</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.prescriptions_organizations && Array.isArray(organizations.prescriptions_organizations) &&
                              organizations.prescriptions_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/prescriptions/prescriptions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="prescribed_at">
                                        { dataFormatter.dateTimeFormatter(item.prescribed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="prescription_status">
                                        { item.prescription_status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.prescriptions_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Prescription_items organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>DoseInstructions</th>
                                
                                
                                
                                <th>Frequency</th>
                                
                                
                                
                                <th>DurationDays</th>
                                
                                
                                
                                <th>QuantityPrescribed</th>
                                
                                
                                
                                <th>SubstitutionAllowed</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.prescription_items_organizations && Array.isArray(organizations.prescription_items_organizations) &&
                              organizations.prescription_items_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/prescription_items/prescription_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="dose_instructions">
                                        { item.dose_instructions }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="frequency">
                                        { item.frequency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="duration_days">
                                        { item.duration_days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity_prescribed">
                                        { item.quantity_prescribed }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="substitution_allowed">
                                        { dataFormatter.booleanFormatter(item.substitution_allowed) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.prescription_items_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Medicine_dispatches FromOrganization</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>DispatchedAt</th>
                                
                                
                                
                                <th>ExpectedDeliveryAt</th>
                                
                                
                                
                                <th>DeliveredAt</th>
                                
                                
                                
                                <th>DispatchStatus</th>
                                
                                
                                
                                <th>TrackingReference</th>
                                
                                
                                
                                <th>LastKnownLatitude</th>
                                
                                
                                
                                <th>LastKnownLongitude</th>
                                
                                
                                
                                <th>DeliveryNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.medicine_dispatches_from_organization && Array.isArray(organizations.medicine_dispatches_from_organization) &&
                              organizations.medicine_dispatches_from_organization.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/medicine_dispatches/medicine_dispatches-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="dispatched_at">
                                        { dataFormatter.dateTimeFormatter(item.dispatched_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expected_delivery_at">
                                        { dataFormatter.dateTimeFormatter(item.expected_delivery_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="delivered_at">
                                        { dataFormatter.dateTimeFormatter(item.delivered_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="dispatch_status">
                                        { item.dispatch_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tracking_reference">
                                        { item.tracking_reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_known_latitude">
                                        { item.last_known_latitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_known_longitude">
                                        { item.last_known_longitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="delivery_notes">
                                        { item.delivery_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.medicine_dispatches_from_organization?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                <>
                    <p className={'block font-bold mb-2'}>Medicine_dispatches ToOrganization</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>DispatchedAt</th>
                                
                                
                                
                                <th>ExpectedDeliveryAt</th>
                                
                                
                                
                                <th>DeliveredAt</th>
                                
                                
                                
                                <th>DispatchStatus</th>
                                
                                
                                
                                <th>TrackingReference</th>
                                
                                
                                
                                <th>LastKnownLatitude</th>
                                
                                
                                
                                <th>LastKnownLongitude</th>
                                
                                
                                
                                <th>DeliveryNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.medicine_dispatches_to_organization && Array.isArray(organizations.medicine_dispatches_to_organization) &&
                              organizations.medicine_dispatches_to_organization.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/medicine_dispatches/medicine_dispatches-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="dispatched_at">
                                        { dataFormatter.dateTimeFormatter(item.dispatched_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expected_delivery_at">
                                        { dataFormatter.dateTimeFormatter(item.expected_delivery_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="delivered_at">
                                        { dataFormatter.dateTimeFormatter(item.delivered_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="dispatch_status">
                                        { item.dispatch_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tracking_reference">
                                        { item.tracking_reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_known_latitude">
                                        { item.last_known_latitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_known_longitude">
                                        { item.last_known_longitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="delivery_notes">
                                        { item.delivery_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.medicine_dispatches_to_organization?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vaccinations organizations</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>VaccineCode</th>
                                
                                
                                
                                <th>RecommendedMinAgeDays</th>
                                
                                
                                
                                <th>RecommendedMaxAgeDays</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.vaccinations_organizations && Array.isArray(organizations.vaccinations_organizations) &&
                              organizations.vaccinations_organizations.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="vaccine_code">
                                        { item.vaccine_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="recommended_min_age_days">
                                        { item.recommended_min_age_days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="recommended_max_age_days">
                                        { item.recommended_max_age_days }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.vaccinations_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Patient_vaccinations organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>DueAt</th>
                                
                                
                                
                                <th>AdministeredAt</th>
                                
                                
                                
                                <th>VaccinationStatus</th>
                                
                                
                                
                                <th>AdministeredBy</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.patient_vaccinations_organizations && Array.isArray(organizations.patient_vaccinations_organizations) &&
                              organizations.patient_vaccinations_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/patient_vaccinations/patient_vaccinations-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="due_at">
                                        { dataFormatter.dateTimeFormatter(item.due_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="administered_at">
                                        { dataFormatter.dateTimeFormatter(item.administered_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vaccination_status">
                                        { item.vaccination_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="administered_by">
                                        { item.administered_by }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.patient_vaccinations_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Reminders organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ReminderType</th>
                                
                                
                                
                                <th>ScheduledAt</th>
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                                
                                <th>Channel</th>
                                
                                
                                
                                <th>DeliveryStatus</th>
                                
                                
                                
                                <th>MessageText</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.reminders_organizations && Array.isArray(organizations.reminders_organizations) &&
                              organizations.reminders_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/reminders/reminders-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reminder_type">
                                        { item.reminder_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="scheduled_at">
                                        { dataFormatter.dateTimeFormatter(item.scheduled_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="channel">
                                        { item.channel }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="delivery_status">
                                        { item.delivery_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="message_text">
                                        { item.message_text }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.reminders_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Chat_sessions organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>SessionType</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>SessionStatus</th>
                                
                                
                                
                                <th>StartedAt</th>
                                
                                
                                
                                <th>EndedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.chat_sessions_organizations && Array.isArray(organizations.chat_sessions_organizations) &&
                              organizations.chat_sessions_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/chat_sessions/chat_sessions-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="session_type">
                                        { item.session_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="session_status">
                                        { item.session_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="started_at">
                                        { dataFormatter.dateTimeFormatter(item.started_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ended_at">
                                        { dataFormatter.dateTimeFormatter(item.ended_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.chat_sessions_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Messages organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>SenderType</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                                
                                <th>IsRead</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.messages_organizations && Array.isArray(organizations.messages_organizations) &&
                              organizations.messages_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/messages/messages-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="sender_type">
                                        { item.sender_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_read">
                                        { dataFormatter.booleanFormatter(item.is_read) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.messages_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Video_calls organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Provider</th>
                                
                                
                                
                                <th>ProviderRoomName</th>
                                
                                
                                
                                <th>ProviderSessionReference</th>
                                
                                
                                
                                <th>StartedAt</th>
                                
                                
                                
                                <th>EndedAt</th>
                                
                                
                                
                                <th>CallStatus</th>
                                
                                
                                
                                <th>CallNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.video_calls_organizations && Array.isArray(organizations.video_calls_organizations) &&
                              organizations.video_calls_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/video_calls/video_calls-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="provider">
                                        { item.provider }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="provider_room_name">
                                        { item.provider_room_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="provider_session_reference">
                                        { item.provider_session_reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="started_at">
                                        { dataFormatter.dateTimeFormatter(item.started_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ended_at">
                                        { dataFormatter.dateTimeFormatter(item.ended_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="call_status">
                                        { item.call_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="call_notes">
                                        { item.call_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.video_calls_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Chatbot_interactions organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>AskedAt</th>
                                
                                
                                
                                <th>UserPrompt</th>
                                
                                
                                
                                
                                
                                <th>ModelName</th>
                                
                                
                                
                                <th>ConfidenceScore</th>
                                
                                
                                
                                <th>TriageLevel</th>
                                
                                
                                
                                <th>EscalatedToDoctor</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.chatbot_interactions_organizations && Array.isArray(organizations.chatbot_interactions_organizations) &&
                              organizations.chatbot_interactions_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/chatbot_interactions/chatbot_interactions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="asked_at">
                                        { dataFormatter.dateTimeFormatter(item.asked_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="user_prompt">
                                        { item.user_prompt }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="model_name">
                                        { item.model_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="confidence_score">
                                        { item.confidence_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="triage_level">
                                        { item.triage_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="escalated_to_doctor">
                                        { dataFormatter.booleanFormatter(item.escalated_to_doctor) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.chatbot_interactions_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Feedbacks organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Rating</th>
                                
                                
                                
                                
                                
                                <th>SubmittedAt</th>
                                
                                
                                
                                <th>Visibility</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.feedbacks_organizations && Array.isArray(organizations.feedbacks_organizations) &&
                              organizations.feedbacks_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/feedbacks/feedbacks-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="rating">
                                        { item.rating }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="submitted_at">
                                        { dataFormatter.dateTimeFormatter(item.submitted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="visibility">
                                        { item.visibility }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.feedbacks_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                

                <BaseDivider />

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

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

export default OrganizationsView;