r class="tag-code nl-0 ol-0">
@@ -0,0 +1,19 @@
1
+# Generated by Django 3.2.5 on 2021-07-17 15:54
2
+
3
+import django.contrib.gis.db.models.fields
4
+from django.db import migrations
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('backend', '0003_alter_hospital_address'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.AlterField(
15
+            model_name='hospital',
16
+            name='location',
17
+            field=django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326),
18
+        ),
19
+    ]

+ 18 - 0
backend/migrations/0005_hospital_address_text.py

@@ -0,0 +1,18 @@
1
+# Generated by Django 3.2.5 on 2021-07-17 15:56
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('backend', '0004_alter_hospital_location'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AddField(
14
+            model_name='hospital',
15
+            name='address_text',
16
+            field=models.TextField(blank=True, null=True),
17
+        ),
18
+    ]

+ 34 - 0
backend/migrations/0006_bed_patient.py

@@ -0,0 +1,34 @@
1
+# Generated by Django 3.2.5 on 2021-07-17 16:17
2
+
3
+from django.db import migrations, models
4
+import django.db.models.deletion
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('backend', '0005_hospital_address_text'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.CreateModel(
15
+            name='Patient',
16
+            fields=[
17
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18
+                ('first_name', models.CharField(max_length=100)),
19
+                ('last_name', models.CharField(max_length=100)),
20
+            ],
21
+        ),
22
+        migrations.CreateModel(
23
+            name='Bed',
24
+            fields=[
25
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
26
+                ('code', models.CharField(max_length=30)),
27
+                ('occupy', models.BooleanField(default=False)),
28
+                ('created_at', models.DateTimeField(auto_now_add=True, null=True)),
29
+                ('updated_at', models.DateTimeField(auto_now=True)),
30
+                ('hospital', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.hospital')),
31
+                ('patient', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='backend.patient')),
32
+            ],
33
+        ),
34
+    ]

+ 24 - 0
backend/migrations/0007_auto_20210718_0249.py

@@ -0,0 +1,24 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 02:49
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('backend', '0006_bed_patient'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AddField(
14
+            model_name='patient',
15
+            name='age',
16
+            field=models.IntegerField(default=5),
17
+            preserve_default=False,
18
+        ),
19
+        migrations.AddField(
20
+            model_name='patient',
21
+            name='prefix',
22
+            field=models.CharField(choices=[('นางสาว', 'นางสาว'), ('นาย', 'นาย'), ('นาง', 'นาง'), ('ด.ช.', 'เด็กชาย'), ('ด.ญ.', 'เด็กหญิง')], max_length=30, null=True),
23
+        ),
24
+    ]

+ 23 - 0
backend/migrations/0008_auto_20210718_0659.py

@@ -0,0 +1,23 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 06:59
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('backend', '0007_auto_20210718_0249'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AddField(
14
+            model_name='patient',
15
+            name='idcard',
16
+            field=models.CharField(max_length=20, null=True),
17
+        ),
18
+        migrations.AddField(
19
+            model_name='patient',
20
+            name='sex',
21
+            field=models.CharField(choices=[('Male', 'male'), ('Female', 'female')], max_length=30, null=True),
22
+        ),
23
+    ]

+ 23 - 0
backend/migrations/0009_auto_20210718_0702.py

@@ -0,0 +1,23 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 07:02
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('backend', '0008_auto_20210718_0659'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AddField(
14
+            model_name='patient',
15
+            name='photo',
16
+            field=models.FileField(blank=True, upload_to='uploads/%Y/%m/%d/', verbose_name='Photo'),
17
+        ),
18
+        migrations.AlterField(
19
+            model_name='patient',
20
+            name='sex',
21
+            field=models.CharField(choices=[('male', 'Male'), ('female', 'Female')], max_length=30, null=True),
22
+        ),
23
+    ]

+ 24 - 0
backend/migrations/0010_auto_20210718_0713.py

@@ -0,0 +1,24 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 07:13
2
+
3
+from django.db import migrations
4
+import django_google_maps.fields
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('backend', '0009_auto_20210718_0702'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.AddField(
15
+            model_name='patient',
16
+            name='address',
17
+            field=django_google_maps.fields.AddressField(blank=True, max_length=200, null=True),
18
+        ),
19
+        migrations.AddField(
20
+            model_name='patient',
21
+            name='geolocation',
22
+            field=django_google_maps.fields.GeoLocationField(blank=True, max_length=100, null=True),
23
+        ),
24
+    ]

+ 29 - 0
backend/migrations/0011_auto_20210718_0722.py

@@ -0,0 +1,29 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 07:22
2
+
3
+from django.db import migrations, models
4
+import django_google_maps.fields
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('backend', '0010_auto_20210718_0713'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.AddField(
15
+            model_name='patient',
16
+            name='condition_level',
17
+            field=models.CharField(choices=[('green', 'Green'), ('yellow', 'Yellow'), ('red', 'Red')], max_length=30, null=True),
18
+        ),
19
+        migrations.AlterField(
20
+            model_name='patient',
21
+            name='address',
22
+            field=django_google_maps.fields.AddressField(max_length=200, null=True),
23
+        ),
24
+        migrations.AlterField(
25
+            model_name='patient',
26
+            name='geolocation',
27
+            field=django_google_maps.fields.GeoLocationField(max_length=100, null=True),
28
+        ),
29
+    ]

+ 18 - 0
backend/migrations/0012_patient_comment.py

@@ -0,0 +1,18 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 07:24
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('backend', '0011_auto_20210718_0722'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AddField(
14
+            model_name='patient',
15
+            name='comment',
16
+            field=models.TextField(blank=True, null=True),
17
+        ),
18
+    ]

+ 28 - 0
backend/migrations/0013_patientlog.py

@@ -0,0 +1,28 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 07:29
2
+
3
+from django.db import migrations, models
4
+import django.db.models.deletion
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('backend', '0012_patient_comment'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.CreateModel(
15
+            name='PatientLog',
16
+            fields=[
17
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18
+                ('notes', models.TextField(blank=True, null=True)),
19
+                ('condition_level', models.CharField(choices=[('green', 'Green'), ('yellow', 'Yellow'), ('red', 'Red')], max_length=30, null=True)),
20
+                ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('transfer', 'Transfer')], max_length=30, null=True)),
21
+                ('created_at', models.DateTimeField(auto_now_add=True, null=True)),
22
+                ('updated_at', models.DateTimeField(auto_now=True)),
23
+                ('bed', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='backend.bed')),
24
+                ('hospital', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='backend.hospital')),
25
+                ('patient', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='backend.patient')),
26
+            ],
27
+        ),
28
+    ]

+ 20 - 0
backend/migrations/0014_alter_patientlog_bed.py

@@ -0,0 +1,20 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 07:49
2
+
3
+from django.db import migrations
4
+import django.db.models.deletion
5
+import smart_selects.db_fields
6
+
7
+
8
+class Migration(migrations.Migration):
9
+
10
+    dependencies = [
11
+        ('backend', '0013_patientlog'),
12
+    ]
13
+
14
+    operations = [
15
+        migrations.AlterField(
16
+            model_name='patientlog',
17
+            name='bed',
18
+            field=smart_selects.db_fields.GroupedForeignKey(group_field='hospital', null=True, on_delete=django.db.models.deletion.CASCADE, to='backend.bed'),
19
+        ),
20
+    ]

+ 20 - 0
backend/migrations/0015_alter_patientlog_bed.py

@@ -0,0 +1,20 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 07:59
2
+
3
+from django.db import migrations
4
+import django.db.models.deletion
5
+import smart_selects.db_fields
6
+
7
+
8
+class Migration(migrations.Migration):
9
+
10
+    dependencies = [
11
+        ('backend', '0014_alter_patientlog_bed'),
12
+    ]
13
+
14
+    operations = [
15
+        migrations.AlterField(
16
+            model_name='patientlog',
17
+            name='bed',
18
+            field=smart_selects.db_fields.ChainedForeignKey(auto_choose=True, chained_field='hospital', chained_model_field='hospital', null=True, on_delete=django.db.models.deletion.CASCADE, to='backend.bed'),
19
+        ),
20
+    ]

+ 29 - 0
backend/migrations/0016_auto_20210718_1031.py

@@ -0,0 +1,29 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 10:31
2
+
3
+from django.db import migrations, models
4
+import django.db.models.deletion
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('backend', '0015_alter_patientlog_bed'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.AddField(
15
+            model_name='patientlog',
16
+            name='checkin_at',
17
+            field=models.DateTimeField(blank=True, null=True),
18
+        ),
19
+        migrations.AddField(
20
+            model_name='patientlog',
21
+            name='checkout_at',
22
+            field=models.DateTimeField(blank=True, null=True),
23
+        ),
24
+        migrations.AlterField(
25
+            model_name='bed',
26
+            name='patient',
27
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='backend.patient'),
28
+        ),
29
+    ]

+ 43 - 0
backend/migrations/0017_ambulance_driver.py

@@ -0,0 +1,43 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 10:43
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('backend', '0016_auto_20210718_1031'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.CreateModel(
14
+            name='Ambulance',
15
+            fields=[
16
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
17
+                ('code', models.CharField(max_length=100)),
18
+                ('license_plate', models.CharField(max_length=100)),
19
+                ('brand', models.CharField(max_length=100)),
20
+                ('model_name', models.CharField(max_length=100)),
21
+                ('comment', models.TextField(blank=True, null=True)),
22
+                ('status', models.CharField(choices=[('working', 'Working'), ('free', 'Free'), ('ma', 'MA')], max_length=30, null=True)),
23
+                ('created_at', models.DateTimeField(auto_now_add=True, null=True)),
24
+                ('updated_at', models.DateTimeField(auto_now=True)),
25
+            ],
26
+        ),
27
+        migrations.CreateModel(
28
+            name='Driver',
29
+            fields=[
30
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
31
+                ('first_name', models.CharField(max_length=100)),
32
+                ('last_name', models.CharField(max_length=100)),
33
+                ('age', models.IntegerField()),
34
+                ('idcard', models.CharField(max_length=20, null=True)),
35
+                ('prefix', models.CharField(choices=[('นางสาว', 'นางสาว'), ('นาย', 'นาย'), ('นาง', 'นาง'), ('ด.ช.', 'เด็กชาย'), ('ด.ญ.', 'เด็กหญิง')], max_length=30, null=True)),
36
+                ('sex', models.CharField(choices=[('male', 'Male'), ('female', 'Female')], max_length=30, null=True)),
37
+                ('photo', models.FileField(blank=True, upload_to='uploads/%Y/%m/%d/', verbose_name='Photo')),
38
+                ('address', models.TextField(blank=True, null=True)),
39
+                ('created_at', models.DateTimeField(auto_now_add=True, null=True)),
40
+                ('updated_at', models.DateTimeField(auto_now=True)),
41
+            ],
42
+        ),
43
+    ]

+ 19 - 0
backend/migrations/0018_ambulance_color.py

@@ -0,0 +1,19 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 10:56
2
+
3
+import colorfield.fields
4
+from django.db import migrations
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('backend', '0017_ambulance_driver'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.AddField(
15
+            model_name='ambulance',
16
+            name='color',
17
+            field=colorfield.fields.ColorField(default='#FF0000', max_length=18),
18
+        ),
19
+    ]

+ 27 - 0
backend/migrations/0019_ambulanceticket.py

@@ -0,0 +1,27 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 16:25
2
+
3
+from django.db import migrations, models
4
+import django.db.models.deletion
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('backend', '0018_ambulance_color'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.CreateModel(
15
+            name='AmbulanceTicket',
16
+            fields=[
17
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18
+                ('status', models.CharField(choices=[('working', 'Working'), ('free', 'Free'), ('ma', 'MA')], max_length=30, null=True)),
19
+                ('checkin_at', models.DateTimeField(blank=True, null=True)),
20
+                ('checkout_at', models.DateTimeField(blank=True, null=True)),
21
+                ('created_at', models.DateTimeField(auto_now_add=True, null=True)),
22
+                ('updated_at', models.DateTimeField(auto_now=True)),
23
+                ('ambulance', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='backend.ambulance')),
24
+                ('driver', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='backend.driver')),
25
+            ],
26
+        ),
27
+    ]

+ 18 - 0
backend/migrations/0020_driver_status.py

@@ -0,0 +1,18 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 16:51
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('backend', '0019_ambulanceticket'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AddField(
14
+            model_name='driver',
15
+            name='status',
16
+            field=models.CharField(choices=[('working', 'Working'), ('free', 'Free'), ('block', 'Block')], max_length=30, null=True),
17
+        ),
18
+    ]

+ 24 - 0
backend/migrations/0021_auto_20210719_0014.py

@@ -0,0 +1,24 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 17:14
2
+
3
+from django.db import migrations
4
+import django_google_maps.fields
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('backend', '0020_driver_status'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.AddField(
15
+            model_name='hospital',
16
+            name='address2',
17
+            field=django_google_maps.fields.AddressField(max_length=200, null=True),
18
+        ),
19
+        migrations.AddField(
20
+            model_name='hospital',
21
+            name='geolocation2',
22
+            field=django_google_maps.fields.GeoLocationField(max_length=100, null=True),
23
+        ),
24
+    ]

+ 21 - 0
backend/migrations/0022_auto_20210719_0024.py

@@ -0,0 +1,21 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 17:24
2
+
3
+from django.db import migrations
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('backend', '0021_auto_20210719_0014'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.RemoveField(
14
+            model_name='hospital',
15
+            name='address2',
16
+        ),
17
+        migrations.RemoveField(
18
+            model_name='hospital',
19
+            name='geolocation2',
20
+        ),
21
+    ]

+ 25 - 0
backend/migrations/0023_place.py

@@ -0,0 +1,25 @@
1
+# Generated by Django 3.2.5 on 2021-07-18 17:29
2
+
3
+from django.db import migrations, models
4
+import django_google_maps.fields
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('backend', '0022_auto_20210719_0024'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.CreateModel(
15
+            name='Place',
16
+            fields=[
17
+                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18
+                ('address', django_google_maps.fields.AddressField(max_length=200)),
19
+                ('geolocation', django_google_maps.fields.GeoLocationField(max_length=100)),
20
+                ('created_at', models.DateTimeField(auto_now_add=True, null=True)),
21
+                ('updated_at', models.DateTimeField(auto_now=True)),
22
+                ('more_info', models.JSONField(blank=True, null=True)),
23
+            ],
24
+        ),
25
+    ]

+ 0 - 0
backend/migrations/__init__.py


二進制
backend/migrations/__pycache__/0001_initial.cpython-39.pyc


二進制
backend/migrations/__pycache__/0002_hospital_geolocation.cpython-39.pyc


二進制
backend/migrations/__pycache__/0003_alter_hospital_address.cpython-39.pyc


二進制
backend/migrations/__pycache__/0004_alter_hospital_location.cpython-39.pyc


二進制
backend/migrations/__pycache__/0005_hospital_address_text.cpython-39.pyc


二進制
backend/migrations/__pycache__/0006_bed_patient.cpython-39.pyc


二進制
backend/migrations/__pycache__/0007_auto_20210718_0246.cpython-39.pyc


二進制
backend/migrations/__pycache__/0007_auto_20210718_0249.cpython-39.pyc


二進制
backend/migrations/__pycache__/0008_alter_patient_prefix.cpython-39.pyc


二進制
backend/migrations/__pycache__/0008_auto_20210718_0659.cpython-39.pyc


二進制
backend/migrations/__pycache__/0009_auto_20210718_0702.cpython-39.pyc


二進制
backend/migrations/__pycache__/0010_auto_20210718_0711.cpython-39.pyc


二進制
backend/migrations/__pycache__/0010_auto_20210718_0713.cpython-39.pyc


二進制
backend/migrations/__pycache__/0011_auto_20210718_0722.cpython-39.pyc


二進制
backend/migrations/__pycache__/0012_patient_comment.cpython-39.pyc


二進制
backend/migrations/__pycache__/0013_patientlog.cpython-39.pyc


二進制
backend/migrations/__pycache__/0014_alter_patientlog_bed.cpython-39.pyc


二進制
backend/migrations/__pycache__/0015_alter_patientlog_bed.cpython-39.pyc


二進制
backend/migrations/__pycache__/0016_auto_20210718_1031.cpython-39.pyc


二進制
backend/migrations/__pycache__/0017_ambulance_driver.cpython-39.pyc


二進制
backend/migrations/__pycache__/0018_ambulance_color.cpython-39.pyc


二進制
backend/migrations/__pycache__/0019_ambulanceticket.cpython-39.pyc


二進制
backend/migrations/__pycache__/0020_driver_status.cpython-39.pyc


二進制
backend/migrations/__pycache__/0021_auto_20210719_0014.cpython-39.pyc


二進制
backend/migrations/__pycache__/0022_auto_20210719_0024.cpython-39.pyc


二進制
backend/migrations/__pycache__/0023_place.cpython-39.pyc


二進制
backend/migrations/__pycache__/__init__.cpython-39.pyc


+ 192 - 0
backend/models.py

@@ -0,0 +1,192 @@
1
+#from django.db import models
2
+from django.contrib.gis.db import models
3
+from django_google_maps import fields as map_fields
4
+from colorfield.fields import ColorField
5
+#from smart_selects.db_fields import GroupedForeignKey
6
+from smart_selects.db_fields import (
7
+    ChainedForeignKey,
8
+    ChainedManyToManyField,
9
+    GroupedForeignKey,
10
+)
11
+# Create your models here.
12
+GENDER_CHOICES = (
13
+    ('นางสาว','นางสาว'),
14
+    ('นาย','นาย'),
15
+    ('นาง', 'นาง'),
16
+    ("ด.ช.","เด็กชาย"),
17
+    ("ด.ญ.","เด็กหญิง"),
18
+)
19
+
20
+class Ambulance(models.Model):
21
+    code = models.CharField(max_length=100)
22
+    license_plate = models.CharField(max_length=100)
23
+    brand = models.CharField(max_length=100)
24
+    model_name = models.CharField(max_length=100)
25
+    comment  = models.TextField(blank=True, null=True)
26
+
27
+    color = ColorField(default='#FF0000')
28
+    status = models.CharField(
29
+        max_length=30,
30
+        choices=(("working", "Working"), ("free", "Free"), ("ma", "MA")),
31
+        null=True,
32
+    )
33
+
34
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
35
+    updated_at = models.DateTimeField(auto_now=True)
36
+
37
+    def __str__(self):
38
+        return f"{self.license_plate} ({self.get_status_display()}) {self.code} {self.brand} / {self.model_name}"
39
+
40
+class Driver(models.Model):
41
+    first_name = models.CharField(max_length=100)
42
+    last_name = models.CharField(max_length=100)
43
+    age = models.IntegerField()
44
+    idcard = models.CharField(max_length=20, null=True, blank=False)
45
+    prefix = models.CharField(
46
+        max_length=30,
47
+        choices=GENDER_CHOICES,
48
+        null=True,
49
+    )
50
+    sex = models.CharField(
51
+        max_length=30,
52
+        choices=(("male", "Male"), ("female", "Female"),),
53
+        null=True,
54
+    )
55
+    photo  = models.FileField(upload_to="uploads/%Y/%m/%d/", blank=True, verbose_name="Photo")
56
+
57
+    address  = models.TextField(blank=True, null=True)
58
+    #test
59
+    status = models.CharField(
60
+        max_length=30,
61
+        choices=(("working", "Working"), ("free", "Free"), ("block", "Block")),
62
+        null=True,
63
+    )
64
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
65
+    updated_at = models.DateTimeField(auto_now=True)
66
+
67
+    def __str__(self):
68
+        return f"{self.first_name} {self.last_name} ({self.get_status_display()})"
69
+
70
+class AmbulanceTicket(models.Model):
71
+    driver = models.ForeignKey(Driver, on_delete=models.SET_NULL, null=True)
72
+    ambulance = models.ForeignKey(Ambulance, on_delete=models.SET_NULL, null=True)
73
+
74
+    status = models.CharField(
75
+        max_length=30,
76
+        choices=(("working", "Working"), ("free", "Free"), ("ma", "MA")),
77
+        null=True,
78
+    )
79
+
80
+    checkin_at = models.DateTimeField(null=True, blank=True)
81
+    checkout_at = models.DateTimeField(null=True, blank=True)
82
+
83
+
84
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
85
+    updated_at = models.DateTimeField(auto_now=True)
86
+
87
+
88
+    def save(self, *args, **kwargs):
89
+        super(AmbulanceTicket, self).save(*args, **kwargs)
90
+        self.ambulance.status = self.status
91
+        self.ambulance.save()
92
+        self.driver.status = "working"
93
+        self.driver.save()
94
+
95
+    def __str__(self):
96
+        return f"{self.driver}@{self.ambulance}"
97
+
98
+class Patient(models.Model):
99
+    first_name = models.CharField(max_length=100)
100
+    last_name = models.CharField(max_length=100)
101
+    age = models.IntegerField()
102
+    idcard = models.CharField(max_length=20, null=True, blank=False)
103
+    prefix = models.CharField(
104
+        max_length=30,
105
+        choices=GENDER_CHOICES,
106
+        null=True,
107
+    )
108
+    sex = models.CharField(
109
+        max_length=30,
110
+        choices=(("male", "Male"), ("female", "Female"),),
111
+        null=True,
112
+    )
113
+    photo  = models.FileField(upload_to="uploads/%Y/%m/%d/", blank=True, verbose_name="Photo")
114
+
115
+    address = map_fields.AddressField(max_length=200, null=True)
116
+    geolocation = map_fields.GeoLocationField(max_length=100, null=True)
117
+    condition_level = models.CharField(
118
+        max_length=30,
119
+        choices=(("green", "Green"), ("yellow", "Yellow"), ("red", "Red")),
120
+        null=True,
121
+    )
122
+    comment  = models.TextField(blank=True, null=True)
123
+    #test
124
+    def __str__(self):
125
+        return f"{self.first_name} {self.last_name}"
126
+
127
+class Place(models.Model):
128
+    address = map_fields.AddressField(max_length=200)
129
+    geolocation = map_fields.GeoLocationField(max_length=100)
130
+
131
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
132
+    updated_at = models.DateTimeField(auto_now=True)
133
+
134
+    more_info  = models.JSONField(null=True, blank=True)
135
+
136
+class Hospital(models.Model):
137
+    title = models.CharField(max_length=200)
138
+    location = models.PointField(blank=True, null=True)
139
+    address_text = models.TextField(blank=True, null=True)
140
+    #address = models.CharField(max_length=100)
141
+    address = map_fields.AddressField(max_length=200)
142
+    geolocation = map_fields.GeoLocationField(max_length=100)
143
+
144
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
145
+    updated_at = models.DateTimeField(auto_now=True)
146
+
147
+    def __str__(self):
148
+        return f"{self.title} {self.address_text}"
149
+
150
+
151
+class Bed(models.Model):
152
+    code = models.CharField(max_length=30)
153
+    occupy = models.BooleanField(default=False)
154
+    patient = models.ForeignKey(Patient, on_delete=models.SET_NULL, null=True, blank=True)
155
+    hospital = models.ForeignKey(Hospital, on_delete=models.CASCADE)
156
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
157
+    updated_at = models.DateTimeField(auto_now=True)
158
+
159
+
160
+    def __str__(self):
161
+        return self.code
162
+
163
+
164
+class PatientLog(models.Model):
165
+    patient = models.ForeignKey(Patient, on_delete=models.SET_NULL, null=True)
166
+    hospital = models.ForeignKey(Hospital, on_delete=models.CASCADE, null=True)
167
+    bed = ChainedForeignKey(
168
+        "Bed",
169
+        chained_field="hospital",
170
+        chained_model_field="hospital",
171
+        show_all=False,
172
+        auto_choose=True,
173
+        null=True
174
+    )
175
+    notes  = models.TextField(blank=True, null=True)
176
+    condition_level = models.CharField(
177
+        max_length=30,
178
+        choices=(("green", "Green"), ("yellow", "Yellow"), ("red", "Red")),
179
+        null=True,
180
+    )
181
+    status = models.CharField(
182
+        max_length=30,
183
+        choices=(("active", "Active"), ("inactive", "Inactive"), ("transfer", "Transfer")),
184
+        null=True,
185
+    )
186
+    checkin_at = models.DateTimeField(null=True, blank=True)
187
+    checkout_at = models.DateTimeField(null=True, blank=True)
188
+
189
+    created_at = models.DateTimeField(auto_now_add=True, null=True)
190
+    updated_at = models.DateTimeField(auto_now=True)
191
+
192
+

+ 3 - 0
backend/tests.py

@@ -0,0 +1,3 @@
1
+from django.test import TestCase
2
+
3
+# Create your tests here.

+ 7 - 0
backend/urls.py

@@ -0,0 +1,7 @@
1
+from django.urls import path
2
+
3
+from . import views
4
+
5
+urlpatterns = [
6
+    path('', views.index, name='index'),
7
+]

+ 8 - 0
backend/views.py

@@ -0,0 +1,8 @@
1
+from django.shortcuts import render
2
+
3
+# Create your views here.
4
+from django.http import HttpResponse
5
+
6
+
7
+def index(request):
8
+    return HttpResponse("Hello, world. You're at the polls index.")

+ 1 - 0
data/db/PG_VERSION

@@ -0,0 +1 @@
1
+13

二進制
data/db/base/1/112


二進制
data/db/base/1/113


二進制
data/db/base/1/1247


二進制
data/db/base/1/1247_fsm


二進制
data/db/base/1/1247_vm


二進制
data/db/base/1/1249


二進制
data/db/base/1/1249_fsm


二進制
data/db/base/1/1249_vm


二進制
data/db/base/1/1255


二進制
data/db/base/1/1255_fsm


二進制
data/db/base/1/1255_vm


二進制
data/db/base/1/1259


二進制
data/db/base/1/1259_fsm


二進制
data/db/base/1/1259_vm


二進制
data/db/base/1/13245


二進制
data/db/base/1/13245_fsm


二進制
data/db/base/1/13245_vm


+ 0 - 0
data/db/base/1/13247


二進制
data/db/base/1/13249


二進制
data/db/base/1/13250


二進制
data/db/base/1/13250_fsm


二進制
data/db/base/1/13250_vm


+ 0 - 0
data/db/base/1/13252


二進制
data/db/base/1/13254


二進制
data/db/base/1/13255


二進制
data/db/base/1/13255_fsm


二進制
data/db/base/1/13255_vm


+ 0 - 0
data/db/base/1/13257


二進制
data/db/base/1/13259


二進制
data/db/base/1/13260


二進制
data/db/base/1/13260_fsm


二進制
data/db/base/1/13260_vm


+ 0 - 0
data/db/base/1/13262


+ 0 - 0
data/db/base/1/13264


Some files were not shown because too many files changed in this diff

tum/whitesports - Gogs: Simplico Git Service

Nessuna descrizione

class.wpcom-json-api-site-user-endpoint.php 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. new WPCOM_JSON_API_Site_User_Endpoint( array(
  3. 'description' => 'Get details of a user of a site by ID.',
  4. 'group' => '__do_not_document', //'users'
  5. 'stat' => 'sites:1:user',
  6. 'method' => 'GET',
  7. 'path' => '/sites/%s/users/%d',
  8. 'path_labels' => array(
  9. '$site' => '(int|string) Site ID or domain',
  10. '$user_id' => '(int) User ID',
  11. ),
  12. 'response_format' => WPCOM_JSON_API_Site_User_Endpoint::$user_format,
  13. 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/30434183/user/23',
  14. 'example_request_data' => array(
  15. 'headers' => array(
  16. 'authorization' => 'Bearer YOUR_API_TOKEN'
  17. ),
  18. ),
  19. 'example_response' => '{
  20. "ID": 18342963,
  21. "login": "binarysmash",
  22. "email": false,
  23. "name": "binarysmash",
  24. "URL": "http:\/\/binarysmash.wordpress.com",
  25. "avatar_URL": "http:\/\/0.gravatar.com\/avatar\/a178ebb1731d432338e6bb0158720fcc?s=96&d=identicon&r=G",
  26. "profile_URL": "http:\/\/en.gravatar.com\/binarysmash",
  27. "roles": [ "administrator" ]
  28. }'
  29. ) );
  30. new WPCOM_JSON_API_Site_User_Endpoint( array(
  31. 'description' => 'Get details of a user of a site by login.',
  32. 'group' => 'users',
  33. 'stat' => 'sites:1:user',
  34. 'method' => 'GET',
  35. 'path' => '/sites/%s/users/login:%s',
  36. 'path_labels' => array(
  37. '$site' => '(int|string) The site ID or domain.',
  38. '$user_id' => '(string) The user\'s login.',
  39. ),
  40. 'response_format' => WPCOM_JSON_API_Site_User_Endpoint::$user_format,
  41. 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/30434183/user/login:binarysmash',
  42. 'example_request_data' => array(
  43. 'headers' => array(
  44. 'authorization' => 'Bearer YOUR_API_TOKEN'
  45. ),
  46. ),
  47. 'example_response' => '{
  48. "ID": 18342963,
  49. "login": "binarysmash",
  50. "email": false,
  51. "name": "binarysmash",
  52. "URL": "http:\/\/binarysmash.wordpress.com",
  53. "avatar_URL": "http:\/\/0.gravatar.com\/avatar\/a178ebb1731d432338e6bb0158720fcc?s=96&d=identicon&r=G",
  54. "profile_URL": "http:\/\/en.gravatar.com\/binarysmash",
  55. "roles": [ "administrator" ]
  56. }'
  57. ) );
  58. new WPCOM_JSON_API_Site_User_Endpoint( array(
  59. 'description' => 'Update details of a user of a site.',
  60. 'group' => 'users',
  61. 'stat' => 'sites:1:user',
  62. 'method' => 'POST',
  63. 'path' => '/sites/%s/users/%d',
  64. 'path_labels' => array(
  65. '$site' => '(int|string) The site ID or domain.',
  66. '$user_id' => '(int) The user\'s ID.',
  67. ),
  68. 'request_format' => WPCOM_JSON_API_Site_User_Endpoint::$user_format,
  69. 'response_format' => WPCOM_JSON_API_Site_User_Endpoint::$user_format,
  70. 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/30434183/user/23',
  71. 'example_request_data' => array(
  72. 'headers' => array(
  73. 'authorization' => 'Bearer YOUR_API_TOKEN'
  74. ),
  75. 'body' => array(
  76. 'roles' => array(
  77. array(
  78. 'administrator',
  79. )
  80. ),
  81. 'first_name' => 'Rocco',
  82. 'last_name' => 'Tripaldi',
  83. )
  84. ),
  85. 'example_response' => '{
  86. "ID": 18342963,
  87. "login": "binarysmash",
  88. "email": false,
  89. "name": "binarysmash",
  90. "URL": "http:\/\/binarysmash.wordpress.com",
  91. "avatar_URL": "http:\/\/0.gravatar.com\/avatar\/a178ebb1731d432338e6bb0158720fcc?s=96&d=identicon&r=G",
  92. "profile_URL": "http:\/\/en.gravatar.com\/binarysmash",
  93. "roles": [ "administrator" ]
  94. }'
  95. ) );
  96. class WPCOM_JSON_API_Site_User_Endpoint extends WPCOM_JSON_API_Endpoint {
  97. public static $user_format = array(
  98. 'ID' => '(int) The ID of the user',
  99. 'login' => '(string) The login username of the user',
  100. 'email' => '(string) The email of the user',
  101. 'name' => '(string) The name to display for the user',
  102. 'first_name' => '(string) The first name of the user',
  103. 'last_name' => '(string) The last name of the user',
  104. 'nice_name' => '(string) The nice_name to display for the user',
  105. 'URL' => '(string) The primary blog of the user',
  106. 'avatar_URL' => '(url) Gravatar image URL',
  107. 'profile_URL' => '(url) Gravatar Profile URL',
  108. 'site_ID' => '(int) ID of the user\'s primary blog',
  109. 'roles' => '(array|string) The role or roles of the user',
  110. );
  111. // /sites/%s/users/%d -> $blog_id, $user_id
  112. function callback( $path = '', $blog_id = 0, $user_id = 0 ) {
  113. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
  114. if ( is_wp_error( $blog_id ) ) {
  115. return $blog_id;
  116. }
  117. if ( ! current_user_can_for_blog( $blog_id, 'list_users' ) ) {
  118. return new WP_Error( 'unauthorized', 'User cannot view users for specified site', 403 );
  119. }
  120. // Get the user by ID or login
  121. $get_by = false !== strpos( $path, '/users/login:' ) ? 'login' : 'id';
  122. $user = get_user_by( $get_by, $user_id );
  123. if ( ! $user ) {
  124. return new WP_Error( 'unknown_user', 'Unknown user', 404 );
  125. }
  126. if ( ! is_user_member_of_blog( $user->ID, $blog_id ) ) {
  127. return new WP_Error( 'unknown_user_for_site', 'Unknown user for site', 404 );
  128. }
  129. if ( 'GET' === $this->api->method ) {
  130. return $this->get_user( $user->ID );
  131. } else if ( 'POST' === $this->api->method ) {
  132. if ( ! current_user_can_for_blog( $blog_id, 'promote_users' ) ) {
  133. return new WP_Error( 'unauthorized_no_promote_cap', 'User cannot promote users for specified site', 403 );
  134. }
  135. return $this->update_user( $user_id, $blog_id );
  136. } else {
  137. return new WP_Error( 'bad_request', 'An unsupported request method was used.' );
  138. }
  139. }
  140. public function get_user( $user_id ) {
  141. $the_user = $this->get_author( $user_id, true );
  142. if ( $the_user && ! is_wp_error( $the_user ) ) {
  143. $userdata = get_userdata( $user_id );
  144. $the_user->roles = ! is_wp_error( $userdata ) ? array_values( $userdata->roles ) : array();
  145. }
  146. return $the_user;
  147. }
  148. /**
  149. * Updates user data
  150. *
  151. * @return array
  152. */
  153. public function update_user( $user_id, $blog_id ) {
  154. $input = $this->input();
  155. $user['ID'] = $user_id;
  156. $is_wpcom = defined( 'IS_WPCOM' ) && IS_WPCOM;
  157. if ( get_current_user_id() == $user_id && isset( $input['roles'] ) ) {
  158. return new WP_Error( 'unauthorized', 'You cannot change your own role', 403 );
  159. }
  160. if ( $is_wpcom && $user_id !== get_current_user_id() && $user_id == wpcom_get_blog_owner( $blog_id ) ) {
  161. return new WP_Error( 'unauthorized_edit_owner', 'Current user can not edit blog owner', 403 );
  162. }
  163. if ( ! $is_wpcom ) {
  164. foreach ( $input as $key => $value ) {
  165. if ( ! is_array( $value ) ) {
  166. $value = trim( $value );
  167. }
  168. $value = wp_unslash( $value );
  169. switch ( $key ) {
  170. case 'first_name':
  171. case 'last_name':
  172. $user[ $key ] = $value;
  173. break;
  174. case 'display_name':
  175. case 'name':
  176. $user[ 'display_name' ] = $value;
  177. break;
  178. }
  179. }
  180. }
  181. if ( isset( $input[ 'roles' ] ) ) {
  182. // For now, we only use the first role in the array.
  183. if ( is_array( $input['roles'] ) ) {
  184. $user['role'] = $input['roles'][0];
  185. } else if ( is_string( $input['roles'] ) ) {
  186. $user['role'] = $input['roles'];
  187. } else {
  188. return new WP_Error( 'invalid_input', __( 'The roles property must be a string or an array.', 'jetpack' ), 400 );
  189. }
  190. $editable_roles = array_keys( get_editable_roles() );
  191. if ( ! in_array( $user['role'], $editable_roles ) ) {
  192. return new WP_Error( 'invalid_input', sprintf( __( '%s is not a valid role.', 'jetpack' ), $editable_roles ), 400 );
  193. }
  194. }
  195. $result = wp_update_user( $user );
  196. if ( is_wp_error( $result ) ) {
  197. return $result;
  198. }
  199. return $this->get_user( $user_id );
  200. }
  201. }