458 lines
11 KiB
Vue
458 lines
11 KiB
Vue
<script setup>
|
|
import { onBeforeMount, onMounted, onUnmounted } from 'vue';
|
|
import { useRouter } from 'vue-router';
|
|
import { useStore } from 'vuex';
|
|
const store = useStore()
|
|
// const route = useRoute()
|
|
const router = useRouter()
|
|
const editDialog = ref(false)
|
|
const deleteDialog = ref(false)
|
|
const search = ref('')
|
|
const defaultItem = ref({
|
|
id: -1,
|
|
avatar: '',
|
|
name: '',
|
|
email: '',
|
|
dob: '',
|
|
phone_no: '',
|
|
|
|
})
|
|
|
|
const editedItem = ref(defaultItem.value)
|
|
const editedIndex = ref(-1)
|
|
const patientList = ref([])
|
|
const isLoading=ref(false)
|
|
// status options
|
|
const selectedOptions = [
|
|
{
|
|
text: 'Active',
|
|
value: 1,
|
|
},
|
|
{
|
|
text: 'InActive',
|
|
value: 2,
|
|
},
|
|
|
|
]
|
|
|
|
const refVForm = ref(null)
|
|
|
|
onBeforeMount(async () => {});
|
|
onMounted(async () => {
|
|
store.dispatch('updateIsLoading', true)
|
|
await store.dispatch('patientList')
|
|
// console.log('patientList',store.getters.getPatientList)
|
|
// patientList.value = store.getters.getPatientList
|
|
store.dispatch('updateIsLoading', false)
|
|
|
|
});
|
|
const getPatientList = computed(async () => {
|
|
patientList.value = store.getters.getPatientList.map(history => ({
|
|
...history,
|
|
dob: changeFormat(history.dob),
|
|
}));
|
|
return patientList.value
|
|
|
|
});
|
|
|
|
onUnmounted(async () => {});
|
|
const formatPhoneNumber = () => {
|
|
console.log(editedItem.value)
|
|
// Remove non-numeric characters from the input
|
|
const numericValue = editedItem.value.phone_no.replace(/\D/g, '');
|
|
|
|
// Apply formatting logic
|
|
if (numericValue.length <= 10) {
|
|
editedItem.value.phone_no = numericValue.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
|
|
} else {
|
|
// Limit the input to a maximum of 14 characters
|
|
const truncatedValue = numericValue.slice(0, 10);
|
|
editedItem.value.phone_no = truncatedValue.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
|
|
}
|
|
};
|
|
// headers
|
|
const headers = [
|
|
// {
|
|
// title: 'ID',
|
|
// key: 'id',
|
|
// },
|
|
{
|
|
title: 'NAME',
|
|
key: 'name',
|
|
},
|
|
{
|
|
title: 'EMAIL',
|
|
key: 'email',
|
|
},
|
|
{
|
|
key: 'dob',
|
|
title: 'Date Of Birth'
|
|
|
|
},
|
|
{
|
|
title: 'Phone',
|
|
key: 'phone_no',
|
|
},
|
|
|
|
{
|
|
title: 'Lab Kit',
|
|
key: 'labkit',
|
|
},
|
|
|
|
|
|
|
|
{
|
|
title: 'ACTIONS',
|
|
key: 'actions',
|
|
},
|
|
]
|
|
|
|
const resolveStatusVariant = status => {
|
|
if (status === 1)
|
|
return {
|
|
color: 'primary',
|
|
text: 'Current',
|
|
}
|
|
else if (status === 2)
|
|
return {
|
|
color: 'success',
|
|
text: 'Professional',
|
|
}
|
|
else if (status === 3)
|
|
return {
|
|
color: 'error',
|
|
text: 'Rejected',
|
|
}
|
|
else if (status === 4)
|
|
return {
|
|
color: 'warning',
|
|
text: 'Resigned',
|
|
}
|
|
else
|
|
return {
|
|
color: 'info',
|
|
text: 'Applied',
|
|
}
|
|
}
|
|
|
|
const editItem = item => {
|
|
editedIndex.value = patientList.value.indexOf(item)
|
|
editedItem.value = { ...item }
|
|
editDialog.value = true
|
|
}
|
|
|
|
const deleteItem = item => {
|
|
console.log('del',item)
|
|
editedIndex.value = patientList.value.indexOf(item)
|
|
editedItem.value = { ...item }
|
|
deleteDialog.value = true
|
|
}
|
|
|
|
const close = () => {
|
|
editDialog.value = false
|
|
editedIndex.value = -1
|
|
editedItem.value = { ...defaultItem.value }
|
|
}
|
|
|
|
const closeDelete = () => {
|
|
deleteDialog.value = false
|
|
editedIndex.value = -1
|
|
editedItem.value = { ...defaultItem.value }
|
|
}
|
|
|
|
const getMettings = (Item) => {
|
|
router.push('/admin/patient/meetings/'+Item.id);
|
|
}
|
|
|
|
const save = async () => {
|
|
const { valid } = await refVForm.value.validate()
|
|
console.log(valid)
|
|
if (valid) {
|
|
console.log('editedItem.value',editedItem.value);
|
|
if (editedIndex.value > -1)
|
|
{
|
|
await store.dispatch('patientUpdate',{
|
|
id: editedItem.value.id,
|
|
first_name: editedItem.value.first_name,
|
|
last_name: editedItem.value.last_name,
|
|
email: editedItem.value.email,
|
|
phone_no: editedItem.value.phone_no,
|
|
dob: editedItem.value.dob,
|
|
})
|
|
Object.assign(patientList.value[editedIndex.value], editedItem.value)
|
|
}else{
|
|
patientList.value.push(editedItem.value)
|
|
}
|
|
close()
|
|
}
|
|
|
|
|
|
}
|
|
|
|
const deleteItemConfirm = async () => {
|
|
console.log('editedIndex.value',editedIndex.value,editedItem.value.id)
|
|
await store.dispatch('patientDelete',{
|
|
id: editedItem.value.id
|
|
})
|
|
patientList.value.splice(editedIndex.value, 1)
|
|
closeDelete()
|
|
}
|
|
|
|
|
|
function changeFormat(dateFormat) {
|
|
const dateParts = dateFormat.split('-'); // Assuming date is in yyyy-mm-dd format
|
|
const year = parseInt(dateParts[0]);
|
|
const month = parseInt(dateParts[1]); // No need for padding
|
|
const day = parseInt(dateParts[2]); // No need for padding
|
|
|
|
// Create a new Date object with the parsed values
|
|
const date = new Date(year, month - 1, day); // Month is zero-based in JavaScript Date object
|
|
|
|
// Format the date as mm-dd-yyyy
|
|
const formattedDate = month + '-' + day + '-' + date.getFullYear();
|
|
console.log("formattedDate",formattedDate)
|
|
return formattedDate;
|
|
}
|
|
const LabKit = (item)=> {
|
|
router.push('/admin/patients/labkit/'+item.id);
|
|
}
|
|
|
|
</script>
|
|
|
|
<template>
|
|
<v-row>
|
|
<v-col cols="12" md="12" v-if="getPatientList">
|
|
<v-card title="Patients">
|
|
<VCardText >
|
|
<VRow>
|
|
<VCol
|
|
cols="12"
|
|
offset-md="8"
|
|
md="4"
|
|
>
|
|
<VTextField
|
|
v-model="search"
|
|
label="Search"
|
|
placeholder="Search ..."
|
|
append-inner-icon="ri-search-line"
|
|
single-line
|
|
hide-details
|
|
dense
|
|
outlined
|
|
/>
|
|
</VCol>
|
|
</VRow>
|
|
</VCardText>
|
|
<VDataTable
|
|
:headers="headers"
|
|
:items="patientList"
|
|
:search="search"
|
|
:items-per-page="5"
|
|
class="text-no-wrap"
|
|
>
|
|
<template #item.id="{ item }">
|
|
{{ item.id }}
|
|
</template>
|
|
<!-- full name -->
|
|
<template #item.name="{ item }">
|
|
<div class="d-flex align-center">
|
|
<!-- avatar -->
|
|
<VAvatar
|
|
size="32"
|
|
:color="item.avatar ? '' : 'primary'"
|
|
:class="item.avatar ? '' : 'v-avatar-light-bg primary--text'"
|
|
:variant="!item.avatar ? 'tonal' : undefined"
|
|
>
|
|
<VImg
|
|
v-if="item.avatar"
|
|
:src="item.avatar"
|
|
/>
|
|
<span
|
|
v-else
|
|
class="text-sm"
|
|
>{{ avatarText(item.name) }}</span>
|
|
</VAvatar>
|
|
|
|
<div class="d-flex flex-column ms-3">
|
|
<span class="d-block font-weight-medium text-high-emphasis text-truncate">{{ item.name }}</span>
|
|
<small>{{ item.post }}</small>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
|
|
|
|
<!-- status -->
|
|
<template #item.status="{ item }">
|
|
<VChip
|
|
:color="resolveStatusVariant(item.status).color"
|
|
density="comfortable"
|
|
>
|
|
{{ resolveStatusVariant(item.status).text }}
|
|
</VChip>
|
|
</template>
|
|
<template #item.labkit="{ item }">
|
|
<div class="text-primary cursor-pointer" @click="LabKit(item)"> LabKits</div>
|
|
</template>
|
|
|
|
<!-- Actions -->
|
|
<template #item.actions="{ item }">
|
|
<div class="d-flex gap-1">
|
|
<IconBtn
|
|
size="small"
|
|
@click="editItem(item)"
|
|
>
|
|
<VIcon icon="ri-pencil-line" />
|
|
</IconBtn>
|
|
<IconBtn
|
|
size="small"
|
|
@click="deleteItem(item)"
|
|
>
|
|
<VIcon icon="ri-delete-bin-line" />
|
|
</IconBtn>
|
|
<IconBtn
|
|
size="small"
|
|
@click="getMettings(item)"
|
|
>
|
|
<VIcon icon="ri-time-line" />
|
|
</IconBtn>
|
|
</div>
|
|
</template>
|
|
</VDataTable>
|
|
</v-card>
|
|
</v-col>
|
|
</v-row>
|
|
<!-- 👉 Edit Dialog -->
|
|
<VDialog
|
|
v-model="editDialog"
|
|
max-width="600px"
|
|
>
|
|
<VForm ref="refVForm" >
|
|
<VCard>
|
|
<VCardTitle>
|
|
<span class="headline">Edit Patient</span>
|
|
</VCardTitle>
|
|
|
|
<VCardText>
|
|
<VContainer >
|
|
|
|
<VRow>
|
|
<!-- fullName -->
|
|
<VCol cols="12" md="6">
|
|
<VTextField
|
|
v-model="editedItem.first_name"
|
|
label="First Name"
|
|
:rules="[requiredFirstName]"
|
|
/>
|
|
</VCol>
|
|
<VCol cols="12" md="6">
|
|
<VTextField
|
|
v-model="editedItem.last_name"
|
|
label="Last Name"
|
|
:rules="[requiredLastName]"
|
|
/>
|
|
</VCol>
|
|
|
|
<!-- email -->
|
|
<VCol cols="12" sm="6" md="12">
|
|
<VTextField
|
|
v-model="editedItem.email"
|
|
label="Email"
|
|
:rules="[requiredEmail, emailValidator]"
|
|
/>
|
|
</VCol>
|
|
|
|
|
|
<VCol cols="12" sm="6" md="12">
|
|
<VTextField
|
|
v-model="editedItem.dob" type="date"
|
|
label="Date Of Birth"
|
|
/>
|
|
</VCol>
|
|
<VCol cols="12" sm="6" md="12">
|
|
<VTextField v-model="editedItem.phone_no" label="Phone Number" pattern="^\(\d{3}\) \d{3}-\d{4}$"
|
|
:rules="[requiredPhone, validUSAPhone]" placeholder="i.e. (000) 000-0000"
|
|
@input="formatPhoneNumber" max="14" density="comfortable" />
|
|
</VCol>
|
|
|
|
|
|
|
|
|
|
<!-- status -->
|
|
<VCol
|
|
cols="12"
|
|
|
|
md="12"
|
|
>
|
|
<VSelect
|
|
v-model="editedItem.status"
|
|
:items="selectedOptions"
|
|
item-title="text"
|
|
item-value="value"
|
|
label="Status"
|
|
variant="outlined"
|
|
/>
|
|
</VCol>
|
|
</VRow>
|
|
</VContainer>
|
|
</VCardText>
|
|
|
|
<VCardActions>
|
|
<VSpacer />
|
|
|
|
<VBtn
|
|
color="error"
|
|
variant="outlined"
|
|
@click="close"
|
|
>
|
|
Cancel
|
|
</VBtn>
|
|
|
|
<VBtn
|
|
color="success"
|
|
variant="elevated"
|
|
@click="save"
|
|
>
|
|
Save
|
|
</VBtn>
|
|
|
|
</VCardActions>
|
|
</VCard>
|
|
</VForm>
|
|
</VDialog>
|
|
|
|
<!-- 👉 Delete Dialog -->
|
|
<VDialog
|
|
v-model="deleteDialog"
|
|
max-width="500px"
|
|
>
|
|
<VCard>
|
|
<VCardTitle>
|
|
Are you sure you want to delete this item?
|
|
</VCardTitle>
|
|
|
|
<VCardActions>
|
|
<VSpacer />
|
|
|
|
<VBtn
|
|
color="error"
|
|
variant="outlined"
|
|
@click="closeDelete"
|
|
>
|
|
Cancel
|
|
</VBtn>
|
|
|
|
<VBtn
|
|
color="success"
|
|
variant="elevated"
|
|
@click="deleteItemConfirm"
|
|
>
|
|
OK
|
|
</VBtn>
|
|
|
|
<VSpacer />
|
|
</VCardActions>
|
|
</VCard>
|
|
</VDialog>
|
|
</template>
|