DESIGNING A MEDICAL EXPERT SYSTEM BASED ON FUZZY LOGIC

During the COVID-19 pandemic, humanity faced various health problems. One of the most common diseases is pneumonia. The life of every person depends on the correct and effective diagnosis of the disease. Currently, a large number of software applications with elements of artificial intelligence are being developed, which can reduce the time of patient care, improve the methodology and efficiency of disease diagnosis. With our research, we strive to contribute to the development of such software applications, namely, to develop software tools with elements of fuzzy logic. To develop a decision-making system, scales and algorithms in order to assess we considered the prognosis of the severity of community-acquired pneumonia PORT(PSI), CURB/CRB-65 and SMART-COP/SMART-CO. To improve the quality of processing fuzzy production rules of knowledge base, the logic programming language Prolog was used. The created application is planned to be integrated into medical information systems.


INTRODUCTION
Modern information and communication technologies are widely introduced and used in all spheres of society. Every year a person uses a large number of software applications with elements of artificial intelligence that functions on various computing devices (Gibadullin et al., 2020;Gibadullin et al., 2021).
One of such software applications is expert systems based on fuzzy logic (Zadeh, 1996;Altunin et al., 2000;Zadeh, 1983), which allow users to make decisions relying on facts and rules in the knowledge base in conditions of incomplete certainty.
The use of fuzzy logic is relevant in cases of incomplete certainty in course of diagnosing, since much in a person's life depends on making the right decision. For example, a doctor cannot always choose the right treatment and diagnosis of a disease, prescribe a medication plan, etc.

RELATED WORKS
To ensure effective healthcare, it is important to make a right decision on the diagnosis and to treat various diseases using modern technologies (Abbod et al., 2001;Boegl et al., 2004;Di Lascio et al., 2002;Park et al., 1996;Phuong et al., 2001).
Taking into account the findings of our previous research, we developed an integrated environment for building expert systems (System) created by using dynamically updated knowledge base (Zainullina et al., 2017;Burnashev et al., 2017). In the expert systems created, we performed data processing and search in the knowledge base using a logical inference mechanism. The functioning of the logical inference mechanism was carried out through the use of the SWI-Prolog environment, which was integrated into the System (Burnashev et al., 2019).
Currently, we have set a new research goal -the design of software tools using elements of fuzzy logic, which will form an adaptive decision-making system in the future.
The present study is devoted to the using of software applications in the medical field, namely, the design of software tools for creating expert systems based on fuzzy logic for the diagnosis of diseases associated with community-acquired pneumonia.
The duration of the course of the disease can be acute and prolonged.  Prolonged pneumonia includes the course of the disease, which does not pass in a four-week period, despite administering timely antibacterial therapy.  Prolonged pneumonia can occur as a secondary disease. In this case, aggravation is often possible. Consequently, it is very difficult for specialists and experts of the subject area to determine the diagnosis, treatment and prevention. In reality, and in conditions of uncertainty, it is very difficult to make the right choice.
In this regard, it was decided to develop software tools for subsequent integration into a single adaptive decision-making system based on fuzzy logic.

PRELIMINARY
There are many methods for diagnosing pneumonia. Consequently, we considered classifying the severity of the course of a disease (Table 1.) and algorithms for assessing the prognosis of the severity of community-acquired pneumonia.
Classification by severity. Pneumonia is classified into the following types according to its severity: mild, medium, severe. There are special scales which determine the severity of the course of pneumonia. They estimate its severity and make prognosis of patients with community-acquired pneumonia (Rudnov et al., 2007).
We considered scales and algorithms for assessing the prognosis of the severity of community-acquired pneumonia PORT (PSI), CURB/CRB-65 and SMART POLICEMAN/SMART-CO to develop a decision-making system.
In our study, the CURB/CRB-65 scale and the corresponding algorithm for assessing the risk of an unfavorable prognosis and choosing a place of treatment for community-acquired pneumonia on the CURB-65 scale were used to develop fuzzy rules.
Symptoms and signs:  Assessment of consciousness.  Blood Urea Nitrogen > 7 mmol/L.  Respiratory rate >= 30/min.  Systolic blood pressure < 90 or diastolic BP <= 60 mmHg.  Age >= 65.   At the algorithmic level of hierarchy design, the algorithm of the system functioning is described, linguistic variables, their membership functions, the mechanism of fuzzy logical inference and the corresponding methods of defuzzification are determined. At the first stage, the input and output interface of the fuzzy system is determined (inputs and outputs are specified).

MODEL AND IMPLEMENTATION
The definition of linguistic variables includes: the definition of the universal set U (the domain of reasoning), the definition of the range of variation of the base variable, the definition of the values of linguistic variables (specifying the form of the membership function, setting reference points).
The model of a fuzzy system at the algorithmic level is given in the form of triples ( , , ), (1) where , -are the base sets on which inputs and outputs are set, is the fuzzy "input-output" correspondence.
The management strategy and the functioning of the system are described in the form of fuzzy production rules linking linguistic variables.
The description of fuzzy systems is carried out using graphical and textual tools integrated into the environment, and it includes a base of fuzzy rules and membership functions. At the same time, fuzzy inference mechanism is used.
The Patients table with the following fields was used as test data: Patient Id, age, blood pressure, respiratory rate, etc. Initialization of facts was performed in the SWI-Prolog software environment for importing facts into the Prolog knowledge base using the predicates specified in Table 2. The shell was developed using the XPCE library (Burnashev et al., 2020).
Each row is a separate row of the table, and the columns are separated by special delimiter characters (Burnashev et al., 2019). The SWI-Prolog inference mechanism was used to make queries to the knowledge base using introduced facts and fuzzy production rules. The following sequence of actions was chosen to determine the degree of affiliation and solve the task: 1. Creating a fact table in CSV format. 2. Importing a fact table from a CSV file into a fact database. 3. Working with the database of facts in SWI-Prolog. The SWI-Prolog implementation includes predicates that simplify working with the file, the main ones are shown in Table 2: 15th IADIS International Conference Information Systems 2022 Entering data from a CSV file Filethe name of the file in a special format. rowList -a list of rows after importing. The name of the file from which the import will be performed is specified at the input of the function. A parameter that defines the separator between the fields is also set. file(base1, csv, 'file.csv'). file(base1, base, 'file.pl').
Loading and reading a database of facts from a file

EXPERIMENTAL ANALYSIS AND RESULTS
To develop fuzzy production rules in the knowledge base of the system based on fuzzy inference, the following stages were implemented:  Stage 1. Formation of the rule bases of the fuzzy inference system;  Stage 2. Fuzzification of input variables;  Stage 3. Aggregation;  Stage 4. Activation;  Stage 5. Defuzzification.

Let's consider each of the stages:
Stage 1. Formation of the rule base of the fuzzy inference system. The developed base of rules for determining the severity of the course and the place of treatment of pneumonia in the decision-making system is described by a system of conditional statements in terms of fuzzy and linguistic variables that establish a relationship between input and output parameters.
In the created system of fuzzy inference, the rules of fuzzy productions are used, in which the conditions and conclusions are formulated in terms of fuzzy linguistic statements.

Stage 2. Fuzzification of input variables
The purpose of this stage is to establish a correspondence between the specific value of a separate input variable of the fuzzy inference system and the value of the membership function of the corresponding term of the input linguistic variable. At this stage, the degree of operation (truth) of each prerequisite of each rule for the given values of input variables of the form is determined: A fragment of the program code combining the rules of fuzzification, aggregation is shown below: computation_of_the_truth(X1,X2,X3,X4,X5,"normal","traced","normal", "not often", "medium", Y), B is 1.

Stage 3. Aggregation.
Aggregation is a procedure for determining the degree of truth of conditions for each of the fuzzy inference rules. Aggregation of the degrees of truth of the premises for each of the rules : In the knowledge base, rules were implemented to perform aggregation of degrees of truth of premises. Below is a fragment of the program code:

Stage 4. Activation
Activation or composition of conclusions in fuzzy rules The procedure for activating conclusions of fuzzy production rules includes in determining the modified membership functions of these conclusions for each i-th (i=1, ..., n) rule ( ) based on performing a composite operation modified for fuzzy products between the aggregated value of the degrees of truth of the premises of this rule determined at the previous stage and the corresponding membership function of its conclusion ( ) For a simplified fuzzy inference algorithm, the activation stage is represented as: In many systems, there is also an accumulation stage, but in our system it is absent due to clear values of output variables.

Stage 5. Defuzzification
The reduction to clarity includes in converting the fuzzy values of the found output variables into clear ones.
The created system uses the fuzzy mean method. Their values are calculated using a modified center of gravity method, namely the fuzzy mean method, as follows: is the aggregated degree of truth for all the prerequisites of the i-th rule; ci is the value of the output variable of the i-th rule = ; n is the number of rules in the database.
Graphical interface for testing knowledge bases. In scientific research, for the development of knowledge bases, most systems with elements of the logical inference mechanism use SWI-Prolog, which has been constantly developing since its creation (Burnashev et al., 2020). For the development of graphical shells of software systems, the distribution package includes tools that allow you to develop a graphical user interface. Such a tool as part of SWI-Prolog is the XPCE graphical shell.
Based on the knowledge of the subject area, a graphical interface was developed (Figure 2), which includes the following:  Identification data (Surname, First Name);  Age (A);  Blood pressure (B);  The level of urea nitrogen in the blood (C);  Impaired consciousness (D);  Respiratory rate (E);  Severity rating level (Prognosis) (Result) and Saving the results in the database. The CURB/CRB-65 scale was used to create the graphical shell. Using the algorithm used, the degree of risk assessment of an unfavorable prognosis and the choice of a place of treatment for community-acquired pneumonia on the CURB-65 scale was determined.
The developed medical expert system based on fuzzy logic includes the following functions: 1. Description of the input and output interfaces of the fuzzy system. 2. Definition of the membership function for input and output data. 3. Setting fuzzy "input-output" correspondences. 4. Translation of the source description files into an internal representation. 5. Choosing a strategy for fuzzy inference and defuzzification. 6. Performing fuzzy inference and graphical representation of simulation results. The following fuzzy methods and operations are implemented in the knowledge base using the SWI-Prolog environment:  simplified fuzzy inference method (Mori & Sone, 1998);  fuzzy values: min operation (Godo et al., 1991);  for single-point sets, a variation of the center of gravity method (Van Broekhoven & De Baets, 2006) is used.
15th IADIS International Conference Information Systems 2022

CONCLUSION
The proposed system is a software tool based on fuzzy logic. The system was implemented in the Prolog language of the SWI-Prolog environment using the XPCE library. The developed software tools can function on all operating systems, thereby ensuring cross-platform compatibility.
We plan further development of software tools and subsequent integration into a single adaptive system with the use of genetic algorithms in medical information systems.