-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Medibase: Drop littletable; instead store as list from ORM's `values_…
…list` (#1443) * custom in memory search * as tuple * fix tests * remove db queryset reference after loading to in-memory * minor optimization * remove commented code * load to in-mem using ORM's `values_list` * Update care/facility/api/viewsets/prescription.py Co-authored-by: Aakash Singh <[email protected]> --------- Co-authored-by: Aakash Singh <[email protected]>
- Loading branch information
1 parent
f0734f5
commit eb98ba0
Showing
3 changed files
with
50 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,34 @@ | ||
from littletable import Table | ||
from django.db.models import CharField, TextField, Value | ||
from django.db.models.functions import Coalesce | ||
|
||
from care.facility.models.prescription import MedibaseMedicine | ||
|
||
MedibaseMedicineTable = Table("MedibaseMedicine") | ||
|
||
medibase_objects = MedibaseMedicine.objects.all() | ||
|
||
for obj in medibase_objects: | ||
MedibaseMedicineTable.insert( | ||
{ | ||
"id": obj.id, | ||
"external_id": obj.external_id, | ||
"name": obj.name, | ||
"type": obj.type, | ||
"generic": obj.generic or "", | ||
"company": obj.company or "", | ||
"contents": obj.contents or "", | ||
"cims_class": obj.cims_class or "", | ||
"atc_classification": obj.atc_classification or "", | ||
"searchable": f"{obj.name} {obj.generic} {obj.company}", | ||
} | ||
def load_medibase_in_memory(): | ||
return ( | ||
MedibaseMedicine.objects.all() | ||
.annotate( | ||
generic_pretty=Coalesce("generic", Value(""), output_field=CharField()), | ||
company_pretty=Coalesce("company", Value(""), output_field=CharField()), | ||
contents_pretty=Coalesce("contents", Value(""), output_field=TextField()), | ||
cims_class_pretty=Coalesce( | ||
"cims_class", Value(""), output_field=CharField() | ||
), | ||
atc_classification_pretty=Coalesce( | ||
"atc_classification", Value(""), output_field=TextField() | ||
), | ||
) | ||
.values_list( | ||
"external_id", | ||
"name", | ||
"type", | ||
"generic_pretty", | ||
"company_pretty", | ||
"contents_pretty", | ||
"cims_class_pretty", | ||
"atc_classification_pretty", | ||
) | ||
) | ||
|
||
MedibaseMedicineTable.create_index("id", unique=True) | ||
MedibaseMedicineTable.create_search_index("searchable") | ||
|
||
MedibaseMedicineTable = load_medibase_in_memory() |
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