I'm new to clojure and been trying to solve a problem where a vector of maps
({:disease Asthma, :st-dt 2018-2-1, :en-dt 2018-4-1, :dose 0.25}
{:disease Asthma, :st-dt 2018-3-1, :en-dt 2018-6-5, :dose 0.65}
{:disease BP, :st-dt 2018-5-1, :en-dt 2018-9-1, :dose 0.75})
is given and i have to get a non overlapping data somewhat like
({:disease Asthma, :st-dt 2018-2-1, :en-dt 2018-2-28, :dose 0.25}
{:disease Asthma, :st-dt 2018-3-1, :en-dt 2018-4-1, :dose 0.25}
{:disease Asthma, :st-dt 2018-3-1, :en-dt 2018-4-1, :dose 0.65}
{:disease Asthma, :st-dt 2018-4-2, :en-dt 2018-4-30, :dose 0.65}
{:disease Asthma, :st-dt 2018-5-1, :en-dt 2018-6-5, :dose 0.65}
{:disease BP, :st-dt 2018-5-1, :en-dt 2018-6-5, :dose 0.75}
{:disease BP, :st-dt 2018-6-6, :en-dt 2018-9-1, :dose 0.75})
I've tried using loop and recur but I think it's not possible to recur in both conditions of if.
(defn ab [x] (let [temp x olap (f/overlap (f/interval ((first temp ):st-dt) ((first temp ):en-dt))
(f/interval ((second temp):st-dt) ((second temp):en-dt) ))]
(if olap
(into [] (concat [{:med-type ((first temp ):med-type) :st-dt ((first temp ):st-dt)
:en-dt (f/minus ((second temp) :st-dt) (f/days 1)) :dose ((first temp):dose )}
{:med-type ((first temp ):med-type) :st-dt ((second temp ):st-dt)
:en-dt ((first temp) :en-dt) :dose ((first temp):dose )}
{:med-type ((second temp ):med-type) :st-dt ((second temp ):st-dt)
:en-dt ((first temp) :en-dt) :dose ((second temp):dose )}
{:med-type ((second temp ):med-type) :st-dt (f/plus ((first temp ):en-dt) (f/days 1))
:en-dt ((second temp) :en-dt) :dose ((second temp):dose )}]
(into [] (rest (rest x))))))))