feat(patient): add callback url support for patient creation
Add callback URL parameter to redirect after successful patient creation. The URL can be passed via 'return-path' query parameter and will include the created patient's ID. This enables seamless integration with external systems that need to handle post-creation flows.
This commit is contained in:
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { PatientEntity, genPatientProps } from '~/models/patient'
|
import type { PatientEntity, genPatientProps } from '~/models/patient'
|
||||||
import type { ExposedForm } from '~/types/form'
|
import type { ExposedForm } from '~/types/form'
|
||||||
|
import type { PatientBase } from '~/models/patient'
|
||||||
import Action from '~/components/pub/my-ui/nav-footer/ba-dr-su.vue'
|
import Action from '~/components/pub/my-ui/nav-footer/ba-dr-su.vue'
|
||||||
import { genPatient } from '~/models/patient'
|
import { genPatient } from '~/models/patient'
|
||||||
import { PatientSchema } from '~/schemas/patient.schema'
|
import { PatientSchema } from '~/schemas/patient.schema'
|
||||||
@@ -12,6 +13,9 @@ import { ResponsiblePersonSchema } from '~/schemas/person-relative.schema'
|
|||||||
import { postPatient } from '~/services/patient.service'
|
import { postPatient } from '~/services/patient.service'
|
||||||
|
|
||||||
// #region Props & Emits
|
// #region Props & Emits
|
||||||
|
const props = defineProps<{
|
||||||
|
callbackUrl?: string
|
||||||
|
}>()
|
||||||
const payload = ref<PatientEntity>()
|
const payload = ref<PatientEntity>()
|
||||||
|
|
||||||
// form related state
|
// form related state
|
||||||
@@ -32,7 +36,11 @@ onMounted(() => {
|
|||||||
// Initial synchronization when forms are mounted and isSameAddress is true by default
|
// Initial synchronization when forms are mounted and isSameAddress is true by default
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
const isSameAddress = personAddressRelativeForm.value?.values?.isSameAddress
|
const isSameAddress = personAddressRelativeForm.value?.values?.isSameAddress
|
||||||
if ((isSameAddress === true || isSameAddress === '1') && personAddressForm.value?.values && personAddressRelativeForm.value) {
|
if (
|
||||||
|
(isSameAddress === true || isSameAddress === '1') &&
|
||||||
|
personAddressForm.value?.values &&
|
||||||
|
personAddressRelativeForm.value
|
||||||
|
) {
|
||||||
const currentAddressValues = personAddressForm.value.values
|
const currentAddressValues = personAddressForm.value.values
|
||||||
if (Object.keys(currentAddressValues).length > 0) {
|
if (Object.keys(currentAddressValues).length > 0) {
|
||||||
personAddressRelativeForm.value.setValues(
|
personAddressRelativeForm.value.setValues(
|
||||||
@@ -91,8 +99,16 @@ async function submitAll() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await postPatient(formData)
|
const result = await postPatient(formData)
|
||||||
|
const patientData: PatientBase = result.body
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
console.log('Patient created successfully:', result.body)
|
console.log('Patient created successfully:', patientData)
|
||||||
|
|
||||||
|
// If has callback provided redirect to callback with patientData
|
||||||
|
if (props.callbackUrl) {
|
||||||
|
await navigateTo(props.callbackUrl + '?patient-id=' + patientData.person_id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Navigate to patient list or show success message
|
// Navigate to patient list or show success message
|
||||||
await navigateTo('/client/patient')
|
await navigateTo('/client/patient')
|
||||||
} else {
|
} else {
|
||||||
@@ -172,7 +188,11 @@ watch(
|
|||||||
watch(
|
watch(
|
||||||
() => personAddressRelativeForm.value?.values?.isSameAddress,
|
() => personAddressRelativeForm.value?.values?.isSameAddress,
|
||||||
(isSameAddress) => {
|
(isSameAddress) => {
|
||||||
if ((isSameAddress === true || isSameAddress === '1') && personAddressForm.value?.values && personAddressRelativeForm.value) {
|
if (
|
||||||
|
(isSameAddress === true || isSameAddress === '1') &&
|
||||||
|
personAddressForm.value?.values &&
|
||||||
|
personAddressRelativeForm.value
|
||||||
|
) {
|
||||||
// Ketika isSameAddress diubah menjadi true, copy alamat sekarang ke alamat KTP
|
// Ketika isSameAddress diubah menjadi true, copy alamat sekarang ke alamat KTP
|
||||||
const currentAddressValues = personAddressForm.value.values
|
const currentAddressValues = personAddressForm.value.values
|
||||||
personAddressRelativeForm.value.setValues(
|
personAddressRelativeForm.value.setValues(
|
||||||
|
|||||||
@@ -28,12 +28,13 @@ if (!hasAccess) {
|
|||||||
|
|
||||||
// Define permission-based computed properties
|
// Define permission-based computed properties
|
||||||
const canRead = hasReadAccess(roleAccess)
|
const canRead = hasReadAccess(roleAccess)
|
||||||
|
const callbackUrl = route.query['return-path'] as string | undefined
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div v-if="canRead">
|
<div v-if="canRead">
|
||||||
<ContentPatientEntry />
|
<ContentPatientEntry :callback-url="callbackUrl" />
|
||||||
</div>
|
</div>
|
||||||
<Error
|
<Error
|
||||||
v-else
|
v-else
|
||||||
|
|||||||
Reference in New Issue
Block a user