%%Launch%%
go :- hypothesize(Illness),
    hypothesize_treatment(Treatment),
    write('You may be suffering from: '),
    write(Illness),
    nl,
    write('We may treat you with '),
    write(Treatment),
    undo.

%%Hypotheses%%
hypothesize(major_depressive_disorder)   :- major_depressive_disorder, !.
hypothesize(bipolar_I)     :- bipolar_I, !.
hypothesize(bipolar_II)     :- bipolar_II, !.
hypothesize(schizophrenia)   :- schizophrenia, !.
hypothesize(post_traumatic_stress_disorder)     :- post_traumatic_stress_disorder, !.
hypothesize(schizoaffective_disorder) :- schizoaffective_disorder, !.
hypothesize(schizotypal_disorder) :- schizotypal_disorder, !.
hypothesize(unknown).             %%no diagnosis%%

hypothesize_treatment(cbt)	:- cbt, !.
hypothesize_treatment(yoga)	:- yoga, !.
hypothesize_treatment(medication)	:- medication, !.
hypothesize_treatment(ect)	:- ect, !.
hypothesize_treatment(unknown). 	%%no treatment%%
   
%%Identification%%
major_depressive_disorder :- mental_health,
           physical_health,
           verify(suicidal_thoughts),
           verify(physical_aches).
bipolar_I :- mental_health,
physical_health,
            behavioral_health,
            verify(cyclic_stages),
            verify(changes_in_sleep),
	verify(full_manic_episode),
verify(psychosis).
bipolar_II :- mental_health,
physical_health,
            behavioral_health,
            verify(cyclic_stages),
            verify(changes_in_sleep),
	verify(hypomania),
	verify(major_depressive_episode).
schizophrenia :- mental_health,
           social_health,
           verify(social_withdrawl),
           verify(unclear_thinking),
verify(psychosis).
post_traumatic_stress_disorder :- behavioral_health,
            social_health,
            verify(easily_frightened),
            verify(experienced_trauma).
schizoaffective_disorder :- mental_health,
            verify(periods_of_manic_mood),
            verify(unusual_behavior),
	verify(psychosis).
schizotypal_disorder :- mental_health,
            social_health,
            verify(constant_anxiety),
            verify(peculiar_thoughts_and_speech),
verify(psychosis).
        
%%Classification%%
mental_health    :- verify(hallucinations), !.
mental_health    :- verify(thought_disorder),
            verify(delusions).
physical_health      :- verify(low_energy), !.
physical_health      :- verify(anhedonia),
             verify(slowed_reactions).
social_health :- verify(irritability), !.
social_health :- verify(worthlessness),
            verify(suspicious_ideation).
behavioral_health :- social_health,
            verify(social_isolation), !.
behavioral_health :- social_health,
            verify(disorganized_behavior).

%%Treatments%%
cbt :- (verify(unresponsive_to_medication);
    verify(unwilling_to_medicate)).
yoga	:- cbt,
    verify(willing_to_embrace_mindfulness).
medication :- (verify(good_physical_health);
    verify(willing_to_improve_physical_health)).
medication :- verify(severe_symptoms), !.
ect :- verify(unresponsive_to_medication),
    verify(good_heart_health).

%%Asking Questions%%
ask(Question) :-
    write('Do you have the following symptom: '),
    write(Question),
    write('? '),
    read(Response),
    nl,
    ( (Response == yes ; Response == y)
      ->
       assert(yes(Question)) ;
       assert(no(Question)), fail).

:- dynamic yes/1,no/1.

%%Verification%%
verify(S) :-
   (yes(S)
    ->
    true ;
    (no(S)
     ->
     fail ;
     ask(S))).

%%undo assertions%%
undo :- retract(yes(_)),fail.
undo :- retract(no(_)),fail.
undo.

