Fix: debug after reset
This commit is contained in:
@@ -383,3 +383,45 @@ export const medicalActionTypeCode: Record<string, string> = {
|
||||
} as const
|
||||
|
||||
export type medicalActionTypeCodeKey = keyof typeof medicalActionTypeCode
|
||||
|
||||
export const encounterDocTypeCode: Record<string, string> = {
|
||||
"person-resident-number": 'person-resident-number',
|
||||
"person-driving-license": 'person-driving-license',
|
||||
"person-passport": 'person-passport',
|
||||
"person-family-card": 'person-family-card',
|
||||
"mcu-item-result": 'mcu-item-result',
|
||||
"vclaim-sep": 'vclaim-sep',
|
||||
"vclaim-sipp": 'vclaim-sipp',
|
||||
} as const
|
||||
export type encounterDocTypeCodeKey = keyof typeof encounterDocTypeCode
|
||||
export const encounterDocOpt: { label: string; value: encounterDocTypeCodeKey }[] = [
|
||||
{ label: 'KTP', value: 'person-resident-number' },
|
||||
{ label: 'SIM', value: 'person-driving-license' },
|
||||
{ label: 'Passport', value: 'person-passport' },
|
||||
{ label: 'Kartu Keluarga', value: 'person-family-card' },
|
||||
{ label: 'Hasil MCU', value: 'mcu-item-result' },
|
||||
{ label: 'Klaim SEP', value: 'vclaim-sep' },
|
||||
{ label: 'Klaim SIPP', value: 'vclaim-sipp' },
|
||||
]
|
||||
|
||||
|
||||
export const docTypeCode = {
|
||||
"encounter-patient": 'encounter-patient',
|
||||
"encounter-support": 'encounter-support',
|
||||
"encounter-other": 'encounter-other',
|
||||
"vclaim-sep": 'vclaim-sep',
|
||||
"vclaim-sipp": 'vclaim-sipp',
|
||||
} as const
|
||||
export const docTypeLabel = {
|
||||
"encounter-patient": 'Data Pasien',
|
||||
"encounter-support": 'Data Penunjang',
|
||||
"encounter-other": 'Lain - Lain',
|
||||
"vclaim-sep": 'SEP',
|
||||
"vclaim-sipp": 'SIPP',
|
||||
} as const
|
||||
export type docTypeCodeKey = keyof typeof docTypeCode
|
||||
export const supportingDocOpt = [
|
||||
{ label: 'Data Pasien', value: 'encounter-patient' },
|
||||
{ label: 'Data Penunjang', value: 'encounter-support' },
|
||||
{ label: 'Lain - Lain', value: 'encounter-other' },
|
||||
]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { ClassValue } from 'clsx'
|
||||
import { clsx } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
import { toast } from '~/components/pub/ui/toast'
|
||||
|
||||
export interface SelectOptionType<_T = string> {
|
||||
value: string
|
||||
@@ -104,3 +105,59 @@ export function calculateAge(birthDate: Date | string | null | undefined): strin
|
||||
return `${years} tahun ${months} bulan`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts a plain JavaScript object (including File objects) into a FormData instance.
|
||||
* @param {object} data - The object to convert (e.g., form values).
|
||||
* @returns {FormData} The new FormData object suitable for API submission.
|
||||
*/
|
||||
export function toFormData(data: Record<string, any>): FormData {
|
||||
const formData = new FormData();
|
||||
|
||||
for (const key in data) {
|
||||
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
||||
const value = data[key];
|
||||
|
||||
// Handle File objects, Blobs, or standard JSON values
|
||||
if (value !== null && value !== undefined) {
|
||||
// Check if the value is a File/Blob instance
|
||||
if (value instanceof File || value instanceof Blob) {
|
||||
// Append the file directly
|
||||
formData.append(key, value);
|
||||
} else if (typeof value === 'object') {
|
||||
// Handle nested objects/arrays by stringifying them (optional, depends on API)
|
||||
// Note: Most APIs expect nested data to be handled separately or passed as JSON string
|
||||
// For simplicity, we stringify non-File objects.
|
||||
formData.append(key, JSON.stringify(value));
|
||||
} else {
|
||||
// Append standard string, number, or boolean values
|
||||
formData.append(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return formData;
|
||||
}
|
||||
|
||||
export function printFormData(formData: FormData) {
|
||||
console.log("--- FormData Contents ---");
|
||||
// Use the entries() iterator to loop through key/value pairs
|
||||
for (const [key, value] of formData.entries()) {
|
||||
if (value instanceof File) {
|
||||
console.log(`Key: ${key}, Value: [File: ${value.name}, Type: ${value.type}, Size: ${value.size} bytes]`);
|
||||
} else {
|
||||
console.log(`Key: ${key}, Value: "${value}"`);
|
||||
}
|
||||
}
|
||||
console.log("-------------------------");
|
||||
}
|
||||
|
||||
export function unauthorizedToast() {
|
||||
toast({
|
||||
title: 'Unauthorized',
|
||||
description: 'You are not authorized to perform this action.',
|
||||
variant: 'destructive',
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user