Skip to main content
Journal of Taibah University Medical Sciences logoLink to Journal of Taibah University Medical Sciences
. 2021 Jul 4;16(5):740–746. doi: 10.1016/j.jtumed.2021.06.002

Web-based chatbot for Frequently Asked Queries (FAQ) in Hospitals

Mamta Mittal a, Gopi Battineni b,, Dharmendra Singh a, Thakursingh Nagarwal a, Prabhakar Yadav a
PMCID: PMC8498791  PMID: 34690656

Abstract

Objectives

Local hospitals are operated by the resigned association of patients as passive communication channels. The online hospital data related to the users’ queries are not transparent and reliable. Therefore, it is crucial to have an intelligent web chatbot that manages user requests and provides quick access to local hospital information. In this paper, we present a framework and functionality of a chatbot developed using web technologies.

Methods

The bot engine was integrated by several machine learning approaches like gradient descent (GD) and natural language processing (NLP) algorithms. The trained data entered into the bot were split into mini-word batches, and the GD algorithm was applied sequentially on each mini-batch. The NLP methods involved in converting a word to its stem with a text result less readable by humans.

Results

The employed ML algorithms were successfully incorporated to manage the alternative synchronisation of text and voice messages.

Conclusions

The proposed bot can be a better solution for data extraction from local hospital which functioning as a good communication channel for both users and hospital staff and helpful in reducing the crowd.

Keywords: Bagging, Hospital bot, Natural language processing, Neural networks, Query, Web technologies

Introduction

A chatbot is a type of software that can communicate with humans. It is integrated with Artificial Intelligence (AI) techniques such as machine learning (ML) and natural language processing (NLP).1 These conversational agents are specially designed as a user interface (UI) that engages as a communication channel. Currently, chatbots are integrated into every business, including hospitals, banks, transport, and other services. There is a great demand for them to work as information agents providing instant responses in the healthcare industry.

Hospitals or healthcare organisations manage patient communications through rudimentary web operations.2 Web-based chatbots overcome this by allowing conversations between hospital staff and patients to collect insights on facilities available in the hospital.3 Chatbots have been receiving close attention in healthcare because these conversational agents provide easy access to information and function as an interactive platform offering personal engagement.4 Medical chatbots provide the necessary information by including classification and ML algorithms.5 The chatbot developed in6 has successfully maintained responses for disease predictions, medication recommendation, doctor availability, and others by adopting simple ML techniques. Additionally, web-based chatbots based on NLP can assess patient sentiments and improve quality care.7

Additionally, the other two popular conversational agents, ELIZA and A.L.I.C.E (Artificial Linguistic Internet Computer Entity), are known as the first human interaction chatbots. ELIZA operates using computational linguistics with simply parsing and keyword substitution into reframed phrases.8 Therefore, it can understand user experiences and feelings. This conversational agent initiates the user chat with simple sentence structure and punctuation, and the user statement is ended with a twofold carriage response. However, A.L.I.C.E can convert readable texts (i.e. corpus) into Artificial Intelligence Markup Language (AIML) to disclose the possibility of useful prototypes without complex ML algorithms.9 It also incorporates NLP techniques that help engage in human conversation by applying heuristically matched rules to the user input. It was inspired by the old ELIZA program.

However, these existing systems failed to save the chat history and were not fully customised to understand the user's ultimate message. Thus, these bots did not fully understand what the user said and provided responses from the knowledge stored in the bot brain. Therefore, we developed a special chatbot that includes collecting local hospital information responses by integrating web-based techniques. Present medical chatbots are integrated with speech recognition such that users can communicate through either voice or text messages.

The major objective of this work is to explain the importance of medical chatbots and present our developed medical chatbot, developed on internet technologies. Our chatbot also assists user queries regarding hospital information, including specialists' availability, OPD timings, room registration, number of beds, emergency information, and doctor availability, among others. This is the first real-time developed medical chatbot for query queue management in hospitals based on the literature survey. Additionally, it improves users’ satisfaction by providing answers to all their health and personal assistance related queries. The proposed chatbot virtually assists users like real reception staff of a hospital. It provides users with total medical assistance 24∗7.

Materials and Methods

Gradient descent algorithm

To implement a chatbot, several techniques and optimisation algorithms are available. Gradient Descent (GD) is an optimisation algorithm used to evaluate the coefficients of function (f) that minimise the cost function.10 It is a primary optimisation algorithm to assess the minimum cost function. The presented bot adopts a mini-batch GD algorithm. By applying the GD algorithm, the model can be accommodated easily in memory with low noise. For instance, if the trained set has 100 training examples, then it is divided into five batches with each batch of 20 training examples, explained as follows:

The GD procedure

  • The algorithm starts with some small random values (possibly 0.0) of the function. i.e., coefficient = 0.0

  • The coefficient costs are calculated by inserting them into the function. i.e., cost = f (coefficient).

  • The derivative cost can be calculated to assess the lower cost in further iterations. i.e., Delta () = derivative (cost).

  • A learning parameter (α) is introduced to control the coefficient change for every update.

Coefficient = coefficient(α)
  • These steps are repeated until the cost of the coefficients is nearly equal to zero.

By combining these steps, the mini-batch GD function can be presented as,

θ=θη.θJ(θ;x(i;i+n)y(i;i+n))

Accordingly, by integrating with different machine learning algorithms such as GD, NLP, and feed-forward neural network (FNN), the chatbot can produce accurate output responses. The description of each algorithm has been discussed in further sections.

Natural language processing techniques

NLP is an integral part of AI that deals with interactions between human languages and computers. Stemming is a sub-stream of NLP techniques, which reduces a word to its stem with a text result, less readable by humans. It is an algorithm that converts the word into a root word.11 In addition to GD, text classification algorithms are included to evaluate better outcome response. Initially, the user inputs are applied to the NLP framework to generate an output response. The input undergoes different steps such as tokenisation, stemming, and enumeration and converted to a bag of words. In tokenisation, simple tokens are broken into simple words. Next, the tokens are transferred as root words; this is called stemming. The bag of words model pre-processes the given text by converting its simple words and keeps a count of total occurrences of high-frequency words. Finally, the bag of words produces the input for the ANN model and evaluates individual probabilities of each response to generate the highest probability words as outcomes fetched from the JavaScript object notation (JSON) file.

Text to speech/Speech to text conversation

The text to speech (TTS) system converts natural human language text into speech.12 Speech is a general way of communication between human beings. Texting and voice are becoming a major bot interface. Soon there will be high demand for speech-enabled chatbots. The TTS system integrated with the proposed chatbot comprises two parts, a front-end and a back-end. TTS converts raw text to numbers and abbreviations into the equivalent of text out words in the front end. Additionally, it assigns phonetic transcriptions to each word and divides the given text into prosodic units like phrases, clauses, and sentences. Finally, the back-end converts the symbolic linguistic representation into sound.

The speech to text (STT) system is trained to accept input like human speech to interpret and transcribe into text. The proposed chatbot has inbuilt technology to break long sentences or words into distinct phonemes. It works based on complex algorithms to create precise text and presents the user's speech to the bot, transforming verbal speech into understandable text.13

Results

The working of a web-based medical chatbot, majorly associated with two functional operations, included word prediction and pattern matching. In this section, the authors present a comprehensible explanation of those operations.

Functionality operations

Pattern matching behaviour of testing outcomes

The pattern matching algorithm followed by the presented bot is similar to that of the ALICE bot system. The employed AIML interpreter matches each word to large patterns to determine the best fit. We tested the bot with different categories of commands to verify the response. Here are four category examples of the commands supplied to the bot.

(1) <category>
<pattern> HOW ARE YOU DOING TODAY </pattern>
<template><sr/> <srai> HOW ARE YOU DOING TODAY</srai></template>
</category>
(2) <category>
<pattern> HOW ARE YOU DOING </pattern>
<template> <random> <li> GOOD</li><li>NOT SO </li><li> WELL </li><li> NOT BAD</li></random></template></category>
(3) <category>
<pattern> HELO </pattern>
<template> <srai>HELLO</srai></template>
</category>
(4) <category>
<pattern> HELLO </pattern>
<template> <random> <li>HI THERE! </li><li>WELL HELLO THERE! </li> <li> HELLO THERE </li><li> HI THERE, CAN I TALK TO YOU </li></random></template>
</category>
User Input: HELO HOW ARE YOU DOING TODAY
Bot response: HI THERE! GOOD.

Figure 1 depicts the tree structure pattern matching procedure.

Figure 1.

Figure 1

The tree structure of pattern matching behaviour.

Word prediction model development

We used a fairly standard model of a feed-forward neural network with two hidden layers. FNN is an artificial neural network in which information moves in only one direction, forward from the input nodes, via the hidden nodes, and to the output nodes. The goal of this network is to assign a class to each word from a bag of words (one of the tags from the JSON file). The trained data are split into small word batches, and the GD algorithm is applied to every batch sequentially to find the appropriate response. It makes the algorithm function faster and efficiently. Only a single batch of words can be passed through the neural networks at a time to compute the loss of every sample batch. Their average is used to update the neural network parameters. The mini-batch descent algorithm finds the best of two words and updates each mini-batch of nn training samples. In a given command, the trained set has 1000 training examples. It is divided into eight batches, with each batch comprising 125 training examples. Model training is conducted using the number of epochs, set according to the number of times that the model will encounter the same information while training. The training command of the model is:

model.fit (training, output, n_epoch=1000, batch_size=8, show_metric=True)
model. save ("model.tflearn")

The outcome model is saved as a model.tflearn to include future scripts. This model is trained by the mini-batch GD algorithm. The model predictions are obtained by feeding the bag of words based on the high probability words selected. Thus, the process generates a response, as shown in Figure 2. Next, the chat function obtains a prediction from the model and grabs an appropriate response from the given JSON file.

Figure 2.

Figure 2

Word prediction model.

Bot designing steps and architecture

The designed chatbot in the study engages with users via a microphone and simultaneous translation of voice to text and text to voice using deep neural networks, producing the relevant matched text response (output). The step-by-step designing of the chatbot has been discussed below.

  • The user starts the conversation by selecting a special code number of a particular hospital. Once the hospital is selected, the corresponding JSON file of that hospital is loaded, including all queries requested by the user related to that hospital. A JSON file with the predefined tags, patterns, and responses encompassing the bot functionality is also included. Integrating with the Google application programming interface (API), the bot can simultaneously respond to voice and text conversations.

  • In the second step, users' queries are accepted through the microphone. Here, the microphone can be in-built or external and can work as a data transmission source. The web-kit speech recognition API is used to recognise the user input, voice or text.

  • In the third step, the input voice is converted into corresponding text using a web-kit speech recognition API. Subsequently, the text data can be analysed using special NLP algorithms like bagging.

  • In the fourth step, the matched responses to the corresponding voice message are converted using gTTS (Google Text-to-Speech) API. Finally, the audio response output is played using the play sound function of the python module and is spoken out through the speaker.

In the end, users can decide whether to continue with the same hospital by providing the next set of queries or switch to another hospital by asking queries particular to it. If a user wants to continue with the same hospital, control moves to steps 2 to 4. However, if a user wants to switch to another hospital, a simple voice or text command can trigger step 1.

The user can ask any query through text or voice without being physically available at the hospital. Thus, the system can conduct a one-to-one conversation with patients and saves time instead of waiting in long queues. This section presents the functional framework of chatbots and NLP preliminary outcomes. The designed bot includes a speech recognition feature to decode voice input and output, stored in a database of the JSON files. Each hospital database is associated with multiple JSON files. When the user enquires about a hospital, the corresponding JSON file is triggered to present relevant responses. Each hospital has a unique identification number. Switching between different hospitals is possible using the command ‘change hospital’. At the front-end, the microphone, used as a speech input source, converts voice to text. This is implemented using python language, including play sound and gTTS modules. A user interface is created using a flask and HTML, CSS, AJAX, and JavaScript. Here, HTML and CSS are used to create the User Interface (UI) structure and page styling, while JavaScript is used to make the web page dynamic and interact with the main python code at the back-end.

The web-based UI manages patient queries through either text or voice and displays the response.14 The user can use the microphone button to deliver voice messages. Based on the voice input system, the response is displayed. Subsequently, the user confirms the response using the send button. Simultaneously, users can use text input for inquiry and response outcomes generated in text and voice form. The architecture of the proposed web-based chatbot is depicted in Figure 3.

Figure 3.

Figure 3

The functional framework for the proposed web-based chatbot

Chatbot performance

The performance of the developed chatbot is defined based on two factors, accuracy and loss. Accuracy is defined as the correct intent returned for the percentage of speech. Overall accuracy is the number of correct predictions vs. the total number of predictions. The accuracy of a neural network depends on many factors, such as the activation function and the number of neurons, among others. We successfully obtained 100% accuracy from the 393rd iteration step for the chatbot trained for approximately 1000 epochs. The accuracy was consistent till the last iteration.

Loss is defined as the percentage of prediction error in the neural network model. The loss function is an important component of neural networks. Loss is used to calculate the gradients and gradient update of the weights of the neural network. The loss function of our chatbot is decreasing from the first iteration and falls to 0 at the 697th iteration. The decrease in loss function starts from the 29th iteration and consistently declines till the last iteration. This proves the efficiency of our chatbot. Figure 4 represents the overall performance of the chatbot model developed.

Figure 4.

Figure 4

Overall chatbot performance curves.

Discussion

Medical chatbots have become popular because of the new ways of communication between patients and doctors. For a decade, many health organisations have adopted these bots in their work. In emergency health conditions, every patient requires information regarding available local hospitals, including information about doctors’ availability, bed facilities, and ambulance services, among others. However, it is not easy to be physically present in emergencies.

Healthcare organisations are adopting modern knowledge through AI technology to manage patient feedback.15 Both AI and NLP are becoming more popular in the medical domain with the continuous advancement of information technology.16,17 Several computing developers have developed effective and efficient systems by including these techniques to save users time and provide accurate results.17 This study presents a designed chatbot application to manage all patient queries regarding different hospitals. The platform uses a training algorithm to train the chatbot depending on a bag of words, helping the patients find responses to corresponding queries. Additionally, the system automatically retrieves the updated hospital information with beds and doctor availability. Subsequently, it sends an input variable to the neural networks to compare other possibilities to recommend similar hospital facilities.

People fall ill at any time, and sometimes, it leads them to mortality. Accordingly, every user anticipates searching for the nearest hospital or health care centre, including better medical facilities. Instead of surfing for the individual hospital site, the present bot produced collective information of medical centres in a domestic region. The front-end of the web-based bot is developed using HTML and JavaScript languages. The engine integrated with NLP techniques behaves as back-end logic to understand user response via API calls.

The efficiency of the chatbot can be improved by adding more combinations of words and increasing the use of the database so that the medical chatbots can handle all types of queries.18 Even voice conversation and Speech Recognition can be added to the system for ease of use. Chatbots have become increasingly more popular in the past two years and are accepted widely. They bring new ways to communicate with humans and make communication interesting. Furthermore, the rise of technologies and AI provide convenience to users.19 Normally when a person visits the hospital, they first go to the help desk to collect information about the doctors, registration, and blood bank, among others. Our chatbot, Chatbot for Hospital Management, helps the users by providing all the necessary information about a hospital in just one click. It proves to be a great help to society as it helps avoid time-consuming long queues at the help desk in any hospital. Hence, our medical chatbot is more useful for different patients seeking various medical assistance.

There are some established medical chatbots like Health Online Medical Suggestion (HOLMeS) and IBM Watson.20 Both bots are well known in the medical industry for their deep learning and NLP approaches. However, these systems are not well developed for word prediction models and pattern matching behaviours. Instead, they create a smooth interaction with the patient to help them with supplied knowledge. Thus, they limit the ability to generate new knowledge.21 However, the designed bot has a special feature of voice recognition, a better graphical interface, and emergency information of city hospitals. When the patient is in a serious condition, this system allows the user to check for hospitals with the appropriate medical opportunities, including emergency. Additionally, it can assist hospital staff to display user responses for particular queries. This proposed web application can allow users to develop an idea about the medical facilities of local hospitals. Moreover, the user can alternate between hospitals using the command ‘change hospital’ and inquire about that particular hospital. NLP techniques like stemming and tokenisation are employed to generate an explicit response.

The present system is a speech recognition based chatbot related to health care. Here, users can request queries through a microphone, and the speech is translated into text using NLP. Then, this text is analysed through deep neural networks to match the relevant response in the corresponding JSON files (the user can select any hospital of his/her own choice, and then that particular JSON file gets loaded). Thereafter, the matched outcome text will be converted into audio, supplied as input to the microphone.

Despite the advantages, the developed bot has some limitations. First, even if the response is quick, there are limited responses to users’ questions. Second, setting up AI on a large scale and testing can be expensive for hospital authorities. However, the bots can learn automatically with little time consumption. Additionally, hospitals aim to provide better healthcare services, reliable data, and good quality care. Thus, information sharing must be transparent between the service provider and patient. However, ensuring reliable information is updated into the standardised medical database would add extra workload to hospital management staff. Therefore, automated data update frameworks have to be incorporated, and presently, no such methods are available.

Conclusions

In this work, the authors presented a patient-friendly chatbot on hospital management, designed to provide all the important information of a hospital in simply one click. The system includes natural language processing methods to interpret human language such that it can identify grammatically incorrect or incomplete sentences using a similar bag of words approach. The chatbot is user friendly and can be used by any person who knows how to type in their language in a computer. Additionally, the medical chatbot provides the details of the availability of doctors. In the future, the symptom recognition and diagnosis performance could be greatly improved by more medical features, such as location, duration, and intensity of symptoms, and more detailed symptom descriptions. Thus, the medical chatbot has a vast future scope. No matter how far people are, they can have access to medical facilities.

Source of funding

This research did not receive any specific grant from funding agencies in the public, commercial, or not for profit sectors.

Conflict of interest

The authors have no conflict of interest to declare.

Ethical approval

The authors did not have permission for direct communication with a human participant in the study, and no ethical issues were encountered during the study presentation.

Authors' contribution

MM and GB conceived and designed the study, conducted research, provided research materials, and collected and organised data; DS: analysed and designed the framework; TSN, GB, and PY Wrote the initial and final drafts of the article and provided logistic support. All authors critically reviewed and approved the final draft and are responsible for the manuscript's content and similarity index.

Footnotes

Peer review under responsibility of Taibah University.

References

  • 1.Singh R., Paste M., Shinde N., Patel H., Mishra N. Proceedings of the international conference on inventive communication and computational technologies, ICICCT 2018. 2018. Chatbot using TensorFlow for small businesses. [DOI] [Google Scholar]
  • 2.Amato F., Marrone S., Moscato V., Piantadosi G., Picariello A., Sansone C. CEUR workshop proceedings. 2017. Chatbots meet ehealth: automatizing healthcare. [Google Scholar]
  • 3.Palanica A., Flaschner P., Thommandram A., Li M., Fossat Y. Physicians' perceptions of chatbots in health care: cross-sectional web-based survey. J Med Internet Res. 2019;21(4) doi: 10.2196/12887. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 4.Kamita T., Ito T., Matsumoto A., Munakata T., Inoue T. A chatbot system for mental healthcare based on SAT counseling method. Mobile Inf Syst. 2019 doi: 10.1155/2019/9517321. [DOI] [Google Scholar]
  • 5.Battineni G., Chintalapudi N., Amenta F. AI chatbot design during an epidemic like the novel coronavirus. Healthcare. 2020 doi: 10.3390/healthcare8020154. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 6.Mathew R.B., Varghese S., Joy S.E., Alex S.S. Proceedings of the international conference on trends in electronics and informatics, ICOEI 2019. 2019. Chatbot for disease prediction and treatment recommendation using machine learning. [DOI] [Google Scholar]
  • 7.Fan X., Chao D., Zhang Z., Wang D., Li X., Tian F. Utilization of self-diagnosis health chatbots in real-world settings: case study. J Med Internet Res. 2021 Jan 6;23(1):e19928. doi: 10.2196/19928. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 8.Weizenbaum J. ELIZA—a computer program for the study of natural language communication between man and machine. Commun ACM. 1983 doi: 10.1145/357980.357991. [DOI] [Google Scholar]
  • 9.Shawar B.A., Atwell E. ALICE chatbot: trials and outputs. Comput Sist. 2015 doi: 10.13053/CyS-19-4-2326. [DOI] [Google Scholar]
  • 10.Andrychowicz M., Denil M., Colmenarejo S.G., Hoffman M.W., Pfau D., Schaul T. Advances in neural information processing systems. In Proceedings of the 30th International Conference on Neural Information Processing Systems (NIPS’16) Curran Associates Inc; Red Hook, NY, USA: 2016. Learning to learn by gradient descent by gradient descent; pp. 3988–3996. [Google Scholar]
  • 11.Mittal M., Iqbaldeep K., Chandra Pandey S., Verma A., Mohan Goyal L. Opinion mining for the tweets in healthcare sector using fuzzy association rule. EAI Endorsed Trans Pervasive Heal Technol. 2018 doi: 10.4108/eai.13-7-2018.159861. [DOI] [Google Scholar]
  • 12.Shiga Y., Ni J., Tachibana K., Okamoto T. SpringerBriefs in computer science. 2020. Text-to-speech synthesis. [DOI] [Google Scholar]
  • 13.Arik S., Chrzanowski M., Coates A., Diamos G., Gibiansky A., Kang Y. 34th international conference on machine learning, ICML 2017. PMLR 70; 2017. Deep voice: real-time neural text-to-speech. [Google Scholar]
  • 14.Hui S.L.T., See S.L. Enhancing user experience through customisation of UI design. Procedia Manuf. 2015 doi: 10.1016/j.promfg.2015.07.237. [DOI] [Google Scholar]
  • 15.Jiang F., Jiang Y., Zhi H., Dong Y., Li H., Ma S. Artificial intelligence in healthcare: past, present and future. Stroke Vasc Neurol. 2017 Jun 21;2(4):230–243. doi: 10.1136/svn-2017-000101. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 16.Siddique S., Chow J.C.L. Machine learning in healthcare communication. Encyclopedia. 2021;1(1):220–239. doi: 10.3390/encyclopedia1010021. [DOI] [Google Scholar]
  • 17.Butow P., Hoque E. Using artificial intelligence to analyse and teach communication in healthcare. Breast. 2020;50:49–55. doi: 10.1016/j.breast.2020.01.008. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 18.Følstad A., Brandtzaeg P.B. Users' experiences with chatbots: findings from a questionnaire study. Qual User Exp. 2020;5(1):3. doi: 10.1007/s41233-020-00033-2. [DOI] [Google Scholar]
  • 19.Buch V.H., Ahmed I., Maruthappu M. Artificial intelligence in medicine: current trends and future possibilities. Br J Gen Pract. Published online. 2018 doi: 10.3399/bjgp18X695213. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 20.Nisbet R., Miner G., Yale K. Handbook of statistical analysis and data mining applications. 2018. IBM watson. [DOI] [Google Scholar]
  • 21.Brandtzaeg P.B., Følstad A. Vol. 10673. Springer Verlag; 2017. Why people use chatbots; pp. 377–392. (Lecture notes in computer science). (including subseries lecture notes in artificial intelligence and lecture notes in bioinformatics) LNCS. [DOI] [Google Scholar]

Articles from Journal of Taibah University Medical Sciences are provided here courtesy of Taibah University

RESOURCES