Esempio n. 1
0
def main(script, task='', case='', output=''):
    """Perform project tasks.

    'task' is the project task to run.
    'case' is a path to the case to run, optional.
    'output' is the output to generate, optional.
    Usage: python3 <task> [<case|chapter>] [latex|json]
    """
    if not task:
        print("Usage: python3 <task> [<case|chapter>] [latex|json]")
        sys.exit(2)

    if get_empty_indices():
        print("Empty indices, run 'python3 index.py build' first!")
        sys.exit(1)

    if case and case in OUTPUTS:
        output = case
        case = ''
    if output in ('json', 'latex') and not os.path.exists(OUTPUT_FOLDER):
        os.mkdir(OUTPUT_FOLDER)
    if output not in OUTPUTS:
        print("Unknown output %s, valid:" % output, ', '.join(OUTPUTS.keys()))
        sys.exit(2)

    populate_all()

    if task == '5':
        task_5()

    # Perform a task which uses patient cases as input
    elif task in CASE_TASKS:
        cases = {name: obj for name, obj in PatientCase.ALL.items()
                    if (not case or name == case)}
        if not cases:
            print("Unknown patient case: %s" % case)
            sys.exit(2)
        _perform_task(task, CASE_TASKS[task], cases, OUTPUTS[output])

    # Perform a task which uses chapters as input
    elif task in CHAPTER_TASKS:
        chapters = {code: obj for code, obj in Therapy.ALL.items()
                        if (not case or case == obj.code)}
        if not chapters:
            print("Unknown therapy code: %s" % case)
            sys.exit(2)
        _perform_task(task, CHAPTER_TASKS[task], chapters,
                      OUTPUTS[output], progress=True)

    else:
        print("Unknown task '%s', valid tasks are: %s" % (task,
            ', '.join(list(CASE_TASKS.keys()) + list(CHAPTER_TASKS.keys()))))
        sys.exit(2)

    sys.exit(None)
Esempio n. 2
0
def main(script=None):
    """Test if objects can be populated and indices contains data."""
    # Check if json files exists
    for cls in (ATC, ICD, PatientCase, Therapy):
        if not os.path.isfile(cls._JSON):
            print("Missing json file %s, use 'parse.py' to fix" % cls._JSON)
            sys.exit(1)

    # Load objects from JSON files
    now = time.time()
    populate_all()
    print("Populated ATC %i, ICD %i, Cases %i, Therapy %i in %.2f seconds" % (
            len(ATC.ALL), len(ICD.ALL), len(PatientCase.ALL),
            len(Therapy.ALL), time.time() - now))

    # Check if indices exists and contains documents
    import index
    empty = index.get_empty_indices()
    if empty:
        print("Empty indices '%s', run 'python3 index.py build' to fix" %
                ', '.join(i.__name__ for i in empty))
        sys.exit(1)

    print("All A-OK")