continuing admission page

This commit is contained in:
faiztyanirh 2026-02-07 13:44:32 +07:00
parent 644feff29f
commit a4c2e0ec5f
6 changed files with 67 additions and 41 deletions

View File

@ -15,7 +15,26 @@ function cleanQuery(searchQuery) {
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 {
const res = await fetch(`${API.BASE_URL}${endpoint}/${id}`);
@ -26,6 +45,11 @@ export async function getById(endpoint, id) {
}
const response = await res.json();
if (returnAll) {
return { data: response.data, error: null };
}
return { data: response.data?.[0] || response.data, error: null };
} catch (err) {
console.error('Network Error:', err);

View File

@ -5,9 +5,12 @@ export async function searchParam(searchQuery) {
return await searchWithParams(API.PATIENTS, searchQuery)
}
export async function getVisitList(searchQuery) {
return await getById(API.VISITLIST, searchQuery, true)
}
export async function getVisit(searchQuery) {
const { data: visit, error } = await getById(API.VISITLIST, searchQuery)
return { visit };
return await getById(API.PATVISIT, searchQuery)
}
export async function getPatient(searchQuery) {

View File

@ -14,34 +14,19 @@
import { Checkbox } from "$lib/components/ui/checkbox/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 selectedPatient = $state({
InternalPID: null,
PatientID: null,
});
let isPatientEmpty = $derived(!selectedPatient);
const isPatientEmpty = $derived(!selectedPatient.InternalPID || !selectedPatient.PatientID);
function togglePatientSelection(patient) {
if (selectedPatient.InternalPID === patient.InternalPID) {
selectedPatient = {
InternalPID: null,
PatientID: null,
};
} else {
selectedPatient = {
InternalPID: patient.InternalPID,
PatientID: patient.PatientID,
};
}
function handleCheckboxChange(patient) {
selectedPatient = patient;
}
function handleButtonClick() {
if (selectedPatient) {
props.onConfirm(selectedPatient.InternalPID);
props.onConfirm(selectedPatient);
}
}
</script>
@ -108,13 +93,13 @@
{#each props.search.searchData as patient, i}
<Table.Row
class="cursor-pointer hover:bg-muted/50"
onclick={() => togglePatientSelection(patient)}
onclick={() => handleCheckboxChange(patient)}
>
<Table.Cell onclick={(e) => e.stopPropagation()}>
<Checkbox
class="cursor-pointer hover:bg-muted/50"
checked={selectedPatient.InternalPID === patient.InternalPID}
onCheckedChange={() => togglePatientSelection(patient)}
checked={selectedPatient?.InternalPID === patient.InternalPID}
onCheckedChange={() => handleCheckboxChange(patient)}
/>
</Table.Cell>
<Table.Cell class="font-medium">{patient.PatientID}</Table.Cell>
@ -134,12 +119,9 @@
disabled={isPatientEmpty}
onclick={handleButtonClick}
>
Confirm
Select Patient
</Button>
</Popover.Close>
<!-- <Button size="sm" class="cursor-pointer" disabled={isPatientEmpty} onclick={handleButtonClick}>
Select Patient
</Button> -->
</div>
</div>
{:else}

View File

@ -1,6 +1,6 @@
<script>
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 { searchFields, admissionActions } from "$lib/components/patient/admission/config/admission-config";
import TopbarWrapper from "$lib/components/topbar/topbar-wrapper.svelte";
@ -10,22 +10,35 @@
import ReusableDataTable from "$lib/components/reusable/reusable-data-table.svelte";
let props = $props();
let selectedInternalPid = $state(null);
let selectedPID = $state(null);
let selectedPatient = $state(null);
let tableData = $state([]);
let isLoading = $state(false);
let searchData = $state([]);
const search = useSearch(searchFields, searchParam);
const actions = admissionActions(props.masterDetail)
actions.find(a => a.label === 'Search Parameters').popoverContent = searchParamSnippet;
let activeRowId = $state(null);
function handlePatientConfirm(internalPid) {
console.log(internalPid);
async function handlePatientConfirm(patient) {
selectedPatient = patient;
selectedPID = patient.InternalPID;
isLoading = true;
try {
searchData = await getVisitList(patient.InternalPID);
} catch (error) {
console.error('Search failed:', error);
} finally {
isLoading = false;
}
}
</script>
{#snippet searchParamSnippet()}
<SearchParamModal {search} {searchFields} onConfirm={handlePatientConfirm}/>
<SearchParamModal {search} {searchFields} bind:selectedPatient onConfirm={handlePatientConfirm}/>
{/snippet}
<div
@ -56,13 +69,13 @@
}}>
<TopbarWrapper {actions}/>
<div class="flex-1 w-full h-full">
<!-- {#if search.searchData.length > 0}
<ReusableDataTable data={search.searchData} columns={visitColumns} handleRowClick={props.masterDetail.select} {activeRowId} rowIdKey="InternalPID"/>
{:else} -->
{#if searchData?.data?.length > 0}
<ReusableDataTable data={searchData.data} columns={visitColumns} handleRowClick={props.masterDetail.select} {activeRowId} rowIdKey="InternalPVID"/>
{:else}
<div class="flex h-full">
<ReusableEmpty desc="Try searching from search parameters"/>
</div>
<!-- {/if} -->
{/if}
</div>
</div>
{/if}

View File

@ -3,4 +3,8 @@ export const visitColumns = [
accessorKey: "PVID",
header: "Visit ID",
},
{
accessorKey: "EpisodeID",
header: "Episode ID",
},
];

View File

@ -9,10 +9,10 @@
const masterDetail = useMasterDetail({
onSelect: async (row) => {
return await getVisit(row.InternalPID);
return await getVisit(row.PVID);
},
});
$inspect(masterDetail.selectedItem)
</script>
<div class="flex w-full h-full overflow-hidden">