felicity-lims/frontend/vite/src/views/sample/SamplesAdd.vue

281 lines
10 KiB
Vue
Raw Normal View History

2021-04-09 06:37:58 +08:00
<template>
2021-10-24 23:22:56 +08:00
<div class="w-3/6 mt-4 py-4">
2021-04-09 06:37:58 +08:00
<h5 class="mb-4">Add Analysis Request</h5>
<form action="post" class="p-4 mb-8 bg-white">
2021-10-24 23:22:56 +08:00
<div class="">
<label class="flex whitespace-nowrap mb-2 w-full">
<span class="text-gray-700 w-4/12">Client Request ID</span>
2021-04-09 06:37:58 +08:00
<input
class="form-input mt-1 block w-full"
v-model="form.clientRequestId"
placeholder="CRID ..."
/>
</label>
2021-10-24 23:22:56 +08:00
<label class="flex whitespace-nowrap mb-2 w-full">
<span class="text-gray-700 w-4/12">Clinical Data</span>
2021-04-09 06:37:58 +08:00
<textarea
cols="2"
2021-10-24 23:22:56 +08:00
class="form-input mt-1 w-full"
2021-04-09 06:37:58 +08:00
v-model="form.clinicalData"
placeholder="Clinical Data ..."
/>
</label>
2021-10-24 23:22:56 +08:00
<label class="flex whitespace-nowrap mb-2 w-full">
<span class="text-gray-700 w-4/12">Client</span>
2021-04-09 06:37:58 +08:00
<input
2021-10-24 23:22:56 +08:00
class="form-input mt-1 w-full"
2021-11-28 18:42:56 +08:00
v-model="form.clientName"
2021-04-09 06:37:58 +08:00
placeholder="Name ..."
list="ice-cream-flavors"
@change="getClientContacts()"
/>
<datalist id="ice-cream-flavors" >
<option value="" />
<option v-for="client in clients" :key="client.uid" :value="client.name" :data-client="client"></option>
</datalist>
</label>
2021-10-24 23:22:56 +08:00
<label class="flex whitespace-nowrap mb-2 w-full">
<span class="text-gray-700 w-4/12">Client Contacts</span>
2021-04-09 06:37:58 +08:00
<select
name="clientContacts"
id="clientContacts"
2021-11-28 18:42:56 +08:00
v-model="form.clientContact"
2021-04-09 06:37:58 +08:00
class="form-input mt-1 block w-full">
<option value=""></option>
<option
v-for="contact in clientContacts"
:key="contact.uid"
:value="contact.uid" >{{ contact.firstName }} {{ contact.lastName }}</option>
2021-04-09 06:37:58 +08:00
</select>
</label>
2021-10-24 23:22:56 +08:00
<label class="flex whitespace-nowrap mb-2 w-full">
<span class="text-gray-700 w-4/12">Priority</span>
2021-04-09 06:37:58 +08:00
<input
2021-10-24 23:22:56 +08:00
type="number"
min="0"
max="2"
2021-04-09 06:37:58 +08:00
class="form-input mt-1 block w-full"
v-model="form.priority"
/>
</label>
2021-10-24 23:22:56 +08:00
2021-04-09 06:37:58 +08:00
</div>
2021-10-24 23:22:56 +08:00
2021-04-09 06:37:58 +08:00
<section id="samples">
<hr>
<div class="flex justify-between items-center py-2">
<h5>Samples</h5>
<button
v-if="form.samples?.length !== 20"
@click.prevent="addSample()"
class="px-2 py-1 mr-2 border-green-500 border text-green-500 rounded transition duration-300 hover:bg-green-700 hover:text-white focus:outline-none">Add Sample</button>
</div>
<hr class="mb-4">
2021-10-24 23:22:56 +08:00
2021-04-09 06:37:58 +08:00
<div v-for="(sample, index) in form.samples" :key="index">
<div class="flex items-center justify-between">
2021-10-24 23:22:56 +08:00
<div class="flex items-top gap-x-4">
<label class="flex flex-col whitespace-nowrap mb-2">
<span class="text-gray-700">Sample Type</span>
<select
name="sampleTypes"
id="sampleTypes"
2021-12-23 16:56:49 +08:00
v-model="sample.sampleType"
2021-10-24 23:22:56 +08:00
class="form-input mt-1" >
<option value=""></option>
<option
v-for="sampleType in sampleTypes"
:key="sampleType.uid"
:value="sampleType.uid" >{{ sampleType.name }}</option>
</select>
</label>
<label class="flex flex-col whitespace-nowrap mb-2">
<span class="text-gray-700">Analysis Profiles</span>
<select
name="analysisProfiles"
id="analysisProfiles"
v-model="sample.profiles"
class="form-input mt-1" multiple>
<option value=""></option>
<option
v-for="(profile, index) in analysesProfiles"
:key="profile.uid"
:value="profile.uid" >{{ profile.name }}</option>
</select>
</label>
<label class="flex flex-col whitespace-nowrap mb-2">
<span class="text-gray-700">Analysis Services</span>
<select
name="analysesServices"
id="analysesServices"
v-model="sample.analyses"
class="form-input mt-1" multiple>
<option value=""></option>
<option
v-for="(service, index) in analysesServices"
:key="service.uid"
:value="service.uid" >{{ service.name }}</option>
</select>
</label>
2021-04-09 06:37:58 +08:00
</div>
<div class="">
<button
@click.prevent="removeSample(index)"
class="px-2 py-1 mr-2 border-red-500 border text-red-500 rounded transition duration-300 hover:bg-red-700 hover:text-white focus:outline-none">Remove</button>
</div>
</div>
<hr>
</div>
</section>
<hr />
<button
type="button"
@click.prevent="saveForm()"
class="-mb-4 w-full border border-green-500 bg-green-500 text-white rounded-md px-4 py-2 m-2 transition-colors duration-500 ease select-none hover:bg-green-600 focus:outline-none focus:shadow-outline"
>
Save Form
</button>
</form>
</div>
</template>
<script lang="ts">
import { useMutation } from '@urql/vue';
2021-11-23 05:48:31 +08:00
import { defineComponent, ref, reactive, computed } from 'vue';
import { useRouter } from 'vue-router';
2021-04-09 06:37:58 +08:00
import { useStore } from 'vuex';
2021-11-12 05:30:10 +08:00
import { ActionTypes as SampleActionTypes } from '../../store/modules/sample';
2021-11-28 18:42:56 +08:00
import { IAnalysisCategory, IAnalysisProfile, IAnalysisRequest, IAnalysisService, ISample, ISampleType } from '../../models/analysis';
2021-11-23 05:48:31 +08:00
import { ADD_ANALYSIS_REQUEST } from '../../graphql/analyses.mutations';
import { ActionTypes } from '../../store/modules/analysis';
2021-11-12 05:30:10 +08:00
import { ActionTypes as ClientActionTypes } from '../../store/modules/client';
2021-04-09 06:37:58 +08:00
import { isNullOrWs } from '../../utils';
export default defineComponent({
name: "add-sample",
props: {
patient: {
2021-11-23 05:48:31 +08:00
type: Object
}
2021-04-09 06:37:58 +08:00
},
2021-11-23 05:48:31 +08:00
setup() {
2021-04-09 06:37:58 +08:00
const store = useStore();
2021-05-30 22:32:13 +08:00
const router = useRouter();
2021-04-09 06:37:58 +08:00
2021-11-23 05:48:31 +08:00
let showModal = ref<boolean>(false);
let formTitle = ref<string>('');
let formAction = ref<boolean>(true);
2021-11-28 18:42:56 +08:00
let form = reactive({ priority: 0, samples: [] as ISample[] }) as IAnalysisRequest;
2021-04-09 06:37:58 +08:00
const analysesProfiles = computed(() =>store.getters.getAnalysesProfiles);
2021-11-23 05:48:31 +08:00
const analysesServices = computed<IAnalysisService[]>(() => {
const services: IAnalysisService[] = store.getters.getAnalysesServicesSimple;
let s = new Set<IAnalysisService>();
services.forEach((service: IAnalysisService, index: number) => {
2021-04-09 06:37:58 +08:00
if(service.profiles?.length === 0){
s.add(service)
}
})
return [...s];
});
store.dispatch(SampleActionTypes.FETCH_SAMPLE_TYPES);
2021-10-01 15:37:34 +08:00
let analysesParams = reactive({
first: undefined,
after: "",
text: "",
sortBy: ["name"]
});
store.dispatch(ActionTypes.FETCH_ANALYSES_SERVICES, analysesParams);
2021-04-09 06:37:58 +08:00
store.dispatch(ActionTypes.FETCH_ANALYSES_PROFILES);
2021-10-01 15:37:34 +08:00
let clientParams = reactive({
first: undefined,
after: "",
text: "",
sortBy: ["name"]
});
store.dispatch(ClientActionTypes.FETCH_CLIENTS, clientParams);
2021-04-09 06:37:58 +08:00
2021-05-30 22:32:13 +08:00
const patient = computed(() => store.getters.getPatient)
2021-04-09 06:37:58 +08:00
const clients = computed(() => store.getters.getClients)
const { executeMutation: createAnalysisRequest } = useMutation(ADD_ANALYSIS_REQUEST);
function addAnalysesRequest(): void {
2021-11-23 05:48:31 +08:00
createAnalysisRequest({ clientRequestId: form.clientRequestId, clientUid: form.client!.uid, patientUid: form.patient!.uid, samples: form.samples}).then((result) => {
2021-10-01 15:37:34 +08:00
// store.dispatch(SampleActionTypes.ADD_SAMPLES, result);
2021-04-09 06:37:58 +08:00
});
2021-11-23 05:48:31 +08:00
router.push({ name: "patient-detail", params: { patientUid: form.patient!.uid }});
2021-04-09 06:37:58 +08:00
}
function addSample(): void {
2021-11-28 18:42:56 +08:00
const sample = {
2021-12-23 16:56:49 +08:00
sampleType: {} as ISampleType,
2021-11-28 18:42:56 +08:00
profiles: [] as IAnalysisProfile[],
analyses: [] as IAnalysisService[],
} as ISample
form.samples.push(sample);
2021-04-09 06:37:58 +08:00
}
2021-11-23 05:48:31 +08:00
function removeSample(index: number): void {
2021-04-09 06:37:58 +08:00
form.samples?.splice(index, 1);
}
2021-11-23 05:48:31 +08:00
function setSampleType(sample: ISample, event: any): void {
2021-12-23 16:56:49 +08:00
sample.sampleType = store.getters.getSampleTypeByName(event.target.value);
2021-04-09 06:37:58 +08:00
}
function FormManager(create: boolean, obj: IAnalysisCategory):void {
formAction.value = create;
showModal.value = true;
formTitle.value = (create ? 'CREATE' : 'EDIT') + ' ' + "ANALYSES ANALYSIS REQUEST";
if (create) {
2021-11-23 05:48:31 +08:00
Object.assign(form, { patient: patient.value } as IAnalysisRequest);
2021-04-09 06:37:58 +08:00
} else {
Object.assign(form, { ...obj });
}
}
function getClientContacts(): void {
2021-11-28 18:42:56 +08:00
if(!isNullOrWs(form.clientName)) {
const clt = store.getters.getClientByName(form.clientName);
2021-04-09 06:37:58 +08:00
store.dispatch(ClientActionTypes.FETCH_CLIENT_CONTACTS, clt?.uid);
form.client = clt;
}
}
function saveForm(): void {
form.patient = patient.value;
2021-11-28 18:42:56 +08:00
const clt = store.getters.getClientByName(form.clientName);
2021-04-09 06:37:58 +08:00
form.client = clt;
if (formAction.value === true) addAnalysesRequest();
}
return {
sampleTypes: computed(() => store.getters.getSampleTypes),
analysesProfiles,
analysesServices,
clients,
form,
saveForm,
addSample,
removeSample,
getClientContacts,
clientContacts: computed(() => store.getters.getClientContacts),
};
},
});
</script>