felicity-lims/webapp/views/patient/PatientsCompact.vue

176 lines
6.5 KiB
Vue
Raw Normal View History

2022-04-04 02:54:31 +08:00
<script setup lang="ts">
import LoadingMessage from "../../components/Spinners/LoadingMessage.vue";
import { ref, reactive, computed } from "vue";
import { storeToRefs } from "pinia";
import tabSamples from "../components/AnalyisRequestListing.vue";
import tabCases from "./comps/CaseTable.vue";
import tabLogs from "../components/AuditLog.vue";
import modal from "../../components/SimpleModal.vue";
import PatientForm from "./PatientForm.vue";
import PatientInfo from "./PatientInfo.vue";
2022-04-04 02:54:31 +08:00
import { useLocationStore, usePatientStore } from "../../stores";
import { IPatient } from "../../models/patient";
2022-04-04 02:54:31 +08:00
import * as shield from "../../guards";
2022-04-04 02:54:31 +08:00
let patientStore = usePatientStore();
let locationStore = useLocationStore();
2022-04-04 02:54:31 +08:00
const { patients, fetchingPatients } = storeToRefs(patientStore);
2022-04-15 16:32:24 +08:00
let showModal = ref<boolean>(false);
let currentTab = ref<string>("samples");
const tabs: string[] = ["samples", "cases", "logs"];
2022-04-04 02:54:31 +08:00
let patientForm = ref({} as IPatient);
2022-04-04 02:54:31 +08:00
let patientParams = reactive({
first: 25,
2022-12-24 05:21:22 +08:00
before: "",
text: "",
sortBy: ["-uid"],
filterAction: false,
});
2022-04-04 02:54:31 +08:00
const genders: string[] = ["Male", "Female", "Missing", "Trans Gender"];
2022-04-04 02:54:31 +08:00
locationStore.fetchCountries();
patientStore.fetchPatients(patientParams);
2022-04-04 02:54:31 +08:00
function searchPatients(event: any) {
patientParams.first = 100;
2022-12-24 05:21:22 +08:00
patientParams.before = "";
patientParams.text = event.target.value;
patientParams.filterAction = true;
patientStore.fetchPatients(patientParams);
}
2022-04-04 02:54:31 +08:00
const isPatientSelected = computed(() => Object.keys(patientForm?.value)?.length > 0)
2022-04-04 02:54:31 +08:00
let getPatientFullName = (pt: IPatient) => {
return pt.firstName + " " + pt.lastName;
};
2022-04-04 02:54:31 +08:00
let getGender = (pos: any) => genders[pos];
2022-04-04 02:54:31 +08:00
let selectPatient = (pt: IPatient) => {
patientForm.value = pt;
patientStore.setPatient(pt);
};
2022-04-04 02:54:31 +08:00
let setPatientToNull = () => {
patientForm.value = {} as IPatient;
patientStore.resetPatient();
};
2022-04-04 02:54:31 +08:00
const quickRegistration = async () => {
setPatientToNull()
showModal.value = true;
};
2022-04-04 02:54:31 +08:00
const updatePatient = (patient: IPatient) => {
selectPatient(patient);
showModal.value = false;
};
2022-04-04 02:54:31 +08:00
</script>
<style lang="css" scoped>
2022-04-04 02:54:31 +08:00
.patient-scroll {
/* min-height: calc(100vh - 250px); */
min-height: 100%;
}
</style>
2021-05-07 01:32:14 +08:00
<template>
<div class="">
<div class="flex justify-between">
<div class="flex items-center content-between">
<!-- <h1 class="h1 my-4 font-bold text-dark-700">Listing</h1> -->
<router-link v-show="shield.hasRights(shield.actions.CREATE, shield.objects.PATIENT)" to="/patients/search"
class="px-4 my-2 p-1 text-sm border-sky-800 border text-dark-800 transition-colors duration-150 rounded-sm focus:outline-none hover:bg-sky-800 hover:text-gray-100">
Add Patient</router-link>
2021-05-07 01:32:14 +08:00
<input
2022-04-15 16:32:24 +08:00
class="w-64 ml-6 pl-4 pr-2 py-1 text-sm text-gray-800 placeholder-gray-400 border-1 border-gray-400 rounded-sm focus:placeholder-gray-500 focus:border-sky-800 focus:outline-none focus:shadow-outline-purple form-input"
type="text" placeholder="Search ..." aria-label="Search" @keyup="searchPatients($event)"
@focus="setPatientToNull()" />
2021-05-07 01:32:14 +08:00
</div>
<button v-show="shield.hasRights(shield.actions.CREATE, shield.objects.PATIENT)" @click.prevent="quickRegistration"
class="px-4 my-2 p-1 text-sm border-sky-800 border text-dark-700 transition-colors duration-150 rounded-sm focus:outline-none hover:bg-sky-800 hover:text-gray-100">
Quick Registration
</button>
2021-05-07 01:32:14 +08:00
</div>
<hr />
<div class="grid grid-cols-12 gap-4 mt-2">
<section v-motion :initial="{ opacity: 0, y: 100 }" :enter="{ opacity: 1, y: 0, scale: 1 }"
:variants="{ custom: { scale: 2 } }" :delay="400"
class="col-span-3 h-screen overflow-y-scroll overscroll-contain patient-scroll">
<div v-if="fetchingPatients" class="py-4 text-center bg-white w-full mb-1 rounded-sm shadow border">
<LoadingMessage message="Fetching patients ..." />
2022-04-15 16:32:24 +08:00
</div>
<div v-else>
<a v-for="pt in patients" :key="pt.patientId" href="#" @click="selectPatient(pt)" :class="[
'bg-white w-full flex items-center p-1 mb-1 rounded-sm shadow border',
{ 'border-sky-800 bg-emerald-200': pt.uid === patientForm?.uid },
]">
<div class="flex-grow p-1">
<div class="font-semibold text-gray-800 flex justify-between">
<span>{{ getPatientFullName(pt) }}</span>
<span class="text-sm text-gray-500">{{ pt.age }} yrs, {{ getGender(pt.gender) }}</span>
2022-04-15 16:32:24 +08:00
</div>
<div class="text-sm text-gray-500 flex justify-between">
<span>{{ pt.patientId }}</span>
<span>{{ pt.clientPatientId }}</span>
2022-04-15 16:32:24 +08:00
</div>
<div class="text-sm text-gray-500 flex justify-between">
<span>{{ pt?.client?.district?.province?.name }}</span>
<span>{{ pt?.client?.name }}</span>
</div>
</div>
<div class="p-2">
<!-- <span class="block h-4 w-4 bg-sky-800 rounded-full bottom-0 right-0"></span> -->
</div>
</a>
</div>
2021-05-07 01:32:14 +08:00
</section>
<section v-if="isPatientSelected" v-motion :initial="{ opacity: 0, y: -100 }"
:enter="{ opacity: 1, y: 0, scale: 1 }" :variants="{ custom: { scale: 2 } }" :delay="400" class="col-span-9">
<!-- PatientInfo -->
<PatientInfo @editPatient="() => (showModal = true)" />
2021-05-07 01:32:14 +08:00
<!-- Sample and Case Data -->
2022-12-22 22:42:05 +08:00
<nav class="bg-white shadow-md mt-2">
2021-05-07 01:32:14 +08:00
<div class="-mb-px flex justify-start">
<a v-for="tab in tabs" :key="tab" :class="[
'no-underline text-gray-500 uppercase tracking-wide font-bold text-xs py-1 px-4 tab hover:bg-sky-600 hover:text-gray-200 hover:bg-sky-600 hover:text-gray-200',
{ 'tab-active': currentTab === tab },
]" @click="currentTab = tab" href="#">
2021-05-07 01:32:14 +08:00
{{ tab }}
</a>
</div>
</nav>
<tab-samples v-if="currentTab === 'samples'" target="patient-samples" :targetUid="patientForm.uid" />
2021-05-07 01:32:14 +08:00
<tab-cases v-if="currentTab === 'cases'" />
<tab-logs v-if="currentTab === 'logs'" targetType="patient" :targetId="patientForm?.uid" />
2021-05-07 01:32:14 +08:00
</section>
</div>
2022-08-19 22:40:02 +08:00
<!-- Patient Edit Form Modal -->
<modal v-if="showModal" @close="showModal = false" :contentWidth="'w-3/6'">
<template v-slot:header>
<h3>Patient Form</h3>
</template>
2021-05-07 01:32:14 +08:00
2022-08-19 22:40:02 +08:00
<template v-slot:body>
<PatientForm :patient="patientForm" :navigate="false" @close="updatePatient" />
</template>
</modal>
</div>
</template>