AndroidアプリとFlask Webアプリとのインターフェイス設計とデータベーステーブル定義は下記のとおりです
(1)登録時
リクエストデータ(JSON)
{
"emailAddress": "user1@examples.com",
"measurementDay":"2023-02-13",
"healthcareData":{
"sleepManagement":{
"wakeupTime":"05:30",
"sleepScore":89,
"sleepingTime":"06:17",
"deepSleepingTime":"01:10"
},
"bloodPressure":{
"morningMeasurementTime":"06:50",
"morningMax":118,
"morningMin":71,
"morningPulseRate":66,
"eveningMeasurementTime":"22:40",
"eveningMax":135,
"eveningMin":76,
"eveningPulseRate":57
},
"bodyTemperature":{
"measurementTime":null,"temperature":null
},
"nocturiaFactors":{
"midnightToiletVisits":1,
"hasCoffee":true,
"hasTea":false,
"hasAlcohol":false,
"hasNutritionDrink":true,
"hasSportsDrink":false,
"hasDiuretic":false,
"takeMedicine":false,
"takeBathing":false,
"conditionMemo":"風邪気味で風邪薬を飲んだ"
},
"walkingCount":{
"counts":8518
}
},
"weatherData": {
"weatherCondition":{
"condition":"曇りのち雪"
}
}
}
レスポンスOK(JSON)
{
"data": {
"emailAddress": "user1@examples.com",
"measurementDay": "2023-02-13"
},
"status": {
"code": 0,
"message": "OK"
}
}
レスポンスNG(JSON)
{
"status": {
"code": 400,
"message": "461,User is not found."
}
}
(2)更新時
リクエストデータ(JSON)
{
"emailAddress": "user1@examples.com",
"measurementDay":"2023-02-13",
"healthcareData":{
"sleepManagement":{
"wakeupTime":"05:30",
"sleepScore":91,
"sleepingTime":"06:30",
"deepSleepingTime":"00:40"
}
},
"weatherData": {
"weatherCondition":{
"condition":"雪"
}
}
}
レスポンスOK(JSON)
{
"data": {
"emailAddress": "user1@examples.com",
"measurementDay": "2023-02-13"
},
"status": {
"code": 0,
"message": "OK"
}
}
レスポンスNG(JSON)
{
"status": {
"code": 400,
"message": "461,User is not found."
}
}
(3)データ取得時
レスポンスOK(JSON)
{
"data": {
"emailAddress": "user1@examples.com",
"healthcareData": {
"bloodPressure": {
"eveningMax": 124,
"eveningMeasurementTime": "22:20",
"eveningMin": 72,
"eveningPulseRate": 59,
"morningMax": 112,
"morningMeasurementTime": "06:45",
"morningMin": 67,
"morningPulseRate": 65
},
"bodyTemperature": {
"measurementTime": null,
"temperature": null
},
"nocturiaFactors": {
"conditionMemo": null,
"hasAlcohol": false,
"hasCoffee": true,
"hasDiuretic": true,
"hasNutritionDrink": false,
"hasSportsDrink": false,
"hasTea": false,
"midnightToiletVisits": 4,
"takeBathing": false,
"takeMedicine": true
},
"sleepManagement": {
"deepSleepingTime": "01:10",
"sleepScore": 78,
"sleepingTime": "06:00",
"wakeupTime": "05:30"
},
"walkingCount": {
"counts": 8576
}
},
"measurementDay": "2023-02-13",
"weatherData": {
"weatherCondition": {
"condition": "曇りのち雪"
}
}
},
"status": {
"code": 0,
"message": "OK"
}
}
レスポンスNG(JSON)
{
"status": {
"code": 404,
"message": "Data is not found."
}
}
CREATE ROLE developer WITH LOGIN PASSWORD 'dev%5588';
--install pgcrypto that is required superuser.
ALTER ROLE developer WITH SUPERUSER;
CREATE DATABASE sensors_pgdb WITH OWNER=developer ENCODING='UTF-8'
LC_COLLATE='ja_JP.UTF-8' LC_CTYPE='ja_JP.UTF-8' TEMPLATE=template0;
GRANT ALL PRIVILEGES ON DATABASE sensors_pgdb TO developer;
CREATE TABLE IF NOT EXISTS weather.weather_condition(
measurement_day date NOT NULL,
condition VARCHAR(60) NOT NULL,
CONSTRAINT pk_weather_condition PRIMARY KEY (measurement_day)
);
CREATE DATABASE healthcare_db WITH OWNER=developer ENCODING='UTF-8'
LC_COLLATE='ja_JP.UTF-8' LC_CTYPE='ja_JP.UTF-8' TEMPLATE=template0;
GRANT ALL PRIVILEGES ON DATABASE healthcare_db TO developer;
-- スキーマ名(体健康)
CREATE SCHEMA IF NOT EXISTS bodyhealth;
-- ユーザーテーブル
CREATE TABLE IF NOT EXISTS bodyhealth.person(
id smallint NOT NULL,
email varchar(50) NOT NULL,
name varchar(24) NOT NULL,
CONSTRAINT pk_person PRIMARY KEY (id)
);
CREATE UNIQUE INDEX idx_person_email ON bodyhealth.person (email);
-- 睡眠管理テーブル
CREATE TABLE IF NOT EXISTS bodyhealth.sleep_management(
pid smallint NOT NULL,
measurement_day date NOT NULL,
wakeup_time time without time zone NOT NULL,
sleep_score smallint,
sleeping_time time without time zone NOT NULL,
deep_sleeping_time time without time zone
);
-- 血圧管理テーブル
CREATE TABLE IF NOT EXISTS bodyhealth.blood_pressure(
pid smallint NOT NULL,
measurement_day date NOT NULL,
morning_measurement_time time without time zone,
morning_max smallint,
morning_min smallint,
morning_pulse_rate smallint,
evening_measurement_time time without time zone,
evening_max smallint,
evening_min smallint,
evening_pulse_rate smallint
);
-- 体温測定テーブル: 任意
CREATE TABLE IF NOT EXISTS bodyhealth.body_temperature(
pid smallint NOT NULL,
measurement_day date NOT NULL,
measurement_time time without time zone,
temperature real
);
-- 歩数テーブル
CREATE TABLE IF NOT EXISTS bodyhealth.walking_count(
pid smallint NOT NULL,
measurement_day date NOT NULL,
counts smallint NOT NULL
);
-- 夜中トイレ回数要因テーブル
CREATE TABLE IF NOT EXISTS bodyhealth.nocturia_factors(
pid smallint NOT NULL,
measurement_day date NOT NULL,
midnight_toilet_visits smallint NOT NULL,
has_coffee boolean,
has_tea boolean,
has_alcohol boolean,
has_nutrition_drink boolean,
has_sports_drink boolean,
has_diuretic boolean,
take_medicine boolean,
take_bathing boolean,
condition_memo varchar(255)
);