首页 > 解决方案 > 如何解决药物持有率(MPR)问题?

问题描述

我正在尝试解决药物持有配给问题。

我尝试使用间隔,然后将它们与观察期进行比较。

(ns clara-rules.mpr-new
  (:require [clj-time.core :as t]
            [clj-time.format :as f]))

(defn observe [interval]
  (def start (map #(f/parse (f/formatter "dd MM yyyy") (% :start_)) interval))
  (def end (map #(f/parse (f/formatter "dd MM yyyy") (% :end_)) interval))

  )
(observe '({:start_ "20 01 2012" :end_ "20 02 2012"}
           {:start_ "20 02 2012" :end_ "20 03 2012"}
           {:start_ "20 04 2012" :end_ "20 05 2012"}
           {:start_ "20 06 2012" :end_ "20 07 2012"}))


(defn calc[a b]
(def start_date (f/parse (f/formatter "dd MM yyyy") a)
  )

  (def end_date (f/parse (f/formatter "dd MM yyyy")b)
      )

  (def observation_period(t/in-days(t/interval start_date end_date)))
  (println observation_period)
  )
(calc "01 02 2012" "01 12 2012")

(defn mpr_ratio[]

  (def overlp (map #(t/overlap (t/interval start_date end_date) (t/interval %1 %2))start end))

  (def x (map #(t/in-days %)overlp))
  (println x)
  (def ratio (reduce +(map #(float(*(/ % observation_period)100))x)))
  (println ratio)
  )
(mpr_ratio)

我期望所有间隔和观察期的计算比率。

标签: clojure

解决方案


这就是天间隔函数的样子:

(defn process []
  (let [from ["20 01 2012"
              "20 03 2012"
              "20 06 2012"
              "20 08 2012"]
        to ["20 02 2012"
            "20 05 2012"
            "20 07 2012"
            "20 09 2012"]
        get-date (partial f/parse (f/formatter "dd MM yyyy"))
        days (map #(t/in-days (t/interval (get-date %1) (get-date %2)))
                  from to)]
    days))

user> (process)
;;=> (31 61 30 31)

不过,我建议你阅读一些关于 clojure 的介绍


推荐阅读