Expert system(medical diagnosis system)

Discussions related to Visual Prolog
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

Expert system(medical diagnosis system)

Unread post by fred malack »

i am developing my final year project(Expert system) medical diagnosis system i couldnt get ESTA because i couldnt afford commertial edition i have a prolog source code but i cant make it work presentation is soon i need your help guys plz i just want the code to run in GUI...... The codes below i want them to run in GUI but i need it to work plz plz plz....

Code: Select all

                                     /*THE FOLLOWING IS THE CODE*/ /***********************************************************************************************************************************                           Copyright (c) 2014 My Company   *********************************************************************************************************************************/   implement main     open core,string     clauses     run():-         console::init(),         succeed(). % place your own code here     domains     disease,indication = symbol     Patient,name = string   predicates     hypothesis (string,disease)     symptom (name,indication)     response (char)     go clauses     go :-         write("What is the patient's name? "),         readln(Patient),         hypothesis(Patient,Disease),         write(Patient,"probably has ",Disease,"."),nl.       go :-         write("Sorry, I don't seem to be able to"),nl,         write("diagnose the disease."),nl.       symptom(Patient,fever) :-         write("Does ",Patient," have a fever (y/n) ?"),         response(Reply),         Reply='y'.       symptom(Patient,rash) :-         write("Does ",Patient," have a rash (y/n) ?"),         response(Reply),         Reply='y'.       symptom(Patient,headache) :-         write("Does ",Patient," have a headache (y/n) ?"),         response(Reply),         Reply='y'.       symptom(Patient,runny_nose) :-         write("Does ",Patient," have a runny_nose (y/n) ?"),         response(Reply),         Reply='y'.       symptom(Patient,conjunctivitis) :-         write("Does ",Patient," have a conjunctivitis (y/n) ?"),         response(Reply),         Reply='y'.       symptom(Patient,cough) :-         write("Does ",Patient," have a cough (y/n) ?"),         response(Reply),         Reply='y'.       symptom(Patient,body_ache) :-         write("Does ",Patient," have a body_ache (y/n) ?"),         response(Reply),         Reply='y'.       symptom(Patient,chills) :-         write("Does ",Patient," have a chills (y/n) ?"),         response(Reply),         Reply='y'.       symptom(Patient,sore_throat) :-         write("Does ",Patient," have a sore_throat (y/n) ?"),         response(Reply),         Reply='y'.       symptom(Patient,sneezing) :-         write("Does ",Patient," have a sneezing (y/n) ?"),         response(Reply),         Reply='y'.       symptom(Patient,swollen_glands) :-         write("Does ",Patient," have a swollen_glands (y/n) ?"),         response(Reply),         Reply='y'.       hypothesis(Patient,measles) :-         symptom(Patient,fever),         symptom(Patient,cough),         symptom(Patient,conjunctivitis),         symptom(Patient,runny_nose),         symptom(Patient,rash).       hypothesis(Patient,german_measles) :-         symptom(Patient,fever),         symptom(Patient,headache),         symptom(Patient,runny_nose),         symptom(Patient,rash).       hypothesis(Patient,flu) :-         symptom(Patient,fever),         symptom(Patient,headache),         symptom(Patient,body_ache),         symptom(Patient,conjunctivitis),         symptom(Patient,chills),         symptom(Patient,sore_throat),         symptom(Patient,runny_nose),         symptom(Patient,cough).       hypothesis(Patient,common_cold) :-         symptom(Patient,headache),         symptom(Patient,sneezing),         symptom(Patient,sore_throat),         symptom(Patient,runny_nose),         symptom(Patient,chills).       hypothesis(Patient,mumps) :-         symptom(Patient,fever),         symptom(Patient,swollen_glands).       hypothesis(Patient,chicken_pox) :-         symptom(Patient,fever),         symptom(Patient,chills),         symptom(Patient,body_ache),         symptom(Patient,rash).       hypothesis(Patient,measles) :-         symptom(Patient,cough),         symptom(Patient,sneezing),         symptom(Patient,runny_nose).       response(Reply) :-         readchar(Reply),         write(Reply),nl.     end implement main   goal     mainExe::run(main::run).
fr@dlu
Martin Meyer
VIP Member
Posts: 280
Joined: 14 Nov 2002 0:01

Unread post by Martin Meyer »

Hi,

the functionality of below code seems to come close to what you are looking for. Just tune it a little to make it fit to your medical diagnosis case.

It's but the code of a console application project, not a GUI project. To start it, click "Run in Window" or Alt+F5.

All the best,
Martin

Code: Select all

implement main     domains     name = string.     performance = symbol.     review = symbol.     clauses     run():-         console::init(),         stdIo::write("What is the pupil's name ? "),         Pupil = stdIo::readline(),         go(Pupil).     class predicates     go : (name Pupil).   clauses     go(Pupil) :-         checkPupil(Pupil),         fail.       go(Pupil) :-         gradePupil(Pupil),         fail.       go(_Pupil).     class facts     symptom : (name, performance) nondeterm.     class predicates     checkPupil : (name Pupil)         multi.   clauses     checkPupil(Pupil) :-         stdIo::write("Did ", Pupil, " pass the test (y/n) ? "),         Reply = stdIo::readLine(),         if Reply = "y" then             assert(symptom(Pupil, "passed test"))         end if.       checkPupil(Pupil) :-         stdIo::write("Did ", Pupil, " do his homeworks (y/n) ? "),         Reply = stdIo::readLine(),         if Reply = "y" then             assert(symptom(Pupil, "did homeworks"))         end if.       checkPupil(Pupil) :-         stdIo::write("Has ", Pupil, " been truant (y/n) ? "),         Reply = stdIo::readLine(),         if Reply = "y" then             assert(symptom(Pupil, "truant"))         end if.     class predicates     gradePupil : (name Pupil) nondeterm.   clauses     gradePupil(Pupil) :-         hypothesis(Pupil, Review),         stdIo::write(Pupil, " ", Review, "\n").     class predicates     hypothesis : (name Pupil, review Performance [out])         nondeterm.   clauses     hypothesis(Pupil, "gets grade A") :-         symptom(Pupil, "did homeworks"),         symptom(Pupil, "passed test").       hypothesis(Pupil, "gets grade B") :-         symptom(Pupil, "passed test"),         not(symptom(Pupil, "did homeworks")).       hypothesis(Pupil, "gets grade C") :-         not(symptom(Pupil, "passed test")).       hypothesis(Pupil, "gets a note to parents") :-         symptom(Pupil, "truant").       hypothesis(Pupil, "is put to detention") :-         not(symptom(Pupil, "truant")),         not(symptom(Pupil, "did homeworks")).       hypothesis(Pupil, "is teacher's pet") :-         symptom(Pupil, "passed test"),         symptom(Pupil, "did homeworks"),         not(symptom(Pupil, "truant")).     end implement main   goal     mainExe::run(main::run).
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

Unread post by fred malack »

thaanks alot @ martin but i wish to include it in my system cz i have place some functionalities and it is in GUI i realy need help.
fr@dlu
Martin Meyer
VIP Member
Posts: 280
Joined: 14 Nov 2002 0:01

Unread post by Martin Meyer »

The dialog flow, which your code indicates, is completely linear. It's asking some questions and then output something. Of course that can be done in a GUI-style application also. However it does not make much use of Windows' asynchronous event driven GUI.

I moved that code, which I posted before, to the attached GUI-project. I have not checked, whether it can be compiled with the Personal Edition, but I suppose Personal Edition will suffice. Try to run it and press "File", "New" to start the questioning. I hope it will give you a code example, from which you can start developing your medical case.

Best regards,
Martin
Attachments
teacherXpertSystem.zip
very simple GUI-style project
(24.35 KiB) Downloaded 673 times
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

Unread post by fred malack »

thaanx alot martin will give u feedback
fr@dlu
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

Unread post by fred malack »

thaanx alot martin its working i tried to upload it but it gave me a general error
fr@dlu
billgates198606

i can borrow your the commertial vertson

Unread post by billgates198606 »

i can borrow your the commertial vertson, by remote access my pc,13735397341@139.com
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

vpiCommonDialogs

Unread post by fred malack »

In my codes i used stdIo::write(Patient, " ", Disease, "\n"). to output the patient's name and disease and it gives me the results in the message but i want it to popup and give me the result in the dialog i used vpiCommonDialogs::note: (string Patient, string Disease). but it gives me a syntax error...need help plz
fr@dlu
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

Hi,

Maybe this code can help you :

Code: Select all

vpiCommonDialogs::note(Patient, toString(Disease)),
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

how to remove if....then from my code

Unread post by fred malack »

hello guys i really need to know if it is possible to remove if...then from the following code and use another way that will replace because the system doesnt respond well ...

Code: Select all

checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("  ", Patient, " have a pain during urination (y/n) ?")) = "y" then             assert(symptom(Patient, "pain-d-u"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("   ", Patient, " do you frequently urinate (y/n) ?")) = "y" then             assert(symptom(Patient, "freq-urination"))         end if.
fr@dlu
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

:idea:

Code: Select all

predicates checkPatient:(string Patient,string Question,string Symptom)  procedure(i,i,i). clauses checkPatient(Patient,Question,Symptom):-     commonDialogs::get_string(This, txt_input, "", string::concat(" ", Patient, Question," (y/n) ?")) = Respons,     string::tolowercase(Respons) = "y",     assert(symptom(Patient, Symptom)),     !. checkPatient(_,_,_).   goal checkPatient("Toto", " have a pain during urination","pain-d-u"), checkPatient("Toto", " do you frequently urinate","freq-urination"),
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

I need help on how to clear the value in the assert.

Unread post by fred malack »

My code has a number of asserts whenever i run the code
For.example if i diagnose and get cholera...next tym when i run
It gives me the same disease even with different inputs...

checkPatient(Patient) :-
if commonDialogs::tryGet_string(This, txt_input, "", string::concat(" ", Patient, " have a pain during urination (y/n) ?")) = "y" then
assert(symptom(Patient, "pain-d-u"))
end if.
checkPatient(Patient) :-
if commonDialogs::tryGet_string(This, txt_input, "", string::concat(" ", Patient, " do you frequently urinate (y/n) ?")) = "y" then
assert(symptom(Patient, "freq-urination"))
end if.

The above is a sample of the whole code...
fr@dlu
User avatar
Thomas Linder Puls
VIP Member
Posts: 1176
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

Please use [code]...[/code] tags around your code.

Code: Select all

    checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("  ", Patient, " have a pain during urination (y/n) ?")) = "y" then             assert(symptom(Patient, "pain-d-u"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("   ", Patient, " do you frequently urinate (y/n) ?")) = "y" then             assert(symptom(Patient, "freq-urination"))         end if.
Regards Thomas Linder Puls
PDC
fred malack
Active Member
Posts: 28
Joined: 9 Mar 2014 6:35

I want to temporarily store the data and delete right after diagnosis

Unread post by fred malack »

I really need help guys because i have find out that by using assert the data keep on adding so whenever i diagnose the disease what happens is that it gives the previous disease and the new disease please i have presentation tomorrow i need to replace it with something that stores data temporarily (i have head about list) but am not familiar with it..

Code: Select all

   checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("  ", Patient, " have a pain during urination (y/n) ?")) = "y" then             assert(symptom(Patient, "pain-d-u"))         end if.     checkPatient(Patient) :-         if commonDialogs::tryGet_string(This, txt_input, "", string::concat("   ", Patient, " do you frequently urinate (y/n) ?")) = "y" then             assert(symptom(Patient, "freq-urination"))         end if.  
fr@dlu
User avatar
Thomas Linder Puls
VIP Member
Posts: 1176
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

The simplest solutionto that problem is to retract all the facts before starting on a new diagnosis:

Code: Select all

clauses     diagnose() :-         retractAll(symptom(_, _)) % retract all symptom facts before starting         ... % do whatever you do in your current program
Regards Thomas Linder Puls
PDC
Post Reply