Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
justintroy committed Nov 22, 2023
1 parent 810491b commit b751e97
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
14 changes: 8 additions & 6 deletions app/api/symptoms/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ async def get_symptoms(
return symptoms.get_symptoms()


@router.get("/result")
@router.post("/result")
async def get_diseases_from_symptoms(
birth_year: int,
gender: Literal["male", "female"],
birth_year: int = Body(...),
gender: Literal["male", "female"] = Body(...),
body_part: Literal[
"head", "upperbody", "lowerbody", "legs", "arms", "general"
],
symptom_ids: str,
] = Body(...),
symptom_ids: list[int] = Body(...),
):
symptoms = SymptomsService(
birth_year=birth_year, gender=gender, body_part=body_part
)
return symptoms.get_diseases_from_symptoms(symptom_ids.split(","))
return symptoms.get_diseases_from_symptoms(
symptom_ids
)


@router.get("/details/{diagnosis_id}")
Expand Down
46 changes: 33 additions & 13 deletions app/api/symptoms/symptoms_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import requests
import json
from random import random
from urllib.parse import urlencode

import requests
from fastapi.exceptions import HTTPException

from app.core.config import settings

Expand Down Expand Up @@ -105,29 +109,45 @@ def get_symptoms(self) -> dict[str, list[dict]]:
def get_diseases_from_symptoms(
self, ids: list[int]
) -> dict[str, list[dict]]:

data = None

res = self.initialize()
if not res:
return False

for id in ids:
rand = random()
data = {
"command": "addSymptom",
"symptomId": id,
"has_red_flag:": False,
"rand": random(),
"rand": rand,
}
res = requests.post(self.base_url, data=data, cookies=self.cookie)
res = requests.post(
self.base_url,
data=data,
cookies=self.cookie,
)
self.cookie = res.cookies

data = {
"command": "getDiagnoses",
"rand": random(),
}
res = requests.get(self.base_url, params=data, cookies=self.cookie)
data = {
"command": "getDiagnoses",
"rand": random(),
}
res = requests.get(self.base_url, params=data, cookies=self.cookie)

if not res:
return False
res = res.json()
if not res:
return False

try:
self.cookie = res.cookies
data = res.json()
except:
raise HTTPException(
400,
"Unable to process the request. Please check your symptom ids.",
)

return {
"diagnosis": [
Expand All @@ -136,14 +156,14 @@ def get_diseases_from_symptoms(
"name": y["Name"],
"accuracy": y["Accuracy"],
}
for y in res["DiagnosisResult"]
for y in data["DiagnosisResult"]
],
"similar_symptoms": [
{
"id": y["ID"],
"name": y["Name"],
}
for y in res["ProposedSymptoms"]
for y in data["ProposedSymptoms"]
],
}

Expand Down

0 comments on commit b751e97

Please sign in to comment.