Skip to content
Snippets Groups Projects
Commit 9b4fc537 authored by Burhan Akbar's avatar Burhan Akbar
Browse files

Resolve "As a user I would like to be able to view information about the...

Resolve "As a user I would like to be able to view information about the nursing home, so that I can get details of the facilities available."
parent 6caba2cc
Branches
No related tags found
2 merge requests!77update system,!72Resolve "As a user I would like to be able to view information about the nursing home, so that I can get details of the facilities available."
/*
Navicat Premium Data Transfer
Source Server : wyl
Source Server Type : MySQL
Source Server Version : 80031
Source Host : localhost:3306
Source Schema : health_care
Target Server Type : MySQL
Target Server Version : 80031
File Encoding : 65001
Date: 09/12/2024 10:09:27
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for common_admin
-- ----------------------------
DROP TABLE IF EXISTS `common_admin`;
CREATE TABLE `common_admin` (
`id` int NOT NULL AUTO_INCREMENT,
`email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`roleId` int NULL DEFAULT NULL,
`phone` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`status` int NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of common_admin
-- ----------------------------
INSERT INTO `common_admin` VALUES (1, '26497@qq.com', '$2a$10$5UzuKUxgR8H0RzLYrP.BUu8.76yKwMD4XkvJIu/xxB7AAHWfphFQm', 'commonAdmin', 1, '111', 'justnoww', 1);
INSERT INTO `common_admin` VALUES (2, '1234@qq.com', '$2a$10$iW/zeL9TLq55SHFaOfyfr.xFMvB4aD3CL2layeAlGC7CqZ9kcscA.', 'commonAdmin', 1, '123', 'BAa', 1);
INSERT INTO `common_admin` VALUES (3, '123cmy@qq.com', '$2a$10$u2KxNBaHuTVwX7KudUgyNelp8j2lymarXKkkUXfWBMRAgbPNryTuW', 'commonAdmin', 1, '123', 'cmy', 1);
-- ----------------------------
-- Table structure for device
-- ----------------------------
DROP TABLE IF EXISTS `device`;
CREATE TABLE `device` (
`id` int NOT NULL AUTO_INCREMENT,
`hospitalId` int NULL DEFAULT NULL,
`name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`freeTime` datetime NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of device
-- ----------------------------
INSERT INTO `device` VALUES (1, 0, 'bed1', 'bed', '2024-12-02 09:51:12');
INSERT INTO `device` VALUES (2, 2, 'bed2', 'bed', '2024-12-03 09:30:00');
INSERT INTO `device` VALUES (3, 2, 'bed3', 'bed', '2025-12-05 10:30:35');
INSERT INTO `device` VALUES (4, 2, 'instrument1', 'instrument', '2024-12-05 07:15:59');
INSERT INTO `device` VALUES (5, 2, 'instrument5', 'instrument', '2024-12-05 10:30:00');
-- ----------------------------
-- Table structure for hospital
-- ----------------------------
DROP TABLE IF EXISTS `hospital`;
CREATE TABLE `hospital` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`amountPatient` int NULL DEFAULT NULL,
`maxAmount` int NULL DEFAULT NULL,
`type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`address` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`phone` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`status` int NULL DEFAULT NULL,
`roleId` int NULL DEFAULT NULL,
`email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`patientId` int NULL DEFAULT NULL,
`deviceId` int NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of hospital
-- ----------------------------
INSERT INTO `hospital` VALUES (1, 'hospital0', 3, 100, 'hospital', 'road', '145267', 1, 3, 'agag', '$2a$10$wvAZoj4V51MH/MLhVIrnG.NrY07/.Gn9Ar6JsyzRAubWtqbWzgKie', 0, 0);
INSERT INTO `hospital` VALUES (2, 'hospital1', 5, 200, 'hospital', 'beijing', '6371', 1, 3, 'soga', '$2a$10$wvAZoj4V51MH/MLhVIrnG.NrY07/.Gn9Ar6JsyzRAubWtqbWzgKie', 0, 0);
INSERT INTO `hospital` VALUES (3, 'hospital2', 10, 50, 'hospital', 'cardiff', '123', 1, 3, 'hospital2@qq.com', '$2a$10$wvAZoj4V51MH/MLhVIrnG.NrY07/.Gn9Ar6JsyzRAubWtqbWzgKie', 0, 0);
-- ----------------------------
-- Table structure for hospital_device
-- ----------------------------
DROP TABLE IF EXISTS `hospital_device`;
CREATE TABLE `hospital_device` (
`hospitalId` int NULL DEFAULT NULL,
`deviceId` int NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of hospital_device
-- ----------------------------
-- ----------------------------
-- Table structure for nurse
-- ----------------------------
DROP TABLE IF EXISTS `nurse`;
CREATE TABLE `nurse` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`status` int NULL DEFAULT NULL,
`hospitalId` int NULL DEFAULT NULL,
`type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`age` int NULL DEFAULT NULL,
`phone` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`address` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of nurse
-- ----------------------------
INSERT INTO `nurse` VALUES (1, 'nn', 0, 2, 'nurse', 23, '111', '23453', 'Cardiff');
INSERT INTO `nurse` VALUES (2, 'Li Xiaoming', 1, 2, 'nurse', 25, '222', '4399', 'Cardiff');
INSERT INTO `nurse` VALUES (3, 'Sun Hao', 1, 0, 'nurse', 24, '123', '23576', 'Bute');
INSERT INTO `nurse` VALUES (4, 'Wang Xiaoming', 0, 2, 'nurse', 26, '333', '34578', 'Cardiff');
INSERT INTO `nurse` VALUES (5, 'Tian Hao', 0, 2, 'nurse', 30, '321', '24353', 'Cardiff');
-- ----------------------------
-- Table structure for patient
-- ----------------------------
DROP TABLE IF EXISTS `patient`;
CREATE TABLE `patient` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`roleId` int NULL DEFAULT NULL,
`status` int NULL DEFAULT NULL,
`hospitalId` int NULL DEFAULT NULL,
`type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`age` int NULL DEFAULT NULL,
`phone` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
`email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of patient
-- ----------------------------
INSERT INTO `patient` VALUES (1, 'Li Ming', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 1, 0, 'patient', 20, '135', 'wwgwg@outlook.com');
INSERT INTO `patient` VALUES (2, 'Li Hua', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 0, 0, 'patient', 21, '166', 'ss@qq.com');
INSERT INTO `patient` VALUES (3, 'Huang Li', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 0, 0, 'patient', 13, '111', '22@qq.com');
INSERT INTO `patient` VALUES (4, 'Xia Ming', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 1, 2, 'patient', 61, '15', '131@qq.com');
INSERT INTO `patient` VALUES (5, 'Xia Yu', '$2a$10$obgmyiqAuhIkBjuw3bROr.LkCh.Nb70e4dL8lwKjSsPxS8gSpQxSC', 2, 1, 2, 'patient', 33, '14315', 'xx@qq.com');
-- ----------------------------
-- Table structure for patient_hospital
-- ----------------------------
DROP TABLE IF EXISTS `patient_hospital`;
CREATE TABLE `patient_hospital` (
`hosptialId` int NULL DEFAULT NULL,
`patientId` int NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of patient_hospital
-- ----------------------------
-- ----------------------------
-- Table structure for role
-- ----------------------------
DROP TABLE IF EXISTS `role`;
CREATE TABLE `role` (
`roleId` int NULL DEFAULT NULL,
`type` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of role
-- ----------------------------
INSERT INTO `role` VALUES (0, 'SUPER');
INSERT INTO `role` VALUES (1, 'ADMIN');
INSERT INTO `role` VALUES (2, 'PATIENT');
INSERT INTO `role` VALUES (3, 'HOSPITAL');
-- ----------------------------
-- Table structure for super_admin
-- ----------------------------
DROP TABLE IF EXISTS `super_admin`;
CREATE TABLE `super_admin` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`roleId` int NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of super_admin
-- ----------------------------
INSERT INTO `super_admin` VALUES (1, '2649783657@qq.com', '$2a$10$5UzuKUxgR8H0RzLYrP.BUu8.76yKwMD4XkvJIu/xxB7AAHWfphFQm', 0);
-- ----------------------------
-- Procedure structure for reset_primary_keys
-- ----------------------------
DROP PROCEDURE IF EXISTS `reset_primary_keys`;
delimiter ;;
CREATE PROCEDURE `reset_primary_keys`()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE current_id INT DEFAULT 0;
DECLARE cur CURSOR FOR
SELECT id FROM common_admin ORDER BY id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur;
-- 重新更新每一条记录的 ID
read_loop: LOOP
FETCH cur INTO current_id;
IF done THEN
LEAVE read_loop;
END IF;
-- 根据新的排序修改 ID
UPDATE common_admin SET id = current_id - 1 WHERE id = current_id;
END LOOP;
CLOSE cur;
END
;;
delimiter ;
SET FOREIGN_KEY_CHECKS = 1;
......@@ -6,8 +6,8 @@ import lombok.Data;
public class HospitalDTO {
private int id;
private String name;
private String address;
private String location;
private String address;
private String phone;
private int totalBeds;
private int availableBeds;
......
package com.cardiff.client_project.pojo.entity;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class NursingHome {
private int id;
private String name;
private String password;
private int maxAmount;
private int amountPatient;
private int patientId;
private int deviceId;
private String type;
private String address;
private String phone;
private String email;
private int roleId;
private int status;
}
package com.cardiff.client_project.service;
import com.cardiff.client_project.pojo.dto.HospitalDTO;
import com.cardiff.client_project.utils.Result;
import java.util.List;
public interface NursingHomeService {
Result<List<HospitalDTO>> getAvailableBeds();
Result<HospitalDTO> insertPatientInfo(HospitalDTO hospitalDTO);
Result<String> updatePatient(HospitalDTO hospitalDTO);
Result<String> deletePatientById(List<Integer> ids);
Result<List<HospitalDTO>> getAllPatients();
Result<String> updateBedCount(int hospitalId, int currentPatients);
}
\ No newline at end of file
healthcare:
datasource:
url: jdbc:mysql://localhost:3306/health_care
url: jdbc:mysql://localhost:3306/healthcare
port: 3306
username: root
password: root
\ No newline at end of file
$(document).ready(function () {
// Constants
const API_BASE_URL = '/api/hospitals';
const DEFAULT_ERROR = 'Operation failed. Please try again.';
// Initialize page
setupNavBar();
loadHospitals();
initializeEventHandlers();
function setupNavBar() {
const nav = `
<nav class="top-nav">
<div class="nav-brand">Digital Insight for Health</div>
<div class="nav-items">
<a href="/dashboard" class="nav-link">
<i class="fas fa-home"></i> Home
</a>
<a href="/beds" class="nav-link active">
<i class="fas fa-bed"></i> Beds
</a>
<button class="nav-link sign-out" onclick="handleSignOut()">
<i class="fas fa-sign-out-alt"></i> Sign Out
</button>
</div>
<div class="user-info">
<span class="user-name">${localStorage.getItem('name') || 'User'}</span>
<span class="user-role">${localStorage.getItem('type') || 'Guest'}</span>
</div>
</nav>
`;
$('.main-container').prepend(nav);
}
function loadHospitals() {
showLoading();
$.ajax({
url: `${API_BASE_URL}/available`,
method: 'GET',
contentType: 'application/json',
success: function(response) {
if(response && response.code === 1) {
if (response.data && response.data.length > 0) {
updateTable(response.data);
} else {
showNoDataMessage();
}
updateTable(response.data || []);
} else {
showError('Error loading hospitals');
showError(response.msg || DEFAULT_ERROR);
}
},
error: function(xhr) {
showError('Failed to load hospitals');
console.error('API Error:', xhr);
}
error: handleAjaxError
});
}
......@@ -59,26 +79,7 @@ $(document).ready(function () {
function initializeEventHandlers() {
// Search Handler
$("#searchButton").click(function() {
const searchName = $("#searchName").val();
$.ajax({
url: `${API_BASE_URL}/available`,
method: 'GET',
data: { name: searchName },
success: function(response) {
if(response && response.code === 200) {
updateTable(response.data);
} else {
showError('Search failed');
}
},
error: function(xhr) {
showError('Search failed');
console.error('Search Error:', xhr);
}
});
});
$("#searchButton").click(handleSearch);
// Add Hospital Handler
$("#addHospitalBtn").click(function() {
......@@ -94,40 +95,7 @@ $(document).ready(function () {
});
// Form Submit Handler
$("#hospitalForm").submit(function(e) {
e.preventDefault();
const hospitalData = {
name: $("#hospitalName").val(),
location: $("#hospitalLocation").val(),
phone: $("#hospitalPhone").val(),
totalBeds: parseInt($("#totalBeds").val()),
availableBeds: parseInt($("#availableBeds").val())
};
const id = $("#hospitalId").val();
const method = id ? 'PUT' : 'POST';
const url = id ? `${API_BASE_URL}/${id}` : API_BASE_URL;
$.ajax({
url: url,
method: method,
contentType: 'application/json',
data: JSON.stringify(hospitalData),
success: function(response) {
if(response.code === 200) {
$("#hospitalModal").fadeOut();
loadHospitals();
} else {
alert(response.msg || 'Operation failed');
}
},
error: function(xhr) {
alert('Error processing request');
console.error('API Error:', xhr);
}
});
});
$("#hospitalForm").submit(handleFormSubmit);
// Delete Handler
$(document).on('click', '.delete-btn', function() {
......@@ -152,6 +120,65 @@ $(document).ready(function () {
});
}
function handleSearch(event) {
event.preventDefault();
const searchTerm = $("#searchName").val().trim();
$.ajax({
url: `${API_BASE_URL}/search`,
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({ name: searchTerm }),
success: function(response) {
if(response && response.code === 1) {
updateTable(response.data || []);
} else {
showError('No hospitals found');
}
},
error: handleAjaxError
});
}
function handleFormSubmit(event) {
event.preventDefault();
const formData = {
name: $("#hospitalName").val(),
address: $("#hospitalLocation").val(),
phone: $("#hospitalPhone").val(),
maxAmount: parseInt($("#totalBeds").val()),
amountPatient: parseInt($("#totalBeds").val() - $("#availableBeds").val()),
type: 'hospital',
status: 1
};
const id = $("#hospitalId").val();
const method = id ? 'PUT' : 'POST';
const url = id ? `${API_BASE_URL}/${id}` : API_BASE_URL;
$.ajax({
url: url,
method: method,
contentType: 'application/json',
data: JSON.stringify(formData),
success: function(response) {
if(response && response.code === 1) {
$("#hospitalModal").fadeOut();
showSuccess('Operation successful');
loadHospitals();
} else {
showError(response.msg || DEFAULT_ERROR);
}
},
error: handleAjaxError
});
}
function handleAjaxError(xhr, status, error) {
console.error('API Error:', {xhr, status, error});
showError(DEFAULT_ERROR);
}
function showLoading() {
$('#hospitalTable tbody').html('<tr><td colspan="8" class="text-center">Loading...</td></tr>');
}
......@@ -163,4 +190,88 @@ $(document).ready(function () {
function showError(message) {
$('#hospitalTable tbody').html(`<tr><td colspan="8" class="text-center text-danger">${message}</td></tr>`);
}
// Add CSS for new components
const styles = `
.top-nav {
background: var(--primary-color);
padding: 1rem 2rem;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 2rem;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.nav-brand {
color: white;
font-size: 1.5rem;
font-weight: 600;
}
.nav-items {
display: flex;
gap: 1rem;
align-items: center;
}
.nav-link {
color: white;
text-decoration: none;
padding: 0.5rem 1rem;
border-radius: 6px;
transition: all 0.3s ease;
}
.nav-link:hover, .nav-link.active {
background: rgba(255,255,255,0.1);
}
.sign-out {
background: var(--danger-color);
border: none;
cursor: pointer;
}
.user-info {
display: flex;
flex-direction: column;
align-items: flex-end;
color: white;
}
.user-name {
font-weight: 500;
}
.user-role {
font-size: 0.875rem;
opacity: 0.8;
}
.success-message {
background: var(--success-color);
color: white;
padding: 1rem;
border-radius: 6px;
margin-bottom: 1rem;
display: flex;
align-items: center;
justify-content: space-between;
}
`;
$('<style>').text(styles).appendTo('head');
// Initialize tooltips and other UI enhancements
$('[data-toggle="tooltip"]').tooltip();
// Add fade effects for smoother transitions
$('.table-container').hide().fadeIn();
});
function handleSignOut() {
localStorage.clear();
window.location.href = '/login';
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment