finish: integrasi create education assessment

note: masih perlu cek terkait new api domain
This commit is contained in:
Khafid Prayoga
2025-10-23 16:20:50 +07:00
parent d879325496
commit dd33bbac8e
6 changed files with 160 additions and 10 deletions
@@ -1,30 +1,33 @@
<script setup lang="ts">
import type { ExposedForm } from '~/types/form'
import { type AssessmentEducationFormData, AssessmentEducationSchema } from '~/schemas/assessment-education'
import { type AssessmentEducationFormData, AssessmentEducationSchema, encode } from '~/schemas/assessment-education'
import Action from '~/components/pub/my-ui/nav-footer/ba-dr-su.vue'
// Handlers
import { isReadonly, isProcessing, onResetState, handleActionSave, handleCancelForm } from '~/handlers/infra.handler'
import {
isReadonly,
isProcessing,
onResetState,
handleActionSave,
handleCancelForm,
} from '~/handlers/assessment-education.handler'
// Helpers
import { toast } from '~/components/pub/ui/toast'
// Services
import { getList, getDetail } from '~/services/infra.service'
const form = ref<ExposedForm<AssessmentEducationFormData> | null>(null)
async function saveData(values: AssessmentEducationFormData) {
const transform = encode(1, values)
handleActionSave(
values,
transform,
() => {
window.location.reload()
},
() => {},
toast,
)
console.log('sending data')
console.log(values)
}
async function cancelData() {}
@@ -32,6 +35,7 @@ async function cancelData() {}
async function handleActionClick(eventType: string) {
if (eventType === 'submit') {
const formValidate = await form.value?.validate()
console.log(formValidate)
if (!formValidate?.valid) return
saveData(formValidate?.values)
}
@@ -49,8 +53,6 @@ async function handleActionClick(eventType: string) {
:is-readonly="isReadonly"
:is-loading="isProcessing"
:schema="AssessmentEducationSchema"
@submit=""
@cancel=""
/>
<div class="my-2 flex justify-end py-2">
@@ -0,0 +1,24 @@
// Handlers
import { genCrudHandler } from '~/handlers/_handler'
// Services
import { create, update, remove } from '~/services/assessment-education.service'
export const {
recId,
recAction,
recItem,
isReadonly,
isProcessing,
isFormEntryDialogOpen,
isRecordConfirmationOpen,
onResetState,
handleActionSave,
handleActionEdit,
handleActionRemove,
handleCancelForm,
} = genCrudHandler({
create,
update,
remove,
})
+29
View File
@@ -85,3 +85,32 @@ export const translatorSrcCode = {
} as const
export type TranslatorSrcCodeKey = keyof typeof translatorSrcCode
// helpers
type EduCodeType = 'general' | 'special'
export function serializeKeyToBoolean(type: EduCodeType, selected: string[]): Record<string, boolean> {
switch (type) {
case 'general': {
return Object.keys(generalEduCode).reduce(
(acc, key) => {
acc[key] = selected.includes(key)
return acc
},
{} as Record<string, boolean>,
)
}
case 'special': {
return Object.keys(specialEduCode).reduce(
(acc, key) => {
acc[key] = selected.includes(key)
return acc
},
{} as Record<string, boolean>,
)
}
default:
throw new Error('unknown type to serialize')
}
}
+41
View File
@@ -0,0 +1,41 @@
import { type Base, genBase } from './_base'
export type JsonRaw = string
export interface EduAssessment extends Base {
encounter_id: number
generalEdus: Record<string, string>
specialEdus: Record<string, string>
assessments: Record<string, string>
plan: Record<string, string>
}
export function genEduAssessment(): EduAssessment {
return {
...genBase(),
encounter_id: 0,
generalEdus: {},
specialEdus: {},
assessments: {},
plan: {},
}
}
export interface EduAssessmentRaw extends Base {
encounter_id: number
generalEdus: string
specialEdus: string
assessments: string
plan: string
}
export function genEduAssessmentRaw(): EduAssessmentRaw {
return {
...genBase(),
encounter_id: 0,
generalEdus: '',
specialEdus: '',
assessments: '',
plan: '',
}
}
+26
View File
@@ -1,4 +1,6 @@
import * as z from 'zod'
import { genEduAssessmentRaw, type EduAssessment, type EduAssessmentRaw } from '../models/edu-assessment'
import { serializeKeyToBoolean } from '../lib/clinical.constants'
const AssessmentEducationSchema = z.object({
generalEducationNeeds: z
@@ -55,3 +57,27 @@ type AssessmentEducationFormData = z.infer<typeof AssessmentEducationSchema>
export { AssessmentEducationSchema }
export type { AssessmentEducationFormData }
export function encode(encounterId: number, formData: AssessmentEducationFormData): EduAssessmentRaw {
let base = genEduAssessmentRaw()
// serialize general data
const general = serializeKeyToBoolean('general', formData.generalEducationNeeds)
const special = serializeKeyToBoolean('special', formData.specificEducationNeeds)
base.encounter_id = encounterId
base.generalEdus = JSON.stringify(general)
base.specialEdus = JSON.stringify(special)
base.assessments = JSON.stringify({
'learn-ability': formData.learningAbility,
'learn-will': formData.learningWillingness,
obstacle: formData.barrier,
'learn-method': formData.learningMethod,
lang: formData.language,
'lang-obstacle': formData.languageBarrier,
belief: formData.beliefValue,
})
base.plan = JSON.stringify(formData.plans)
return base
}
@@ -0,0 +1,28 @@
// Base
import * as base from './_crud-base'
// Types
import type { EduAssessmentRaw, EduAssessment } from '~/models/edu-assessment'
const path = '/api/v1/edu-assessment'
const name = 'edu-assessment'
export function create(data: EduAssessmentRaw) {
return base.create(path, data, name)
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}