-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add consultation specific assets (#1524)
- Loading branch information
Showing
7 changed files
with
262 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
care/facility/migrations/0378_consultationbedasset_consultationbed_assets.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Generated by Django 4.2.2 on 2023-08-16 12:44 | ||
|
||
import uuid | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("facility", "0377_merge_20230809_0009"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="ConsultationBedAsset", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"external_id", | ||
models.UUIDField(db_index=True, default=uuid.uuid4, unique=True), | ||
), | ||
( | ||
"created_date", | ||
models.DateTimeField(auto_now_add=True, db_index=True, null=True), | ||
), | ||
( | ||
"modified_date", | ||
models.DateTimeField(auto_now=True, db_index=True, null=True), | ||
), | ||
("deleted", models.BooleanField(db_index=True, default=False)), | ||
( | ||
"asset", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, to="facility.asset" | ||
), | ||
), | ||
( | ||
"consultation_bed", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="facility.consultationbed", | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name="consultationbed", | ||
name="assets", | ||
field=models.ManyToManyField( | ||
related_name="assigned_consultation_beds", | ||
through="facility.ConsultationBedAsset", | ||
to="facility.asset", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from datetime import datetime | ||
|
||
from django.db.models import Q | ||
from rest_framework import status | ||
|
||
from care.facility.models import Asset, AssetLocation, Bed, ConsultationBedAsset | ||
from care.utils.tests.test_base import TestBase | ||
|
||
|
||
class ConsultationBedAssetApiTestCase(TestBase): | ||
def create_asset(self, **kwargs): | ||
return Asset.objects.create(**kwargs) | ||
|
||
def setUp(self) -> None: | ||
super().setUp() | ||
self.asset_location: AssetLocation = AssetLocation.objects.create( | ||
name="asset location", location_type=1, facility=self.facility | ||
) | ||
self.bed1 = Bed.objects.create( | ||
name="bed1", location=self.asset_location, facility=self.facility | ||
) | ||
self.asset1 = self.create_asset( | ||
name="asset1", current_location=self.asset_location | ||
) | ||
self.asset2 = self.create_asset( | ||
name="asset2", current_location=self.asset_location | ||
) | ||
self.asset3 = self.create_asset( | ||
name="asset3", current_location=self.asset_location | ||
) | ||
|
||
def test_link_asset_to_consultation_bed(self): | ||
consultation = self.create_consultation() | ||
response = self.client.post( | ||
"/api/v1/consultationbed/", | ||
{ | ||
"consultation": consultation.external_id, | ||
"bed": self.bed1.external_id, | ||
"start_date": datetime.now().isoformat(), | ||
"assets": [self.asset1.external_id, self.asset2.external_id], | ||
}, | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
self.assertEqual(ConsultationBedAsset.objects.count(), 2) | ||
self.assertEqual( | ||
Asset.objects.filter( | ||
Q(assigned_consultation_beds__isnull=True) | ||
| Q(assigned_consultation_beds__end_date__isnull=False) | ||
).count(), | ||
1, | ||
) |