Beispiel #1
0
def savePatient():
    patient_name = "Ritwik"
    patient_age = 21
    username = "******"
    files = [
        DicomSeries('152265', 'T2 MRI', [
            DicomImage('IMG5465.dcm', 'dksdfisdfjijskdk'),
            DicomImage('IMG4465.dcm', 'dksdfisdfjijskds')
        ]),
        DicomSeries('152265', 'T1 MRI', [
            DicomImage('IMG5467.dcm', 'dksdfissfjijskdk'),
            DicomImage('IMG4468.dcm', 'dksdfisdfjijsdds')
        ])
    ]

    patient_cases = PatientCases(username, patient_name, patient_age, files)

    caseid = patient_cases.save()

    return "done"
Beispiel #2
0
def upload():
    response = {"error": {}}
    #if username is in session then the call is web call, so use that username
    if 'username' in session and len(session['username']) > 0:
        username = session['username']
    else:
        if 'key' not in request.form or len(request.form['key']) == 0:
            response['error']['error'] = True
            response['error']['error_message'] = "key not specified"
            response['error']['error_type'] = "AUTH_ERROR"
            return jsonify(response)

        auth_result = Auth.checkKeyValidity(request.form['key'])

        if not auth_result['valid']:
            response['error']['error'] = True
            response['error']['error_message'] = "key not valid"
            response['error']['error_type'] = "AUTH_ERROR"
            return jsonify(response)

        username = auth_result['username']

    if 'case_name' in request.form:
        case_name = request.form['case_name']
    else:
        case_name = None

    uploaded_files = flask.request.files.getlist("files[]")
    if len(uploaded_files) == 0:
        response['error']['error'] = True
        response['error']['error_message'] = "Files not Selected"
        response['error']['error_type'] = "PARAMETER_ERROR"
        return jsonify(response)
    #print uploaded_files
    files = []
    #directory = '/var/www/temp_uploads/'
    directory = UPLOAD_DIR
    print "Uploading to directory: " + directory
    for f in uploaded_files:
        fi = {}
        name = os.path.splitext(f.filename)[0]
        suffix = time.time()
        filename = name + str(suffix)
        filename = filename.replace('.', '')
        fi['name_on_disk'] = filename
        fi['original_name'] = f.filename
        files.append(fi)
        f.save(os.path.join(directory, filename))

    result = Upload(files)

    if result.errorPresent:
        response['error'] = result.error
        return jsonify(response)
    else:
        #group the images
        dv = DicomDirValidator(result.validators)
        dicomSeries = []
        i = 0
        response['images'] = []
        for series in dv.series:
            images = []
            res_images = {}
            res_images['series_time'] = series.seriesTime
            res_images['series_description'] = series.seriesDescription
            res_images['images'] = []
            for validator in series.dv:
                images.append(
                    DicomImage(validator['org_filename'],
                               validator['disk_filename']))
                image = {}
                image['filename'] = validator['org_filename']
                res_images['images'].append(image)
            response['images'].append(res_images)
            dicomSeries.append(
                DicomSeries(series.seriesTime, series.seriesDescription,
                            images))
        case_id = PatientCases(username, case_name, dv.patientName,
                               dv.patientAge, dicomSeries).save()
        response['case_id'] = case_id
        response['patient_name'] = dv.patientName
        if case_name != None:
            response['case_name'] = case_name
        response['patient_age'] = dv.patientAge
        response['error']['error'] = False
        i = 0
        for series in response['images']:
            j = 0
            for image in series['images']:
                image['url'] = BASE_URL + url_for('patient_cases_api.getImage',
                                                  case_id=response['case_id'],
                                                  index_1=i,
                                                  index_2=j)
                j += 1
            i += 1
        return jsonify(response)