Exemple #1
0
    def handle(self, *args, **options):
        # start indexing once on launch
        if am_i_in_docker():
            first_index_history = HasBeenIndexed.objects.all()
            if not first_index_history:
                for directory in BASE_DICOM_DIR:
                    index_dicoms(directory)
                first_index = HasBeenIndexed.objects.create(
                    date_indexed=datetime.datetime.now(),
                    directories_indexed=str(BASE_DICOM_DIR))
                first_index.save()
            else:
                pass
        current_time = datetime.datetime.now()
        next_scan_time = current_time + datetime.timedelta(hours=24)
        print(
            "Initiating daily indexer, next index will begin after {}".format(
                next_scan_time))
        while True:
            time.sleep(900)
            current_time = datetime.datetime.now()
            if current_time >= next_scan_time:
                for directory in BASE_DICOM_DIR:
                    index_dicoms(directory)
                next_scan_time = datetime.datetime.now() + datetime.timedelta(
                    hours=24)
                print("Next index scheduled to begin after {}".format(
                    next_scan_time))

        pass
Exemple #2
0
import os
import pathlib
import sys
import time
import traceback

# importing django specific modules
import django
import pydicom
import pytz
from dateutil import parser as dateparser
from utils.docker_check import am_i_in_docker

if not am_i_in_docker():
    print("dicoms.indexer is not in docker.")
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bids_tryworks.settings')
    django.setup()
else:
    print("dicoms.indexer is in docker.")
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bids_tryworks.docker')
    django.setup()

from dicoms.models import Session, Subject, Series
from django.template.defaultfilters import slugify
from django.utils import timezone


def clean_name(name):
    return name.replace('_', '').replace('-', '').lower()