Commit e94bb10a authored by Olav Dagestad Eikrem's avatar Olav Dagestad Eikrem
Browse files

JavaDoc and some cleanup

parent 36022e8e
......@@ -21,7 +21,7 @@ public class Main extends Application {
stage.show();
}catch (Exception e){
e.printStackTrace();
throw new Exception(e);
}
}
}
......@@ -11,6 +11,9 @@ import mappe.del2.hospital.Pasient;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Controller for DeleteConfirmation.fxml
*/
public class DeleteConfirmationController implements Initializable {
private Pasient patient;
private PatientRegister controller;
......
......@@ -4,6 +4,9 @@ import javafx.event.ActionEvent;
import javafx.scene.Node;
import javafx.stage.Stage;
/**
* Controller for InformationDialog.fxml
*/
public class InformationDialog {
......
......@@ -11,6 +11,9 @@ import mappe.del2.hospital.Pasient;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Controller for NewPatientDetails.fxml
*/
public class NewPatientDetails implements Initializable {
private Pasient patient;
......
......@@ -6,9 +6,8 @@ import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
......@@ -28,7 +27,9 @@ import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Controller for PatientRegister.fxml
*/
public class PatientRegister implements Initializable {
private ObservableList<Pasient> people;
CSVManager csvManager;
......@@ -61,7 +62,6 @@ public class PatientRegister implements Initializable {
} catch (Exception e) {
}
tableView.refresh();
tableView.refresh();
}catch (Exception fileChooserNull){
......@@ -236,11 +236,6 @@ public class PatientRegister implements Initializable {
tableView.refresh();
}
public void getPeople() throws IOException {
csvManager = new CSVManager();
people = csvManager.readFile();
}
public void removePatient(Pasient p){
people.remove(p);
tableView.setItems(people);
......
......@@ -8,6 +8,9 @@ import mappe.del2.GUI.controllers.NewPatientDetails;
import java.io.IOException;
/**
* Class loads a delete confirmation window and can return the correct controller
*/
public class DeleteConfirmation implements GuiWindow{
private FXMLLoader loader;
......@@ -23,6 +26,11 @@ public class DeleteConfirmation implements GuiWindow{
return scene;
}
/**
* Used to get correct controller
* @return Spesific controller for instance of object
* @throws IOException for unknown errors
*/
public DeleteConfirmationController getController() throws IOException {
if (this.loader != null) {
return this.loader.getController();
......
......@@ -4,6 +4,9 @@ import javafx.scene.Scene;
import java.io.IOException;
/**
* Interface used to load correct FXML file
*/
public interface GuiWindow {
Scene loadScene() throws IOException;
......
......@@ -6,6 +6,9 @@ import javafx.scene.layout.AnchorPane;
import java.io.IOException;
/**
* Class loads a information window
*/
public class InformationDialog implements GuiWindow{
@Override
public Scene loadScene() throws IOException {
......
......@@ -6,7 +6,9 @@ import javafx.scene.layout.AnchorPane;
import mappe.del2.GUI.controllers.NewPatientDetails;
import java.io.IOException;
/**
* Class loads a new patient dialog, can be used for both editing and creating window and can return the correct controller
*/
public class NewPatientDialog implements GuiWindow{
private FXMLLoader loader;
@Override
......@@ -19,6 +21,12 @@ public class NewPatientDialog implements GuiWindow{
return scene;
}
/**
* Used to get correct controller
* @return Spesific controller for instance of object
* @throws IOException for unknown errors
*/
public NewPatientDetails getController() throws IOException {
if (this.loader != null) {
return this.loader.getController();
......
......@@ -8,7 +8,9 @@ import mappe.del2.hospital.Pasient;
import mappe.del2.persistence.CSVManager;
import java.io.IOException;
/**
* Class loads a patient register main window
*/
public class PatientRegister implements GuiWindow{
@Override
public Scene loadScene() throws IOException {
......
......@@ -3,6 +3,9 @@ package mappe.del2.factory;
import mappe.del2.hospital.Pasient;
/**
* Object is used to load the correct window for the main application
*/
public class SceneFactory {
public GuiWindow getScene(String sceneType){
if (sceneType == null){
......
......@@ -2,6 +2,10 @@ package mappe.del2.hospital;
import java.util.Objects;
/**
* Represents Patient, class named in Norwegian because of task specification
* Social security number must be 11 char long and not contain letters
*/
public class Pasient {
private String firstName;
......
......@@ -10,11 +10,21 @@ import java.io.*;
import java.util.Arrays;
import java.util.List;
/**
* manages reading and writing for Object Pasient to and from CSV files
*/
public class CSVManager {
String fileName;
String filePath;
ObservableList<Pasient> patientList;
public CSVManager(){
this.filePath = System.getProperty("user.home");
this.fileName = "PatientTestData";
this.patientList = FXCollections.observableArrayList();
}
public String getFileName() {
return fileName;
}
......@@ -39,46 +49,8 @@ public class CSVManager {
this.patientList = patientList;
}
public CSVManager(String fileName, String filePath){
this.fileName = fileName;
this.filePath = filePath;
this.patientList = FXCollections.observableArrayList();
}
public CSVManager(){
this.filePath = "src/main/resources";
this.fileName = "PatientTestData";
this.patientList = FXCollections.observableArrayList();
}
public ObservableList<Pasient> readFile() throws IOException {
FileReader reader = new FileReader(this.filePath + "/" + this.fileName + ".csv");
this.patientList = FXCollections.observableArrayList();
CSVReader csvReader = new CSVReader(reader);
try{
String[] nextLine;
while ((nextLine = csvReader.readNext()) != null){
for (var e: nextLine){
System.out.println(e);
String[] patient = e.split(";");
try {
this.patientList.add(new Pasient(patient[0], patient[1], patient[2], patient[3]));
}catch (Exception e1){
}
}
}
}catch (Exception e){
e.printStackTrace();
}
reader.close();
return patientList;
}
public ObservableList<Pasient> readFileCustomPath(String path) throws IOException {
FileReader reader = new FileReader(path);
this.patientList = FXCollections.observableArrayList();
......@@ -108,8 +80,6 @@ public class CSVManager {
List<String> patient;
FileWriter csvWriter = new FileWriter(filePath);
try {
for (Pasient p: patientList) {
patient = Arrays.asList(p.getFirstName(), p.getLastName(), p.getGeneralPractitioner(), p.getSocialSecurityNumber());
......
......@@ -29,9 +29,9 @@
</Menu>
</menus>
</MenuBar>
<Button layoutX="14.0" layoutY="57.0" mnemonicParsing="false" onAction="#addPatient" prefHeight="60.0" prefWidth="60.0" text="Add" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="40.0" />
<Button layoutX="73.0" layoutY="57.0" mnemonicParsing="false" onAction="#removeSelectedPatient" prefHeight="60.0" prefWidth="60.0" text="Remove" AnchorPane.leftAnchor="80.0" AnchorPane.topAnchor="40.0" />
<Button layoutX="136.0" layoutY="57.0" mnemonicParsing="false" onAction="#editSelectedPatient" prefHeight="60.0" prefWidth="60.0" text="Edit" AnchorPane.leftAnchor="150.0" AnchorPane.topAnchor="40.0" />
<Button fx:id="addNew" layoutX="14.0" layoutY="57.0" maxHeight="60.0" maxWidth="60.0" mnemonicParsing="false" onAction="#addPatient" prefHeight="60.0" prefWidth="60.0" text="Add" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="40.0" />
<Button fx:id="removeSelected" layoutX="73.0" layoutY="57.0" mnemonicParsing="false" onAction="#removeSelectedPatient" prefHeight="60.0" prefWidth="60.0" text="Remove" AnchorPane.leftAnchor="80.0" AnchorPane.topAnchor="40.0" />
<Button fx:id="editSelected" layoutX="136.0" layoutY="57.0" mnemonicParsing="false" onAction="#editSelectedPatient" prefHeight="60.0" prefWidth="60.0" text="Edit" AnchorPane.leftAnchor="150.0" AnchorPane.topAnchor="40.0" />
<TableView fx:id="tableView" prefHeight="255.0" prefWidth="600.0" AnchorPane.bottomAnchor="25.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="110.0">
<columns>
<TableColumn fx:id="firstNameColumn" prefWidth="206.0" text="First name" />
......@@ -39,6 +39,5 @@
<TableColumn fx:id="ssnColumn" prefWidth="200.0" text="Social security number" />
</columns>
</TableView>
<Label layoutX="14.0" layoutY="378.0" text="Status" />
</children>
</AnchorPane>
package mappe.del2.factory;
import javafx.scene.Scene;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.*;
class SceneFactoryTest {
@Test
@DisplayName("Test factory creation")
void FactoryCreationTest(){
SceneFactory f = new SceneFactory();
assertNotNull(f);
}
@Test
@DisplayName("test scene factory PatientRegister is returned")
void FactorReturnsPatientRegisterTest(){
SceneFactory f = new SceneFactory();
PatientRegister p = new PatientRegister();
Object o = f.getScene("patientRegister");
assertSame(p.getClass(), o.getClass());
}
@Test
@DisplayName("test scene factory NewPatientDialog is returned")
public void FactorReturnsNewPatientDetailsTest(){
SceneFactory f = new SceneFactory();
NewPatientDialog p = new NewPatientDialog();
Object o = f.getScene("newPatient");
assertSame(p.getClass(), o.getClass());
}
@Test
@DisplayName("test scene factory InformationDialog is returned")
void FactorReturnInformationDialogTest(){
SceneFactory f = new SceneFactory();
InformationDialog p = new InformationDialog();
Object o = f.getScene("informationDialog");
assertSame(p.getClass(), o.getClass());
}
@Test
@DisplayName("test scene factory DeleteConfirmation is returned")
void FactorReturnsDeleteConfirmationTest(){
SceneFactory f = new SceneFactory();
DeleteConfirmation p = new DeleteConfirmation();
Object o = f.getScene("deleteConfirmation");
assertSame(p.getClass(), o.getClass());
}
@Test
@DisplayName("test scene factory Null is returned")
void FactorReturnsNullTest(){
SceneFactory f = new SceneFactory();
assertNull(f.getScene("Something else"));
}
}
\ No newline at end of file
package mappe.del2.persistence;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class CSVManagerTest {
@Test
@DisplayName("CSVManager creation test")
void CSVManagerCreationTest(){
CSVManager c = new CSVManager();
assertTrue(c.getFileName().equalsIgnoreCase("PatientTestData"));
assertTrue(c.getFilePath().equals(System.getProperty("user.home")));
c = new CSVManager("Test1", "Test2");
assertEquals("Test1", c.getFileName());
assertEquals("Test2", c.getFilePath());
}
}
\ No newline at end of file
......@@ -29,9 +29,9 @@
</Menu>
</menus>
</MenuBar>
<Button layoutX="14.0" layoutY="57.0" mnemonicParsing="false" onAction="#addPatient" prefHeight="60.0" prefWidth="60.0" text="Add" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="40.0" />
<Button layoutX="73.0" layoutY="57.0" mnemonicParsing="false" onAction="#removeSelectedPatient" prefHeight="60.0" prefWidth="60.0" text="Remove" AnchorPane.leftAnchor="80.0" AnchorPane.topAnchor="40.0" />
<Button layoutX="136.0" layoutY="57.0" mnemonicParsing="false" onAction="#editSelectedPatient" prefHeight="60.0" prefWidth="60.0" text="Edit" AnchorPane.leftAnchor="150.0" AnchorPane.topAnchor="40.0" />
<Button fx:id="addNew" layoutX="14.0" layoutY="57.0" maxHeight="60.0" maxWidth="60.0" mnemonicParsing="false" onAction="#addPatient" prefHeight="60.0" prefWidth="60.0" text="Add" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="40.0" />
<Button fx:id="removeSelected" layoutX="73.0" layoutY="57.0" mnemonicParsing="false" onAction="#removeSelectedPatient" prefHeight="60.0" prefWidth="60.0" text="Remove" AnchorPane.leftAnchor="80.0" AnchorPane.topAnchor="40.0" />
<Button fx:id="editSelected" layoutX="136.0" layoutY="57.0" mnemonicParsing="false" onAction="#editSelectedPatient" prefHeight="60.0" prefWidth="60.0" text="Edit" AnchorPane.leftAnchor="150.0" AnchorPane.topAnchor="40.0" />
<TableView fx:id="tableView" prefHeight="255.0" prefWidth="600.0" AnchorPane.bottomAnchor="25.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="110.0">
<columns>
<TableColumn fx:id="firstNameColumn" prefWidth="206.0" text="First name" />
......@@ -39,6 +39,5 @@
<TableColumn fx:id="ssnColumn" prefWidth="200.0" text="Social security number" />
</columns>
</TableView>
<Label layoutX="14.0" layoutY="378.0" text="Status" />
</children>
</AnchorPane>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment