mirror of
https://github.com/faiztyanirh/clqms-shadcn-v1.git
synced 2026-04-25 18:42:05 +07:00
continuing admission page
This commit is contained in:
parent
644feff29f
commit
a4c2e0ec5f
@ -15,7 +15,26 @@ function cleanQuery(searchQuery) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getById(endpoint, id) {
|
// export async function getById(endpoint, id) {
|
||||||
|
// try {
|
||||||
|
// const res = await fetch(`${API.BASE_URL}${endpoint}/${id}`);
|
||||||
|
|
||||||
|
// if (!res.ok) {
|
||||||
|
// const error = await res.json();
|
||||||
|
// console.error('API Error:', error);
|
||||||
|
// return { data: null, error };
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const response = await res.json();
|
||||||
|
// console.log(response);
|
||||||
|
// return { data: response.data?.[0] || response.data, error: null };
|
||||||
|
// } catch (err) {
|
||||||
|
// console.error('Network Error:', err);
|
||||||
|
// return { data: null, error: err };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
export async function getById(endpoint, id, returnAll = false) {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API.BASE_URL}${endpoint}/${id}`);
|
const res = await fetch(`${API.BASE_URL}${endpoint}/${id}`);
|
||||||
|
|
||||||
@ -26,6 +45,11 @@ export async function getById(endpoint, id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const response = await res.json();
|
const response = await res.json();
|
||||||
|
|
||||||
|
if (returnAll) {
|
||||||
|
return { data: response.data, error: null };
|
||||||
|
}
|
||||||
|
|
||||||
return { data: response.data?.[0] || response.data, error: null };
|
return { data: response.data?.[0] || response.data, error: null };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Network Error:', err);
|
console.error('Network Error:', err);
|
||||||
|
|||||||
@ -5,9 +5,12 @@ export async function searchParam(searchQuery) {
|
|||||||
return await searchWithParams(API.PATIENTS, searchQuery)
|
return await searchWithParams(API.PATIENTS, searchQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getVisitList(searchQuery) {
|
||||||
|
return await getById(API.VISITLIST, searchQuery, true)
|
||||||
|
}
|
||||||
|
|
||||||
export async function getVisit(searchQuery) {
|
export async function getVisit(searchQuery) {
|
||||||
const { data: visit, error } = await getById(API.VISITLIST, searchQuery)
|
return await getById(API.PATVISIT, searchQuery)
|
||||||
return { visit };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPatient(searchQuery) {
|
export async function getPatient(searchQuery) {
|
||||||
|
|||||||
@ -14,34 +14,19 @@
|
|||||||
import { Checkbox } from "$lib/components/ui/checkbox/index.js";
|
import { Checkbox } from "$lib/components/ui/checkbox/index.js";
|
||||||
import * as Popover from "$lib/components/ui/popover/index.js";
|
import * as Popover from "$lib/components/ui/popover/index.js";
|
||||||
|
|
||||||
let props = $props();
|
let { selectedPatient = $bindable(null), ...props } = $props();
|
||||||
|
|
||||||
let activeRowId = $state(null);
|
let activeRowId = $state(null);
|
||||||
|
|
||||||
let selectedPatient = $state({
|
let isPatientEmpty = $derived(!selectedPatient);
|
||||||
InternalPID: null,
|
|
||||||
PatientID: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
const isPatientEmpty = $derived(!selectedPatient.InternalPID || !selectedPatient.PatientID);
|
function handleCheckboxChange(patient) {
|
||||||
|
selectedPatient = patient;
|
||||||
function togglePatientSelection(patient) {
|
|
||||||
if (selectedPatient.InternalPID === patient.InternalPID) {
|
|
||||||
selectedPatient = {
|
|
||||||
InternalPID: null,
|
|
||||||
PatientID: null,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
selectedPatient = {
|
|
||||||
InternalPID: patient.InternalPID,
|
|
||||||
PatientID: patient.PatientID,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleButtonClick() {
|
function handleButtonClick() {
|
||||||
if (selectedPatient) {
|
if (selectedPatient) {
|
||||||
props.onConfirm(selectedPatient.InternalPID);
|
props.onConfirm(selectedPatient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -108,13 +93,13 @@
|
|||||||
{#each props.search.searchData as patient, i}
|
{#each props.search.searchData as patient, i}
|
||||||
<Table.Row
|
<Table.Row
|
||||||
class="cursor-pointer hover:bg-muted/50"
|
class="cursor-pointer hover:bg-muted/50"
|
||||||
onclick={() => togglePatientSelection(patient)}
|
onclick={() => handleCheckboxChange(patient)}
|
||||||
>
|
>
|
||||||
<Table.Cell onclick={(e) => e.stopPropagation()}>
|
<Table.Cell onclick={(e) => e.stopPropagation()}>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
class="cursor-pointer hover:bg-muted/50"
|
class="cursor-pointer hover:bg-muted/50"
|
||||||
checked={selectedPatient.InternalPID === patient.InternalPID}
|
checked={selectedPatient?.InternalPID === patient.InternalPID}
|
||||||
onCheckedChange={() => togglePatientSelection(patient)}
|
onCheckedChange={() => handleCheckboxChange(patient)}
|
||||||
/>
|
/>
|
||||||
</Table.Cell>
|
</Table.Cell>
|
||||||
<Table.Cell class="font-medium">{patient.PatientID}</Table.Cell>
|
<Table.Cell class="font-medium">{patient.PatientID}</Table.Cell>
|
||||||
@ -134,12 +119,9 @@
|
|||||||
disabled={isPatientEmpty}
|
disabled={isPatientEmpty}
|
||||||
onclick={handleButtonClick}
|
onclick={handleButtonClick}
|
||||||
>
|
>
|
||||||
Confirm
|
Select Patient
|
||||||
</Button>
|
</Button>
|
||||||
</Popover.Close>
|
</Popover.Close>
|
||||||
<!-- <Button size="sm" class="cursor-pointer" disabled={isPatientEmpty} onclick={handleButtonClick}>
|
|
||||||
Select Patient
|
|
||||||
</Button> -->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import { visitColumns } from "$lib/components/patient/admission/table/visit-columns";
|
import { visitColumns } from "$lib/components/patient/admission/table/visit-columns";
|
||||||
import { searchParam } from "$lib/components/patient/admission/api/patient-admission-api";
|
import { searchParam, getVisitList } from "$lib/components/patient/admission/api/patient-admission-api";
|
||||||
import { useSearch } from "$lib/components/composable/use-search.svelte";
|
import { useSearch } from "$lib/components/composable/use-search.svelte";
|
||||||
import { searchFields, admissionActions } from "$lib/components/patient/admission/config/admission-config";
|
import { searchFields, admissionActions } from "$lib/components/patient/admission/config/admission-config";
|
||||||
import TopbarWrapper from "$lib/components/topbar/topbar-wrapper.svelte";
|
import TopbarWrapper from "$lib/components/topbar/topbar-wrapper.svelte";
|
||||||
@ -10,22 +10,35 @@
|
|||||||
import ReusableDataTable from "$lib/components/reusable/reusable-data-table.svelte";
|
import ReusableDataTable from "$lib/components/reusable/reusable-data-table.svelte";
|
||||||
|
|
||||||
let props = $props();
|
let props = $props();
|
||||||
let selectedInternalPid = $state(null);
|
let selectedPID = $state(null);
|
||||||
|
let selectedPatient = $state(null);
|
||||||
let tableData = $state([]);
|
let tableData = $state([]);
|
||||||
|
let isLoading = $state(false);
|
||||||
|
let searchData = $state([]);
|
||||||
|
|
||||||
const search = useSearch(searchFields, searchParam);
|
const search = useSearch(searchFields, searchParam);
|
||||||
|
|
||||||
const actions = admissionActions(props.masterDetail)
|
const actions = admissionActions(props.masterDetail)
|
||||||
actions.find(a => a.label === 'Search Parameters').popoverContent = searchParamSnippet;
|
actions.find(a => a.label === 'Search Parameters').popoverContent = searchParamSnippet;
|
||||||
|
|
||||||
let activeRowId = $state(null);
|
let activeRowId = $state(null);
|
||||||
|
|
||||||
function handlePatientConfirm(internalPid) {
|
async function handlePatientConfirm(patient) {
|
||||||
console.log(internalPid);
|
selectedPatient = patient;
|
||||||
|
selectedPID = patient.InternalPID;
|
||||||
|
isLoading = true;
|
||||||
|
try {
|
||||||
|
searchData = await getVisitList(patient.InternalPID);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Search failed:', error);
|
||||||
|
} finally {
|
||||||
|
isLoading = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#snippet searchParamSnippet()}
|
{#snippet searchParamSnippet()}
|
||||||
<SearchParamModal {search} {searchFields} onConfirm={handlePatientConfirm}/>
|
<SearchParamModal {search} {searchFields} bind:selectedPatient onConfirm={handlePatientConfirm}/>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@ -56,13 +69,13 @@
|
|||||||
}}>
|
}}>
|
||||||
<TopbarWrapper {actions}/>
|
<TopbarWrapper {actions}/>
|
||||||
<div class="flex-1 w-full h-full">
|
<div class="flex-1 w-full h-full">
|
||||||
<!-- {#if search.searchData.length > 0}
|
{#if searchData?.data?.length > 0}
|
||||||
<ReusableDataTable data={search.searchData} columns={visitColumns} handleRowClick={props.masterDetail.select} {activeRowId} rowIdKey="InternalPID"/>
|
<ReusableDataTable data={searchData.data} columns={visitColumns} handleRowClick={props.masterDetail.select} {activeRowId} rowIdKey="InternalPVID"/>
|
||||||
{:else} -->
|
{:else}
|
||||||
<div class="flex h-full">
|
<div class="flex h-full">
|
||||||
<ReusableEmpty desc="Try searching from search parameters"/>
|
<ReusableEmpty desc="Try searching from search parameters"/>
|
||||||
</div>
|
</div>
|
||||||
<!-- {/if} -->
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@ -3,4 +3,8 @@ export const visitColumns = [
|
|||||||
accessorKey: "PVID",
|
accessorKey: "PVID",
|
||||||
header: "Visit ID",
|
header: "Visit ID",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "EpisodeID",
|
||||||
|
header: "Episode ID",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
@ -9,10 +9,10 @@
|
|||||||
|
|
||||||
const masterDetail = useMasterDetail({
|
const masterDetail = useMasterDetail({
|
||||||
onSelect: async (row) => {
|
onSelect: async (row) => {
|
||||||
return await getVisit(row.InternalPID);
|
return await getVisit(row.PVID);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
$inspect(masterDetail.selectedItem)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex w-full h-full overflow-hidden">
|
<div class="flex w-full h-full overflow-hidden">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user