From 54c411b3c3fee0c042b2c2d98ceaec956d499b2d Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Wed, 12 Apr 2023 14:29:26 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E6=8C=87=E6=91=98=E5=8F=8D=E6=98=A0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecs/jskult-batch-daily/README.md | 4 +- .../src/batch/ultmarc/datfile.py | 2 - .../src/batch/ultmarc/ultmarc_process.py | 3 +- .../ultmarc_table_mapper_factory.py | 46 +++++++------------ ecs/jskult-batch-daily/src/jobctrl_daily.py | 2 +- .../tests/testing_utility.py | 2 - 6 files changed, 21 insertions(+), 38 deletions(-) diff --git a/ecs/jskult-batch-daily/README.md b/ecs/jskult-batch-daily/README.md index 46d1c3b6..d0f37149 100644 --- a/ecs/jskult-batch-daily/README.md +++ b/ecs/jskult-batch-daily/README.md @@ -63,12 +63,12 @@ ### テスト用のサブコマンド一覧 - `pipenv run`のあとに、サブコマンドとしてユーザー定義スクリプトを実行できる - - `Pipfile`内の「scripts」セクションに宣言する + - `Pipfile`内の「scripts」セクションに宣言されている | コマンド | 概要 | | ---------------- | -------------------------------------------------------------------------------------------- | | test:ultmarc | tests/batch/ultmarc フォルダ配下のユニットテストを実行する | -| test:ultmarc:csv | tests/batch/ultmarc フォルダ配下のユニットテストを実行し、テストカバレッジを取得する(C1, C2) | +| test:ultmarc:cov | tests/batch/ultmarc フォルダ配下のユニットテストを実行し、テストカバレッジを取得する(C1, C2) | ### テスト共通関数の仕様 diff --git a/ecs/jskult-batch-daily/src/batch/ultmarc/datfile.py b/ecs/jskult-batch-daily/src/batch/ultmarc/datfile.py index 0c8ac150..2631eaff 100644 --- a/ecs/jskult-batch-daily/src/batch/ultmarc/datfile.py +++ b/ecs/jskult-batch-daily/src/batch/ultmarc/datfile.py @@ -4,12 +4,10 @@ from io import TextIOWrapper class DatFileLine: layout_class: str - record_id: str records: list[str] def __init__(self, dat_line: list[str]) -> None: self.layout_class = dat_line[0] - self.record_id = dat_line[1] self.records = dat_line diff --git a/ecs/jskult-batch-daily/src/batch/ultmarc/ultmarc_process.py b/ecs/jskult-batch-daily/src/batch/ultmarc/ultmarc_process.py index 88a40a8e..f4d8fafe 100644 --- a/ecs/jskult-batch-daily/src/batch/ultmarc/ultmarc_process.py +++ b/ecs/jskult-batch-daily/src/batch/ultmarc/ultmarc_process.py @@ -13,7 +13,7 @@ logger = get_logger('アルトマークデータ保管') ultmarc_bucket = UltmarcBucket() -def import_process(): +def exec_import(): """アルトマーク取り込み処理""" try: logger.info('ultmarc import process START') @@ -57,7 +57,6 @@ def import_process(): # 書き込み先のテーブルを特定 mapper_class = mapper_factory.create( line.layout_class, - line.record_id, line.records, db ) 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 4424e11b..ebea9e55 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 @@ -9,33 +9,32 @@ from src.db.database import Database COM_TABLE_LIST = { # レコードID固定 # COM_医師学会 - "521": {"01": null_mapper.NullMapper}, + # TODO: 入れ子にしない + "521": null_mapper.NullMapper, # COM_施設属性 - "111": {"00": null_mapper.NullMapper}, + "111": null_mapper.NullMapper, # COM_臨床研修病院 - "112": {"00": null_mapper.NullMapper}, + "112": null_mapper.NullMapper, # COM_医師 - "501": {"01": null_mapper.NullMapper}, + "501": null_mapper.NullMapper, # COM_施設 - "101": {"00": com_inst_mapper.ComInstMapper}, + "101": com_inst_mapper.ComInstMapper, # COM_薬局 - "102": {"03": null_mapper.NullMapper}, + "102": null_mapper.NullMapper, # COM_医師勤務先 - "502": {"01": com_dr_wrkplace_mapper.ComDrWrkplaceMapper}, + "502": com_dr_wrkplace_mapper.ComDrWrkplaceMapper, # COM_専門分野 - "511": {"01": null_mapper.NullMapper}, + "511": null_mapper.NullMapper, # COM_都道府県医療機能情報(基本) - "132": {"00": null_mapper.NullMapper}, + "132": null_mapper.NullMapper, # COM_都道府県医療機能情報(施設設備) - "133": {"00": null_mapper.NullMapper}, + "133": null_mapper.NullMapper, # COM_都道府県医療機能情報(疾患治療) - "134": {"00": null_mapper.NullMapper}, + "134": null_mapper.NullMapper, # COM_都道府県医療機能情報(短期滞在手術) - "135": {"00": null_mapper.NullMapper}, + "135": null_mapper.NullMapper, # COM_都道府県医療機能情報(専門外来) - "136": {"00": null_mapper.NullMapper}, - - # レコードID浮動 + "136": null_mapper.NullMapper, # COM_診療科目 "001": null_mapper.NullMapper, # COM_病院種別 @@ -85,12 +84,11 @@ COM_TABLE_LIST = { class UltmarcTableMapperFactory: - def create(self, layout_class: str, record_id: str, records: list[str], db: Database) -> UltmarcTableMapper: + def create(self, layout_class: str, records: list[str], db: Database) -> UltmarcTableMapper: """レイアウト区分とレコードIDから、マッピング先のテーブルマッパーを特定する Args: layout_class (str): レイアウト区分 - record_id (str): レコードID records (list[str]): アルトマークデータの1行 db (Database): データベース操作クラス @@ -101,19 +99,9 @@ class UltmarcTableMapperFactory: UltmarcTableMapper: マッパークラス """ # レイアウト区分から、マッピング先のテーブルを特定 - table_by_layout_class = COM_TABLE_LIST.get(layout_class) - + mapper_class = COM_TABLE_LIST.get(layout_class) # レイアウト区分が特定できない場合はエラーとする - if table_by_layout_class is None: - raise Exception(f'マッピング先のテーブルを特定できませんでした。レイアウト区分={layout_class}, レコードID={record_id}') - - mapper_class: UltmarcTableMapper = None - if type(table_by_layout_class) is dict: - mapper_class = table_by_layout_class.get(record_id) - elif issubclass(table_by_layout_class, UltmarcTableMapper): - mapper_class = table_by_layout_class - if mapper_class is None: - raise Exception(f'マッピング先のテーブルを特定できませんでした。レイアウト区分={layout_class}, レコードID={record_id}') + raise Exception(f'マッピング先のテーブルを特定できませんでした。レイアウト区分={layout_class}') return mapper_class(records, db) diff --git a/ecs/jskult-batch-daily/src/jobctrl_daily.py b/ecs/jskult-batch-daily/src/jobctrl_daily.py index 9bd83bc2..f91437b5 100644 --- a/ecs/jskult-batch-daily/src/jobctrl_daily.py +++ b/ecs/jskult-batch-daily/src/jobctrl_daily.py @@ -73,7 +73,7 @@ def batch_process(): logger.info('日次処理(アルトマーク)実行対象日でない為未実行') try: logger.info('アルトマーク取込:起動') - ultmarc_process.import_process() + ultmarc_process.exec_import() logger.info('アルトマーク取込:終了') except BatchOperationException as e: logger.error(f'アルトマーク取込処理エラー(異常終了){e}') diff --git a/ecs/jskult-batch-daily/tests/testing_utility.py b/ecs/jskult-batch-daily/tests/testing_utility.py index d11aa163..e95da8e7 100644 --- a/ecs/jskult-batch-daily/tests/testing_utility.py +++ b/ecs/jskult-batch-daily/tests/testing_utility.py @@ -115,11 +115,9 @@ def create_ultmarc_table_mapper_sut(line: DatFileLine, db: Database) -> UltmarcT UltmarcTableMapper: マッパークラス """ layout_class = line.layout_class - record_id = line.record_id factory = UltmarcTableMapperFactory() sut = factory.create( layout_class=layout_class, - record_id=record_id, records=line.records, db=db )