-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPatientMessageController.java
More file actions
83 lines (72 loc) · 2.46 KB
/
PatientMessageController.java
File metadata and controls
83 lines (72 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
public class PatientMessageController extends Controller {
@FXML
TextArea textArea;
@FXML
TextField textBox;
@FXML
Button sendMessage, patientMessageBackButton;
private String messageToSend, messageToShow, filename, doctorHash, patientHash;
private MessageHandler messageHandler = new MessageHandler();
private Doctor doctor;
private Patient patient;
@Override
public void initData() {
patient = (Patient) super.currentUser;
doctor = patient.currentDoctor;
// i want to set the textArea to any previous existing messages
try {
showMessage();
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
void handleBackButton(ActionEvent event) throws IOException {
super.backButton(super.prevPage, patientMessageBackButton);
}
@FXML
void handlePatientSendMessage(ActionEvent event) throws IOException {
// if text is empty, dont do anything
if (textBox.getText() == null || textBox.getText().trim().isEmpty()) {
textBox.setPromptText("Message is empty");
return;
}
// set the message equal to whatever is in the text box
messageToSend = textBox.getText();
// message the patient
patient.sendMessage(doctor, messageToSend);
// update the textArea
showMessage();
// clears the text after sending
textBox.clear();
}
/**
* This method will update the textArea to show the messages between the doctor
* and their current patient
*
* @throws IOException
*/
private void showMessage() throws IOException {
// get hashes of the doctor and patient
doctorHash = doctor.getDoctorFirstName();
patientHash = patient.getPatientFirstName();
// this is where the message is stored
filename = doctorHash + patientHash + ".txt";
// update the textArea and show the message
messageToShow = messageHandler.readMessage(filename);
textArea.setText(messageToShow);
}
}