fix: Add No clinical approval view + No live capture view for bedside data entry + EntryForm missing allergy, medication, and discharge fields

This commit is contained in:
voltsrage
2026-06-27 16:27:58 +08:00
parent 1c7e7fee7d
commit efd3974d1f
13 changed files with 1184 additions and 12 deletions
@@ -60,6 +60,82 @@
</div>
</fieldset>
<!-- Allergies section (ALLERGY_UPDATE or MIXED) -->
<fieldset v-if="showAllergies" class="border border-gray-200 rounded-md p-4">
<legend class="text-sm font-medium text-gray-700 px-2">Allergies</legend>
<label class="flex items-center gap-2 mb-3 cursor-pointer">
<input
v-model="patient.noKnownAllergies"
@change="onNoKnownAllergiesChange"
type="checkbox"
class="w-4 h-4 text-clinical-safe rounded"
/>
<span class="text-sm">No known allergies (NKA)</span>
</label>
<div v-if="!patient.noKnownAllergies" class="space-y-2">
<div
v-for="(allergy, idx) in allergies"
:key="idx"
class="flex items-center gap-2"
>
<input
v-model="allergies[idx]"
@blur="saveAllergies"
type="text"
class="form-input text-sm flex-1"
placeholder="Allergy (e.g. Penicillin)"
/>
<button
@click="removeAllergy(idx)"
class="text-clinical-danger hover:text-red-800 text-sm"
>
Remove
</button>
</div>
<button @click="addAllergy" class="text-sm text-primary-600 hover:text-primary-800">
+ Add Allergy
</button>
</div>
</fieldset>
<!-- Medications section (MEDICATION_LIST or MIXED) -->
<fieldset v-if="showMedications" class="border border-gray-200 rounded-md p-4">
<legend class="text-sm font-medium text-gray-700 px-2">Medications</legend>
<label class="flex items-center gap-2 mb-3 cursor-pointer">
<input
v-model="patient.noActiveMedications"
@change="onNoActiveMedicationsChange"
type="checkbox"
class="w-4 h-4 text-clinical-safe rounded"
/>
<span class="text-sm">No active medications</span>
</label>
<div v-if="!patient.noActiveMedications" class="space-y-2">
<div
v-for="(med, idx) in medications"
:key="idx"
class="flex items-center gap-2"
>
<input
v-model="medications[idx]"
@blur="saveMedications"
type="text"
class="form-input text-sm flex-1"
placeholder="Medication (e.g. Metoprolol 50mg BID)"
/>
<button
@click="removeMedication(idx)"
class="text-clinical-danger hover:text-red-800 text-sm"
>
Remove
</button>
</div>
<button @click="addMedication" class="text-sm text-primary-600 hover:text-primary-800">
+ Add Medication
</button>
</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>
@@ -98,6 +174,24 @@
class="form-input text-sm"
/>
</div>
<div v-if="showEncounterSummary">
<label class="block text-xs text-gray-500">Encounter Status</label>
<select v-model="encounter.status" @change="saveEncounter" class="form-input text-sm">
<option value="">—</option>
<option value="active">Active</option>
<option value="discharged">Discharged</option>
</select>
</div>
<div v-if="showEncounterSummary" class="col-span-2">
<label class="block text-xs text-gray-500">Discharge Diagnosis</label>
<textarea
v-model="encounter.dischargeDiagnosis"
@blur="saveEncounter"
class="form-input text-sm"
rows="2"
placeholder="Discharge diagnosis..."
/>
</div>
</div>
</fieldset>
@@ -136,7 +230,7 @@
</template>
<script setup lang="ts">
import { ref, reactive, watch } from 'vue'
import { ref, reactive, computed, watch } from 'vue'
import { useBatchStore } from '../stores/batches'
import ObservationRow from '../components/ObservationRow.vue'
import type { BatchDetailResponse, DraftObservation } from '../types'
@@ -174,25 +268,53 @@ const departments = [
'Anesthesiology',
]
const batchType = computed(() => props.batch?.batchType ?? '')
const showAllergies = computed(() =>
['ALLERGY_UPDATE', 'MIXED'].includes(batchType.value)
)
const showMedications = computed(() =>
['MEDICATION_LIST', 'MIXED'].includes(batchType.value)
)
const showEncounterSummary = computed(() =>
['ENCOUNTER_SUMMARY', 'MIXED'].includes(batchType.value)
)
const patient = reactive({
fullName: '',
dateOfBirth: '',
sex: '',
bloodType: '',
emergencyContact: '',
noKnownAllergies: false,
noActiveMedications: false,
})
const allergies = ref<string[]>([])
const medications = ref<string[]>([])
const encounter = reactive({
admissionDate: '',
department: '',
roomBed: '',
admissionReason: '',
dischargeDiagnosis: '',
status: '',
})
const observations = ref<DraftObservation[]>([])
const statusColor = ref('bg-gray-100 text-gray-800')
function parseJsonList(json: string | null): string[] {
if (!json) return []
try {
const parsed = JSON.parse(json)
return Array.isArray(parsed) ? parsed : []
} catch {
return []
}
}
// Load draft data when batch changes
watch(
() => batchStore.currentDraft,
@@ -205,7 +327,11 @@ watch(
sex: draft.patient.sex ?? '',
bloodType: draft.patient.bloodType ?? '',
emergencyContact: draft.patient.emergencyContact ?? '',
noKnownAllergies: draft.patient.noKnownAllergies ?? false,
noActiveMedications: draft.patient.noActiveMedications ?? false,
})
allergies.value = parseJsonList(draft.patient.allergiesJson)
medications.value = parseJsonList(draft.patient.medicationsJson)
}
if (draft.encounter) {
Object.assign(encounter, {
@@ -213,6 +339,8 @@ watch(
department: draft.encounter.department ?? '',
roomBed: draft.encounter.roomBed ?? '',
admissionReason: draft.encounter.admissionReason ?? '',
dischargeDiagnosis: draft.encounter.dischargeDiagnosis ?? '',
status: draft.encounter.status ?? '',
})
}
observations.value = draft.observations ?? []
@@ -220,9 +348,67 @@ watch(
{ immediate: true }
)
function addAllergy() {
allergies.value.push('')
}
function removeAllergy(idx: number) {
allergies.value.splice(idx, 1)
saveAllergies()
}
async function saveAllergies() {
try {
await batchStore.saveDraftPatient(props.batchId, {
...patient,
allergiesJson: JSON.stringify(allergies.value.filter(a => a.trim())),
})
} catch (e: unknown) {
errorMessage.value = e instanceof Error ? e.message : 'Failed to save allergies'
}
}
function onNoKnownAllergiesChange() {
if (patient.noKnownAllergies) {
allergies.value = []
}
savePatient()
}
function addMedication() {
medications.value.push('')
}
function removeMedication(idx: number) {
medications.value.splice(idx, 1)
saveMedications()
}
async function saveMedications() {
try {
await batchStore.saveDraftPatient(props.batchId, {
...patient,
medicationsJson: JSON.stringify(medications.value.filter(m => m.trim())),
})
} catch (e: unknown) {
errorMessage.value = e instanceof Error ? e.message : 'Failed to save medications'
}
}
function onNoActiveMedicationsChange() {
if (patient.noActiveMedications) {
medications.value = []
}
savePatient()
}
async function savePatient() {
try {
await batchStore.saveDraftPatient(props.batchId, patient)
await batchStore.saveDraftPatient(props.batchId, {
...patient,
allergiesJson: patient.noKnownAllergies ? null : JSON.stringify(allergies.value.filter(a => a.trim())),
medicationsJson: patient.noActiveMedications ? null : JSON.stringify(medications.value.filter(m => m.trim())),
})
} catch (e: unknown) {
errorMessage.value = e instanceof Error ? e.message : 'Failed to save patient'
}