#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4
# Alan Viars

import argparse
from jdt.fhirbundles2mongo import ndjsonFHIRBundle2mongo

if __name__ == "__main__":

    # Parse args
    parser = argparse.ArgumentParser(
        description='Input NDJSON file.')
    parser.add_argument(
        dest='input_ndjson_file',
        action='store',
        help='Input the NDJSON file to load here')
    parser.add_argument(
        dest='db_name',
        action='store',
        help="Enter the Database name you want to import the JSON to")
    parser.add_argument('-d', '--delete', dest='delete', action='store_true',
                        help='Delete previous collection upon import')
    parser.add_argument(
        '--host',
        dest='host',
        action='store',
        default='127.0.0.1',
        help='Specify host. Default is 127.0.0.1 ')
    parser.add_argument(
        '-c', '--collection_name_prefix',
        dest='cnp',
        action='store',
        default='',
        help='Specify a prefix for FHIR resource collection names.Default is blank')
    parser.add_argument(
        '-p',
        '--port',
        dest='port',
        action='store',
        default=27017,
        help='Specify port. Default is 27017')
    args = parser.parse_args()
    ndjson_file = args.input_ndjson_file
    database = args.db_name
    delete_database_before_import = args.delete
    collection_name_prefix = args.cnp
    host = args.host
    port = args.port

    result = ndjsonFHIRBundle2mongo(
        ndjson_file,
        database,
        delete_database_before_import,
        host,
        port,
        collection_name_prefix)

    # output the JSON transaction summary
    print(json.dumps(result, indent=4))
