Skip to content

Commit ed19b38

Browse files
authored
Merge pull request #61 from solutionchallenge/feat/#58/feat-diagnosis
Feat/#58/feat-diagnosis
2 parents baf4f93 + b1b7436 commit ed19b38

File tree

11 files changed

+306
-386
lines changed

11 files changed

+306
-386
lines changed

src/App.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ import LoginPage from "./services/auth/login";
99
import OAuthCallback from "./services/auth/oauth";
1010
import Layout from "./layout.tsx";
1111
import { AnimatePresence } from "framer-motion";
12-
import PHQPage from "./services/home/test/phq/index.tsx"; //error 수정
1312
import SettingPage from "./services/setting/index.tsx";
14-
import GADPage from "./services/home/test/gad/index.tsx";
15-
import PSSPage from "./services/home/test/pss/index.tsx";
1613
import RootRedirect from "./services/redirect/rootRedirect.tsx";
1714
import { useTokenMonitor } from "./hooks/auth/useTokenMonitor";
1815
import ReportMainPage from "./services/report/main/index.tsx";
1916
import ReportDetailPage from "./services/report/detail/index.tsx";
17+
import DiagnosisTest from "./services/home/test/index.tsx";
2018

2119
function App() {
2220
const location = useLocation();
@@ -30,9 +28,9 @@ function App() {
3028
<Route path="home">
3129
<Route index path="*" element={<HomePage />} />
3230
<Route path="test">
33-
<Route path="phq" element={<PHQPage />} />
34-
<Route path="pss" element={<PSSPage />} />
35-
<Route path="gad" element={<GADPage />} />
31+
<Route path="phq" element={<DiagnosisTest type="phq-9" />} />
32+
<Route path="pss" element={<DiagnosisTest type="pss" />} />
33+
<Route path="gad" element={<DiagnosisTest type="gad-7" />} />
3634
</Route>
3735
</Route>
3836
<Route path="*" element={<NotFoundPage />} />

src/api/test/diagnosis.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { http } from "../fetch";
2+
3+
export interface DiagnosisQuestion {
4+
index: number;
5+
question: string;
6+
answers: {
7+
score: number;
8+
text: string;
9+
}[];
10+
}
11+
12+
interface GetDiagnosisParams {
13+
paper_id: string;
14+
}
15+
16+
export const getDiagnosis = async ({
17+
paper_id,
18+
}: GetDiagnosisParams): Promise<{
19+
name: string;
20+
guides: string;
21+
questions: DiagnosisQuestion[];
22+
results: {
23+
min: number;
24+
max: number;
25+
name: string;
26+
description: string;
27+
critical: boolean;
28+
}[];
29+
scoring: {
30+
min: number;
31+
max: number;
32+
};
33+
}> => {
34+
const { response } = await http.get<{
35+
name: string;
36+
guides: string;
37+
questions: DiagnosisQuestion[];
38+
results: {
39+
min: number;
40+
max: number;
41+
name: string;
42+
description: string;
43+
critical: boolean;
44+
}[];
45+
scoring: {
46+
min: number;
47+
max: number;
48+
};
49+
}>(`/diagnosis-papers/${paper_id}`);
50+
return response;
51+
};
52+
53+
interface DiagnosisResultRequest {
54+
diagnosis: string;
55+
result_score: number;
56+
total_score: number;
57+
result_name: string;
58+
result_description: string;
59+
result_critical: boolean;
60+
}
61+
62+
export const postDiagnosisResult = async (
63+
result: DiagnosisResultRequest
64+
): Promise<{ id: number; success: boolean }> => {
65+
const { response } = await http.post<{ id: number; success: boolean }>(
66+
"/diagnoses",
67+
result
68+
);
69+
return response;
70+
};
71+
72+
interface DiagnosisResultResponse {
73+
diagnosis: string;
74+
id: number;
75+
result_critical: boolean;
76+
result_description: string;
77+
result_name: string;
78+
result_score: number;
79+
total_score: number;
80+
}
81+
82+
export const getDiagnosisResult = async (
83+
diagnosis_id: number
84+
): Promise<DiagnosisResultResponse> => {
85+
const { response } = await http.get<DiagnosisResultResponse>(
86+
`/diagnosis-papers/${diagnosis_id}`
87+
);
88+
return response;
89+
};
Lines changed: 15 additions & 0 deletions
Loading

src/services/home/test/AnswerToggle/group.tsx

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,13 @@
11
import { useState, useEffect } from "react";
22
import AnswerItem from "./item";
33

4-
interface Answer {
5-
title: string;
6-
}
7-
8-
const defaultAnswers: Answer[] = [
9-
{ title: "Not at all" },
10-
{ title: "Several days" },
11-
{ title: "More than half the days" },
12-
{ title: "Nearly every day" },
13-
];
14-
15-
const pssAnswers: Answer[] = [
16-
{ title: "Never" },
17-
{ title: "Almost Never" },
18-
{ title: "Sometimes" },
19-
{ title: "Fairly Often" },
20-
{ title: "Very Often" },
21-
];
22-
234
const AnswerGroup: React.FC<{
245
onSelect: (score: number) => void;
256
questionIndex: number;
26-
type?: string;
27-
}> = ({ onSelect, questionIndex, type }) => {
7+
answers: { title: string }[];
8+
}> = ({ onSelect, questionIndex, answers }) => {
289
const [selectedIndex, setSelectedIndex] = useState<number | null>(null);
2910

30-
const answers = type === "PSS" ? pssAnswers : defaultAnswers;
31-
3211
useEffect(() => {
3312
setSelectedIndex(null);
3413
}, [questionIndex]);

src/services/home/test/AnswerToggle/item.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react";
2+
import IconNever from "../../../../assets/images/test/answer/icon_never.svg?react";
23
import IconNot from "../../../../assets/images/test/answer/icon_not.svg?react";
34
import IconSeveral from "../../../../assets/images/test/answer/icon_several.svg?react";
45
import IconMore from "../../../../assets/images/test/answer/icon_more.svg?react";
@@ -11,7 +12,7 @@ interface AnswerItemProps {
1112
onClick?: () => void;
1213
}
1314

14-
const orderIcons = [IconNot, IconSeveral, IconMore, IconEvery];
15+
const orderIcons = [IconNever, IconNot, IconSeveral, IconMore, IconEvery];
1516

1617
const AnswerItem: React.FC<AnswerItemProps> = ({
1718
title,

src/services/home/test/QuestionStepperText/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const QuestionStepperText = ({
88
totalSteps,
99
}: QuestionStepperProps) => {
1010
return (
11-
<div className="inline-flex items-end gap-1 sm:gap-2">
11+
<div className="inline-flex items-end gap-1 sm:gap-2 px-4 py-3 pb-3">
1212
<div className="text-second text-2xl sm:text-3xl md:text-4xl font-semibold leading-none">
1313
{String(currentStep).padStart(2, "0")}
1414
</div>

src/services/home/test/StartCard/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import pssIcon from "../../../../assets/images/test/img_pss_start.svg?react";
44
import gadIcon from "../../../../assets/images/test/img_gad_start.svg?react";
55

66
interface StartCardProps {
7-
type: "phq" | "pss" | "gad";
7+
type: "phq-9" | "pss" | "gad-7";
88
}
99

1010
const CONTENT = {
11-
phq: {
11+
"phq-9": {
1212
description:
1313
"PHQ-9 is a clinically validated questionnaire used to screen for depression.",
1414
icon: phqIcon,
@@ -28,7 +28,7 @@ const CONTENT = {
2828
"Your answers will stay private.",
2929
],
3030
},
31-
gad: {
31+
"gad-7": {
3232
description:
3333
"GAD-7 is a tool used to identify general anxiety disorder symptoms.",
3434
icon: gadIcon,

src/services/home/test/gad/index.tsx

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)