Пример #1
0
            stat['arrival'] += lateness_offset
            if stat['arrival'] > get_mins(time):
                stat['arrival'] = None

        ret.append(p)
    return ret

def get_state(time):
	return {
		'time': get_mins(time),
		'patients': get_patients(get_schedule(time), time),
		'sites': config_coll.find_one({'name': 'site'})['data'],
		'optimizer': {
			"active": False,
			"advanceTime": 60,
			"objective": {
				"waitNorm": "l1",
				"overTimeWeight": 10
			},
			"confidenceLevel": 0.7,
			"patientConfidenceLevel": 0.7,
			"numSamples": 100
		}
	}

if __name__ == '__main__':
    time = parse_dt('2014-09-27 8:30:15')
    state = get_state(time)
    r = requests.post('http://localhost:4567/evaluate', json=state)
    print(r.text)
Пример #2
0
def post_state():
    msg = flask.request.get_json()
    state = get_state(parse_dt(msg['time']))
    return flask.jsonify(state)
Пример #3
0
            xs[i - 1]["completed_dt"] = smin(xs[i - 1]["completed_dt"], xs[i]["begin_dt"])


def get_schedule(time):
    # time is str of format '2012-05-05 12:30:15'
    # and we will get schedule of that day until that time
    sites = config_coll.find_one({"name": "site"})["data"]

    day = datetime.combine(time.date(), datetime.min.time())
    next_day = day + timedelta(1)

    orders = list(raw_order_coll.find({"appointment_dt": {"$gt": day, "$lt": next_day}}))
    for x in orders:
        del x["_id"]

    mask_dt(orders, time)
    orders = [x for x in orders if valid_order(x)]
    orders = filter_orders(orders, sites)
    orders = condense_orders(orders)
    fix_completion_time(orders)
    orders.sort(key=lambda x: x["appointment_dt"])
    #   time_to_str(orders)
    return orders


if __name__ == "__main__":
    time = parse_dt("2014-09-27 8:30:15")
    orders = get_schedule(time)
    for x in orders:
        print(x["site"], x["machine"])
Пример #4
0
def hl7json():
    msg = flask.request.get_json()
    # NOTE we're only processing for outpatient MRI here
    if msg['Modality'] != 'MRI' or msg['Patient.Class'] != 'O':
        return flask.jsonify({'status': 'ignore'})

    if msg['Service.Description'].find('READ') != -1:
        return flask.jsonify({'status': 'ignore'})

    if msg['Service.Description'].find('ARCHIVE') != -1:
        return flask.jsonify({'status': 'ignore'})

    for x in ['Message.DT', 'Result.Change.DT', 'Scheduled.DT']:
        if msg[x] != None:
            msg[x] = parse_dt(msg[x])
    msg['Observation.Duration'] = int(msg['Observation.Duration'])
    if msg['Machine'] == '': msg['Machine'] = None

    key = {'accession': msg['h.accession.']}

    if raw_order.find_one(key) == None:
        raw_order.insert({
            'accession': msg['h.accession.'],
            'mrn': msg['h.mrn.'],
            'schedule_dt': msg['Message.DT'],
            'appointment_dt': None,
            'arrival_dt': None,
            'begin_dt': None,
            'completed_dt': None,
            'service': None,
            'slot': None,
            'site': None,
            'machine': None,
        })

    raw_order.update_one(
        key,
        {'$set': {
            'appointment_dt': msg['Scheduled.DT'],
            'service': msg['Service.Description'],
            'slot': msg['Observation.Duration'],
            'site': msg['Site'],
            'machine': msg['Machine'],
        }}
    )

    # Patient arrival message
    if msg['ResultStatus'] == 'I' and msg['OrderControlCode'] == 'SC' and msg['Result.Change.DT'] == None:
        raw_order.update_one(
            key,
            {'$set': {
                'arrival_dt': msg['Message.DT']
            }}
        )
    # Study begin message
    elif msg['ResultStatus'] == 'I' and msg['OrderControlCode'] == 'SC' and msg['Result.Change.DT'] != None:
        raw_order.update_one(
            key,
            {'$set': {
                'begin_dt': msg['Result.Change.DT']
            }}
        )
    # Study completion message
    elif msg['ResultStatus'] == 'C' and msg['OrderControlCode'] == 'SC' and msg['Result.Change.DT'] != None:
        raw_order.update_one(
            key,
            {'$set': {
                'completed_dt': msg['Result.Change.DT']
            }}
        )
    # Study cancel message
    elif msg['ResultStatus'] == 'X' and msg['OrderControlCode'] == 'CA':
        raw_order.delete_one(key)
    return flask.jsonify({'status': 'ok'})