From 42e6ac73d00e61d519bd743ac18e924b40b82e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E9=96=93?= Date: Mon, 24 Apr 2023 18:20:08 +0900 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E8=A6=8F=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../concrete/com_rehabili_mapper.py | 96 +++++++++ .../utmp_tables/tables/com_rehabili.py | 14 ++ .../ultmarc_table_mapper_factory.py | 4 +- .../table_mapper/com_rehabili/__init__.py | 0 .../com_rehabili/com_rehabili_delete.csv | 7 + .../com_rehabili/com_rehabili_insert.csv | 6 + .../com_rehabili/com_rehabili_update.csv | 5 + .../db_com_rehabili_before_delete.csv | 6 + .../db_com_rehabili_before_update.csv | 6 + .../expect_com_rehabili_delete.csv | 7 + .../expect_com_rehabili_insert.csv | 7 + .../expect_com_rehabili_update.csv | 6 + .../com_rehabili/test_com_rehabili_mapper.py | 197 ++++++++++++++++++ 13 files changed, 360 insertions(+), 1 deletion(-) create mode 100644 ecs/jskult-batch-daily/src/batch/ultmarc/utmp_tables/table_mapper/concrete/com_rehabili_mapper.py create mode 100644 ecs/jskult-batch-daily/src/batch/ultmarc/utmp_tables/tables/com_rehabili.py create mode 100644 ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/__init__.py create mode 100644 ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/com_rehabili_delete.csv create mode 100644 ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/com_rehabili_insert.csv create mode 100644 ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/com_rehabili_update.csv create mode 100644 ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/db_com_rehabili_before_delete.csv create mode 100644 ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/db_com_rehabili_before_update.csv create mode 100644 ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/expect_com_rehabili_delete.csv create mode 100644 ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/expect_com_rehabili_insert.csv create mode 100644 ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/expect_com_rehabili_update.csv create mode 100644 ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/test_com_rehabili_mapper.py diff --git a/ecs/jskult-batch-daily/src/batch/ultmarc/utmp_tables/table_mapper/concrete/com_rehabili_mapper.py b/ecs/jskult-batch-daily/src/batch/ultmarc/utmp_tables/table_mapper/concrete/com_rehabili_mapper.py new file mode 100644 index 00000000..1ff87694 --- /dev/null +++ b/ecs/jskult-batch-daily/src/batch/ultmarc/utmp_tables/table_mapper/concrete/com_rehabili_mapper.py @@ -0,0 +1,96 @@ +from src.batch.ultmarc.utmp_tables.table_mapper.ultmarc_table_mapper import \ + UltmarcTableMapper +from src.batch.ultmarc.utmp_tables.tables.com_rehabili import ComRehabili + + +class ComRehabiliMapper(UltmarcTableMapper): + """レイアウト区分027: COM_疾患別リハビリテーション科 登録処理""" + + # レコード存在確認SQL + RECORD_EXISTS_QUERY = """\ + SELECT + COUNT(*) AS count_num + FROM + src05.com_rehabili + WHERE + rehabili_cd = :rehabili_cd + """ + # データ登録用SQL + INSERT_QUERY = """\ + INSERT INTO src05.com_rehabili + ( + rehabili_cd, + rehabili_name, + regist_ymd, + sys_regist_date, + regist_prgm_id, + sys_update_date, + update_prgm_id + ) + VALUES ( + :rehabili_cd, + :rehabili_name, + :execute_date_str_ymd, + :execute_datetime, + :program_name, + :execute_datetime, + :program_name + ) + """ + + UPDATE_QUERY = """\ + UPDATE + src05.com_rehabili + SET + rehabili_name = :rehabili_name, + update_ymd = :execute_date_str_ymd, + delete_ymd = NULL, + sys_update_date = :execute_datetime, + update_prgm_id = :program_name + WHERE + rehabili_cd = :rehabili_cd + """ + + # 修正区分が「C(削除)」の場合の更新SQL + LOGICAL_DELETE_QUERY = """\ + UPDATE + src05.com_rehabili + SET + delete_ymd = :execute_date_str_ymd, + sys_update_date = :execute_date_str_ymd, + update_prgm_id = :program_name + WHERE + rehabili_cd = :rehabili_cd + """ + record: ComRehabili + + def __init__(self, record: list[str], db) -> None: + super().__init__(record, db, ComRehabili) + program_name = __name__.split('.')[-1] # 当モジュール名(現行から変わっている) + # モジュール名をクエリパラメータに設定 + self.query_parameter['program_name'] = program_name + # 読み込んだレコード値もクエリパラメータに追加 + self.query_parameter = {**self.query_parameter, **self.record.to_sql_parameter()} + + def make_query(self): + # 修正区分がC(削除)の場合、論理削除 + if self.record.maint_flag == 'C': + self.queries.append(self.LOGICAL_DELETE_QUERY) + return + + # 追加、更新の場合 + self.queries.append(self.__make_upsert_query()) + return + + def __make_upsert_query(self): + # レコードの存在確認 + record_count = self.db.execute_select(self.RECORD_EXISTS_QUERY, self.query_parameter) + # 存在しない場合はInsert + if record_count[0]['count_num'] == 0: + return self.INSERT_QUERY + + # 存在する場合ではUpdate + if self.record.rehabili_name == '': + return None + else: + return self.UPDATE_QUERY diff --git a/ecs/jskult-batch-daily/src/batch/ultmarc/utmp_tables/tables/com_rehabili.py b/ecs/jskult-batch-daily/src/batch/ultmarc/utmp_tables/tables/com_rehabili.py new file mode 100644 index 00000000..f1e13bb2 --- /dev/null +++ b/ecs/jskult-batch-daily/src/batch/ultmarc/utmp_tables/tables/com_rehabili.py @@ -0,0 +1,14 @@ +from src.batch.ultmarc.utmp_tables.tables.ultmarc_table import UltmarcTable + + +class ComRehabili(UltmarcTable): + """レイアウト区分027: COM_疾患別リハビリテーション科""" + maint_flag: str # 修正区分 + rehabili_cd: str # 疾患別リハビリコード + rehabili_name: str # リハビリテーション名称(漢字) + + def __init__(self, record: list[str]): + super().__init__(record) + self.maint_flag = record[2] + self.rehabili_cd = record[1] + self.rehabili_name = record[5] diff --git a/ecs/jskult-batch-daily/src/batch/ultmarc/utmp_tables/ultmarc_table_mapper_factory.py b/ecs/jskult-batch-daily/src/batch/ultmarc/utmp_tables/ultmarc_table_mapper_factory.py index 1c9f8a81..5146aa90 100644 --- a/ecs/jskult-batch-daily/src/batch/ultmarc/utmp_tables/ultmarc_table_mapper_factory.py +++ b/ecs/jskult-batch-daily/src/batch/ultmarc/utmp_tables/ultmarc_table_mapper_factory.py @@ -12,6 +12,8 @@ from src.batch.ultmarc.utmp_tables.table_mapper.concrete.com_nurse_assrt_mapper ComNurseAssrtMapper from src.batch.ultmarc.utmp_tables.table_mapper.concrete.com_pharm_mapper import \ ComPharmMapper +from src.batch.ultmarc.utmp_tables.table_mapper.concrete.com_rehabili_mapper import \ + ComRehabiliMapper from src.batch.ultmarc.utmp_tables.table_mapper.concrete.null_mapper import \ NullMapper from src.batch.ultmarc.utmp_tables.table_mapper.ultmarc_table_mapper import \ @@ -80,7 +82,7 @@ COM_TABLE_LIST = { # COM_地域クリティカルパス "026": NullMapper, # COM_疾患別リハビリテーション科 - "027": NullMapper, + "027": ComRehabiliMapper, # COM_政策医療 "028": NullMapper, # COM_医療圏都道府県 diff --git a/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/__init__.py b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/com_rehabili_delete.csv b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/com_rehabili_delete.csv new file mode 100644 index 00000000..85d5cb95 --- /dev/null +++ b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/com_rehabili_delete.csv @@ -0,0 +1,7 @@ +"027","01","A","20141113","20141114","" +"027","02","A","20141113","20141114","運動器リハビリテーション" +"027","03","A","20141113","20141114","呼吸器リハビリテーション" +"027","04","C","20141113","20141114","廃用症候群リハビリテーション" +"027","05","A","20141113","20141114","心大血管疾患リハビリテーション" +"027","06","A","20141113","20141114","糖尿病リハビリテーション" +"027","99","C","20141113","20141114","糖尿病リハビリテーション" diff --git a/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/com_rehabili_insert.csv b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/com_rehabili_insert.csv new file mode 100644 index 00000000..a3d3096b --- /dev/null +++ b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/com_rehabili_insert.csv @@ -0,0 +1,6 @@ +"027","01","A","20141113","20141114","脳血管疾患等リハビリテーション" +"027","02","A","20141113","20141114","運動器リハビリテーション" +"027","03","A","20141113","20141114","呼吸器リハビリテーション" +"027","04","A","20141113","20141114","心大血管疾患リハビリテーション" +"027","05","A","20141113","20141114","廃用症候群リハビリテーション" +"027","99","A","20141113","20141114","あいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかき" diff --git a/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/com_rehabili_update.csv b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/com_rehabili_update.csv new file mode 100644 index 00000000..a9450b84 --- /dev/null +++ b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/com_rehabili_update.csv @@ -0,0 +1,5 @@ +"027","01","A","20141113","20141114","" +"027","02","A","20141113","20141114","運動器リハビリテーション" +"027","03","A","20141113","20141114","呼吸器リハビリテーション" +"027","04","A","20141113","20141114","廃用症候群リハビリテーション" +"027","05","A","20141113","20141114","心大血管疾患リハビリテーション" diff --git a/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/db_com_rehabili_before_delete.csv b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/db_com_rehabili_before_delete.csv new file mode 100644 index 00000000..50610683 --- /dev/null +++ b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/db_com_rehabili_before_delete.csv @@ -0,0 +1,6 @@ +"rehabili_cd","rehabili_name","regist_ymd","update_ymd","delete_ymd","regist_date","create_user","update_date","update_user","sys_regist_date","regist_prgm_id","sys_update_date","update_prgm_id" +"01","脳血管疾患等リハビリテーション","20171019","NULL","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2017/10/19 14:44:23","clsComRehabili" +"02","運動器リハビリテーション","20171019","20171019","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2017/10/19 14:51:32","clsComRehabili" +"03","呼吸器リハビリテーション","20171019","20171019","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2017/10/19 14:51:32","clsComRehabili" +"04","廃用症候群リハビリテーション","20171019","20171019","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2017/10/19 14:51:32","clsComRehabili" +"05","心大血管疾患リハビリテーション","20171019","20171019","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2017/10/19 14:51:32","clsComRehabili" diff --git a/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/db_com_rehabili_before_update.csv b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/db_com_rehabili_before_update.csv new file mode 100644 index 00000000..5990cb40 --- /dev/null +++ b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/db_com_rehabili_before_update.csv @@ -0,0 +1,6 @@ +"rehabili_cd","rehabili_name","regist_ymd","update_ymd","delete_ymd","regist_date","create_user","update_date","update_user","sys_regist_date","regist_prgm_id","sys_update_date","update_prgm_id" +"01","脳血管疾患等リハビリテーション","20171019","NULL","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2017/10/19 14:44:23","clsComRehabili" +"02","運動器リハビリテーション","20171019","NULL","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2017/10/19 14:44:23","clsComRehabili" +"03","呼吸器リハビリテーション","20171019","NULL","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2017/10/19 14:44:23","clsComRehabili" +"04","心大血管疾患リハビリテーション","20171019","NULL","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2017/10/19 14:44:23","clsComRehabili" +"05","廃用症候群リハビリテーション","20171019","NULL","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2017/10/19 14:44:23","clsComRehabili" diff --git a/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/expect_com_rehabili_delete.csv b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/expect_com_rehabili_delete.csv new file mode 100644 index 00000000..fa1a79eb --- /dev/null +++ b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/expect_com_rehabili_delete.csv @@ -0,0 +1,7 @@ +"rehabili_cd","rehabili_name","regist_ymd","update_ymd","delete_ymd","regist_date","create_user","update_date","update_user","sys_regist_date","regist_prgm_id","sys_update_date","update_prgm_id" +"01","脳血管疾患等リハビリテーション","20171019","NULL","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2017/10/19 14:44:23","clsComRehabili" +"02","運動器リハビリテーション","20171019","20230423","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2022/10/19 15:01:11","com_rehabili_mapper" +"03","呼吸器リハビリテーション","20171019","20230423","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2022/10/19 15:01:11","com_rehabili_mapper" +"04","廃用症候群リハビリテーション","20171019","20171019","20230423","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2022/10/19 15:01:11","com_rehabili_mapper" +"05","心大血管疾患リハビリテーション","20171019","20230423","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2022/10/19 15:01:11","com_rehabili_mapper" +"06","糖尿病リハビリテーション","20230423","NULL","NULL","NULL","NULL","NULL","NULL","2022/10/19 15:01:11","com_rehabili_mapper","2022/10/19 15:01:11","com_rehabili_mapper" diff --git a/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/expect_com_rehabili_insert.csv b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/expect_com_rehabili_insert.csv new file mode 100644 index 00000000..1e292c75 --- /dev/null +++ b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/expect_com_rehabili_insert.csv @@ -0,0 +1,7 @@ +"rehabili_cd","rehabili_name","regist_ymd","update_ymd","delete_ymd","regist_date","create_user","update_date","update_user","sys_regist_date","regist_prgm_id","sys_update_date","update_prgm_id" +"01","脳血管疾患等リハビリテーション","20230423","NULL","NULL","NULL","NULL","NULL","NULL","2022/10/19 14:44:23","com_rehabili_mapper","2022/10/19 14:44:23","com_rehabili_mapper" +"02","運動器リハビリテーション","20230423","NULL","NULL","NULL","NULL","NULL","NULL","2022/10/19 14:44:23","com_rehabili_mapper","2022/10/19 14:44:23","com_rehabili_mapper" +"03","呼吸器リハビリテーション","20230423","NULL","NULL","NULL","NULL","NULL","NULL","2022/10/19 14:44:23","com_rehabili_mapper","2022/10/19 14:44:23","com_rehabili_mapper" +"04","心大血管疾患リハビリテーション","20230423","NULL","NULL","NULL","NULL","NULL","NULL","2022/10/19 14:44:23","com_rehabili_mapper","2022/10/19 14:44:23","com_rehabili_mapper" +"05","廃用症候群リハビリテーション","20230423","NULL","NULL","NULL","NULL","NULL","NULL","2022/10/19 14:44:23","com_rehabili_mapper","2022/10/19 14:44:23","com_rehabili_mapper" +"99","あいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかき","20230423","NULL","NULL","NULL","NULL","NULL","NULL","2022/10/19 14:44:23","com_rehabili_mapper","2022/10/19 14:44:23","com_rehabili_mapper" diff --git a/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/expect_com_rehabili_update.csv b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/expect_com_rehabili_update.csv new file mode 100644 index 00000000..f39d0ed8 --- /dev/null +++ b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/expect_com_rehabili_update.csv @@ -0,0 +1,6 @@ +"rehabili_cd","rehabili_name","regist_ymd","update_ymd","delete_ymd","regist_date","create_user","update_date","update_user","sys_regist_date","regist_prgm_id","sys_update_date","update_prgm_id" +"01","脳血管疾患等リハビリテーション","20171019","NULL","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2017/10/19 14:44:23","clsComRehabili" +"02","運動器リハビリテーション","20171019","20230423","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2022/10/19 14:51:32","com_rehabili_mapper" +"03","呼吸器リハビリテーション","20171019","20230423","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2022/10/19 14:51:32","com_rehabili_mapper" +"04","廃用症候群リハビリテーション","20171019","20230423","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2022/10/19 14:51:32","com_rehabili_mapper" +"05","心大血管疾患リハビリテーション","20171019","20230423","NULL","NULL","NULL","NULL","NULL","2017/10/19 14:44:23","clsComRehabili","2022/10/19 14:51:32","com_rehabili_mapper" diff --git a/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/test_com_rehabili_mapper.py b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/test_com_rehabili_mapper.py new file mode 100644 index 00000000..29d44f4b --- /dev/null +++ b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/com_rehabili/test_com_rehabili_mapper.py @@ -0,0 +1,197 @@ +import os.path as path +from datetime import datetime + +import pytest + +from src.batch.common.batch_context import BatchContext +from src.batch.ultmarc.utmp_tables.table_mapper.concrete import com_rehabili_mapper +from src.db.database import Database +from tests.testing_utility import (assert_table_results, + create_db_data_from_csv, + create_delete_sql_with_parameter, + create_insert_sql_with_parameter, + create_ultmarc_table_mapper_sut, + create_ultmarc_test_data_from_csv) + + +class TestComRehabiliMapper: + """レイアウト区分027: COM_疾患別リハビリテーション科""" + + db: Database + batch_context: BatchContext + test_file_path: str = path.dirname(__file__) + + @pytest.fixture(autouse=True, scope='function') + def pre_test(self, database: Database): + """テスト実行前後処理""" + self.batch_context = BatchContext.get_instance() + # setup + self.db = database + self.db.connect() + self.db.begin() + + # testing + yield + + # teardown + self.db.rollback() + self.db.disconnect() + + def test_insert_record(self): + """ + Cases: + COM_疾患別リハビリテーション科テーブルにレコードを登録する + Arranges: + - CSVデータを用意し、読み込む + - 追加対象となるレコードを削除する + Expects: + - 登録内容が期待値と一致すること + """ + + # Arrange + # 処理日設定 + self.batch_context.syor_date = datetime.strftime(datetime.now(), '%Y/%m/%d') + # テスト用のCSVを読み込む + test_dat_file = create_ultmarc_test_data_from_csv(path.join(self.test_file_path, 'com_rehabili_insert.csv')) + # 一旦全データをDBから削除 + delete_sql, delete_parameter = create_delete_sql_with_parameter('src05.com_rehabili', {'1': '1'}) + self.db.execute(delete_sql, delete_parameter) + + # Act + for line_number, line in enumerate(test_dat_file, start=1): + sut: com_rehabili_mapper.ComRehabiliMapper = create_ultmarc_table_mapper_sut(line, self.db) + assert type(sut) is com_rehabili_mapper.ComRehabiliMapper, f'{line_number}行目:マッパークラスが期通りか' + + sut.make_query() + sut.execute_queries() + + # Assert + # 期待値ファイルを読み込む + expect_data_list = create_db_data_from_csv(path.join(self.test_file_path, 'expect_com_rehabili_insert.csv')) + primary_keys = [f"'{primary_key['rehabili_cd']}'" for primary_key in expect_data_list] + actual_select_sql = f"SELECT * FROM src05.com_rehabili WHERE rehabili_cd IN ({','.join(primary_keys)})" + actual_data_list = self.db.execute_select(actual_select_sql) + # 期待値検査 + ignore_columns = ['regist_ymd', 'sys_update_date', 'sys_regist_date'] + assert_table_results(actual_data_list, expect_data_list, ignore_col_name=ignore_columns) + # 動的日付項目の個別確認 + line_number = 0 + for actual_row, expect_row in zip(actual_data_list, expect_data_list): + line_number += 1 + for actual_col_name, expect_col_name in zip(actual_row, expect_row): + if actual_col_name in ignore_columns: + assert actual_row[actual_col_name] >= expect_row[expect_col_name], f'{line_number}行目:{actual_col_name}が、期待値以降であること' + + def test_update_record(self): + """ + Cases: + COM_疾患別リハビリテーション科テーブルのレコードを更新する + Arranges: + - CSVデータを用意し、読み込む + - 更新対象となるレコードを登録する + Expects: + - 登録内容が期待値と一致すること + """ + + # Arrange + # 処理日設定 + self.batch_context.syor_date = datetime.strftime(datetime.now(), '%Y/%m/%d') + # テスト用のCSVを読み込む + test_dat_file = create_ultmarc_test_data_from_csv(path.join(self.test_file_path, 'com_rehabili_update.csv')) + # 一旦全データをDBから削除 + delete_sql, delete_parameter = create_delete_sql_with_parameter('src05.com_rehabili', {'1': '1'}) + self.db.execute(delete_sql, delete_parameter) + # テストデータをDBに登録 + # DBデータを読み込む + test_sql_data_list = create_db_data_from_csv(path.join(self.test_file_path, 'db_com_rehabili_before_update.csv')) + for test_data in test_sql_data_list: + insert_sql, insert_parameter = create_insert_sql_with_parameter( + 'src05.com_rehabili', + test_data.keys(), + test_data.values() + ) + self.db.execute(insert_sql, insert_parameter) + + # Act + for line_number, line in enumerate(test_dat_file, start=1): + sut: com_rehabili_mapper.ComRehabiliMapper = create_ultmarc_table_mapper_sut(line, self.db) + assert type(sut) is com_rehabili_mapper.ComRehabiliMapper, f'{line_number}行目:マッパークラスが期通りか' + sut.make_query() + sut.execute_queries() + + # Assert + # 期待値ファイルを読み込む + expect_data_list = create_db_data_from_csv(path.join(self.test_file_path, 'expect_com_rehabili_update.csv')) + primary_keys = [f"'{primary_key['rehabili_cd']}'" for primary_key in expect_data_list] + actual_select_sql = f"SELECT * FROM src05.com_rehabili WHERE rehabili_cd IN ({','.join(primary_keys)})" + actual_data_list = self.db.execute_select(actual_select_sql) + # 期待値検査 + ignore_columns = ['regist_ymd', 'update_ymd', 'sys_update_date', 'sys_regist_date'] + assert_table_results(actual_data_list, expect_data_list, ignore_col_name=ignore_columns) + # 動的日付項目の個別確認 + line_number = 0 + for actual_row, expect_row in zip(actual_data_list, expect_data_list): + line_number += 1 + for actual_col_name, expect_col_name in zip(actual_row, expect_row): + if actual_col_name in ignore_columns: + if expect_row[expect_col_name] is None: + assert actual_row[actual_col_name] is None, f'{line_number}行目:{actual_col_name}が、登録されていないこと' + else: + assert actual_row[actual_col_name] >= expect_row[expect_col_name], f'{line_number}行目:{actual_col_name}が、期待値以降であること' + + def test_logical_delete(self): + """ + Cases: + COM_疾患別リハビリテーション科テーブルのレコードを1件論理削除する + Arranges: + - CSVデータを用意し、読み込む + - 削除対象となるレコードを登録する + Expects: + - 登録内容が期待値と一致すること + """ + + # Arrange + # 処理日設定 + self.batch_context.syor_date = datetime.strftime(datetime.now(), '%Y/%m/%d') + # テスト用のCSVを読み込む + test_dat_file = create_ultmarc_test_data_from_csv(path.join(self.test_file_path, 'com_rehabili_delete.csv')) + # 一旦全データをDBから削除 + delete_sql, delete_parameter = create_delete_sql_with_parameter('src05.com_rehabili', {'1': '1'}) + self.db.execute(delete_sql, delete_parameter) + # テストデータをDBに登録 + # DBデータを読み込む + test_sql_data_list = create_db_data_from_csv(path.join(self.test_file_path, 'db_com_rehabili_before_delete.csv')) + for test_data in test_sql_data_list: + insert_sql, insert_parameter = create_insert_sql_with_parameter( + 'src05.com_rehabili', + test_data.keys(), + test_data.values() + ) + self.db.execute(insert_sql, insert_parameter) + + # Act + for line_number, line in enumerate(test_dat_file, start=1): + sut: com_rehabili_mapper.ComRehabiliMapper = create_ultmarc_table_mapper_sut(line, self.db) + assert type(sut) is com_rehabili_mapper.ComRehabiliMapper, f'{line_number}行目:マッパークラスが期通りか' + sut.make_query() + sut.execute_queries() + + # Assert + # 期待値ファイルを読み込む + expect_data_list = create_db_data_from_csv(path.join(self.test_file_path, 'expect_com_rehabili_delete.csv')) + primary_keys = [f"'{primary_key['rehabili_cd']}'" for primary_key in expect_data_list] + actual_select_sql = f"SELECT * FROM src05.com_rehabili WHERE rehabili_cd IN ({','.join(primary_keys)})" + actual_data_list = self.db.execute_select(actual_select_sql) + # 期待値検査 + ignore_columns = ['regist_ymd', 'update_ymd', 'delete_ymd', 'sys_update_date', 'sys_regist_date'] + assert_table_results(actual_data_list, expect_data_list, ignore_col_name=ignore_columns) + # 動的日付項目の個別確認 + line_number = 0 + for actual_row, expect_row in zip(actual_data_list, expect_data_list): + line_number += 1 + for actual_col_name, expect_col_name in zip(actual_row, expect_row): + if actual_col_name in ignore_columns: + if expect_row[expect_col_name] is None: + assert actual_row[actual_col_name] is None, f'{line_number}行目:{actual_col_name}が、登録されていないこと' + else: + assert actual_row[actual_col_name] >= expect_row[expect_col_name], f'{line_number}行目:{actual_col_name}が、期待値以降であること'