Personal Medical Unit Lars Sarbæk Kristiansen Kasper J. Nielsen Martin Kjeldsen
Agenda Last time Updated classdiagram First draft of implementation Today Updated classdiagram Implementation of selected classes/ops. Testing with VDMUnit
Updated class diagram Class Clock represents global time
Classes of interest Class Clock Representation of global time i.e. Need to determine patient records last update Class MedicalDevice Class PMUSystem (main)
Class Clock class Clock instance variables static private time : nat := 0; operations static public GetTime : () ==> nat GetTime() == return time; static public IncrementClock : () ==> nat IncrementClock() == ( time := time + 1; return time ) end Clock
Class MedicalDevice class MedicalDevice... public RetrieveDeviceData : () ==> Data RetrieveDeviceData() == ( def deviceData = mk_Data(deviceId, dataLog) in ( PurgeData(); return deviceData ); ); public CreateDataEntry: seq of char * nat ==> () CreateDataEntry (data, t) == def newLogEntry = mk_LogEntry(t, data) in dataLog := [newLogEntry] ^ dataLog post entryExists(mk_LogEntry(t,data)); (continued->)
Class MedicalDevice (cont.) … public entryExists: LogEntry ==> bool entryExists(logEntry) == for entry in dataLog do if logEntry.timeStamp = entry.timeStamp then return true else return false; public GetLatestEntries: nat ==> seq of LogEntry GetLatestEntries(amount) == return dataLog(1,...,amount) pre amount <= len dataLog post len dataLog(1,...,amount) = amount end MedicalDevice
Class PMUSystem (main) Operation of interest: CollectDataFromDevices class PMUSystem … public CollectDataFromDevices: seq of char ==> () CollectDataFromDevices(patientId) == ( for all pmu in set pmus do ( def patientIdFromRecord = pmu.RetrievePatientRecord().GetPatientId() in ( if (patientIdFromRecord = patientId) then def deviceList = pmu.RetrieveDeviceList() in for all device in set deviceList do pmu.PollDevice(device.GetDeviceId()) ) pre exists pmu in set pmus & pmu.RetrievePatientRecord().GetPatientId() = patientId; end PMUSystem
Testing the PMU System Benefits of the testing process Discover required functionality Testing with VDMUnit / IO Testcases Example: MedicalDevice unittest
Test case: MedicalUnit (1) class MedicalDeviceTest is subclass of TestCase … -- Test constructor protected TestInit: () ==> () TestInit() == (dcl mUnit : MedicalDevice := new MedicalDevice(1); AssertTrue(mUnit.GetDeviceId()= 1)); -- Test data entries protected TestDataEntries: () ==> () TestDataEntries() == (dcl mUnit : MedicalDevice := new MedicalDevice(1); mUnit.CreateDataEntry("some medical device data", 1); def lastDataEntry = mUnit.GetLatestEntries(1) in AssertTrue(hd lastDataEntry = mk_MedicalDevice`LogEntry(1,"some data")); ); end MedicalDeviceTest Code from MedicalUnitTest.vpp
Test case: MedicalUnit (3) Code from CompletePMUTest class CompletePMUTest operations public Execute: () ==> () Execute() == ( dcl ts: TestSuite:=new TestSuite(); ts.AddTest(new MedicalDeviceTest("MedicalDeviceTest")); ts.Run() ) end CompletePMUTest
Test case: MedicalUnit (1) Result ok?
Summary Todays presentation Recap and introduction of new class Clock Implementation of selected classes/ops. Testing with VDMUnit What’s next? Finish polishing off the implementation Extend test to other units and components Write down what we’ve learned in a really good report!