Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
chore: add hooks for use patient and use patients
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed Aug 9, 2020
1 parent 5e8284f commit 1d13532
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/patients/hooks/usePatient.tsx
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)
}
20 changes: 20 additions & 0 deletions src/patients/hooks/usePatients.tsx
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)
}

0 comments on commit 1d13532

Please sign in to comment.