feature: Digitization Workstation UI

This commit is contained in:
voltsrage
2026-06-27 12:15:43 +08:00
parent 88e70b3dbe
commit e22d33b654
55 changed files with 6411 additions and 143 deletions
@@ -0,0 +1,273 @@
<template>
<div class="h-full overflow-y-auto p-4 space-y-6">
<div class="flex items-center justify-between">
<h2 class="text-lg font-semibold">Data Entry</h2>
<span
:class="statusColor"
class="status-badge"
>
{{ batch?.status?.replace(/_/g, ' ') }}
</span>
</div>
<!-- Patient section -->
<fieldset class="border border-gray-200 rounded-md p-4">
<legend class="text-sm font-medium text-gray-700 px-2">Patient Demographics</legend>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-xs text-gray-500">Full Name</label>
<input
v-model="patient.fullName"
@blur="savePatient"
type="text"
class="form-input text-sm"
/>
</div>
<div>
<label class="block text-xs text-gray-500">Date of Birth</label>
<input
v-model="patient.dateOfBirth"
@blur="savePatient"
type="date"
class="form-input text-sm"
/>
</div>
<div>
<label class="block text-xs text-gray-500">Sex</label>
<select v-model="patient.sex" @change="savePatient" class="form-input text-sm">
<option value="">Select...</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select>
</div>
<div>
<label class="block text-xs text-gray-500">Blood Type</label>
<select v-model="patient.bloodType" @change="savePatient" class="form-input text-sm">
<option value="">Unknown</option>
<option v-for="bt in bloodTypes" :key="bt" :value="bt">{{ bt }}</option>
</select>
</div>
<div class="col-span-2">
<label class="block text-xs text-gray-500">Emergency Contact</label>
<input
v-model="patient.emergencyContact"
@blur="savePatient"
type="text"
class="form-input text-sm"
/>
</div>
</div>
</fieldset>
<!-- Encounter section -->
<fieldset class="border border-gray-200 rounded-md p-4">
<legend class="text-sm font-medium text-gray-700 px-2">Encounter Context</legend>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-xs text-gray-500">Admission Date</label>
<input
v-model="encounter.admissionDate"
@blur="saveEncounter"
type="datetime-local"
class="form-input text-sm"
/>
</div>
<div>
<label class="block text-xs text-gray-500">Department</label>
<select v-model="encounter.department" @change="saveEncounter" class="form-input text-sm">
<option value="">—</option>
<option v-for="dept in departments" :key="dept" :value="dept">{{ dept }}</option>
</select>
</div>
<div>
<label class="block text-xs text-gray-500">Room / Bed</label>
<input
v-model="encounter.roomBed"
@blur="saveEncounter"
type="text"
class="form-input text-sm"
/>
</div>
<div>
<label class="block text-xs text-gray-500">Admission Reason</label>
<input
v-model="encounter.admissionReason"
@blur="saveEncounter"
type="text"
class="form-input text-sm"
/>
</div>
</div>
</fieldset>
<!-- Observations section -->
<fieldset class="border border-gray-200 rounded-md p-4">
<legend class="text-sm font-medium text-gray-700 px-2">Observations</legend>
<div class="space-y-2">
<ObservationRow
v-for="obs in observations"
:key="obs.id"
:observation="obs"
@update="(field, value) => handleObsUpdate(obs.id, field, value)"
@delete="handleObsDelete"
/>
<button @click="addObservation" class="btn-primary text-sm">
+ Add Observation
</button>
</div>
</fieldset>
<!-- Submit -->
<div class="flex flex-col sm:flex-row gap-4 pt-4 border-t">
<button
@click="submitForVerification"
class="btn-primary"
:disabled="submitting"
>
{{ submitting ? 'Submitting...' : 'Submit for Verification' }}
</button>
</div>
<div v-if="errorMessage" class="text-clinical-danger text-sm">
{{ errorMessage }}
</div>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, watch } from 'vue'
import { useBatchStore } from '../stores/batches'
import ObservationRow from '../components/ObservationRow.vue'
import type { BatchDetailResponse, DraftObservation } from '../types'
const props = defineProps<{
batch: BatchDetailResponse | null
batchId: string
}>()
const batchStore = useBatchStore()
const submitting = ref(false)
const errorMessage = ref('')
const bloodTypes = ['A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-']
const departments = [
'Emergency Department',
'Internal Medicine',
'General Medicine',
'Surgery',
'ICU',
'NICU',
'Medical-Surgical',
'Outpatient Clinic',
'Pediatrics',
'Obstetrics & Gynecology',
'Labor & Delivery',
'Cardiology',
'Orthopedics',
'Neurology',
'Oncology',
'Radiology',
'Laboratory',
'Psychiatry',
'Physical Therapy',
'Anesthesiology',
]
const patient = reactive({
fullName: '',
dateOfBirth: '',
sex: '',
bloodType: '',
emergencyContact: '',
})
const encounter = reactive({
admissionDate: '',
department: '',
roomBed: '',
admissionReason: '',
})
const observations = ref<DraftObservation[]>([])
const statusColor = ref('bg-gray-100 text-gray-800')
// Load draft data when batch changes
watch(
() => batchStore.currentDraft,
(draft) => {
if (!draft) return
if (draft.patient) {
Object.assign(patient, {
fullName: draft.patient.fullName ?? '',
dateOfBirth: draft.patient.dateOfBirth ?? '',
sex: draft.patient.sex ?? '',
bloodType: draft.patient.bloodType ?? '',
emergencyContact: draft.patient.emergencyContact ?? '',
})
}
if (draft.encounter) {
Object.assign(encounter, {
admissionDate: draft.encounter.admissionDate?.substring(0, 16) ?? '',
department: draft.encounter.department ?? '',
roomBed: draft.encounter.roomBed ?? '',
admissionReason: draft.encounter.admissionReason ?? '',
})
}
observations.value = draft.observations ?? []
},
{ immediate: true }
)
async function savePatient() {
try {
await batchStore.saveDraftPatient(props.batchId, patient)
} catch (e: unknown) {
errorMessage.value = e instanceof Error ? e.message : 'Failed to save patient'
}
}
async function saveEncounter() {
try {
await batchStore.saveDraftEncounter(props.batchId, encounter)
} catch (e: unknown) {
errorMessage.value = e instanceof Error ? e.message : 'Failed to save encounter'
}
}
async function addObservation() {
await batchStore.addObservation(props.batchId, {
observationCode: '',
value: 0,
unit: '',
recordedAt: new Date().toISOString(),
note: null,
})
observations.value = batchStore.currentDraft?.observations ?? []
}
async function handleObsUpdate(obsId: string, field: string, value: unknown) {
const obs = observations.value.find((o) => o.id === obsId)
if (!obs) return
;(obs as Record<string, unknown>)[field] = value
await batchStore.updateObservation(props.batchId, obsId, obs)
}
async function handleObsDelete(obsId: string) {
await batchStore.deleteObservation(props.batchId, obsId)
observations.value = batchStore.currentDraft?.observations ?? []
}
async function submitForVerification() {
submitting.value = true
errorMessage.value = ''
try {
await batchStore.submitForVerification(props.batchId)
} catch (e: unknown) {
errorMessage.value = e instanceof Error ? e.message : 'Submit failed'
} finally {
submitting.value = false
}
}
</script>