def main(): parser = argparse.ArgumentParser(description='A pain.008 to pain.002 converter.') parser.add_argument('-i', '--input-pain8', dest='pain8_file', help='The name of the pain.008 file to parse.') parser.add_argument('-v', '--pain8-version', dest='pain8_version', default='pain.008.001.02', help='The pain.008 schema version, defaults to "pain.008.001.02" .') parser.add_argument('-o', '--output-pain2', dest='pain2_file', help='The name of the pain.002 file to build.') parser.add_argument('-r', '--reasons-file', dest='reasons_file', default=None, help='(Optional) CSV file mapping E2E ID\'s to reason codes.') parser.add_argument('-d', '--default-reason', dest='default_reason', default=None, help='(Optional) Default reason code to use if mapping is not supplied.') parser.add_argument('-e', '--expanded', dest='expanded', action='store_true', help='Use non-compact (indented) pain.002 template. If missing compact template is used).') args = parser.parse_args() if args.pain2_file is None: args.pain2_file = 'pain.002_' + timestamp_string() + '.xml' pain8 = Pain8Doc(args.pain8_file, args.pain8_version) pacs2 = build_pain2(pain8, args.reasons_file, args.default_reason, args.expanded) with open(args.pain2_file, 'w') as f: f.write(pacs2)
def make_pain2(pain2_file, pain8_file, pain8_version, mappings_file, default_reason, expand): pain8_data = Pain8Doc(pain8_file, pain8_version) if default_reason == '': default_reason = None pain2 = build_pain2(pain8_data, mappings_file, default_reason, expand) pain2_path = os.path.join(BUILD_DIR, pain2_file) with open(pain2_path, 'w') as f: f.write(pain2) return pain2_path