81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"fmt"
|
|
"inou/lib"
|
|
"os"
|
|
)
|
|
|
|
const labPrompt = `Extract raw lab data only. No interpretations.
|
|
|
|
Return JSON:
|
|
{
|
|
"lab_date": "YYYY-MM-DD",
|
|
"lab_name": "laboratory name",
|
|
"patient_name": "as written",
|
|
"tests": [
|
|
{
|
|
"name": "test name in original language",
|
|
"value": "number only",
|
|
"unit": "unit only"
|
|
}
|
|
]
|
|
}
|
|
|
|
Rules:
|
|
- Extract ONLY: test name, numeric value, unit
|
|
- DO NOT include: reference ranges, normal/abnormal flags, interpretations, comments
|
|
- DO NOT include any text like "within normal limits" or "elevated"
|
|
- If a test has no numeric value, skip it
|
|
- Keep test names in original language (Russian)
|
|
- Value must be the raw number, nothing else`
|
|
|
|
func main() {
|
|
if err := lib.CryptoInit("/tank/inou/master.key"); err != nil {
|
|
fmt.Fprintf(os.Stderr, "CryptoInit: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
lib.ConfigInit()
|
|
|
|
// Pick first lab file
|
|
pdfPath := "/tank/inou/anastasiia-restored/labs/21000299-01-r.pdf"
|
|
if len(os.Args) > 1 {
|
|
pdfPath = os.Args[1]
|
|
}
|
|
|
|
pdfBytes, err := os.ReadFile(pdfPath)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "ReadFile: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
b64 := base64.StdEncoding.EncodeToString(pdfBytes)
|
|
parts := []lib.GeminiPart{
|
|
{Text: labPrompt},
|
|
{
|
|
InlineData: &lib.GeminiInlineData{
|
|
MimeType: "application/pdf",
|
|
Data: b64,
|
|
},
|
|
},
|
|
}
|
|
|
|
resp, err := lib.CallGeminiMultimodal(parts, nil)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Gemini: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Pretty print
|
|
var result map[string]interface{}
|
|
if err := json.Unmarshal([]byte(resp), &result); err != nil {
|
|
fmt.Println("Raw response:", resp)
|
|
return
|
|
}
|
|
|
|
pretty, _ := json.MarshalIndent(result, "", " ")
|
|
fmt.Println(string(pretty))
|
|
}
|