def api_get_action_ped(): at_id = parse_id(request.args, 'action_type_id') if at_id is False: return abort(404) at = ActionType.query.get(at_id) if not at: return abort(404) return jsonify({'ped': get_planned_end_datetime(at_id)})
def patient(): client_id = parse_id(request.args, 'client_id') if client_id is False: return abort(404) if client_id: client = Client.query.get(client_id) if not client: return abort(404) return render_template('patients/patient_info.html')
def api_patient_appointments(): client_id = parse_id(request.args, 'client_id') every = request.args.get('every', False) if client_id is False: return abort(404) context = ClientVisualizer() if client_id: if Client.query.filter(Client.id == client_id).count(): return jsonify(context.make_appointments(client_id, every)) else: return abort(404) return jsonify(None, 400, 'Can\'t!')
def api_day_schedule(): person_id = parse_id(request.args, 'person_id') if person_id is False: return abort(400) try: start_date = datetime.datetime.strptime(request.args.get('start_date'), '%Y-%m-%d').date() end_date = start_date + datetime.timedelta(days=1) except ValueError: return abort(400) context = ScheduleVisualizer() person = Person.query.get(person_id) return jsonify( context.make_person_schedule_description(person, start_date, end_date))
def api_schedule_description(): person_id = parse_id(request.args, 'person_id') if person_id is False: return abort(400) start_date_s = request.args.get('start_date') try: start_date = datetime.datetime.strptime(start_date_s, '%Y-%m').date() end_date = start_date + datetime.timedelta( calendar.monthrange(start_date.year, start_date.month)[1]) except ValueError: return abort(400) context = ScheduleVisualizer() person = Person.query.get(person_id) return jsonify( context.make_person_schedule_description(person, start_date, end_date))
def api_copy_schedule_description(): person_id = parse_id(request.args, 'person_id') if person_id is False: return abort(400) from_start_date = safe_date(request.args.get('from_start_date')) from_end_date = safe_date(request.args.get('from_end_date')) to_start_date = safe_date(request.args.get('to_start_date')) to_end_date = safe_date(request.args.get('to_end_date')) if not (from_start_date and from_end_date and to_start_date and to_end_date): return abort(400) context = ScheduleVisualizer() person = Person.query.get(person_id) return jsonify( context.make_copy_schedule_description(person, from_start_date, from_end_date, to_start_date, to_end_date))
def api_patient_get(): client_id = parse_id(request.args, 'client_id') if client_id is False: return abort(404) context = ClientVisualizer() if client_id: client = Client.query.get(client_id) if not client: return abort(404) if 'for_servicing' in request.args: return jsonify(context.make_client_info_for_servicing(client)) elif 'short' in request.args: return jsonify(context.make_short_client_info(client)) return jsonify({'client_data': context.make_client_info(client)}) else: client = Client() db.session.add( client ) # требуется привязанный к сессии клиент для доступа к некоторым атрибутам (documents) return jsonify({'client_data': context.make_client_info(client)})
def api_patient_save(): client_data = request.json client_id = parse_id(client_data, 'client_id', True) if client_id is False: return abort(404) err_msg = u'Ошибка сохранения данных пациента' try: if client_id: client = Client.query.get(client_id) client_info = client_data.get('info') if client_info: client = set_client_main_info(client, client_info) db.session.add(client) id_doc_info = client_data.get('id_docs') if id_doc_info: for id_doc in id_doc_info: doc = add_or_update_doc(client, id_doc) db.session.add(doc) reg_addr_info = client_data.get('reg_addresses') actual_reg_address = None if reg_addr_info: for reg_addr in reg_addr_info: ra = add_or_update_address(client, reg_addr) if ra.deleted != 1 and ra.deleted != 2: actual_reg_address = ra db.session.add(ra) live_addr_info = client_data.get('live_addresses') if live_addr_info: for live_addr in live_addr_info: same_as_reg = live_addr.get('synced', False) if same_as_reg: la = add_or_update_copy_address( client, live_addr, actual_reg_address) else: la = add_or_update_address(client, live_addr) db.session.add(la) cpol_info = client_data.get('compulsory_policies') if cpol_info: for cpol in cpol_info: pol = add_or_update_policy(client, cpol) db.session.add(pol) vpol_info = client_data.get('voluntary_policies') if vpol_info: for vpol in vpol_info: pol = add_or_update_policy(client, vpol) db.session.add(pol) blood_type_info = client_data.get('blood_types') if blood_type_info: for bt in blood_type_info: bt = add_or_update_blood_type(client, bt) db.session.add(bt) allergy_info = client_data.get('allergies') if allergy_info: for allergy in allergy_info: alg = add_or_update_allergy(client, allergy) db.session.add(alg) intolerance_info = client_data.get('intolerances') if intolerance_info: for intolerance in intolerance_info: intlr = add_or_update_intolerance(client, intolerance) db.session.add(intlr) ss_info = client_data.get('soc_statuses') if ss_info: for ss in ss_info: sstat = add_or_update_soc_status(client, ss) db.session.add(sstat) relation_info = client_data.get('relations') if relation_info: for relation in relation_info: rel = add_or_update_relation(client, relation) db.session.add(rel) contact_info = client_data.get('contacts') if contact_info: for contact in contact_info: cont = add_or_update_contact(client, contact) db.session.add(cont) else: client = Client() client_info = client_data.get('info') if not client_info: raise ClientSaveException( err_msg, u'Отсутствует основная информация о пациенте.') client = set_client_main_info(client, client_info) db.session.add(client) id_doc_info = client_data.get('id_docs') if id_doc_info: for id_doc in id_doc_info: doc = add_or_update_doc(client, id_doc) db.session.add(doc) reg_addr_info = client_data.get('reg_addresses') actual_reg_address = None if reg_addr_info: for reg_addr in reg_addr_info: ra = add_or_update_address(client, reg_addr) if ra.deleted != 1 and ra.deleted != 2: actual_reg_address = ra db.session.add(ra) live_addr_info = client_data.get('live_addresses') if live_addr_info: for live_addr in live_addr_info: same_as_reg = live_addr.get('synced', False) if same_as_reg: la = add_or_update_copy_address( client, live_addr, actual_reg_address) else: la = add_or_update_address(client, live_addr) db.session.add(la) cpol_info = client_data.get('compulsory_policies') if cpol_info: for cpol in cpol_info: pol = add_or_update_policy(client, cpol) db.session.add(pol) vpol_info = client_data.get('voluntary_policies') if vpol_info: for vpol in vpol_info: pol = add_or_update_policy(client, vpol) db.session.add(pol) blood_type_info = client_data.get('blood_types') if blood_type_info: for bt in blood_type_info: bt = add_or_update_blood_type(client, bt) db.session.add(bt) allergy_info = client_data.get('allergies') if allergy_info: for allergy in allergy_info: alg = add_or_update_allergy(client, allergy) db.session.add(alg) intolerance_info = client_data.get('intolerances') if intolerance_info: for intolerance in intolerance_info: intlr = add_or_update_intolerance(client, intolerance) db.session.add(intlr) ss_info = client_data.get('soc_statuses') if ss_info: for ss in ss_info: sstat = add_or_update_soc_status(client, ss) db.session.add(sstat) relation_info = client_data.get('relations') if relation_info: for relation in relation_info: rel = add_or_update_relation(client, relation) db.session.add(rel) contact_info = client_data.get('contacts') if contact_info: for contact in contact_info: cont = add_or_update_contact(client, contact) db.session.add(cont) # for id_info in client_info['identifications']: # if not 'id' in id_info: # id_ext = get_new_identification(id_info) # client.identifications.append(id_ext) # else: # id_ext = get_modified_identification(client, id_info) # db.session.add(id_ext) db.session.commit() except ClientSaveException: raise except Exception, e: logger.error(e, exc_info=True) db.session.rollback() return jsonify( { 'name': err_msg, 'data': { 'err_msg': 'INTERNAL SERVER ERROR' } }, 500, 'save client data error')