Exemple #1
0
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)
Exemple #2
0
def do_upload():
    pain8_file = request.files.get('pain8-upload')
    pain8_name, pain8_ext = os.path.splitext(pain8_file.filename)
    if pain8_ext not in ('.xml','.XML'):
        return 'Pain.008 file extension not allowed ({}).'.format(pain8_ext)

    pain8_path = save_upload(pain8_file)

    pain8_version = request.forms.get('pain8-version')

    mappings_path = None
    mappings_file = request.files.get('mappings-upload')
    if mappings_file:
        mappings_path = save_upload(mappings_file)

    default_reason = request.forms.get('default-reason')
    expand = not request.forms.get('compact')
    pain2_filename = 'pain.002_{}.xml'.format(timestamp_string())

    make_pain2(pain2_filename, pain8_path, pain8_version, mappings_path, default_reason, expand)
    redirect('/download/{}'.format(pain2_filename))
Exemple #3
0
def do_upload():
    pain8_file = request.files.get('pain8-upload')
    pain8_name, pain8_ext = os.path.splitext(pain8_file.filename)
    if pain8_ext not in ('.xml', '.XML'):
        return 'Pain.008 file extension not allowed ({}).'.format(pain8_ext)

    pain8_path = save_upload(pain8_file)

    pain8_version = request.forms.get('pain8-version')

    mappings_path = None
    mappings_file = request.files.get('mappings-upload')
    if mappings_file:
        mappings_path = save_upload(mappings_file)

    default_reason = request.forms.get('default-reason')
    expand = not request.forms.get('compact')
    pain2_filename = 'pain.002_{}.xml'.format(timestamp_string())

    make_pain2(pain2_filename, pain8_path, pain8_version, mappings_path,
               default_reason, expand)
    redirect('/download/{}'.format(pain2_filename))