-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcli.py
More file actions
50 lines (33 loc) · 1.04 KB
/
Copy pathcli.py
File metadata and controls
50 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import click
from patient import Patient, PatientCollection
@click.group()
def cli():
pass
@click.command()
@click.argument('first_name')
@click.argument('last_name')
@click.option('--birth-date')
@click.option('--phone')
@click.option('--document-type')
@click.option('--document-id', type=(str, str))
def create(first_name, last_name, birth_date,
phone, document_type, document_id):
document_id = ''.join(document_id)
new_patient = Patient(first_name, last_name, birth_date,
phone, document_type, document_id, _with_check=False)
new_patient.save()
@click.command()
@click.argument('last', default=10)
def show(last):
collection = PatientCollection(create_from_db=True)
for patient in collection.limit(last):
print(patient)
@click.command()
def count():
collection = PatientCollection(create_from_db=True)
print(f"In the database: {len(collection)} patients.")
cli.add_command(create)
cli.add_command(show)
cli.add_command(count)
if __name__ == '__main__':
cli()