Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mvnw.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added readme2.docx
Binary file not shown.
9 changes: 9 additions & 0 deletions readme2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Pharmacy Database: Service for Doctors to Receive Information for Their Patients Medications and Experiences.
Team: Noah Evantash
Problem Statement: The problem this database design seeks to resolve is patients trying to relay information to their doctor about a new medication they are on. How can they effectively tell their doctor how the medication makes them feel through a web service that records the prescriptions of these patients. Doctors are then able to view their patients, prescriptions, and the symptoms of those prescriptions. The database allows doctors to record which patients are under their care for what conditions, what those patient�s prescriptions are, and the symptoms those patients are experiencing.
Solution Statement: The solution created to help track these patients taking new medication is to create a database that keeps records of these patients, their prescriptions, medications, and symptoms. To do this, I must create a database on MySQL that represents this database as done in part 1. Next, I must create a relational mapping of a java model for the database diagram that translates the SQL code into java. Lastly, and unsuccessfully, I wanted to create a UI that allowed doctors to implement new patients and write prescriptions for them.
Users: While patients are usually a User class, in the UI it exists as a relational object of the doctors, so it can be treated similarly to a domain object with one-to-many relationships to another domain object prescriptions. Doctors are the primary user implemented in this design and has objects patients that can be created and edited under the patient�s tab of whatever doctor that patients belong� to. For each doctor, there is an inline-editor script created that allows the doctors conditions to be changed and updated in the main list interface. Under the doctors is a patient�s tab that connects to the patients list of that specific doctor. Those patients can be edited in an inline editor that updates or creates the patients� parameters. There is a back on that list that returns to the list of all the other objects.
Domain Objects: The objects in this database are the prescriptions and the symptoms, as well as the patients described above in relation to the doctor users. For the other domain objects, the doctor user is able to create new prescriptions under the patients tab. The patients have a tab that relays which prescriptions they have and allows for creating and editing of new prescriptions with CCUD (cancel, create, update, delete) editor format. Once the prescription is made, the only updatable parameter should be the dosage. In the inline editor, it would only be allowing changing of the dosage and updating of that parameter (which returns the whole body, but only with the updated dose). This is to keep prescriptions in line and prevent changing the medication which was a difficult parameter to implement due to it being a portable enumeration. Therefore, to mitigate errors of passing an invalid medication, we only want the medication to be changed in the editor with a dropdown list of acceptable medications. If I had more time, I would have included another form for the medications that allows the doctor to create new medication names. This was an issue since I was not sure how to include the new meds in the dropdown list. The final list was the symptoms list which showed all the reactions to the prescription. Under each prescription in the list under the main screen, the user can create new symptoms for the prescription. Each symptom allows the user to relay information about the efficacy, benefits, and/or side effects of the prescription given. Such information can be used by the doctor to access their patient�s information of prescriptions and symptoms.
Note On functionality: As of today, the only services that have been working for the design UI is the doctors and patients. There was a litany of unforeseen errors and complications relating to development of the UI that made it unreadable with the index.html. The object relational mapping is working as intended and the user can receive information from the database using localhost:8080/api/� but it does not yet fully extend to the UI implementation. So far, the UI only works up to the patients list trying to get prescriptions but runs into a Reach.createElement error that has not been fixed yet. Therefore, the project is only finished and requires more time to try and correct these problems. Nonetheless, the database is set up to create new doctors, add new patients to those doctors, edit those doctors, or delete those doctors. The patients can be accessed through whichever doctor they are a part of and edited or deleted. This functionality is supposed to be extended to the prescriptions and symptoms models but isn�t able to due to the errors.


55 changes: 0 additions & 55 deletions src/main/java/com/example/springtemplate/daos/CourseOrmDao.java

This file was deleted.

167 changes: 167 additions & 0 deletions src/main/java/com/example/springtemplate/daos/DoctorJdbcDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package com.example.springtemplate.daos;

import com.example.springtemplate.models.Doctor;

import java.sql.*;
import java.sql.Date;
import java.util.*;

public class DoctorJdbcDao {
static final String DRIVER = "com.mysql.cj.jdbc.Driver";
static final String HOST = "localhost:3306";
static final String SCHEMA = "db_project";
static final String CONFIG = "serverTimezone=UTC";
static final String URL =
"jdbc:mysql://"+HOST+"/"+SCHEMA+"?"+CONFIG;
static final String USERNAME = "root";
static final String PASSWORD = "P@ssw0rd";

static Connection connection = null;
static PreparedStatement statement = null;
String CREATE_DOCTOR = "INSERT INTO `db_project`.`doctors`\n" +
"(`firstname`,\n" +
"`lastname`,\n" +
"`username`,\n" +
"`password`,\n" +
"`email`,\n" +
"`DOB`,\n" +
"`hospital`,\n" +
"`position`)\n" +
"VALUES\n" +
"(?,\n" +
"?,\n" +
"?,\n" +
"?,\n" +
"?,\n" +
"?,\n" +
"?,\n" +
"?);\n";
String FIND_ALL_DOCTORS = "SELECT * FROM doctors";
String FIND_DOCTOR_BY_ID = "SELECT * FROM doctors WHERE id=?";
String DELETE_DOCTOR = "DELETE FROM doctors WHERE id=?";
String UPDATE_DOCTOR_PASSWORD = "UPDATE doctors SET password=? WHERE id=?";
String UPDATE_DOCTOR = "UPDATE doctors SET firstname=?, lastname=?, username=?, password=? " +
"email=?, DOB=?, position=?, hospital=? WHERE id=?";



private Connection getConnection() throws ClassNotFoundException, SQLException {
Class.forName(DRIVER);
return DriverManager.getConnection(URL, USERNAME, PASSWORD);
}

private void closeConnection(Connection connection) throws SQLException {
connection.close();
}

public Doctor findDoctorById(Integer id) throws SQLException, ClassNotFoundException {
Doctor doctor = null;
connection = getConnection();
statement = connection.prepareStatement(FIND_DOCTOR_BY_ID);
statement.setInt(1, id);
ResultSet resultSet = statement.executeQuery();
if(resultSet.next()) {
doctor = new Doctor(
resultSet.getString("firstname"),
resultSet.getString("lastname"),
resultSet.getString("username"),
resultSet.getString("password"),
resultSet.getString("email"),
resultSet.getDate("DOB"),
resultSet.getString("position"),
resultSet.getString("hospital")
);
}
closeConnection(connection);
return doctor;
}

public Integer deleteDoctor(Integer userId) throws SQLException, ClassNotFoundException {
Integer rowsDeleted = 0;
connection = getConnection();
statement = connection.prepareStatement(DELETE_DOCTOR);
statement.setInt(1, userId);
rowsDeleted = statement.executeUpdate();
closeConnection(connection);
return rowsDeleted;
}

public Integer updateDoctor(Integer userId, Doctor newDoctor) throws SQLException, ClassNotFoundException {
Integer rowsUpdated = 0;
connection = getConnection();
statement = connection.prepareStatement(UPDATE_DOCTOR);
statement.setString(1, newDoctor.getFirstname());
statement.setString(2, newDoctor.getLastname());
statement.setString(3, newDoctor.getUsername());
statement.setString(4, newDoctor.getPassword());
statement.setString(5, newDoctor.getEmail());
statement.setDate(6, newDoctor.getDOB());
statement.setString(7, newDoctor.getPosition());
statement.setString(8, newDoctor.getHospital());
statement.setInt(9, userId);

rowsUpdated = statement.executeUpdate();
closeConnection(connection);
return rowsUpdated;
}

public List<Doctor> findAllDoctors() throws ClassNotFoundException, SQLException {
List<Doctor> doctors = new ArrayList<Doctor>();
connection = getConnection();
statement = connection.prepareStatement(FIND_ALL_DOCTORS);
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
Doctor doctor = new Doctor(
resultSet.getString("firstname"),
resultSet.getString("lastname"),
resultSet.getString("username"),
resultSet.getString("password"),
resultSet.getString("email"),
resultSet.getDate("DOB"),
resultSet.getString("position"),
resultSet.getString("hospital")
);
doctors.add(doctor);
}
closeConnection(connection);
return doctors;
}
public Integer createDoctor(Doctor doctor)
throws ClassNotFoundException, SQLException {
Integer rowsUpdated = 0;
connection = getConnection();
statement = connection.prepareStatement(CREATE_DOCTOR);
statement.setString(1, doctor.getFirstname());
statement.setString(2, doctor.getLastname());
statement.setString(3, doctor.getUsername());
statement.setString(4, doctor.getPassword());
statement.setString(5, doctor.getEmail());
statement.setDate(6,doctor.getDOB());
statement.setString(7, doctor.getPosition());
statement.setString(8, doctor.getHospital());
rowsUpdated = statement.executeUpdate();
closeConnection(connection);
return rowsUpdated;
}

public static void main(String[] args) throws SQLException, ClassNotFoundException{
System.out.println("JDBC DAO");
DoctorJdbcDao dao = new DoctorJdbcDao();

Doctor DrRob = new Doctor(
"Robert",
"Phoughts",
"rphoughts",
"robisnumber1",
"rpho@partners.org",
Date.valueOf("1980-10-10"),
"Lead Psychiatrist",
"Mass General");
dao.createDoctor(DrRob);

System.out.println(dao.findDoctorById(1).getUsername());

}
}


57 changes: 57 additions & 0 deletions src/main/java/com/example/springtemplate/daos/DoctorOrmDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.example.springtemplate.daos;

import com.example.springtemplate.models.Doctor;
import com.example.springtemplate.repositories.DoctorRepository;
import com.example.springtemplate.repositories.PatientRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@CrossOrigin(origins = "*")
public class DoctorOrmDao {
@Autowired
DoctorRepository doctorRepository;

@Autowired
PatientRepository patientRepository;


@PostMapping("/api/doctors")
public Doctor createDoctor(@RequestBody Doctor doctor) {
return doctorRepository.save(doctor);
}

@GetMapping("/api/doctors")
public List<Doctor> findAllDoctors() {
return (List<Doctor>) doctorRepository.findAll();
}

@GetMapping("/api/doctors/{userId}")
public Doctor findDoctorById(
@PathVariable("userId") Integer id) {
return doctorRepository.findById(id).get();
}

@PutMapping("/api/doctors/{userId}")
public Doctor updateDoctor(
@PathVariable("userId") Integer id,
@RequestBody Doctor doctorUpdates) {
Doctor doctor = doctorRepository.findById(id).get();
doctor.setFirstname(doctorUpdates.getFirstname());
doctor.setLastname(doctorUpdates.getLastname());
doctor.setUsername(doctorUpdates.getUsername());
doctor.setPassword(doctorUpdates.getPassword());
doctor.setEmail(doctorUpdates.getEmail());
doctor.setDOB(doctorUpdates.getDOB());
doctor.setPosition(doctorUpdates.getPosition());
doctor.setHospital(doctorUpdates.getHospital());
return doctorRepository.save(doctor);
}

@DeleteMapping("/api/doctors/{userId}")
public void deleteUser(
@PathVariable("userId") Integer id) {
doctorRepository.deleteById(id);
}
}
44 changes: 44 additions & 0 deletions src/main/java/com/example/springtemplate/daos/MedicationDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.springtemplate.daos;

import com.example.springtemplate.models.Medications;
import com.example.springtemplate.repositories.MedicationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
public class MedicationDao {
@Autowired
MedicationRepository medicationRepository;
@GetMapping("/api/medications/findAllMeds")
public List<Medications> findAllMeds() {
return (List<Medications>) medicationRepository.findAll();
}
@GetMapping("/api/medications/findMedById/{id}")
public Medications findMedById(@PathVariable("id") String name) {

return medicationRepository.findMedByName(name);
}
@PostMapping("/api/medications/createMed/{name}")
public Medications createMed(@PathVariable("name") String name) {
Medications medications = new Medications();
medications.setName(name);
medicationRepository.save(medications);
return medicationRepository.save(medications);
}
@PutMapping("/api/medications/updateMedication/{name}/{newName}")
public Medications updateMedication(
@PathVariable("id") String name,
@PathVariable("newName") String newName) {
Medications medications = medicationRepository.findMedByName(name);
medications.setName(newName);
return medicationRepository.save(medications);
}
@DeleteMapping("/api/medications/deleteMedication/{id}")
public void deleteMedication(
@PathVariable("id") Integer id) {
medicationRepository.deleteById(id);
}
}
Loading