×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Java Program to Create Patient Database App Assignment Solution

June 19, 2024
Katrina J. Lambdin
Katrina J.
🇺🇸 United States
Database
a PhD-qualified expert in Computer Science from Greenfield University, USA, has 8 years of experience in database assignments. Specialized in database design, optimization, and management, she delivers top-notch solutions for academic and professional needs.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
For HTML assignments, ensure that your code is clean and properly indented. This improves readability and helps identify errors quickly. Use semantic tags (like <header>, <article>, and <footer>) to enhance accessibility.
News
In 2024, the new programming language Mojo is gaining traction among AI-focused programming students, promising Python-like simplicity with speeds closer to C++ for AI and scientific applications​.

Instructions

Objective

Write a java assignment program to create patient database app.

Requirements and Specifications

program-to-create-patient-database-app-in-java (1)

Source Code

ALLERGY HISTORY import javax.swing.*; import java.awt.Component; import java.awt.event.*; import java.sql.PreparedStatement; public class AllergyHistoryForm extends JFrame { private int questionId = 1; public void start(DBConnection con, int patientId) { // Create frame JFrame frame = new JFrame(); // Create labels and textfields JLabel patientIdLbl = new JLabel("Patient ID"); JLabel allergenQuestionLbl = new JLabel("Allergen"); JLabel allergyStartDateLbl = new JLabel("When did the allergy started?"); JLabel allergyEndDateLbl = new JLabel("When did the allergy ended?"); JLabel allergyDescriptionLbl = new JLabel("Describe the allergy"); JTextField patientIdTxt = new JTextField(String.valueOf(patientId)); JTextField allergenQuestionTxt = new JTextField(""); JTextField allergyStartDateTxt = new JTextField(""); JTextField allergyEndDateTxt = new JTextField(""); JTextArea allergyDescriptionTxt = new JTextArea(""); patientIdLbl.setBounds(20, 20, 100, 20); patientIdTxt.setBounds(140, 20, 100, 20); allergenQuestionLbl.setBounds(20, 60, 100, 20); allergenQuestionTxt.setBounds(140, 60, 100, 20); allergyStartDateLbl.setBounds(20, 100, 100, 20); allergyStartDateTxt.setBounds(140, 100, 100, 20); allergyEndDateLbl.setBounds(260, 100, 100, 20); allergyEndDateTxt.setBounds(380, 100, 100, 20); allergyDescriptionLbl.setBounds(20, 140, 100, 20); allergyDescriptionTxt.setBounds(140, 140, 300, 100); // next button JButton nextBtn = new JButton("Start Quiz"); nextBtn.setBounds(560, 280, 120, 20); // Create nBinary Tree BinaryTree allergyTree = new BinaryTree(); // add action nextBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Check if a patient is selected from list setTextFieldsEditable(frame, false); if(questionId >= 1 && questionId <= 5) { nextBtn.setText(("Next question")); } if(questionId == 1) { allergenQuestionTxt.setEditable(true); } else if(questionId == 2) { // Add the results from question 1 allergyTree.add(allergenQuestionLbl.getText(), allergenQuestionTxt.getText()); allergyStartDateTxt.setEditable(true); allergyEndDateTxt.setEditable(true); } else if(questionId == 3) { // Add the results from question 2 allergyTree.add(allergyStartDateLbl.getText(), allergyStartDateTxt.getText()); allergyTree.add(allergyEndDateLbl.getText(), allergyEndDateTxt.getText()); allergyDescriptionTxt.setEditable(true); nextBtn.setText("Save"); } else if(questionId == 4) { // Add the results from question 3 allergyTree.add(allergyDescriptionLbl.getText(), allergyDescriptionTxt.getText()); try { String query = "INSERT INTO `allergyhistorytable` VALUES (?, ?, ?, ?, ?, ?, ?);"; PreparedStatement prepStatement = con.getConnection().prepareStatement(query); prepStatement.setInt(1, 0); prepStatement.setInt(2, patientId); prepStatement.setString(3, allergenQuestionTxt.getText()); prepStatement.setString(4, allergyStartDateTxt.getText()); prepStatement.setString(5,allergyEndDateTxt.getText()); prepStatement.setString(6, allergyDescriptionTxt.getText()); prepStatement.setInt(7, 0); prepStatement.execute(); prepStatement.close(); } catch (Exception ex ){ ex.printStackTrace(); } frame.setVisible(false); dispose(); } questionId++; } }); frame.add(nextBtn); frame.add(patientIdLbl); frame.add(patientIdTxt); frame.add(allergenQuestionLbl); frame.add(allergenQuestionTxt); frame.add(allergyStartDateLbl); frame.add(allergyStartDateTxt); frame.add(allergyEndDateLbl); frame.add(allergyEndDateTxt); frame.add(allergyDescriptionLbl); frame.add(allergyDescriptionTxt); // Set all fields to readonly setTextFieldsEditable(frame, false); frame.setSize(750,350); frame.setLayout(null); frame.setVisible(true); } public static void setTextFieldsEditable(JFrame frame, boolean editable) { // Set all textfields as readonly for (Component component : frame.getContentPane().getComponents()) { if (component instanceof JTextField) { ((JTextField)component).setEditable(editable); } else if(component instanceof JTextArea) { ((JTextArea)component).setEditable(editable); } } } } GENERAL MEDICAL HISTORY FORM import javax.swing.*; import java.awt.Component; import java.awt.event.*; import java.sql.PreparedStatement; public class GeneralMedicalHistoryForm extends JFrame { private int questionId = 1; public void start(DBConnection con, int patientId) { // Create frame JFrame frame = new JFrame(); // Create labels and textfields JLabel patientIdLbl = new JLabel("Patient ID"); JLabel tobaccoQuestionLbl = new JLabel("Do you smoke?"); JLabel tobaccoQtyLbl = new JLabel("Quantity"); JLabel alcoholQuestionLbl = new JLabel("Do you drink alcohol?"); JLabel alcoholQtyLbl = new JLabel("Quantity"); JLabel alcoholDurationLbl = new JLabel("Duration"); JLabel drugQuestionLbl = new JLabel("Do you consume drugs?"); JLabel drugTypeLbl = new JLabel("Type"); JLabel drugDurationLbl = new JLabel("Duration"); JLabel bloodTypeLbl = new JLabel("Blood Type"); JLabel rhLbl = new JLabel("Rh"); JTextField patientIdTxt = new JTextField(String.valueOf(patientId)); JTextField tobaccoQuestionTxt = new JTextField(""); JTextField tobaccoQtyTxt = new JTextField(""); JTextField alcoholQuestionTxt = new JTextField(""); JTextField alcoholQtyTxt = new JTextField(""); JTextField alcoholDurationTxt = new JTextField(""); JTextField drugQuestionTxt = new JTextField(""); JTextField drugTypeTxt = new JTextField(""); JTextField drugDurationTxt = new JTextField(""); JTextField bloodTypeTxt = new JTextField(); JTextField rhTxt = new JTextField(); patientIdLbl.setBounds(20, 20, 100, 20); patientIdTxt.setBounds(140, 20, 100, 20); tobaccoQuestionLbl.setBounds(20, 60, 100, 20); tobaccoQuestionTxt.setBounds(140, 60, 100, 20); tobaccoQtyLbl.setBounds(260, 60, 100, 20); tobaccoQtyTxt.setBounds(380, 60, 100, 20); alcoholQuestionLbl.setBounds(20, 100, 100, 20); alcoholQuestionTxt.setBounds(140, 100, 100, 20); alcoholQtyLbl.setBounds(260, 100, 100, 20); alcoholQtyTxt.setBounds(380, 100, 100, 20); alcoholDurationLbl.setBounds(500, 100, 100, 20); alcoholDurationTxt.setBounds(620, 100, 100, 20); drugQuestionLbl.setBounds(20, 140, 100, 20); drugQuestionTxt.setBounds(140, 140, 100, 20); drugTypeLbl.setBounds(260, 140, 100, 20); drugTypeTxt.setBounds(380, 140, 100, 20); drugDurationLbl.setBounds(500, 140, 100, 20); drugDurationTxt.setBounds(620, 140, 100, 20); bloodTypeLbl.setBounds(20, 180, 100, 20); bloodTypeTxt.setBounds(140, 180, 100, 20); rhLbl.setBounds(20, 220, 100, 20); rhTxt.setBounds(140, 220, 100, 20); // next button JButton nextBtn = new JButton("Start Quiz"); nextBtn.setBounds(560, 280, 120, 20); // Create nBinary Tree BinaryTree generalTree = new BinaryTree(); // add action nextBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Check if a patient is selected from list setTextFieldsEditable(frame, false); if(questionId >= 1 && questionId <= 6) { nextBtn.setText(("Next question")); } if(questionId == 1) { tobaccoQtyTxt.setEditable(true); tobaccoQuestionTxt.setEditable(true); } else if(questionId == 2) { // Add the results from question 1 generalTree.add(tobaccoQuestionLbl.getText(), tobaccoQuestionTxt.getText()); generalTree.add(tobaccoQtyLbl.getText(), tobaccoQtyTxt.getText()); alcoholQuestionTxt.setEditable(true); alcoholQtyTxt.setEditable(true); TODO Auto-generated catch block e1.printStackTrace(); } } } }); frame.add(patientsCB); frame.add(selectBtn); frame.setSize(400,250); frame.setLayout(null); frame.setVisible(true); } }

Similar Samples

Explore our curated samples at ProgrammingHomeworkHelp.com to see our expertise in action. These examples cover a range of programming languages and concepts, demonstrating our ability to deliver high-quality solutions. Whether you're looking for assistance with basic assignments or complex projects, our samples showcase how we can help you excel in your programming endeavors.