Created
November 22, 2019 02:06
-
-
Save stasSajin/4880ac0f72a5deefe21c8813e6f0093f to your computer and use it in GitHub Desktop.
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
from typing import Optional, Union | |
from enum import Enum | |
from dataclasses import dataclass | |
from pydantic import ValidationError | |
class ProcedureType(Enum): | |
cancer = "cancer" | |
flu = "flu" | |
class HealthOutcome(Enum): | |
healthy = "healthy" | |
at_risk = "at risk" | |
unknown = "unknown" | |
@dataclass | |
class Response: | |
outcome: HealthOutcome | |
probability: float | |
@dataclass | |
class UserAssessment: | |
procedure: ProcedureType | |
age: int | |
occupation: str | |
doctor_approved: Optional[bool] = None | |
response = Union[ValidationError, Response] | |
def apply_treatment(user_data: UserAssessment) -> response: | |
if user_data.procedure == "cancer" and user_data.doctor_approved == False: | |
return ValidationError( | |
"Automatic model based diagnosis is not available without doctor approval" | |
) | |
return Response(HealthOutcome.healthy, 0.05) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment