Skip to content

Commit 2ed5780

Browse files
committed
Added Regions, Zones, Region-Zone mappings and Hospital-Region mappings.
1 parent b64f447 commit 2ed5780

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

tmh_registry/registry/admin.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
Patient,
1313
PatientHospitalMapping,
1414
PreferredHospital,
15+
Zone,
16+
Region,
17+
HospitalRegionMapping,
18+
RegionZoneMapping,
1519
)
1620

1721

@@ -47,6 +51,22 @@ class PreferredHospitalAdmin(ExportMixin, admin.ModelAdmin):
4751
class EpisodeAdmin(ExportMixin, admin.ModelAdmin):
4852
model = Episode
4953

54+
@admin.register(Zone)
55+
class ZoneAdmin(ExportMixin, admin.ModelAdmin):
56+
model = Zone
57+
58+
@admin.register(Region)
59+
class RegionAdmin(ExportMixin, admin.ModelAdmin):
60+
model = Region
61+
62+
@admin.register(HospitalRegionMapping)
63+
class HospitalRegionMappingAdmin(ExportMixin, admin.ModelAdmin):
64+
model = HospitalRegionMapping
65+
66+
@admin.register(RegionZoneMapping)
67+
class RegionZoneMappingAdmin(ExportMixin, admin.ModelAdmin):
68+
model = RegionZoneMapping
69+
5070

5171
"""
5272
To allow CSV export on User model
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Generated by Django 3.1.3 on 2025-05-19 09:03
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+
('registry', '0037_preferredhospital'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Region',
16+
fields=[
17+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('name', models.CharField(max_length=255, unique=True)),
19+
],
20+
options={
21+
'verbose_name_plural': 'Regions',
22+
},
23+
),
24+
migrations.CreateModel(
25+
name='Zone',
26+
fields=[
27+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
28+
('name', models.CharField(max_length=255, unique=True)),
29+
],
30+
options={
31+
'verbose_name_plural': 'Zones',
32+
},
33+
),
34+
migrations.AlterModelOptions(
35+
name='patienthospitalmapping',
36+
options={'verbose_name_plural': 'Patient-Hospital Mappings'},
37+
),
38+
migrations.CreateModel(
39+
name='RegionZoneMapping',
40+
fields=[
41+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
42+
('region', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='zone_mapping', to='registry.region')),
43+
('zone', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='region_mappings', to='registry.zone')),
44+
],
45+
options={
46+
'verbose_name_plural': 'Region-Zone Mappings',
47+
},
48+
),
49+
migrations.CreateModel(
50+
name='HospitalRegionMapping',
51+
fields=[
52+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
53+
('hospital', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='region_mapping', to='registry.hospital')),
54+
('region', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='hospital_mappings', to='registry.region')),
55+
],
56+
options={
57+
'verbose_name_plural': 'Hospital-Region Mappings',
58+
},
59+
),
60+
]

tmh_registry/registry/models.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,50 @@ def __str__(self):
226226

227227
class Meta:
228228
verbose_name_plural = "Follow Ups"
229+
230+
class Zone(Model):
231+
name = CharField(max_length=255, unique=True)
232+
def __str__(self):
233+
return self.name
234+
class Meta:
235+
verbose_name_plural = "Zones"
236+
237+
class Region(Model):
238+
name = CharField(max_length=255, unique=True)
239+
def __str__(self):
240+
return self.name
241+
class Meta:
242+
verbose_name_plural = "Regions"
243+
244+
class HospitalRegionMapping(Model):
245+
hospital = OneToOneField(
246+
Hospital,
247+
on_delete=CASCADE,
248+
related_name="region_mapping"
249+
)
250+
region = ForeignKey(
251+
Region,
252+
on_delete=CASCADE,
253+
related_name="hospital_mappings"
254+
)
255+
def __str__(self):
256+
return f"{self.hospital.name} - {self.region.name}"
257+
class Meta:
258+
verbose_name_plural = "Hospital-Region Mappings"
259+
260+
class RegionZoneMapping(Model):
261+
region = OneToOneField(
262+
Region,
263+
on_delete=CASCADE,
264+
related_name="zone_mapping"
265+
)
266+
zone = ForeignKey(
267+
Zone,
268+
on_delete=CASCADE,
269+
related_name="region_mappings"
270+
)
271+
def __str__(self):
272+
return f"{self.region.name} - {self.zone.name}"
273+
class Meta:
274+
verbose_name_plural = "Region-Zone Mappings"
275+

0 commit comments

Comments
 (0)