// ParasitemIA file format. module Parasitemia.GUI.Pia open System.Drawing open System.IO open System.IO.Compression open FSharp.Data open Emgu.CV open Emgu.CV.Structure open Types let extension = ".pia" let filter = "PIA|*.pia" type FileData = { sources: SourceImage list patientID: string } // The json type associated to a source image. type JSONSourceImage = JsonProvider<""" { "rbcs": [ { "num": 1, "infected": true, "addedManually": false, "removed": false, "posX" : 42, "posY" : 42, "width" : 10, "height" : 10, "stainArea" : 10 } ] } """> // The json type associated to a file. type JSONMainInformation = JsonProvider<""" { "patientID": "1234abcd" } """> let mainFilename = "info.json" let save (filePath: string) (data: FileData) = use file = ZipFile.Open(filePath, ZipArchiveMode.Update) let mainJSON = JSONMainInformation.Root(data.patientID) let mainFile = match file.GetEntry(mainFilename) with | null -> file.CreateEntry(mainFilename) | entry -> entry use mainFileWriter = new StreamWriter(mainFile.Open()) mainJSON.JsonValue.WriteTo(mainFileWriter, JsonSaveOptions.None) let load (filePath: string) : FileData = use file = ZipFile.Open(filePath, ZipArchiveMode.Read) let mainFile = file.GetEntry(mainFilename) let mainJSON = JSONMainInformation.Load(mainFile.Open()) { sources = []; patientID = mainJSON.PatientId }