Introduction

Obstructive sleep apnea (OSA) is the most common form of sleep-disordered breathing and its prevalence in the general population ranges from 6–17% up to 49% in aged subjects [3, 11]. OSA is characterized by repetitive collapse of the pharyngeal airway during sleep [17]. The cause of OSA is thought to be multiple morphological and functional alterations, whose relative contributions may vary between patients. These alterations may include anatomical factors decreasing the upper airway caliber, reduced activation of upper airway dilator muscles, increased chemoreceptor drive required to recruit the pharyngeal muscles, increased loop gain of the chemoreflex control of breathing, and increased respiratory arousal threshold [17]. Furthermore, OSA increases nocturnal blood pressure due to repetitive cycles of airway obstruction and has been associated with an increased risk of cardiovascular events such as stroke, unstable angina, heart failure, and myocardial infarction [5, 12].

The most effective treatment for OSA is the use of continuous positive airway pressure (CPAP), which physically counteracts the tendency of the upper airway to collapse in inspiration during sleep [17]. Good adherence to long-term CPAP treatment significantly reduces blood pressure in patients with OSA and resistant hypertension [6]. However, a recent systematic review and meta-analysis did not report significant evidence that CPAP therapy improves cardiovascular outcomes [5]. Insufficient CPAP adherence may be one of the factors that reduce the strength of the findings to support the CPAP benefit in all patients [5]. The CPAP systems are pressure-generating devices connected via flexible tubing to a nasal or an oronasal mask worn during sleep. CPAP usage is often sub-optimal due to discomfort, leading to the relapse of OSA[10] and, possibly, to suboptimal cardiovascular protection [5, 10]. Based on these considerations, adherence to CPAP should be regarded as the main determinant for therapeutic success. Self-reports are inaccurate tools to determine adherence to CPAP [15]. It is, therefore, of paramount importance to develop and test targeted and tailored interventions to measure and promote adherence to CPAP [9].

There is significant evidence that telemonitor care, defined as real-time feedback on compliance and problem solving, helps CPAP adherence in patients with OSA [2]. However, application of advanced devices for CPAP telemonitoring may depend largely on individual income, which may restrict their use to patients of higher socioeconomic status [2]. Most CPAP devices on the market currently have wireless built-in connectivity that allows for daily transfer of technical data via a central secured data center to sleep labs or home-care providers [1]. Some CPAP device manufacturers provide web platforms allowing physicians and patients to receive data on compliance, apnea-hypopnea index (AHI) and mask leaks (Table 1). However, companies employ their own proprietary algorithms making it difficult to carefully interpret the results [13]. The lack of standardization also hinders interoperability with existing electronic patient records and may be a problem for health care systems that employ CPAP devices of multiple brands [15]. The cost of CPAP telemonitoring systems and their compatibility with different CPAP devices and masks may, therefore, be key factors for their widespread application.

We aimed to provide proof of principle for the operation of a low-cost, self-standing system for CPAP telemonitoring. The system includes acceleration sensors attached to the CPAP mask and wrist and a mobile app, which collects data acquired by sensors and which feeds back to the patient through a chatbot, with the goal to improve adherence to CPAP treatment.

To our knowledge, our integrated system is technically novel in published scientific literature. A similar concept has been formulated in a patent application (WO 2016/192941 A1). The concept that the adoption of telemedicine may support OSA management and help obtain adequate adherence to CPAP is progressively gaining ground also in published literature [1, 2, 13, 15, 16].

In the following sections, we will provide a description of the architecture and first prototype of the proposed system, including the mask and wristband subsystems and the mobile app and chatbot, and detailing high-level algorithms to collect and analyze data from sensors. We will then provide a proof of principle of system function based on test recordings from the mask and wrist subsystems.

Table 1 Comparison between existing systems to monitor and increase continuous positive airway pressure usage

Proposed System: Architecture and First Prototype

We did not define a formal model of the system due to its technical simplicity. Rather, we designed the system architecture according to the requirements and then we moved to the implementation of a first prototype to support data retrieval and analysis.

The system purpose is to equip a CPAP mask with smart capabilities to monitor CPAP utilization during sleep. The monitoring result is represented by an accurate report of both patient and mask motion, generated to detect whether the patient wore the mask during the night and, in case, for how long. Finally, such information acts as input knowledge base for a chatbot able to discuss with the patient with the objective of increasing adherence to CPAP. Such a ICT system is the result of an integration of low-cost hardware and software technologies coming from the current mainstream information and communication technology scenario, and in particular: internet of medical things (IoMT) [4], mobile and wearable computing, and artificial intelligence (AI). Figure 1 shows a conceptualization of the system, composed of the following three main sub-parts:

Fig. 1
figure 1

System components

  • Mask subsystem: The embedded system to monitor the CPAP mask motion.

  • Wristband subsystem: The embedded system to monitor the patient motion.

  • Mobile app and chatbot: The mobile app to collect data from the mask and wristband subsystems and interact with users, with the option of exchanging information with a dedicated cloud server for data analysis.

Mask and Wristband Subsystems

The CPAP mask is equipped with an embedded device including a micro-controller (Bluno Beetle v.1.0) that monitors data from sensors (accelerometer ADXL-345) at a frequency of 50 Hz. A rapid prototyping instance of such a device can be obtained in low-budgeting (approx. $35). Algorithm 1 reports a high-level description of the routine deployed on the micro-controller ROM. The routine collects data from sensors and sends them to the mobile app in execution on the patient smartphone exploiting a Bluetooth low energy (BLE) connection, technically managed as a software serial. Data from sensors are collected accessing the data stream generated by sensors’ routine through the software serial and then transmitted to the mobile app via Bluetooth using common BLE libraries available for micro-controllers.

In particular, when the monitoring is active (the micro-controller behaves as in the SENDING state), it carries out a sampling of the acceleration values of the sensor, considering the desired sampling frequency. Such values, encoded according to a JSON format, are then sent to the mobile app.

An identical embedded device with the same software and hardware features is worn by the patient as a wristband on the dominant arm. Information produced by this device is sent to the smartphone app using another dedicated BLE connection with the purpose of improving the data analysis (Sect. 3).

figure a

Mobile App and Chatbot

On the patient’s smartphone, a dedicated app is executed. The app does not require any particular hardware: every smartphone supporting BLE connection is suitable. Our prototype was developed considering Google Android as the reference operating system. The mobile app is developed with two tasks. First, the app collects raw information from mask and wristband sensors to be processed by a properly designed algorithm. Data processing can be completed directly by the smartphone or, if more powerful computational resources are needed, sending collected data to the cloud and receiving back results. In this latter scenario, responses offered by the system can be more accurate than in the first one, but the patient might notice latency in receiving responses. Second, the app offers chatbot capability through its front-end user interface. A chatbot is an AI—acting in place of a human agent—used to conduct an on-line text conversation without the need of providing direct contact with a live person. Chatbots are becoming widely used in healthcare. However, particularly in the field of sleep medicine, there is not enough evidence regarding acceptability, potential risks and, most of all, capability of determining behaviour changes [14]. Nevertheless, studies have confirmed that engaging with patients by means of messaging can increase motivation and therefore improve compliance to treatment [7]. The chatbot can engage with the patient, help troubleshooting, and encourage adherence to CPAP treatment. In detail, when the patient wakes up, the chatbot can start a dialogue, exploiting analysed data of CPAP usage during the previous night. The chatbot may be used to:

  1. 1.

    Encourage the patient to continue using the mask;

  2. 2.

    Ask why he/she removed the mask in a particular moment;

  3. 3.

    Interview the patient about his/her health status, specific complaints regarding CPAP usage, and possibly other issues the patient wants to communicate to his/her treating physician, after expressing appropriate and informed consent to do so.

Figure 2 reports an example of a human-chatbot dialogue developed in our prototype: the chatbot engages the patient in conversation when he/she wakes up, asking feedback about the comfort in using the CPAP through interactions designed to deliver a satisfying user experience.

The chatbot may be improved exploiting libraries and API publicly available from the major social networks or cloud services, including, e.g., Telegram Bot APIFootnote 1, Google Dialogflow CXFootnote 2, and Amazon LexFootnote 3. These libraries and API implement advanced AI algorithms for natural language process and reasoning, thus enabling a higher level of interaction.

Fig. 2
figure 2

Example of a human-chatbot dialogue

Prototype Evaluation

The developed prototype is currently at an early stage of development. This section provides a preliminary discussion about the prototype technical performance and limitations.

First, since the system relates to the ICT area of embedded devices and IoT, an important consideration is about battery consumption. In the current version of the prototype, we considered two sets of batteries (mask subsystem: two 3.7 V 220 mAh batteries in series; wrist subsystem: two 3.7 V 650 mAh batteries in series) that were as light as possible but, at the same time, ensured autonomy for 4–6 h. In case of an industrialization of the prototype, other choices could be considered to optimize the subsystems in terms of form factor, power consumption, and battery duration. Our objective in the current stage of development was to demonstrate the effectiveness of the approach. On the smartphone side, no issues about power consumption have been detected with respect to typical smartphone usage. In fact, the developed app has been conceived to reduce consumption during its use, that is mainly limited to receiving data from the active BLE channels.

Second, regarding the chatbot dialogues and interactions with the patient, we developed a solution that mixes constrained responses according to proposed options and open-text answers given by the patient. The latter case is the more critical because the chatbot must interpret text, eventually exploiting dedicated online machine learning and AI services. Nonetheless, in the current ICT panorama, this is a well-known pattern for interacting with a chatbot that does not represent a possible point of failure for the proposed solution, in particular in terms of latency in the case of external/online requests for data analysis.

Data Analysis and Results

The mask subsystem sensor was designed to be fixed to a standard orofacial mask connected to a CPAP device. Triaxial acceleration data are sampled at 50 Hz. For each 1-min window and each axis of acceleration, a routine implemented in Matlab 2019b (The Matworks, Inc) computes the ratio between acceleration spectral power at frequencies \(< 0.35\) Hz vs. 0.35–2 Hz. The maximum of the three ratios (PR) that correspond to the three axes of acceleration is selected for each 1-min window. Physiological mechanisms such as breathing are expected to modulate the numerator of PR more than its denominator. The numerator and the denominator of PR are expected to be similarly modulated by white noise, including the noise potentially produced by the CPAP system functioning. Relatively high values of PR are, thus, consistent with periods with the mask put on, affording discrimination based on suitably selected threshold values. Simultaneous recordings with the wrist subsystem in the dominant arm as well as with the mask subsystem are designed to increase the accuracy of the discrimination of mask usage time above that based on the mask subsystem alone. The standard deviation of the acceleration recorded by the wrist device on the three axes is computed for each 1-min time window, and its maximum value among the three axes (referred to as SD) is selected for each window. Surges in SD are expected to reflect dominant arm movements to put on and take off the mask and are employed as markers to modify threshold values for mask-based discrimination of periods with mask on or off. Algorithm 2 reports a high-level description of the Matlab routine employed for data analysis.

figure b

To provide a proof of principle for system function, the system was self-tested by one of the authors, with the sensor fixed to a standard orofacial mask connected to a CPAP device (pressure 10 cm H20). We performed nine test recordings with a total duration of 34.5 h, of which 20.0 h with the mask off and 14.5 h with the mask on, while lying in bed either awake or asleep with the lights off. Timing was recorded in a sleep diary.

Fig. 3
figure 3

Representative raw and elaborated recordings from the mask and wrist subsystems. xyz ACC: triaxial acceleration. PR: maximum value of the spectral power ratio (0.017–0.333 Hz/0.350–2 Hz) of acceleration along the three axes computed over 1-min windows (mask: black; wrist: green). SD: maximum value of the standard deviation of acceleration along the three axes computed over 1-min windows. AU arbitrary units. Thick arrows: time when the mask was put on or taken off by one of the experimenters. Thin arrows: time when the continuous positive airway pressure (CPAP) device automatically switched off. In the bottom panels, red dots indicate 1-min windows with mask taken off as estimated based only on mask subsystem information

The accelerometer had sufficient sensitivity to detect the movements associated with putting the mask on and taking it off. In particular, these movements entailed wide and short-lasting fluctuations of the triaxial accelerations, which were evident as wide and short-lasting swings of the three colored traces in the top panel of Fig. 3b when the mask was put on (thick arrow to the left) and when it was taken off (thick arrow to the right).

However, the system was also sensitive to the mask vibrations produced by the operation of the CPAP device. This was evident in the top panel of Fig. 3b as the occurrence of apparently thicker colored lines (due to low-amplitude fluctuations at higher frequency) to the left than to the right of the thin arrows, which marked automatic switch-off of the CPAP device. A spectral analysis of acceleration raw data over 1 min windows revealed that the mask vibrations due to CPAP device operation had bandwidth extending at least up to 2 Hz. This was evident in the middle panel of Fig. 3b as an apparently lighter shade of blue (indicating a somewhat uniform distribution of spectral power) to the left than to the right of the thin arrows on the upper panel of Fig. 3b. Note that major movements of the mask, including those associated with putting the mask on and with taking it off (thick arrows, upper panel of Fig. 3b) entailed high values of the spectral power of acceleration at least up to 2 Hz (narrow yellow vertical stripes, middle panel of Fig. 3b).

Setting an empirical threshold at 1.5 for PR effectively discriminated the time with the mask taken off (red dots, bottom panel of Fig. 3b) from the time with the mask put on, regardless of the noise due to the vibrations generated by the CPAP device. This simple method identified CPAP usage with sensitivity \(84 \pm 11 \%\) and specificity \(84 \pm 6 \%\).

To explore the potential for accuracy improvements, two self-recording sessions (total duration: 4 h) were performed with simultaneous recordings from the mask and wrist (dominant arm) subsystems (top and middle panels of Fig. 3b). Clear-cut surges in SD (peaks of the green trace, bottom panel of Fig. 3b), indicating variability of wrist acceleration (wide short-lasting fluctuations of the colored traces, middle panel of Fig. 3b), accompanied the putting on and taking off of the mask (thick arrows, top panel, Fig. 3b). These surges represent markers to improve the discrimination of periods with mask on or off. As expected, the wrist subsystem (cf. green trace, bottom panel of Fig. 3b) was unaffected by the automatic switch-off of the CPAP device (thin arrow, top panel of Fig. 3b).

Discussion

We provided proof of principle for the operation of a low-cost, self-standing system for CPAP telemonitoring. Our prototype should be tested in samples of patients with OSA to validate adherence data against those recorded by CPAP machines, to confirm the system effectiveness, and to optimize the mask usage detection algorithm. In perspective, data on wrist acceleration may also be analyzed to estimate the time awake or asleep with the mask put on or taken off, employing algorithms for actigraphy scoring and therefore providing more detailed information on the patient’s sleep quality and duration.

Clinical testing should be preceded by pilot studies to fully develop the chatbot capabilities and design in a real-life clinical setting. Chatbot development, and in particular its method of collecting feedback and delivering messages to patients, should take account of all prior research investigating the role of specific message framing to improve adherence to CPAP [7], as well as of the risk of patients growing wary of the system in the course of treatment after an initial interest [1]. For instance, ‘gains and losses’ due to treatment are not equally perceived by patients: some patients experience a stronger emotional response from a ‘loss’ than from a similar ‘gain’ in their health status, or vice versa. Thus, a careful review by psychologists experts in ICT-patient interactions should evaluate our prototype in order to tailor the messages according to the patient’s profile. This should take proper account of cultural differences between populations, as well as of economic status and social factors, which could also conceivably affect CPAP compliance.

Development of CPAP telemedicine systems also cannot avoid tackling and successfully solving issues related to data security and patient privacy [15]. In this respect, for highest privacy settings, our mobile app may be operated with the local computational resources of the smartphone for data analysis. In these settings, patient interface may be limited to constrained responses according to proposed options.

Ideally, effective CPAP compliance would be assessed based on the time spent at the prescribed effective CPAP pressure per night, using a pressure monitor coupled with a microprocessor [15]. In its proposed form, our system estimates CPAP mask-on time, which may be larger than time of exposure to therapeutic airway pressure, for example in case of mask leaks. However, our system would be easily scalable to include information from mask pressure sensors as well as from a range of other relatively inexpensive sensors. These additional sensors may include ankle accelerometers to estimate leg movements during sleep [8], voltage sensors to measure the electrocardiogram, optic sensors to measure haemoglobin oxygen saturation, and the smartphone microphone to measure respiratory sounds such as snoring. The low-cost and open-source characteristics of our system may also allow integration with third-party mobile health applications such as the recently designed Appnea-Q mobile app [13] as well as with third-party wearable monitors [18].

The main limitation of our study is that we performed only a proof of principle of system function. In future clinical testing, it will be essential to perform recordings during the whole physiological nocturnal sleep period in patients with OSA, including at least 6 h of nocturnal sleep.

Novel Contribution

Most CPAP device manufacturers presently provide mHealth web platforms for CPAP telemedicine [13] (Table 1). Modern CPAP devices may be equipped with smart cards that store recorded data and may then be transported to the appropriate professional [15]. The production and operation costs of all these proprietary platforms and their related signal hardware are not public knowledge and cannot, therefore, be directly compared with those of our proposed system. Nevertheless, with a prototyping cost of approx. $35, our proposed system is arguably very competitive in terms of cost. However, our proposed system does require that the patient own at least a basic smartphone supporting BLE connection, which may still represent a budget barrier for some low-income patients. On the other hand, one of the major limitations of telemedicine devices for OSA is represented by the lack of a standardized device that can be adapted to different CPAP machines. In fact, companies provide CPAP machines with built-in compliance monitors. Our system can work in parallel with any built-in system and provide data on CPAP use.

Conclusions

In conclusion, our system may represent a unique tool to monitor and improve patients’ adherence to CPAP treatment, with resulting improvements in sleep quality, OSA symptoms, and, potentially, cardiovascular risk. The main strength of our proposed system and its improvement over existing devices lie in its simplicity, low cost, and independence from the specific CPAP device and mask employed.