@@ -17,15 +17,24 @@ def map_to_logbook_template(json_output):
1717 with open ("templates/modified_templates.json" , 'r' ) as f :
1818 modified_templates = json .load (f )
1919
20- # Get the field names in order
21- modified_fields = list (modified_templates ["adult_cardiac_log_2" ].keys ())
22- logbook_fields = list (logbook_templates ["Adult_cardiac_log_2" ].keys ())
20+ # Initialize result dictionary with all fields from both templates set to None
21+ result = {}
22+ result .update ({key : None for key in logbook_templates ["Adult_cardiac_log" ].keys ()})
23+ result .update ({key : None for key in logbook_templates ["Adult_cardiac_log_2" ].keys ()})
2324
24- # Create result dictionary with all fields initialized to None
25- result = {key : None for key in logbook_fields }
25+ # Map fields for adult_cardiac_log
26+ modified_fields_1 = list (modified_templates ["Adult_cardiac_log" ].keys ())
27+ logbook_fields_1 = list (logbook_templates ["Adult_cardiac_log" ].keys ())
2628
27- # Map fields by position
28- for modified_field , logbook_field in zip (modified_fields , logbook_fields ):
29+ for modified_field , logbook_field in zip (modified_fields_1 , logbook_fields_1 ):
30+ if modified_field in json_output :
31+ result [logbook_field ] = json_output [modified_field ].replace ("###SECTION###" , "" )
32+
33+ # Map fields for adult_cardiac_log_2
34+ modified_fields_2 = list (modified_templates ["adult_cardiac_log_2" ].keys ())
35+ logbook_fields_2 = list (logbook_templates ["Adult_cardiac_log_2" ].keys ())
36+
37+ for modified_field , logbook_field in zip (modified_fields_2 , logbook_fields_2 ):
2938 if modified_field in json_output :
3039 result [logbook_field ] = json_output [modified_field ].replace ("###SECTION###" , "" )
3140
@@ -42,6 +51,21 @@ def process_image(image_path):
4251
4352def qwen (image_paths = ["../assets/kkl3.jpg" , "../assets/kkl2.jpg" ]):
4453 try :
54+ # Load templates first
55+ with open ("templates/modified_templates.json" , 'r' ) as f :
56+ modified_templates = json .load (f )
57+
58+ # Get all field names from both templates
59+ field_names = []
60+ field_names .extend (list (modified_templates ["Adult_cardiac_log" ].keys ()))
61+ field_names .extend (list (modified_templates ["adult_cardiac_log_2" ].keys ()))
62+
63+ if not field_names :
64+ raise ValueError ("No field names found in templates" )
65+
66+ # Ensure field names are unique
67+ field_names = list (dict .fromkeys (field_names ))
68+
4569 # Load the model and processor with explicit trust_remote_code
4670 model_name = "Qwen/Qwen2.5-VL-3B-Instruct"
4771
@@ -188,9 +212,9 @@ def qwen(image_paths=["../assets/kkl3.jpg", "../assets/kkl2.jpg"]):
188212 section_order = ["basics" , "case_details" , "hpi" , "social" , "PMHx" , "medications" , "allergies" , "exam" , "veins" , "allen_test" , "INVx" , "CXR/CT" , "surgical_plan" , "flags" , "operative_notes" , "post_op_notes" , "learning_points" ]
189213 combined_text = SECTION_SEPARATOR .join (all_transcribed_sections .get (section , "" ) for section in section_order )
190214
191- # Convert to JSON using the existing parser
192- json_output = process_text_file (combined_text )
193-
215+ # Convert to JSON using the text processor with field names
216+ json_output = process_text_file (combined_text , field_names )
217+ json_output [ 'type' ] = 'adult_cardiac_logs'
194218 # Map to logbook template format
195219 final_output = map_to_logbook_template (json_output )
196220
0 commit comments