55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
import datetime
|
|
|
|
import requests
|
|
from constance import config
|
|
|
|
|
|
def get_bookings(date):
|
|
bookings = []
|
|
limit = 50
|
|
offset = 0
|
|
while True:
|
|
r = requests.get(
|
|
f'{config.MEDICINE_HOST}api/1/booking/',
|
|
params={
|
|
'date_start__date': date.strftime('%d.%m.%Y'),
|
|
'patient__phone_mobile__isnull': False,
|
|
'patient__isnull': False,
|
|
'status': 1,
|
|
'limit': limit,
|
|
'offset': offset,
|
|
},
|
|
headers={
|
|
'Authorization': f'Token {config.MEDICINE_TOKEN}'
|
|
}
|
|
)
|
|
if r.status_code == 200:
|
|
response = r.json()
|
|
for booking in response['results']:
|
|
detail_request = requests.get(
|
|
f'{config.MEDICINE_HOST}api/1/booking/{booking["id"]}/',
|
|
headers = {
|
|
'Authorization': f'Token {config.MEDICINE_TOKEN}'
|
|
}
|
|
)
|
|
bookings.append(detail_request.json())
|
|
|
|
if response['next'] is None:
|
|
break
|
|
|
|
offset += 50
|
|
|
|
return bookings
|
|
|
|
|
|
def cancel_booking(booking_id):
|
|
r = requests.post(
|
|
f'{config.MEDICINE_HOST}api/1/booking/{booking_id}/failed/',
|
|
data={
|
|
'failed_reason': 'CANCELED'
|
|
},
|
|
headers={
|
|
'Authorization': f'Token {config.MEDICINE_TOKEN}'
|
|
}
|
|
)
|