通知病人是否发烧

时间:2019-04-18 22:46:25

标签: java medical

如果每隔几分钟给出一次温度读数,您将如何设计一个对象以在患者发烧时发送警报? 假设您有将测量等级的温度等级。这是班级温度:

public class Temperature {
    private float temperature;
    private Location location;

    public Temperature(int temperature, Location location) {
        this.temperature = temperature;
        this.location = location;
    }

    public Temperature(Location location) {
        this.temperature = 0;
        this.location = location;
    }

    public float getTemperature() {
        return temperature;
    }

    public void setTemperature(int temperature) {
        this.temperature = temperature;
    }

    public Location getLocation() {
        return location;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    public double getTemperatureInFahrenheit() {
        return ( temperature * (9/5.0) + 32 );
    }
}

3 个答案:

答案 0 :(得分:2)

如果您只需要打印出温度已超过阈值,则将其添加到设置器中

public void setTemperature(int temperature) {
    this.temperature = temperature;
    if (temperature > YOUR_THRESHOLD) { System.out.println("BURNING MAN!"); }
}

此外,请从构造函数中调用此setter,而不要重复代码。

答案 1 :(得分:1)

我将应用观察者模式,看看Wiki:

https://en.wikipedia.org/wiki/Observer_pattern

当您希望收到通知或交付时,将使用此模式。

正如@Nirup Iyer所述,您应该在激活警报时调度事件。您可以接受警报列表并在设置时对其进行验证。

答案 2 :(得分:0)

我想创建一个专用的线程来充当您的发烧监控器,并保持判断温度是否为发烧的依据,而不是从要从事该工作的班级中删除一个步骤(并在更多本地控制下)保持温度。

假设我们有一个名为FeverMonitor的JPanel。有多种方法可以创建以给定时间间隔重复的代码,但是util.Timer是实现此目的的一个很好的类。

您将创建一个TimerTask来检查温度并将其与发烧值进行比较。将TimerTaskTimer关联时,您将有机会设置每次执行任务之间应该经过多少时间,以及是否继续重复执行该任务。

可以将任务设置为更改FeverMonitor上JLabel的值或属性。例如,我正在考虑每30秒发布一次患者的当前体温,如果该值发烧,则背景颜色或字体颜色会变成红色。

但是也可以将TimerTask设置为执行触发电子邮件或构成“通知”的许多任务中的任何一项。

最后,甚至可以赋予FeverMonitor定义发热的成分(100?102?104?)的能力。 TimerTask可以引用实例变量,也可以生成新的TimerTask并可以替换以前的TimerTask。