Extract values for the specified IDs in order:

P4-0009: 168 mg (行0010)
P4-0060: 148 mg (行0061)
P4-0121: 230 mg (行0122)
P4-0194: 705 mg (行0195)
P4-0261: 264 mg (行0262)
P4-0309: 332 mg (行0310)

records as 6-element arrays [id, code, value_mg]? "recordsはid,code,value_mgの6要素配列" — likely each record is [id, code, value] triple, and records is array of 6. So records = [[id, code, value], ...] six entries.

Codes:
P4-0009: 7ed13a79f7ef
P4-0060: 9188772de636
P4-0121: 24978b3815ae
P4-0194: 3ff14169240e
P4-0261: f7d04b4b0766
P4-0309: 60359a9d5dda

total_mg = 1st, 3rd, 6th values: 168 + 230 + 332 = 730.

missing: P4-9999 not present → null.