Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (69 sloc) 3.8 KB
#!/usr/bin/env python
# Copyright (c) 2016, Mayo Clinic
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of the Mayo Clinic nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
import argparse
import logging
import os
import sys
from dirlistproc import DirectoryListProcessor
from fhir_to_sdo.sdo_template import sdo_template
script_path = os.path.join(os.getcwd(), os.path.dirname(__file__))
if __name__ == "__main__":
sys.path.append(os.path.join(script_path, '..'))
from fhir_to_sdo.w5_metadata import W5Metadata
DEFAULT_LOG_FILE = os.path.join(script_path, os.path.basename(__file__) + ".log")
DEFAULT_LOGGING_LEVEL = logging.getLevelName(logging.INFO)
logNames = [logging.getLevelName(l) for l in [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR]]
def addargs(parser: argparse.ArgumentParser) -> None:
""" Add local args to the dirlistproc set. Stub
:param parser: dirlistproc parser
"""
parser._get_option_tuples('--infile')[0][0].required = True
parser._get_option_tuples('--infile')[0][0].help = "W5 Ontology file (typically fhir.ttl)"
parser._get_option_tuples('--outfile')[0][0].help = "Schema.org output file"
parser.add_argument("--logfile", help="Logging file. Default is '%s'" % DEFAULT_LOG_FILE, default=DEFAULT_LOG_FILE)
parser.add_argument("--loglevel", help="Logging level. Default is %s" % DEFAULT_LOGGING_LEVEL,
default=DEFAULT_LOGGING_LEVEL,
choices=logNames)
parser.add_argument("-v", "--version", help="Ontology version number", required=True)
def procargs(opts: argparse.Namespace) -> None:
""" Evaluate the return arguments. Stub
:param opts: argument parser output
"""
logging.basicConfig(filename=opts.logfile, level=opts.loglevel, filemode='w',
format='%(asctime)s %(levelname)s - %(message)s')
def main():
dlp = DirectoryListProcessor(None, "Generate schema.org definitions from FHIR W5 specification", None, None, addargs, procargs)
w5m = W5Metadata(os.path.join(script_path, '..', 'data', 'ttl', 'fhir.ttl'))
outf = open(dlp.opts.outfile[0], 'w') if dlp.opts.outfile else sys.stdout
print(sdo_template(w5m.as_sdo(), None, dlp.opts.version, prefix='w5', base='w5.schema.org'), file=outf)
logging.info("Output written to %s" % dlp.opts.outfile[0] if dlp.opts.outfile else "STDOUT")
if dlp.opts.outfile:
print("%s written" % dlp.opts.outfile[0])
if __name__ == '__main__':
main()
You can’t perform that action at this time.