【问题标题】:Notify nurse about the frequency of a medicine the patient must take通知护士患者必须服用的药物频率
【发布时间】:2016-09-26 17:40:51
【问题描述】:

当您从药房获得处方时,会有一个与药物相关的开始日期。药物也有一个预定的频率,告诉您何时服用。频率有相当常见的模式。您可以每 4 小时服用一次。您可以每天服用一次。您可以在用餐时或临睡前服用。您也可以使用 PRN 或“根据需要”。许多药物也有停止作用。您可能需要服药 7 天。您可能需要服用一定数量的剂量。您也可以在余生中服药。假设您必须实施一个系统来告诉护士患者何时应该接受药物治疗。您将如何为处理开始日期、结束日期和频率的药物时间表建模?

我已经完成了基本设计..但我坚持实施计划功能(通知护士用药频率的通知功能)

我的解决方案是

频率等级

    package patientmedicine;

公开课频率{

public PartoftheDay part;
public enum PartoftheDay
{
    Morning,
    Afternoon,
    Evening,
    Night
}

public Frequency( PartoftheDay part ) {
    this.part = part;

} 

public PartoftheDay getPart() {
    return part;
}
public void setPart(PartoftheDay part) {
    this.part = part;
}

}

医学类

    package patientmedicine;

导入 java.util.List;

公开课医学{

private String name;
private String disease;
private String composition;
private String details;
private List<Frequency> frequencyList;



public List<Frequency> getFrequencyList() {
    return frequencyList;
}

public void setFrequencyList(List<Frequency> frequencyList) {
    this.frequencyList = frequencyList;
}

public String getName() {
    return name;
}

public Medicine(String name, String composition, String details) {
    this.name = name;
    this.setComposition(composition);
    this.setDetails(details);

}

public void setName(String name) {
    this.name = name;
}
public String getDisease() {
    return disease;
}
public void setDisease(String disease) {
    this.disease = disease;
}

/**
 * @return the composition
 */
public String getComposition() {
    return composition;
}

/**
 * @param composition the composition to set
 */
public void setComposition(String composition) {
    this.composition = composition;
}

/**
 * @return the details
 */
public String getDetails() {
    return details;
}

/**
 * @param details the details to set
 */
public void setDetails(String details) {
    this.details = details;
}

}

患者分类

    package patientmedicine;

导入 java.util.List;

公共类患者{

private String name;
private String disease;
private List<Medicine> medicineList;



public Patient(String name, String disease) {
    this.setName(name);
    this.setDisease(disease);

}



public List<Medicine> getMedicineList() {
    return medicineList;
}



public void setMedicineList(List<Medicine> medicineList) {
    this.medicineList = medicineList;
}



/**
 * @return the name
 */
public String getName() {
    return name;
}

/**
 * @param name the name to set
 */
public void setName(String name) {
    this.name = name;
}

/**
 * @return the disease
 */
public String getDisease() {
    return disease;
}

/**
 * @param disease the disease to set
 */
public void setDisease(String disease) {
    this.disease = disease;
}

}

程序类

    package patientmedicine;

导入 java.util.ArrayList; 导入 java.util.List;

导入patientmedicine.Frequency.PartoftheDay;

公开课程序{ // 私有列表 patientList;

public static void main(String[] args) {

    List<Frequency> freque1 = new ArrayList<Frequency>();
    freque1.add(new Frequency(PartoftheDay.Morning));
    freque1.add(new Frequency(PartoftheDay.Evening));

    // List<Medicine> medicine = new ArrayList<Medicine>();
    Medicine med1 = new Medicine("Paracetemol", "38g", "For fever");
    med1.setFrequencyList(freque1);

    List<Frequency> freque2 = new ArrayList<Frequency>();
    freque2.add(new Frequency(PartoftheDay.Morning));
    freque2.add(new Frequency(PartoftheDay.Evening));

    Medicine med2 = new Medicine("Ibuprofen", "38g", "For body pains");
    med2.setFrequencyList(freque2);

    List<Medicine> medicineList = new ArrayList<Medicine>();
    medicineList.add(med1);
    medicineList.add(med2);

    Patient patient1 = new Patient("Deepthi", "For body pains");
    patient1.setMedicineList(medicineList);

    List<Patient> patientList = new ArrayList<Patient>();
    patientList.add(patient1);

    for (Patient patientt : patientList) {
        System.out.println(patientt.getDisease());
        System.out.println(patientt.getName());

        for (Medicine medi : patientt.getMedicineList()) {

            System.out.println(medi.getDetails() + medi.getComposition()
                    + medi.getName());

            for (Frequency freq : medi.getFrequencyList()) {
                System.out.println(freq.getPart());
            }

        }

    }

}

}

【问题讨论】:

  • 对不起,我的错误。移除 JS
  • 您介意编辑您的问题并更清楚地说明您遇到的问题吗?你想达到什么目的?你是如何尝试做到这一点的?你卡在哪一部分了?
  • 我已经实现了服用患者药物和频率的类..但我坚持实施计划功能(通知护士患者每天必须服用的药物频率的通知功能)跨度>
  • 所以您正在寻找一种方法来在某个患者需要服药时通知护士?
  • 是的,这就是我要找的

标签: java list design-patterns notifications frequency


【解决方案1】:

这是 Jay 建议的使用侦听器的部分实现。您可以将此骨架代码合并到您的部分实现中。

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

interface AlarmListener {
    void notify(Frequency.PartoftheDay time, String msg);
}

class Nurse implements AlarmListener {
    private String name;
    private Set<Frequency.PartoftheDay> times = new HashSet<>();

    Nurse(String name) {
        this.name = name;
    }

    // Add times of day that this nurse will be notified
    public void addTime(Frequency.PartoftheDay time) {
        this.times.add(time);
    }

    public void notify(Frequency.PartoftheDay time, String msg) {
        if (times.contains(time)) {
            System.out.println("Nurse " + name + ", you are being notified of event:  " + msg);
        }
    }

    @Override
    public String toString() {
        StringBuffer b = new StringBuffer();
        b.append(name).append(":  scheduled for\n");
        for (Frequency.PartoftheDay time : times) {
            b.append("  ").append(time).append("\n");
        }

        return b.toString();
    }
}

class Scheduler {
    List<AlarmListener> alarmListenerList = new ArrayList<>();

    public void addListener(AlarmListener alarmListener) {
        alarmListenerList.add(alarmListener);
    }

    public void rollCall() {
        System.out.println("Roll call:");
        for (AlarmListener a : alarmListenerList) {
            System.out.println(a.toString());
        }
    }

    public void notifyListeners(Frequency.PartoftheDay time) {
        for (AlarmListener a : alarmListenerList) {
            a.notify(time, time.name());
        }
    }
}

class Frequency {
    public enum PartoftheDay
    {
        Morning,
        Afternoon,
        Evening,
        Night
    }
    public PartoftheDay part;
}

public class Main {
    public static void main(String[] args) {
        Nurse alice = new Nurse("Alice");
        alice.addTime(Frequency.PartoftheDay.Morning);
        alice.addTime(Frequency.PartoftheDay.Afternoon);

        Nurse bob = new Nurse("Bob");
        bob.addTime(Frequency.PartoftheDay.Afternoon);
        bob.addTime(Frequency.PartoftheDay.Evening);

        Scheduler scheduler = new Scheduler();
        scheduler.addListener(alice);
        scheduler.addListener(bob);

        // Show who is scheduled to respond to alarms and when
        scheduler.rollCall();

        // Do this if "Morning" has arrived
        System.out.println("Morning now! ----------------");
        scheduler.notifyListeners(Frequency.PartoftheDay.Morning);
        System.out.println("");

        // Do this if "Afternoon" has arrived
        System.out.println("Afternoon now! --------------");
        scheduler.notifyListeners(Frequency.PartoftheDay.Afternoon);
        System.out.println("");

        // Do this if "Evening" has arrived
        System.out.println("Evening now! --------------");
        scheduler.notifyListeners(Frequency.PartoftheDay.Evening);
    }
}

输出:

Roll call:
Alice:  scheduled for
  Morning
  Afternoon

Bob:  scheduled for
  Afternoon
  Evening

Morning now! ----------------
Nurse Alice, you are being notified of event:  Morning

Afternoon now! --------------
Nurse Alice, you are being notified of event:  Afternoon
Nurse Bob, you are being notified of event:  Afternoon

Evening now! --------------
Nurse Bob, you are being notified of event:  Evening

【讨论】:

  • 我正要编写完全相同的实现,但你已经做到了。好工作。我可以把它放在我的公共回购中吗?
  • 是的,很好,杰伊,谢谢你的想法。如果您不介意,请相信我。
  • 当然。如果您不介意,您可以为它做出贡献。我把我的例子放在那里。它也有一些不错的实现;)
  • 非常感谢您的解决方案
  • 您好,想知道这是您正在使用的设计模式吗?如果是的话,它有名字吗?或者这只是你想出的一个实现?谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-04
  • 1970-01-01
相关资源
最近更新 更多