473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How do I Find Best Match of Disease from Symptoms

I have three tables.

I have the following database table with information about symptoms, diseases, and diseaseSymptoms:
Expand|Select|Wrap|Line Numbers
  1. DISEASE_T   SYMPTOMS    diseaseSymptoms
  2. ==========  ==========  ========
  3. DISEASE_ID  SYMPTOM_ID  DISEASE_ID
  4. VALUE       VALUE       SYMPTOM_ID
I want to search user selected symptoms, which are array of symptoms id in diseaseSymptoms table and return top 5 matching disease IDs , based on, where most of the symptoms are matching with which disease.

For example, user select symptoms are 1,2,3 (cough,cold,headache)

Expand|Select|Wrap|Line Numbers
  1. DISEASE_T  SYMPTOMS_T  diseaseSymptoms
  2. =========  ==========  ===============
  3. 1,fever    1,cough          1,1
  4. 2,flu      2,cold           1,2
  5. 3,xyz      3,headache       2,2
  6.                             2,3
  7.                             3,1
  8.                             3,2
  9.                             3,3
Now, i want to find disease ids from disaseSymptoms table, where all these three of idz matches, ranked as 1, where symptoms matched are less than Rank 1, like only two symptoms match, ranked as 2 and so on.

which approach you people suggests for doing so?

it might be a noob question to ask but i am a newbie in database development, still learning. any help will be appreciated.

Regards
Jan 12 '12 #1
7 3296
NeoPa
32,556 Expert Mod 16PB
You would design a query in SQL which filters only those records from [diseaseSymptoms] that match your specified symptoms and then groups the results by disease. The results would include the ID of the disease as well as the count of records in the group. The count would be the field you order by in descending order for the data you need.
Jan 12 '12 #2
NeoPa
32,556 Expert Mod 16PB
In fact, the SQL would be something like :
Expand|Select|Wrap|Line Numbers
  1. SELECT   [DISEASE_ID]
  2.        , COUNT(*) AS [Rank]
  3. FROM     [diseaseSymptoms]
  4. WHERE    ([SYMPTOM_ID] IN(X, Y, Z))
  5. GROUP BY [DISEASE_ID]
  6. ORDER BY [Rank] DESC
X, Y & Z are the symptoms you'd like to match against.
Jan 12 '12 #3
Rabbit
12,516 Expert Mod 8TB
What if disease A has 10 symptoms but matches all 3 while disease B has 3 symptoms but only matches 2.
Jan 13 '12 #4
NeoPa
32,556 Expert Mod 16PB
According to the question, disease A has the higher score of 3 compared to 2 for disease B. As far as I can see this is also reflected in the example SQL shown.
Jan 13 '12 #5
Rabbit
12,516 Expert Mod 8TB
I was just playing devil's advocate and pointing out a situation in which it may be preferable to account for the total number of symptoms in relation to the number of matched symptoms.
Jan 13 '12 #6
NeoPa
32,556 Expert Mod 16PB
Probably worth throwing into the mix, but would certainly complicate the SQL if taken up, that's for sure.
Jan 13 '12 #7
Rabbit
12,516 Expert Mod 8TB
Well, if I was a patient being diagnosed by this database, I wouldn't mind complicated SQL lol.
Jan 13 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Daniel Pryde | last post by:
Hi everyone. I was wondering if anyone might be able to help me out here. I'm currently looking to find the quickest way to find a best fit match in a large array. My problem is that I have an...
8
by: Christopher Parent | last post by:
I have perused through the groups and a couple C++ manuals and haven't been able to figure this one out. Maybe I'm staring at it too much. Here's the setup, I have 2 files. One is a library and one...
11
by: Pete | last post by:
Is there any way to change the default search to "Any Part Of Field" instead of whole field? The first thing I ever do when searching for something in a field is change the default setting from...
3
by: skosmicki | last post by:
I need to create an function similar to the "MATCH" function in Excel that evaluates a number within a set of numbers and returns whether there is a match. I have put the example of what I see in...
2
by: Note Myself | last post by:
Today I wanted to solve an problem: I need to find out in the code if the iterator passed is a st::vector<T>::iterator, or std::vector<T>::reverse_iterator. I spent a lot of time tweaking a...
2
by: RiverstoneJebin | last post by:
Hi, I have 2 tables with same fields like event, venue, date and cost. Table 1 has 5 records and Table 2 has 100 records. How can i match a record from Table 1 with Table 2 to get the exact match...
2
by: Sejoro | last post by:
Hello, I am trying to write a program that opens a file; reads through it; outputs the text; then outputs the number of lines, words, and characters. Problem is, every time I try to compile, no...
11
by: ankitmathur | last post by:
Hi, I'm trying to overcome a situation whereby I have to search through 4-5 columns and produce the results with an order by according to the values matched in these columns. Example: My...
3
by: raylopez99 | last post by:
I suspect the answer to this question is that it's impossible, but how do I make the below code work, at the point where it breaks (marked below). See error CS0411 This is the complete code. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.