feat: レビュー指摘反映。
This commit is contained in:
parent
989c894f60
commit
54c411b3c3
@ -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) |
|
||||
|
||||
### テスト共通関数の仕様
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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}')
|
||||
|
||||
@ -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
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user