Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { GovtOrganization } from "@/types/govtOrganization";
import { HealthFacility } from "@/types/healthFacility";
import { HealthInformation } from "@/types/healthInformation";
import { PaginatedResponse } from "./types";
import { PartialPatient } from "@/types/patient";
import { Patient } from "@/types/patient";
import { User } from "@/types/user";

// FIXME: Move all the api specific types to a ./types.ts file
Expand Down Expand Up @@ -421,7 +421,7 @@ export const apis = {
token: number;
facility_id: string;
}) => {
return await request<PartialPatient>(
return await request<Patient>(
`/api/abdm/v3/hip/patient/fetch-by-token/` + queryString(query)
);
},
Expand Down
53 changes: 18 additions & 35 deletions src/components/TokenSearchDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FC, useMemo, useState } from "react";
import { ArrowRightIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { PartialPatient } from "@/types/patient";
import { Patient } from "@/types/patient";
import { Skeleton } from "@/components/ui/skeleton";
import { apis } from "@/apis";
import { navigate } from "raviger";
Expand Down Expand Up @@ -107,7 +107,7 @@ const TokenSearchDialog: FC<TokenSearchDialogProps> = ({
)}

{!isFetching && isEnabled && patient && (
<PartialPatientCard patient={patient} />
<PatientCard patient={patient} />
)}
</div>
</div>
Expand All @@ -116,11 +116,24 @@ const TokenSearchDialog: FC<TokenSearchDialogProps> = ({
);
};

const PartialPatientCard: FC<{ patient: PartialPatient }> = ({ patient }) => {
const [yearOfBirth, setYearOfBirth] = useState("");
const PatientCard: FC<{ patient: Patient }> = ({ patient }) => {
const yearOfBirth = useMemo(() => {
return patient.year_of_birth ?? patient.date_of_birth?.split("-")[0];
}, [patient]);

return (
<div className="border rounded-md p-4">
<div
onClick={() => {
navigate("patients/verify", {
query: {
phone_number: patient.phone_number,
year_of_birth: yearOfBirth,
partial_id: patient.partial_id || patient.id.slice(0, 5),
},
});
}}
className="border rounded-md p-4 cursor-pointer"
>
<div className="flex items-center justify-between">
<div className="space-y-1">
<div className="font-medium text-base">{patient.name}</div>
Expand All @@ -132,36 +145,6 @@ const PartialPatientCard: FC<{ patient: PartialPatient }> = ({ patient }) => {
#{patient.id.slice(0, 8)}
</div>
</div>

<div className="mt-3 flex items-center gap-3">
<Input
placeholder="Enter the year of birth to verify"
inputMode="numeric"
pattern="[0-9]*"
value={yearOfBirth}
onChange={(e) => setYearOfBirth(e.target.value)}
minLength={4}
maxLength={4}
className="flex-1"
/>
<Button
size="icon"
variant="outline"
aria-label="Open patient page"
disabled={yearOfBirth.length !== 4}
onClick={() => {
navigate("patients/verify", {
query: {
phone_number: patient.phone_number,
year_of_birth: yearOfBirth,
partial_id: patient.partial_id || patient.id.slice(0, 5),
},
});
}}
>
<ArrowRightIcon />
</Button>
</div>
</div>
);
};
Expand Down
5 changes: 5 additions & 0 deletions src/types/patient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export type Patient = {
id: string;
name: string;
gender: "male" | "female" | "transgender";
phone_number: string;
date_of_birth?: string | null;
year_of_birth?: string | null;

[key: string]: unknown;
};
Expand Down