Yo chat i'm cooked

This commit is contained in:
2025-03-24 11:59:25 -05:00
parent 46057701ca
commit eca6d173f0
5 changed files with 323 additions and 1 deletions

View File

@@ -121,7 +121,7 @@ public class Dashboard extends JFrame {
Object receivedMessage = inputStream.readObject();
if(receivedMessage instanceof Message) {
Message message = (Message) receivedMessage;
logger.info("Received EHR response: {}", message);
logger.info("Received Message response response: {}", message);
if(message.data().length == 0) {continue;}
receivedMessages.add(message);
updateMessageDisplay(message); // Update the GUI with the new message

View File

@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.ayyalasomayajula.net.client.EHRGen">
<grid id="27dc6" binding="main" layout-manager="GridLayoutManager" row-count="13" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="652" height="1122"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="8d5d9" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Patient Name"/>
</properties>
</component>
<component id="4ee4a" class="javax.swing.JTextField" binding="patientNameValue">
<constraints>
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="ab11d" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="UUID"/>
</properties>
</component>
<component id="5123d" class="javax.swing.JTextField" binding="uuidVAlue">
<constraints>
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="aebca" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Medical Notes"/>
</properties>
</component>
<component id="47eac" class="javax.swing.JList" binding="medicalNotesList">
<constraints>
<grid row="5" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
</constraints>
<properties/>
</component>
<component id="713d6" class="javax.swing.JLabel">
<constraints>
<grid row="6" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Appointment Log"/>
</properties>
</component>
<component id="eb0a9" class="javax.swing.JList" binding="appointmentLogList">
<constraints>
<grid row="7" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
</constraints>
<properties/>
</component>
<component id="e9d6c" class="javax.swing.JLabel">
<constraints>
<grid row="8" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="XRAYs"/>
</properties>
</component>
<component id="c25a7" class="javax.swing.JList" binding="xrayList">
<constraints>
<grid row="9" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
</constraints>
<properties/>
</component>
<component id="ba8b7" class="javax.swing.JLabel">
<constraints>
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="DOB"/>
</properties>
</component>
<component id="da3c9" class="javax.swing.JTextField" binding="textField3" default-binding="true">
<constraints>
<grid row="11" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="b5025" class="javax.swing.JTextField" binding="textField4" default-binding="true">
<constraints>
<grid row="11" column="3" row-span="1" col-span="2" vsize-policy="0" hsize-policy="7" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="67949" class="javax.swing.JLabel">
<constraints>
<grid row="10" column="3" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="JoinDate"/>
</properties>
</component>
<component id="852d8" class="javax.swing.JButton" binding="insertButton" default-binding="true">
<constraints>
<grid row="12" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Insert"/>
</properties>
</component>
<component id="b3893" class="javax.swing.JButton" binding="updateButton" default-binding="true">
<constraints>
<grid row="12" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Update"/>
</properties>
</component>
</children>
</grid>
</form>

View File

@@ -0,0 +1,164 @@
package net.ayyalasomayajula.net.client;
import net.ayyalasomayajula.net.shared.Appointment;
import net.ayyalasomayajula.net.shared.Message;
import net.ayyalasomayajula.net.shared.MessageVariant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.nio.file.Path;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import net.ayyalasomayajula.net.shared.EHR;
/**
* A graphical user interface for viewing and managing an Electronic Health Record (EHR).
*/
public class EHRGen extends JFrame {
private static final Logger logger = LoggerFactory.getLogger(EHRGen.class);
private JTextField patientNameValue;
private JTextField uuidValue;
private JList<String> medicalNotesList;
private JList<String> appointmentLogList;
private JList<String> xrayList;
private JButton updateButton;
private JButton insertButton;
private JPanel main;
private final Socket connection;
private final ObjectOutputStream outputStream;
private EHR currentEHR; // Stores the current EHR instance
/**
* Constructs an EHRGen window with a given socket connection and EHR data.
*
* @param connection the socket connection to the server
* @param ehr the EHR object containing patient data
* @throws IOException if an I/O error occurs while creating the output stream
*/
public EHRGen(Socket connection, EHR ehr) throws IOException {
this.connection = connection;
this.currentEHR = ehr;
this.outputStream = new ObjectOutputStream(connection.getOutputStream());
setTitle("Electronic Health Record");
setContentPane(main);
setSize(600, 400);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
populateFields(); // Populate fields with EHR data if available
insertButton.addActionListener(e -> insertEHR());
updateButton.addActionListener(e -> updateEHR());
}
/**
* Populates the UI fields with data from the current EHR.
*/
private void populateFields() {
if (currentEHR != null) {
patientNameValue.setText(currentEHR.getPatientName());
uuidValue.setText(currentEHR.getUuid().toString());
// Populate lists
populateList(medicalNotesList, currentEHR.getMedicalNotes());
populateList(appointmentLogList, currentEHR.getAppointmentLog().stream().map(Appointment::toString).toList());
populateList(xrayList, currentEHR.getXrays().stream().map(Path::toString).toList());
}
}
/**
* Populates a JList with data.
*
* @param list the JList to populate
* @param data the list of strings to display in the JList
*/
private void populateList(JList<String> list, List<String> data) {
if (data != null) {
list.setListData(data.toArray(new String[0]));
}
}
/**
* Converts a date string from "yyyy-MM-dd" format to "dd/MM/yyyy" format.
*
* @param inputDate the date string in "yyyy-MM-dd" format
* @return the formatted date string in "dd/MM/yyyy" format, or the original string if parsing fails
*/
private String convertDate(String inputDate) {
try {
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat ehrFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = inputFormat.parse(inputDate);
return ehrFormat.format(date);
} catch (ParseException e) {
logger.error("Date conversion failed: {}", e.getMessage());
return inputDate; // Return original in case of error
}
}
/**
* Handles the insertion of a new EHR record.
* Displays an error message if required fields are missing.
*/
private void insertEHR() {
if (!fieldsPopulated()) {
JOptionPane.showMessageDialog(this, "All fields must be populated before inserting.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
// Insertion logic to be implemented
dispose();
}
/**
* Handles updating an existing EHR record.
* Displays an error message if required fields are missing.
*/
private void updateEHR() {
if (!fieldsPopulated()) {
JOptionPane.showMessageDialog(this, "All fields must be populated before updating.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
// Update logic to be implemented
dispose();
}
/**
* Checks if all required fields are populated.
*
* @return true if all required fields contain data, false otherwise
*/
private boolean fieldsPopulated() {
return !patientNameValue.getText().isEmpty() &&
!uuidValue.getText().isEmpty() &&
medicalNotesList.getModel().getSize() > 0 &&
appointmentLogList.getModel().getSize() > 0 &&
xrayList.getModel().getSize() > 0;
}
/**
* Launches the EHRGen window in a separate UI thread.
*
* @param connection the socket connection to the server
* @param ehr the EHR object to display
*/
public static void showEHR(Socket connection, EHR ehr) {
SwingUtilities.invokeLater(() -> {
try {
new EHRGen(connection, ehr).setVisible(true);
} catch (IOException e) {
e.printStackTrace();
}
});
}
}

View File

@@ -18,4 +18,21 @@ public record Appointment(UUID uuid, UUID patient, LocalDateTime time, boolean a
public boolean isPast() {
return time.isBefore(LocalDateTime.now());
}
@Override
/**
* Returns a string representation of the Appointment record.
* The format includes the UUID, patient ID, time, attendance status, and description.
*
* @return A string containing the appointment details.
*/
public String toString() {
return "Appointment{" +
"uuid=" + uuid +
", patient=" + patient +
", time=" + time +
", attendance=" + attendance +
", description='" + description + '\'' +
'}';
}
}