LoginSignup
6
3

More than 3 years have passed since last update.

花粉症の重症度を判定し自分に合う市販薬を教えてくれるLINE Botの作成

Last updated at Posted at 2019-12-25

概要

プログラムの勉強を始めて半年ほどの開業医です。

そろそろスギ花粉の季節ですね。
2月の中旬ごろからスギ花粉は飛散開始します。花粉症の方はその前にお薬を準備しておくといいですね。

医療費削減のため一部の花粉症の薬が今後医療機関で処方できなくなるかもしれないといわれています。そうすると市販の薬で対応しなけらばならない花粉症患者さんが少なからず出てきそうです。そのような時に患者さんが困らないように、自分の花粉症の重症度が分かったり、自分に合った市販の花粉症薬が探せるサービスがあれば良いかと思い今回「花粉症の重症度を判定し自分に合う市販薬を教えてくれるLINE Bot」を作ってみました。

以前作ったWEBアプリはこちら
花粉症の重症度が分かるWEBアプリの作成~Auth0でユーザー認証~
自分に合った市販の花粉症薬を探すアプリの作成

動作確認

実装内容

・鼻アレルギー診療ガイドライン ―通年性鼻炎と花粉症― の診断アルゴリズムによる花粉症の重症度判定
・眠気の強さや効き目の強さ、服用回数、値段など自分の好みの市販のアレルギー薬の検索機能
・検索された薬剤とamazonのリンク

概念図

node.js expressでLINE bot APIを連携しました。
line nodejs.png

作成方法

1. Botアカウントを作成する

2. Node.jsでBot開発

3. ngrokでトンネリング

上記の1~3を以下の参考記事の通りに行います。
1時間でLINE BOTを作るハンズオン (資料+レポート) in Node学園祭2017

4. プログラム作成

重症度判定部分のコードの一部です。
今回は、LINE Developersのボタンテンプレートを使いました。


//重症度判定プログラム
  let [mes, count] = event.message.text.split(":");    

  if (event.message.type === 'text' && event.message.text === '判定') {
    return client.replyMessage(event.replyToken,

      {
        "type": "template",
        "altText": "This is a buttons template",
        "template": {
            "type": "buttons",
            "thumbnailImageUrl": "https://www.doi-jibika.net/images/material/11_img_01.jpg",
            "imageAspectRatio": "rectangle",
            "imageSize": "cover",
            "imageBackgroundColor": "#FFFFFF",
            "title": "あなたの花粉症の重症度を判定しましょう!くしゃみの回数は1日何回?",
            "text": "以下から選んでください",
            "defaultAction": {
                "type": "uri",
                "label": "View detail",
                "uri": "http://example.com/page/123"
            },
            "actions": [
                {
                  "type": "message",
                  "label": "21回以上",
                  "text": "くしゃみ:21回以上"
                },
                {
                  "type": "message",
                  "label": "20~11回",
                  "text": "くしゃみ:20~11回"
                },
                {
                  "type": "message",
                  "label": "10~6回",
                  "text": "くしゃみ:10~6回"
                },
                {
                  "type": "message",
                  "label": "5~1回",
                  "text": "くしゃみ:5~1回"
                },

            ]
        }
      }
    )
  }
  else if (event.message.type === 'text' && mes === 'くしゃみ') {

    console.log(count);
    return client.replyMessage(event.replyToken,

      {
        "type": "template",
        "altText": "This is a buttons template",
        "template": {
            "type": "buttons",
            "thumbnailImageUrl": "https://www.doi-jibika.net/images/material/11_img_02.jpg",
            "imageAspectRatio": "rectangle",
            "imageSize": "cover",
            "imageBackgroundColor": "#FFFFFF",
            "title": "鼻をかむ回数は1日何回?",
            "text": "以下から選んでください",
            "defaultAction": {
                "type": "uri",
                "label": "View detail",
                "uri": "http://example.com/page/123"
            },
            "actions": [
                {
                  "type": "message",
                  "label": "21回以上",
                  "text": "鼻水:21回以上/"+count
                },
                {
                  "type": "message",
                  "label": "20~11回",
                  "text": "鼻水:20~11回/"+count
                },
                {
                  "type": "message",
                  "label": "10~6回",
                  "text": "鼻水:10~6回/"+count
                },
                {
                  "type": "message",
                  "label": "5~1回",
                  "text": "鼻水:5~1回/"+count
                },

            ]
        }
      }
    )
  }
  else if (event.message.type === 'text' && mes === '鼻水') {

    console.log(count);
    return client.replyMessage(event.replyToken,

      {
        "type": "template",
        "altText": "This is a buttons template",
        "template": {
            "type": "buttons",
            "thumbnailImageUrl": "https://peta-eri.com/wp-content/uploads/2018/03/kafun_bottoshiteru.png",
            "imageAspectRatio": "rectangle",
            "imageSize": "cover",
            "imageBackgroundColor": "#FFFFFF",
            "title": "鼻づまりと口呼吸の程度はどのくらい?",
            "text": "以下から選んでください",
            "defaultAction": {
                "type": "uri",
                "label": "View detail",
                "uri": "http://example.com/page/123"
            },
            "actions": [
                {
                  "type": "message",
                  "label": "完全に口呼吸",
                  "text": "鼻閉:完全に口呼吸/"+count
                },
                {
                  "type": "message",
                  "label": "1日のうち、かなりの時間",
                  "text": "鼻閉:1日のうち、かなりの時間/"+count
                },
                {
                  "type": "message",
                  "label": "1日のうち、ときどきあり",
                  "text": "鼻閉:1日のうち、ときどきあり/"+count
                },
                {
                  "type": "message",
                  "label": "口呼吸ないが鼻閉あり",
                  "text": "鼻閉:口呼吸はないが鼻閉あり/"+count
                },

            ]
        }
      }
    )
  }

  else if (mes === '鼻閉') {    
    console.log(count);
    let [count3, count2, count1] = count.split("/");
    console.log(count1, count2, count3);
    if (count1 === "21回以上" || count2 === "21回以上" || count3 === "完全に口呼吸") {
      return client.replyMessage(event.replyToken,

        {
          "type": "template",
          "altText": "This is a buttons template",
          "template": {
            "type": "buttons",
            "thumbnailImageUrl": "https://peta-eri.com/wp-content/uploads/2018/03/kafun_bottoshiteru.png",
            "imageAspectRatio": "rectangle",
            "imageSize": "cover",
            "imageBackgroundColor": "#FFFFFF",
            "title": "あなたのアレルギーの重症度は最重症です。ステロイド点鼻薬の併用がおすすめです。",
            "text": "以下から選んでください",
            "defaultAction": {
              "type": "uri",
              "label": "View detail",
              "uri": "http://example.com/page/123"
            },
            "actions": [
              {
                'type' : 'datetimepicker',
                'label' : '日時を選択し重症度を記録',
                'data'  : '重症度:最重症',
                 'mode'  : 'datetime'
              },
              {
                "type": "message",
                "label": "ステロイド点鼻薬はこちら",
                "text": "ステロイド点鼻薬"
              },
              {
                "type": "message",
                "label": "自分に合った内服薬を探す",
                "text": "検索"
              },
              {
                "type": "message",
                "label": "花粉飛散情報",
                "text": "花粉飛散情報"
              },

            ]
          }
        }
      )
    }

考察

ボタンテンプレートを利用することによって、なかなかUIのよいBotを簡単に作ることが出来ました。今後、Firebaseを利用してデータの出し入れを行ったり、花粉飛散APIなどと連携していきたいと思っています。機能が増えたらまたご報告したいと思います。

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3