Add support for a comment column in timelines
This commit is contained in:
parent
3ac6c2d40c
commit
1801082c71
3 changed files with 9 additions and 3 deletions
|
@ -1,5 +1,9 @@
|
|||
# Revision history for pilu
|
||||
|
||||
## 0.1.1.0 -- 2019-08-31
|
||||
|
||||
* Add support for a comment column in timelines
|
||||
|
||||
## 0.1.0.0 -- YYYY-mm-dd
|
||||
|
||||
* First version. Released on an unsuspecting world.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
-- see http://haskell.org/cabal/users-guide/
|
||||
|
||||
name: pilu
|
||||
version: 0.1.0.0
|
||||
version: 0.1.1.0
|
||||
-- synopsis:
|
||||
-- description:
|
||||
license: BSD3
|
||||
|
|
|
@ -7,7 +7,7 @@ import CSV (Row(..))
|
|||
import Control.Monad (foldM)
|
||||
import Data.List (isSuffixOf, takeWhile)
|
||||
import Data.Map (Map)
|
||||
import qualified Data.Map as Map (delete, empty, insert, lookup, toList)
|
||||
import qualified Data.Map as Map (difference, empty, fromList, insert, lookup, toList)
|
||||
import Data.Time (Day)
|
||||
import Medicine (MedicineName)
|
||||
import Text.ParserCombinators.Parsec.Error (Message(..))
|
||||
|
@ -23,7 +23,7 @@ data Event = Event {
|
|||
instance Row Event where
|
||||
fromRow assoc = do
|
||||
rowDate <- read <$> get "date"
|
||||
(kind, ints) <- foldM addAmount (Nothing, Map.empty) . Map.toList $ Map.delete "date" assoc
|
||||
(kind, ints) <- foldM addAmount (Nothing, Map.empty) $ Map.toList medicineNames
|
||||
maybe
|
||||
(Left $ Expect "A prescription or provisioning for a medicine")
|
||||
(Right . Event rowDate ints)
|
||||
|
@ -31,6 +31,8 @@ instance Row Event where
|
|||
where
|
||||
get key = maybe (Left $ Expect key) Right $ Map.lookup key assoc
|
||||
unexpected = Left . UnExpect . show
|
||||
ignoredKeys = Map.fromList [("date", ""), ("comment", "")]
|
||||
medicineNames = Map.difference assoc ignoredKeys
|
||||
addAmount (evType, ints) (key, val) = do
|
||||
(newEvType, amount) <- readAmount val
|
||||
let newFloats = Map.insert key amount ints
|
||||
|
|
Loading…
Reference in a new issue