1010
1111def process_imported_patient_categories (row ):
1212 # Transform the patient category data
13- adult_cat = int (row [ "adult_cat" ] )
14- minor_cat = int (row [ "minor_cat" ] )
15- female_cat = int (row [ "female_cat" ] )
16- male_cat = int (row [ "male_cat" ] )
13+ adult_cat = int (row . pop ( "adult_cat" , 1 ) )
14+ minor_cat = int (row . pop ( "minor_cat" , 1 ) )
15+ female_cat = int (row . pop ( "female_cat" , 1 ) )
16+ male_cat = int (row . pop ( "male_cat" , 1 ) )
1717
1818 category = 0
1919 if male_cat :
@@ -26,10 +26,6 @@ def process_imported_patient_categories(row):
2626 category = category | PATIENT_CATEGORY_MASK_MINOR
2727
2828 # Remove the now useless fields
29- row .pop ("adult_cat" )
30- row .pop ("minor_cat" )
31- row .pop ("female_cat" )
32- row .pop ("male_cat" )
3329
3430 # Add the merged patient category value
3531 row ["patient_category" ] = category
@@ -78,7 +74,7 @@ def dehydrate_minor_cat(self, item_service):
7874 # This method is called once before importing data
7975 # This is used to add the two mandatory fields that are required for creating a medical.Item
8076 # If self.fields do not have a fields.Field, with the column_name set up, then these columns are ignored during import
81- def before_import (self , dataset , using_transactions , dry_run , ** kwargs ):
77+ def before_import (self , dataset , ** kwargs ):
8278 if "patient_category" not in self .fields :
8379 self .fields ["patient_category" ] = fields .Field (attribute = 'patient_category' , column_name = "patient_category" ,
8480 saves_null_values = False ,
@@ -87,13 +83,21 @@ def before_import(self, dataset, using_transactions, dry_run, **kwargs):
8783 self .fields ["audit_user_id" ] = fields .Field (attribute = 'audit_user_id' , column_name = "audit_user_id" ,
8884 saves_null_values = False ,
8985 widget = IntegerWidget ())
86+ super ().before_import (dataset , ** kwargs )
9087
9188 # This method is called when the user flags a row to be deleted (the "delete" column value is '1')
9289 def for_delete (self , row , instance ):
9390 if "delete" in row :
9491 return self .fields ['delete' ].clean (row )
9592
96-
93+ def __init__ (self , user , queryset = None , ):
94+ """
95+ @param user: User to be used for location rights for import and export, and for audit_user_id
96+ @param queryset: Queryset to use for export, Default to full quetyset
97+ """
98+ super ().__init__ ()
99+ self ._user = user
100+
97101# This class is responsible for customizing the import and export processes
98102class ItemResource (ItemServiceResource ):
99103
@@ -102,10 +106,12 @@ class Meta:
102106
103107 # These are the fields that are going to get exported/
104108 fields = ('code' , 'name' , 'type' , 'package' , 'price' , 'quantity' ,
105- 'care_type' , 'frequency' , 'patient_category' )
109+ 'care_type' , 'frequency' , 'patient_category' ,
110+ 'male_cat' , 'female_cat' , 'adult_cat' , 'minor_cat' )
106111
107112 # You can customize the order for exports, but this order is also used during upload
108113 # (to know which fields will be there, instead of reading the headers)
114+ export_order = fields
109115 # export_order = ('code', 'name', 'type', 'package', 'price', 'quantity',
110116 # 'care_type', 'frequency', 'male_cat', 'female_cat', 'adult_cat', 'minor_cat')
111117
@@ -131,7 +137,9 @@ class Meta:
131137
132138 # These are the fields that are going to get exported/
133139 fields = ('code' , 'name' , 'type' , 'level' , 'price' , 'category' ,
134- 'care_type' , 'frequency' , 'patient_category' )
140+ 'care_type' , 'frequency' , 'patient_category' ,
141+ 'male_cat' , 'female_cat' , 'adult_cat' , 'minor_cat' )
142+ export_order = fields
135143
136144 # This method is called once for each row during import
137145 # This is where you can do some data validation/modification + add the missing data
0 commit comments