%Being able to add and delete facts on the fly are important to the
% belief revision of this program.
:- dynamic patient/1.
:- dynamic age/2.
:- dynamic symptom/2.

%rules
olderThan40(Patient):- age(Patient, Age), Age >= 40.
observe(Patient) :- symptom(Patient, chondrosarcoma), symptom(Patient, low_grade_and_intracompartmental), symptom(Patient, positive_margins), write("Consider RT or consider re-resection to achieve negative surgical margins").
observe(Patient) :- symptom(Patient, chondrosarcoma), symptom(Patient, low_grade_and_intracompartmental), symptom(Patient, negative_margins), write("Continue to observe the patient.").
observe(Patient) :- symptom(Patient, chondrosarcoma), symptom(Patient, high_grade), symptom(Patient, positive_margins), write("Consider RT or consider re-resection to achieve negative surgical margins").
observe(Patient) :- symptom(Patient, chondrosarcoma), symptom(Patient, high_grade), symptom(Patient, negative_margins), write("Continue to observe the patient.").

recurrence(patient) :- symptom(Patient, chondrosarcoma), symptom(Patient, high_grade), symptom(Patient, local),write("Perform a wide excision if resectable or RT if unresectable."),nl, write("Did the tumor display positive or negative margins?"),nl,read(Results), assert(symptom(Patient,Results)), observe(Patient).

recurrence(patient) :- symptom(Patient, chondrosarcoma), symptom(Patient, high_grade), symptom(Patient, systemic),write("This means that the cancer is Metastatic Chondrosarcoma which is out of the scope of this project."),nl.

diagnose(Patient):-
    \+olderThan40(Patient),
    write("Refer the patient to an orthopedic oncologist and perform a biopsy."),nl, write("What were the results of the biopsy?"),nl, read(Results), assert(symptom(Patient,Results)), nl, write("What was the grade of the cancer?"),
    read(Grade), assert(symptom(Patient,Grade)).

diagnose(Patient):-
    olderThan40(Patient),
    write("Workup for potential bone metastasis as clinically intended. Perform the following tests as needed: 1.)History and physical. 2.) Bone scan or PET/CT 3.) Chest Radiograph 4.) SPEP/labs 5.) Chest/abdominal/pelvic CT with contrast. 6.) PSA 7.) Mammogram. Record the results in the knowledge base."),nl,(symptom(Patient,no_other_lesions)->write("Refer the patient to an orthopedic oncologist. A biopsy should be performed at the treating institution."); write("There are lesions not on the bone, refer to the appropriate NCCN Guidelines for treatment by cancer type.")).


treatment(Patient):- symptom(Patient, chondrosarcoma), symptom(Patient, low_grade_and_intracompartmental),write("apply one of the following treatment methods : 1.)Intralesional excision + surgical adjuvant 2.) Wide excision, if resectable 3.)Consider RT is unresectable"),nl, write("Afterwards, the patient should undergo a physical examination as well as radiographs of the primary site as clinically indicated every 6-12 months for 2 years, then yearly as appropriate. Do this with the chest as well. If a recurrence occurs perform a wide excision is reectable or RT if unresectable."), nl, write("After performing treatment on the patient, what were the results?"),nl, read(Results), assert(symptom(Patient, Results)), observe(Patient).

treatment(Patient) :- symptom(Patient, chondrosarcoma),symptom(Patient, high_grade), write("Perform a wide excision if resectable or consider RT if borderline resectable or unrectable. For surveillance: Perform a physical exam, perform radiographs of primary site and/or cross-sectional imaging MRI or CT as clinically indicated, chest imaging every 3-6 months (may include a CT at least every 6 months for 5 years, then yearly for a minimum of 10 years), reasses function at every follow-up visit."),nl,write("If a recurrence occured, what type of occurence was it?"), read(Results), assert(symptom(Patient, Results)).

%convenience rules
createNewPatient :- write("Enter the name of the patient"), nl, read(Patient), assert(patient(Patient)),nl, write(Patient), write( " is now a patient. How old are they? "),nl, read(Age), assert(age(Patient,Age)).

reviseSymptom(Patient, Symptom) :- retract(symptom(Patient, Symptom)),write("What is the revised symptom?"), nl, read(NewSymptom), assert(symptom(Patient,NewSymptom)).
deleteSymptom(Patient, Symptom) :- retract(symptom(Patient, Symptom)).
addSymptom(Patient, Symptom) :- assert(symptom(Patient,Symptom)).



