-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Medibase Medicines Integration (#1369)
* Adds medibase medicines data * Adds MedibaseMedicine Table and migrations * in-memory search and updated viewsetrs and serializers * rebase migrations * fix import preventing migration * set batch_size on medibase population * noop for medibase population migration * minor fix * cleanup * sort by word matches first * adds test for medibase * fix test casing * fix discharge summary * merge migrations * load medicines data management command * update docs * updated load_dummy_data to call load_medicines_data * merge migrations * fresh migrations, drop medibase_id, use name as unique * remove redundant slice operator * call load_medicines_data in migration * merge migrations --------- Co-authored-by: Vignesh Hari <vichuhari100@gmail.com> Co-authored-by: Aakash Singh <mail@singhaakash.dev>
- Loading branch information
1 parent
b0eefd1
commit 46d6b35
Showing
15 changed files
with
1,144,658 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import json | ||
|
||
from django.core.management import BaseCommand | ||
|
||
from care.facility.models import MedibaseMedicine | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Command to load medibase medicines | ||
Usage: python manage.py load_medicines_data | ||
""" | ||
|
||
help = "Loads Medibase Medicines into the database from medibase.json" | ||
|
||
def fetch_data(self): | ||
with open("data/medibase.json", "r") as json_file: | ||
return json.load(json_file) | ||
|
||
def handle(self, *args, **options): | ||
print("Loading Medibase Medicines into the database from medibase.json") | ||
|
||
medibase_objects = self.fetch_data() | ||
MedibaseMedicine.objects.bulk_create( | ||
[ | ||
MedibaseMedicine( | ||
name=medicine["name"], | ||
type=medicine["type"], | ||
company=medicine.get("company"), | ||
contents=medicine.get("contents"), | ||
cims_class=medicine.get("cims_class"), | ||
atc_classification=medicine.get("atc_classification"), | ||
generic=medicine.get("generic"), | ||
) | ||
for medicine in medibase_objects | ||
], | ||
batch_size=1000, | ||
ignore_conflicts=True, | ||
) |
73 changes: 73 additions & 0 deletions
73
care/facility/migrations/0366_medibasemedicine_and_more.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,73 @@ | ||
# Generated by Django 4.2.2 on 2023-06-28 02:50 | ||
|
||
import uuid | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("facility", "0365_merge_20230626_1834"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="MedibaseMedicine", | ||
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)), | ||
("name", models.CharField(db_index=True, max_length=255, unique=True)), | ||
( | ||
"type", | ||
models.CharField( | ||
choices=[("BRAND", "brand"), ("GENERIC", "generic")], | ||
db_index=True, | ||
max_length=16, | ||
), | ||
), | ||
( | ||
"generic", | ||
models.CharField( | ||
blank=True, db_index=True, max_length=255, null=True | ||
), | ||
), | ||
( | ||
"company", | ||
models.CharField( | ||
blank=True, db_index=True, max_length=255, null=True | ||
), | ||
), | ||
("contents", models.TextField(blank=True, null=True)), | ||
("cims_class", models.CharField(blank=True, max_length=255, null=True)), | ||
("atc_classification", models.TextField(blank=True, null=True)), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
migrations.RenameField( | ||
model_name="prescription", | ||
old_name="medicine", | ||
new_name="medicine_old", | ||
), | ||
] |
27 changes: 27 additions & 0 deletions
27
care/facility/migrations/0367_prescription_medicine_and_more.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,27 @@ | ||
# Generated by Django 4.2.2 on 2023-06-28 02:50 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("facility", "0366_medibasemedicine_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="prescription", | ||
name="medicine", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="facility.medibasemedicine", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="prescription", | ||
name="medicine_old", | ||
field=models.CharField(max_length=1023, null=True), | ||
), | ||
] |
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,17 @@ | ||
# Generated by Django 4.2.2 on 2023-06-28 09:58 | ||
|
||
from django.core.management import call_command | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("facility", "0367_prescription_medicine_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
lambda apps, schema_editor: call_command("load_medicines_data"), | ||
reverse_code=migrations.RunPython.noop, | ||
) | ||
] |
12 changes: 12 additions & 0 deletions
12
care/facility/migrations/0369_merge_0366_auto_20230627_1806_0368_populate_medibase.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,12 @@ | ||
# Generated by Django 4.2.2 on 2023-06-30 02:01 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("facility", "0366_auto_20230627_1806"), | ||
("facility", "0368_populate_medibase"), | ||
] | ||
|
||
operations = [] |
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
Oops, something went wrong.