-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpatientFile.java
More file actions
executable file
·132 lines (102 loc) · 3.54 KB
/
patientFile.java
File metadata and controls
executable file
·132 lines (102 loc) · 3.54 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import java.io.*;
class patientFile
{
/* Global variables */
private String name;
private String address;
private int hospitalNumber;
private String gender;
private double height;
private double bmi;
/* Made public for heart rate conversion purposes */
public double weight;
public int age;
/* Most relevant details of patient */
public void identityDetails(){
System.out.print("Enter patient name: ");
name = Console.readString();
System.out.print("Enter patient address: ");
address = Console.readString();
System.out.print("Enter patient hospital number: ");
hospitalNumber = Console.readInt();
}
/* Additional details of patient */
public void patientInformation(){
System.out.print("Enter patient age: ");
age = Console.readInt();
System.out.print("Enter patient gender: ");
gender = Console.readToken();
System.out.print("Enter patient weight (pounds): ");
weight = Console.readDouble();
System.out.print("Enter patient height (inches): ");
height = Console.readDouble();
/* Calculate body mass index */
bmi = bodyMassIndex(weight, height);
}
/* Prints all details of registered user to the screen and stores in a txt file for future use */
public void patientBio(){
try{
/* Initialise PrintWriter */
PrintWriter pw = new PrintWriter("Patient_Bio_File.txt");
pw.println("Patient Name: " + name + " .");
pw.println("Patient Address: " + address + " .");
pw.println("Patient Hospital Number: " + hospitalNumber + " .");
pw.println("Patient age: " + age + " .");
pw.println("Patient gender: " + gender + " .");
pw.println("Patient body mass index: " + bmi + " .");
/* Close PrintWriter */
pw.close();
}
catch(IOException e){
e.printStackTrace();
}
}
/* Returns body mass index based on weight and height previously supplied */
private double bodyMassIndex(double weight, double height){
weight *= 703;
height *= height;
return weight/height;
}
/* Allow additional notes based on the patient to be entered */
public void writeBriefNotesLog(){
try{
PrintWriter notesLog = new PrintWriter("Patient_notes_log.txt");
String word = "";
System.out.println('\n' + "Type 'end' to finish writing" + '\n');
System.out.print("Note: ");
/* Continuously allow words to be entered into the file, until 'end' is inserted */
while(!word.equals("end")){
word = Console.readToken();
/* Prevents the word 'end' being included in the file */
if(!word.equals("end"))
notesLog.print(word + " ");
}
notesLog.close();
}
catch(IOException e){
e.printStackTrace();
}
}
/* Extracts previously entered notes based on patient */
public void readBriefNotesLog(){
try{
/* Supports both synchronous and asynchronous read and write operations */
FileInputStream fstream = new FileInputStream("Patient_notes_log.txt");
/* Enables the ability to read Java primitives */
DataInputStream in = new DataInputStream(fstream);
/* Reads text from a character-input stream */
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
/* While pointer has not reached the end of the file, continue */
while((strLine = br.readLine()) != null)
System.out.println(strLine);
System.out.println();
fstream.close();
in.close();
br.close();
}
catch(IOException e){
System.err.println("Error: " + e.getMessage());
}
}
}