This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add hooks for use patient and use patients
- Loading branch information
1 parent
5e8284f
commit 1d13532
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useQuery } from 'react-query' | ||
|
||
import PatientRepository from '../../shared/db/PatientRepository' | ||
import Patient from '../../shared/model/Patient' | ||
|
||
function fetchPatient(_: any, id: string): Promise<Patient> { | ||
return PatientRepository.find(id) | ||
} | ||
|
||
export default function usePatient(id: string) { | ||
return useQuery(['patient', id], fetchPatient) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useQuery } from 'react-query' | ||
|
||
import PatientRepository from '../../shared/db/PatientRepository' | ||
import Patient from '../../shared/model/Patient' | ||
import PatientSearchRequest from '../models/PatientSearchRequest' | ||
|
||
interface PatientsResult { | ||
totalCount: number | ||
patients: Patient[] | ||
} | ||
|
||
async function fetchPatients(_: any, searchRequest: PatientSearchRequest): Promise<PatientsResult> { | ||
const patients = await PatientRepository.search(searchRequest.queryString) | ||
const totalCount = await PatientRepository.count() | ||
return { totalCount, patients } | ||
} | ||
|
||
export default function usePatients(searchRequest: PatientSearchRequest) { | ||
return useQuery(['patients', searchRequest], fetchPatients) | ||
} |