新規作成(施設設備)

This commit is contained in:
野間 2023-05-11 08:39:34 +09:00
parent a8a808682e
commit fe8d0fd142
14 changed files with 438 additions and 2 deletions

View File

@ -0,0 +1,104 @@
from src.batch.ultmarc.utmp_tables.table_mapper.ultmarc_table_mapper import \
UltmarcTableMapper
from src.batch.ultmarc.utmp_tables.tables.com_prefc_med_equpment import ComPrefcMedEqupment
class ComPrefcMedEqupmentMapper(UltmarcTableMapper):
"""レイアウト区分132: COM_都道府県医療機能情報(施設設備)"""
# レコード存在確認SQL
RECORD_EXISTS_QUERY = """\
SELECT
COUNT(*) AS count_num
FROM
src05.com_prefc_med_equpment
WHERE
dcf_dsf_inst_cd = :dcfdsf_inst_code
AND
equipment_code = :equipment_code
"""
# データ登録用SQL
INSERT_QUERY = """\
INSERT INTO src05.com_prefc_med_equpment
(
dcf_dsf_inst_cd,
equipment_code,
bednum,
regist_ymd,
sys_regist_date,
regist_prgm_id,
sys_update_date,
update_prgm_id
)
VALUES (
:dcfdsf_inst_code,
:equipment_code,
:bed_num,
:execute_date_str_ymd,
:execute_datetime,
:program_name,
:execute_datetime,
:program_name
)
"""
# データ変更用SQL
UPDATE_QUERY = """\
UPDATE
src05.com_prefc_med_equpment
SET
bednum = :bed_num,
update_ymd = :execute_date_str_ymd,
sys_update_date = :execute_datetime,
update_prgm_id = :program_name
WHERE
dcf_dsf_inst_cd = :dcfdsf_inst_code
AND
equipment_code = :equipment_code
"""
# 『修正区分がB(修正)かつ専門医メンテナンス区分が1(退職)』の場合、物理削除
PHYSICAL_DELETE_QUERY = """\
DELETE FROM
src05.com_prefc_med_equpment
WHERE
dcf_dsf_inst_cd = :dcfdsf_inst_code
AND
equipment_code = :equipment_code
"""
record: ComPrefcMedEqupment
def __init__(self, record: list[str], db) -> None:
super().__init__(record, db, ComPrefcMedEqupment)
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):
# 『修正区分がB(修正)かつ専門医メンテナンス区分が1(退職)』の場合、物理削除
if self.record.maint_flag == 'B' and self.record.adddel_div == '1':
self.queries.append(self.PHYSICAL_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.bed_num is not None:
if self.record.bed_num == '@':
self.query_parameter['bed_num'] = None
return self.UPDATE_QUERY
else:
return None

View File

@ -5,7 +5,7 @@ class ComPrefcMedBase(UltmarcTable):
"""レイアウト区分132: COM_都道府県医療機能情報(基本)"""
dcfhp_id: str # DCFコードレコードID
dcfhp_code: str # DCFコード施設コード
dcfhp_yobi: str # DCFコード予備10/8asa
dcfhp_yobi: str # DCFコード予備
maint_flag: str # 修正区分
adddel_div: str # 予備/追加削除区分
maint_date: str # メンテナンス年月日

View File

@ -0,0 +1,30 @@
from src.batch.ultmarc.utmp_tables.tables.ultmarc_table import UltmarcTable
class ComPrefcMedEqupment(UltmarcTable):
"""レイアウト区分132: COM_都道府県医療機能情報(施設設備)"""
dcfhp_id: str # DCFコードレコードID
dcfhp_code: str # DCFコード施設コード
dcfhp_yobi: str # DCFコード予備
equipment_code: str # 施設設備コード
bed_num: str # 病床数
adddel_div: str # 追加削除区分
maint_flag: str # 修正区分
dcfdsf_inst_code: str # DCFDSF施設コード
def __init__(self, record: list[str]):
super().__init__(record)
self.dcfhp_id = record[1]
self.dcfhp_code = record[2]
self.dcfhp_yobi = record[3].strip()
self.maint_flag = record[4]
self.equipment_code = record[5].strip()
self.adddel_div = record[6]
self.bed_num = record[9]
# smallint型のカラム値は、空文字で渡ってきた場合はNULLに変換する
self.bed_num = self.bed_num if len(self.bed_num) > 0 else None
# DCFDSF施設コード
self.dcfdsf_inst_code = ''.join([self.dcfhp_id, self.dcfhp_code, self.dcfhp_yobi])

View File

@ -32,6 +32,8 @@ from src.batch.ultmarc.utmp_tables.table_mapper.concrete.com_dr_sosiety_mapper i
ComDrSosietyMapper
from src.batch.ultmarc.utmp_tables.table_mapper.concrete.com_prefc_med_base_mapper import \
ComPrefcMedBaseMapper
from src.batch.ultmarc.utmp_tables.table_mapper.concrete.com_prefc_med_equpment_mapper import \
ComPrefcMedEqupmentMapper
from src.batch.ultmarc.utmp_tables.table_mapper.concrete.null_mapper import \
NullMapper
@ -57,7 +59,7 @@ COM_TABLE_LIST = {
# COM_都道府県医療機能情報(基本)
"132": ComPrefcMedBaseMapper,
# COM_都道府県医療機能情報(施設設備)
"133": NullMapper,
"133": ComPrefcMedEqupmentMapper,
# COM_都道府県医療機能情報(疾患治療)
"134": NullMapper,
# COM_都道府県医療機能情報(短期滞在手術)

View File

@ -0,0 +1,3 @@
"133","00","9900194","","B","008","1","20141211","20141213",""
"133","00","9901649","","B","009","1","20141211","20141213",""
"133","00","9901679","","B","015","1","20141211","20141213",""
1 133 00 9900194 B 008 1 20141211 20141213
2 133 00 9901649 B 009 1 20141211 20141213
3 133 00 9901679 B 015 1 20141211 20141213

View File

@ -0,0 +1,6 @@
"133","00","9900146","","A","012","2","20141113","20141114","0"
"133","00","9900194","","A","008","2","20141113","20141114","32"
"133","00","9901649","","A","009","2","20141113","20141114","3"
"133","00","9901679","","A","015","2","20141113","20141114",""
"133","00","9904439","","A","006","2","20141113","20141114",""
"133","00","9929798","","A","010","2","20141113","20141114",""
1 133 00 9900146 A 012 2 20141113 20141114 0
2 133 00 9900194 A 008 2 20141113 20141114 32
3 133 00 9901649 A 009 2 20141113 20141114 3
4 133 00 9901679 A 015 2 20141113 20141114
5 133 00 9904439 A 006 2 20141113 20141114
6 133 00 9929798 A 010 2 20141113 20141114

View File

@ -0,0 +1,7 @@
"133","99","9999999","99","B","111","2","20141113","20141114",""
"133","00","9900146","","B","012","2","20141113","20141114","@"
"133","00","9900194","","B","008","2","20141113","20141114","@"
"133","00","9901649","","B","009","2","20141113","20141114","6"
"133","00","9901679","","B","015","2","20141113","20141114","@"
"133","00","9904439","","B","006","2","20141113","20141114","10"
"133","00","9929798","","B","010","2","20141113","20141114","9"
1 133 99 9999999 99 B 111 2 20141113 20141114
2 133 00 9900146 B 012 2 20141113 20141114 @
3 133 00 9900194 B 008 2 20141113 20141114 @
4 133 00 9901649 B 009 2 20141113 20141114 6
5 133 00 9901679 B 015 2 20141113 20141114 @
6 133 00 9904439 B 006 2 20141113 20141114 10
7 133 00 9929798 B 010 2 20141113 20141114 9

View File

@ -0,0 +1,7 @@
"dcf_dsf_inst_cd","equipment_code","bednum","regist_ymd","update_ymd","regist_date","create_user","update_date","update_user","sys_regist_date","regist_prgm_id","sys_update_date","update_prgm_id"
"009900146","012","NULL","20171008","20171011","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/11 21:20:37","clsPrefcMedEquipment"
"009900194","008","NULL","20171008","20171011","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/11 21:20:37","clsPrefcMedEquipment"
"009901649","009","6","20171008","20171011","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/11 21:20:37","clsPrefcMedEquipment"
"009901679","015","NULL","20171008","20171011","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/11 21:20:37","clsPrefcMedEquipment"
"009904439","006","10","20171008","20171011","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/11 21:20:37","clsPrefcMedEquipment"
"009929798","010","9","20171008","20171011","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/11 21:20:37","clsPrefcMedEquipment"
1 dcf_dsf_inst_cd equipment_code bednum regist_ymd update_ymd regist_date create_user update_date update_user sys_regist_date regist_prgm_id sys_update_date update_prgm_id
2 009900146 012 NULL 20171008 20171011 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/11 21:20:37 clsPrefcMedEquipment
3 009900194 008 NULL 20171008 20171011 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/11 21:20:37 clsPrefcMedEquipment
4 009901649 009 6 20171008 20171011 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/11 21:20:37 clsPrefcMedEquipment
5 009901679 015 NULL 20171008 20171011 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/11 21:20:37 clsPrefcMedEquipment
6 009904439 006 10 20171008 20171011 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/11 21:20:37 clsPrefcMedEquipment
7 009929798 010 9 20171008 20171011 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/11 21:20:37 clsPrefcMedEquipment

View File

@ -0,0 +1,8 @@
"dcf_dsf_inst_cd","equipment_code","bednum","regist_ymd","update_ymd","regist_date","create_user","update_date","update_user","sys_regist_date","regist_prgm_id","sys_update_date","update_prgm_id"
"009900146","012","0","20171008","NULL","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/08 20:57:12","clsPrefcMedEquipment"
"009900194","008","32","20171008","NULL","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/08 20:57:12","clsPrefcMedEquipment"
"009901649","009","3","20171008","NULL","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/08 20:57:12","clsPrefcMedEquipment"
"009901679","015","NULL","20171008","NULL","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/08 20:57:12","clsPrefcMedEquipment"
"009904439","006","NULL","20171008","NULL","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/08 20:57:12","clsPrefcMedEquipment"
"009929798","010","NULL","20171008","NULL","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/08 20:57:12","clsPrefcMedEquipment"
"99999999999","111","NULL","20171008","NULL","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/08 20:57:12","clsPrefcMedEquipment"
1 dcf_dsf_inst_cd equipment_code bednum regist_ymd update_ymd regist_date create_user update_date update_user sys_regist_date regist_prgm_id sys_update_date update_prgm_id
2 009900146 012 0 20171008 NULL NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/08 20:57:12 clsPrefcMedEquipment
3 009900194 008 32 20171008 NULL NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/08 20:57:12 clsPrefcMedEquipment
4 009901649 009 3 20171008 NULL NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/08 20:57:12 clsPrefcMedEquipment
5 009901679 015 NULL 20171008 NULL NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/08 20:57:12 clsPrefcMedEquipment
6 009904439 006 NULL 20171008 NULL NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/08 20:57:12 clsPrefcMedEquipment
7 009929798 010 NULL 20171008 NULL NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/08 20:57:12 clsPrefcMedEquipment
8 99999999999 111 NULL 20171008 NULL NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/08 20:57:12 clsPrefcMedEquipment

View File

@ -0,0 +1,4 @@
"dcf_dsf_inst_cd","equipment_code","bednum","regist_ymd","update_ymd","regist_date","create_user","update_date","update_user","sys_regist_date","regist_prgm_id","sys_update_date","update_prgm_id"
"009900146","012","NULL","20171008","20171011","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/11 21:20:37","clsPrefcMedEquipment"
"009904439","006","10","20171008","20171011","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/11 21:20:37","clsPrefcMedEquipment"
"009929798","010","9","20171008","20171011","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/11 21:20:37","clsPrefcMedEquipment"
1 dcf_dsf_inst_cd equipment_code bednum regist_ymd update_ymd regist_date create_user update_date update_user sys_regist_date regist_prgm_id sys_update_date update_prgm_id
2 009900146 012 NULL 20171008 20171011 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/11 21:20:37 clsPrefcMedEquipment
3 009904439 006 10 20171008 20171011 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/11 21:20:37 clsPrefcMedEquipment
4 009929798 010 9 20171008 20171011 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/11 21:20:37 clsPrefcMedEquipment

View File

@ -0,0 +1,7 @@
"dcf_dsf_inst_cd","equipment_code","bednum","regist_ymd","update_ymd","regist_date","create_user","update_date","update_user","sys_regist_date","regist_prgm_id","sys_update_date","update_prgm_id"
"009900146","012","0","20230510","NULL","NULL","NULL","NULL","NULL","2023/05/10 10:57:12","com_prefc_med_equpment_mapper","2023/05/10 10:57:12","com_prefc_med_equpment_mapper"
"009900194","008","32","20230510","NULL","NULL","NULL","NULL","NULL","2023/05/10 10:57:12","com_prefc_med_equpment_mapper","2023/05/10 10:57:12","com_prefc_med_equpment_mapper"
"009901649","009","3","20230510","NULL","NULL","NULL","NULL","NULL","2023/05/10 10:57:12","com_prefc_med_equpment_mapper","2023/05/10 10:57:12","com_prefc_med_equpment_mapper"
"009901679","015","NULL","20230510","NULL","NULL","NULL","NULL","NULL","2023/05/10 10:57:12","com_prefc_med_equpment_mapper","2023/05/10 10:57:12","com_prefc_med_equpment_mapper"
"009904439","006","NULL","20230510","NULL","NULL","NULL","NULL","NULL","2023/05/10 10:57:12","com_prefc_med_equpment_mapper","2023/05/10 10:57:12","com_prefc_med_equpment_mapper"
"009929798","010","NULL","20230510","NULL","NULL","NULL","NULL","NULL","2023/05/10 10:57:12","com_prefc_med_equpment_mapper","2023/05/10 10:57:12","com_prefc_med_equpment_mapper"
1 dcf_dsf_inst_cd equipment_code bednum regist_ymd update_ymd regist_date create_user update_date update_user sys_regist_date regist_prgm_id sys_update_date update_prgm_id
2 009900146 012 0 20230510 NULL NULL NULL NULL NULL 2023/05/10 10:57:12 com_prefc_med_equpment_mapper 2023/05/10 10:57:12 com_prefc_med_equpment_mapper
3 009900194 008 32 20230510 NULL NULL NULL NULL NULL 2023/05/10 10:57:12 com_prefc_med_equpment_mapper 2023/05/10 10:57:12 com_prefc_med_equpment_mapper
4 009901649 009 3 20230510 NULL NULL NULL NULL NULL 2023/05/10 10:57:12 com_prefc_med_equpment_mapper 2023/05/10 10:57:12 com_prefc_med_equpment_mapper
5 009901679 015 NULL 20230510 NULL NULL NULL NULL NULL 2023/05/10 10:57:12 com_prefc_med_equpment_mapper 2023/05/10 10:57:12 com_prefc_med_equpment_mapper
6 009904439 006 NULL 20230510 NULL NULL NULL NULL NULL 2023/05/10 10:57:12 com_prefc_med_equpment_mapper 2023/05/10 10:57:12 com_prefc_med_equpment_mapper
7 009929798 010 NULL 20230510 NULL NULL NULL NULL NULL 2023/05/10 10:57:12 com_prefc_med_equpment_mapper 2023/05/10 10:57:12 com_prefc_med_equpment_mapper

View File

@ -0,0 +1,8 @@
"dcf_dsf_inst_cd","equipment_code","bednum","regist_ymd","update_ymd","regist_date","create_user","update_date","update_user","sys_regist_date","regist_prgm_id","sys_update_date","update_prgm_id"
"009900146","012","NULL","20171008","20230510","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2023/05/10 11:49:28","com_prefc_med_equpment_mapper"
"009900194","008","NULL","20171008","20230510","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2023/05/10 11:49:28","com_prefc_med_equpment_mapper"
"009901649","009","6","20171008","20230510","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2023/05/10 11:49:28","com_prefc_med_equpment_mapper"
"009901679","015","NULL","20171008","20230510","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2023/05/10 11:49:28","com_prefc_med_equpment_mapper"
"009904439","006","10","20171008","20230510","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2023/05/10 11:49:28","com_prefc_med_equpment_mapper"
"009929798","010","9","20171008","20230510","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2023/05/10 11:49:28","com_prefc_med_equpment_mapper"
"99999999999","111","NULL","20171008","NULL","NULL","NULL","NULL","NULL","2017/10/08 20:57:12","clsPrefcMedEquipment","2017/10/08 20:57:12","clsPrefcMedEquipment"
1 dcf_dsf_inst_cd equipment_code bednum regist_ymd update_ymd regist_date create_user update_date update_user sys_regist_date regist_prgm_id sys_update_date update_prgm_id
2 009900146 012 NULL 20171008 20230510 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2023/05/10 11:49:28 com_prefc_med_equpment_mapper
3 009900194 008 NULL 20171008 20230510 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2023/05/10 11:49:28 com_prefc_med_equpment_mapper
4 009901649 009 6 20171008 20230510 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2023/05/10 11:49:28 com_prefc_med_equpment_mapper
5 009901679 015 NULL 20171008 20230510 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2023/05/10 11:49:28 com_prefc_med_equpment_mapper
6 009904439 006 10 20171008 20230510 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2023/05/10 11:49:28 com_prefc_med_equpment_mapper
7 009929798 010 9 20171008 20230510 NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2023/05/10 11:49:28 com_prefc_med_equpment_mapper
8 99999999999 111 NULL 20171008 NULL NULL NULL NULL NULL 2017/10/08 20:57:12 clsPrefcMedEquipment 2017/10/08 20:57:12 clsPrefcMedEquipment

View File

@ -0,0 +1,250 @@
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_prefc_med_equpment_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 TestComPrefcMedEqupmentMapper:
"""レイアウト区分133: 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_prefc_med_equpment_insert.csv'))
# 一旦全データをDBから削除
delete_sql, delete_parameter = create_delete_sql_with_parameter('src05.com_prefc_med_equpment', {'1': '1'})
self.db.execute(delete_sql, delete_parameter)
# Act
for line_number, line in enumerate(test_dat_file, start=1):
sut: com_prefc_med_equpment_mapper.ComPrefcMedEqupmentMapper = create_ultmarc_table_mapper_sut(line, self.db)
assert type(sut) is com_prefc_med_equpment_mapper.ComPrefcMedEqupmentMapper, 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_prefc_med_equpment_insert.csv'))
primary_keys_dcf_dsf_inst_cd = [{'dcf_dsf_inst_cd': columns['dcf_dsf_inst_cd']} for columns in expect_data_list]
primary_keys_equipment_code = [{'equipment_code': columns['equipment_code']} for columns in expect_data_list]
actual_data_list = []
sp_field_select_sql = """\
SELECT * FROM src05.com_prefc_med_equpment
WHERE
dcf_dsf_inst_cd = :dcf_dsf_inst_cd
AND
equipment_code = :equipment_code
"""
for param_dcf_dsf_inst_cd, param_equipment_code in zip(primary_keys_dcf_dsf_inst_cd, primary_keys_equipment_code):
sp_field_data = self.db.execute_select(
sp_field_select_sql,
{**param_dcf_dsf_inst_cd, **param_equipment_code})
assert len(sp_field_data) == 1, '1件取得できていること'
actual_data_list.append(sp_field_data[0])
# 期待値検査
ignore_columns = ['bednum', '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:
if actual_col_name == 'bednum':
if expect_row[expect_col_name] is not None and len(expect_row[expect_col_name]) > 0:
assert actual_row[actual_col_name] == int(expect_row[expect_col_name]), 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_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_prefc_med_equpment_update.csv'))
# 一旦全データをDBから削除
delete_sql, delete_parameter = create_delete_sql_with_parameter('src05.com_prefc_med_equpment', {'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_prefc_med_equpment_before_update.csv'))
for test_data in test_sql_data_list:
insert_sql, insert_parameter = create_insert_sql_with_parameter(
'src05.com_prefc_med_equpment',
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_prefc_med_equpment_mapper.ComPrefcMedEqupmentMapper = create_ultmarc_table_mapper_sut(line, self.db)
assert type(sut) is com_prefc_med_equpment_mapper.ComPrefcMedEqupmentMapper, 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_prefc_med_equpment_update.csv'))
primary_keys_dcf_dsf_inst_cd = [{'dcf_dsf_inst_cd': columns['dcf_dsf_inst_cd']} for columns in expect_data_list]
primary_keys_equipment_code = [{'equipment_code': columns['equipment_code']} for columns in expect_data_list]
actual_data_list = []
sp_field_select_sql = """\
SELECT * FROM src05.com_prefc_med_equpment
WHERE
dcf_dsf_inst_cd = :dcf_dsf_inst_cd
AND
equipment_code = :equipment_code
"""
for param_dcf_dsf_inst_cd, param_equipment_code in zip(primary_keys_dcf_dsf_inst_cd, primary_keys_equipment_code):
sp_field_data = self.db.execute_select(
sp_field_select_sql,
{**param_dcf_dsf_inst_cd, **param_equipment_code})
assert len(sp_field_data) == 1, '1件取得できていること'
actual_data_list.append(sp_field_data[0])
# 期待値検査
ignore_columns = ['bednum', '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:
if actual_col_name == 'bednum':
if expect_row[expect_col_name] is not None and len(expect_row[expect_col_name]) > 0:
assert actual_row[actual_col_name] == int(expect_row[expect_col_name]), 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_prefc_med_equpment_delete.csv'))
# 一旦全データをDBから削除
delete_sql, delete_parameter = create_delete_sql_with_parameter('src05.com_prefc_med_equpment', {'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_prefc_med_equpment_before_delete.csv'))
for test_data in test_sql_data_list:
insert_sql, insert_parameter = create_insert_sql_with_parameter(
'src05.com_prefc_med_equpment',
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_prefc_med_equpment_mapper.ComPrefcMedEqupmentMapper = create_ultmarc_table_mapper_sut(line, self.db)
assert type(sut) is com_prefc_med_equpment_mapper.ComPrefcMedEqupmentMapper, 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_prefc_med_equpment_delete.csv'))
primary_keys_dcf_dsf_inst_cd = [{'dcf_dsf_inst_cd': columns['dcf_dsf_inst_cd']} for columns in expect_data_list]
primary_keys_equipment_code = [{'equipment_code': columns['equipment_code']} for columns in expect_data_list]
actual_data_list = []
sp_field_select_sql = """\
SELECT * FROM src05.com_prefc_med_equpment
WHERE
dcf_dsf_inst_cd = :dcf_dsf_inst_cd
AND
equipment_code = :equipment_code
"""
for param_dcf_dsf_inst_cd, param_equipment_code in zip(primary_keys_dcf_dsf_inst_cd, primary_keys_equipment_code):
sp_field_data = self.db.execute_select(
sp_field_select_sql,
{**param_dcf_dsf_inst_cd, **param_equipment_code})
assert len(sp_field_data) == 1, '1件取得できていること'
actual_data_list.append(sp_field_data[0])
# 期待値検査
ignore_columns = ['bednum', '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:
if actual_col_name == 'bednum':
if expect_row[expect_col_name] is not None and len(expect_row[expect_col_name]) > 0:
assert actual_row[actual_col_name] == int(expect_row[expect_col_name]), f'{line_number}行目:{actual_col_name}が、期待値と一致すること'
else:
assert actual_row[actual_col_name] >= expect_row[expect_col_name], f'{line_number}行目:{actual_col_name}が、期待値以降であること'