import React from 'react';
import { capitalize } from 'lodash-es';
import { InlineLoading, Toggletip, ToggletipButton, ToggletipContent } from '@carbon/react';
import { useTranslation } from 'react-i18next';
import { formatDate, UserIcon } from '@openmrs/esm-framework';
import { type Order, useDrugOrderByUuid } from '@openmrs/esm-patient-common-lib';
import styles from './medication-record.scss';
interface MedicationRecordProps {
medication: Order;
}
export default function MedicationRecord({ medication }: MedicationRecordProps) {
const { t } = useTranslation();
const { data: drugOrder, isLoading } = useDrugOrderByUuid(medication.uuid);
if (isLoading) {
return
{capitalize(order.drug?.display)}{' '} {order.drug?.strength && <>— {order.drug.strength.toLowerCase()}>}{' '} {order.drug?.dosageForm?.display && <>— {order.drug.dosageForm.display.toLowerCase()}>}
{order.dose != null && ( <> {t('dose', 'Dose').toUpperCase()}{' '} {order.dose} {order.doseUnits?.display?.toLowerCase()} {' '} > )} {order.route?.display && ( <> {order.dose != null && <>— >} {order.route.display.toLowerCase()}{' '} > )} {order.frequency?.display && <>— {order.frequency.display.toLowerCase()}>} {order.duration != null && ( <> {(order.dose != null || order.route?.display || order.frequency?.display) && <> — >} {t('medicationDurationAndUnit', 'for {{duration}} {{durationUnit}}', { duration: order.duration, durationUnit: order.durationUnits?.display?.toLowerCase(), })} > )}{' '} {order.numRefills != null && order.numRefills !== 0 && ( {(order.dose != null || order.route?.display || order.frequency?.display || order.duration != null) && ( <> — > )} {t('refills', 'Refills').toUpperCase()} {order.numRefills} )} {order.dosingInstructions && ( {(order.dose != null || order.route?.display || order.frequency?.display || order.duration != null || (order.numRefills != null && order.numRefills !== 0)) && <> — >} {order.dosingInstructions.toLowerCase()} )}
{order.orderReasonNonCoded ? ( {t('indication', 'Indication').toUpperCase()}{' '} {order.orderReasonNonCoded} ) : null} {order.orderReasonNonCoded && order.quantity != null ? <> —> : null} {order.quantity != null ? ( {t('quantity', 'Quantity').toUpperCase()} {order.quantity}{' '} {order.quantityUnits?.display} ) : null} {order.dateStopped ? ( — {t('endDate', 'End date').toUpperCase()}{' '} {formatDate(new Date(order.dateStopped))} ) : null}
{orderer}