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/medical_chronology_reports/medical_chronology_reportsSlice'
import {saveFile} from "../../helpers/fileSaver";
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from "../../components/ImageField";
import LayoutAuthenticated from "../../layouts/Authenticated";
import {getPageTitle} from "../../config";
import SectionTitleLineWithButton from "../../components/SectionTitleLineWithButton";
import SectionMain from "../../components/SectionMain";
import CardBox from "../../components/CardBox";
import BaseButton from "../../components/BaseButton";
import BaseDivider from "../../components/BaseDivider";
import {mdiChartTimelineVariant} from "@mdi/js";
import {SwitchField} from "../../components/SwitchField";
import FormField from "../../components/FormField";


const Medical_chronology_reportsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { medical_chronology_reports } = useAppSelector((state) => state.medical_chronology_reports)
    

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

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>RequestedBy</p>
                    
                    
                        <p>{medical_chronology_reports?.requested_by?.firstName ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Matter</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{medical_chronology_reports?.matter?.title ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ReportTitle</p>
                    <p>{medical_chronology_reports?.report_title}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Status</p>
                    <p>{medical_chronology_reports?.status ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Overview</p>
                  {medical_chronology_reports.overview
                    ? <p dangerouslySetInnerHTML={{__html: medical_chronology_reports.overview}}/>
                    : <p>No data</p>
                  }
                </div>
              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              
                <>
                    <p className={'block font-bold mb-2'}>SourceFiles</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                    <th>FileName</th>
                                
                                
                                
                                    <th>ContentType</th>
                                
                                
                                
                                    <th>FileExtension</th>
                                
                                
                                
                                    <th>SizeBytes</th>
                                
                                
                                
                                    <th>StorageProvider</th>
                                
                                
                                
                                    <th>StorageKey</th>
                                
                                
                                
                                    <th>ChecksumSha256</th>
                                
                                
                                
                                    <th>IsOcrRequired</th>
                                
                                
                                
                                    <th>ProcessingStatus</th>
                                
                                
                                
                                    <th>UploadedAt</th>
                                
                                
                                
                                    <th>Tags</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {medical_chronology_reports.source_files && Array.isArray(medical_chronology_reports.source_files) &&
                              medical_chronology_reports.source_files.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/files/files-view/?id=${item.id}`)}>
                                  
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                  
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="file_name">
                                        { item.file_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="content_type">
                                        { item.content_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="file_extension">
                                        { item.file_extension }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="size_bytes">
                                        { item.size_bytes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="storage_provider">
                                        { item.storage_provider }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="storage_key">
                                        { item.storage_key }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="checksum_sha256">
                                        { item.checksum_sha256 }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_ocr_required">
                                        { dataFormatter.booleanFormatter(item.is_ocr_required) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="processing_status">
                                        { item.processing_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="uploaded_at">
                                        { dataFormatter.dateTimeFormatter(item.uploaded_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tags">
                                        { item.tags }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!medical_chronology_reports?.source_files?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ExportFile</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{medical_chronology_reports?.export_file?.file_name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              
                <FormField label='GeneratedAt'>
                    {medical_chronology_reports.generated_at ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={medical_chronology_reports.generated_at ?
                        new Date(
                          dayjs(medical_chronology_reports.generated_at).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No GeneratedAt</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Medical_events Report</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>EventAt</th>
                                
                                
                                
                                <th>ProviderName</th>
                                
                                
                                
                                <th>FacilityName</th>
                                
                                
                                
                                <th>Diagnoses</th>
                                
                                
                                
                                <th>Icd10Codes</th>
                                
                                
                                
                                <th>Procedures</th>
                                
                                
                                
                                <th>Medications</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {medical_chronology_reports.medical_events_report && Array.isArray(medical_chronology_reports.medical_events_report) &&
                              medical_chronology_reports.medical_events_report.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/medical_events/medical_events-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="event_at">
                                        { dataFormatter.dateTimeFormatter(item.event_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="provider_name">
                                        { item.provider_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="facility_name">
                                        { item.facility_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="diagnoses">
                                        { item.diagnoses }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="icd10_codes">
                                        { item.icd10_codes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="procedures">
                                        { item.procedures }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="medications">
                                        { item.medications }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!medical_chronology_reports?.medical_events_report?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                

                <BaseDivider />

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

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

export default Medical_chronology_reportsView;