Quick Appointment Service
DoctorAppointment
package com.cts.das.bean;
import java.time.LocalDateTime;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
public class DoctorAppointment {
private static int appointmentId=1000;
//Use validation annotations as per the requirement
// add constructor and increment appointmentId by 1
@NotNull(message="Patient name is required")
private String patientName;
@NotNull(message="Phone number is required")
@Pattern(regexp="^//d{10}$",message="Phone number should be 10 digits.")
private String phoneNumber;
private LocalDateTime dateOfAappointment;
@NotNull(message="Email is required")
private String email;
@NotNull(message="Age is required")
private Integer age;
@NotNull(message="Gender is required")
private String gender;
private String problemName;
private String doctorName;
private String appointmentStatus;
public DoctorAppointment()
{
appointmentId++;
}
public int getAppointmentId() {
return appointmentId;
}
public void setAppointmentId(int appointmentId) {
this.appointmentId = appointmentId;
}
public String getPatientName() {
return patientName;
}
public void setPatientName(String patientName) {
this.patientName = patientName;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public LocalDateTime getDateOfAappointment() {
return dateOfAappointment;
}
public void setDateOfAappointment(LocalDateTime dateOfAappointment) {
this.dateOfAappointment = dateOfAappointment;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getProblemName() {
return problemName;
}
public void setProblemName(String problemName) {
this.problemName = problemName;
}
public String getDoctorName() {
return doctorName;
}
public void setDoctorName(String doctorName) {
this.doctorName = doctorName;
}
public String getAppointmentStatus() {
return appointmentStatus;
}
public void setAppointmentStatus(String appointmentStatus) {
this.appointmentStatus = appointmentStatus;
}
@Override
public String toString() {
return "DoctorAppointment [appointmentId=" + appointmentId + ", patientName="
+ patientName + ", phoneNumber="
+ phoneNumber + ", dateOfAappointment=" +
dateOfAappointment + ", email=" + email + ", age=" + age
+ ", gender=" + gender + ", problemName=" + problemName + ",
doctorName=" + doctorName
+ ", appointmentStatus=" + appointmentStatus + "]";
}
}
DoctorAppointmentController
package com.cts.das.controller;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Validator;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.cts.das.bean.DoctorAppointment;
import com.cts.das.service.DoctorAppointmentDaoService;
@Controller
public class DoctorAppointmentController {
@Autowired
private DoctorAppointmentDaoService doctorAppointmentDaoService;
@Autowired
private Validator validator;
// add the mapping as per the requirement
@RequestMapping(value="/showAppointmentForm",method=RequestMethod.GET)
public String showAppointmentForm(@ModelAttribute("doctorAppointment")
DoctorAppointment doctorAppointment) {
return "doctorAppointment";
}
@RequestMapping(value="/getAppointment",method=RequestMethod.POST)
public String getAppoinmentStatus(@ModelAttribute("doctorAppointment")
DoctorAppointment doctorAppointment,ModelMap map,BindingResult result) {
if(result.hasErrors())
{
return "doctorAppointment";
}
int appointmentId=0;
if(doctorAppointmentDaoService.doctorList.keySet().contains(doctorAppointment.getProblemNa
me()))
{
String doctorName =
doctorAppointmentDaoService.doctorList.get(doctorAppointment.getProblemName());
doctorAppointment.setDoctorName(doctorName);
doctorAppointment.setDateOfAappointment(LocalDateTime.now().plusDays(1));
doctorAppointment.setAppointmentStatus("APPROVED");
appointmentId=doctorAppointmentDaoService.addDoctorAppointmentDetails(doctorAppointmen
t);
}
if(appointmentId>0)
{
map.addAttribute("doctorAppointment",doctorAppointment);
return "appointmentStatus";
}
else
{
doctorAppointment.setAppointmentStatus("DISAPPROVED");
map.addAttribute("message","Appointment not approved try
again");
return "doctorAppointment";
}
}
@ModelAttribute("problemList")
public Set<String> populateProblemList(){
return doctorAppointmentDaoService.doctorList.keySet();
}
}
Doctorappointmentdaoservice
package com.cts.das.service;
import java.util.HashMap;
import java.util.Map;
import com.cts.das.bean.DoctorAppointment;
public interface DoctorAppointmentDaoService {
public Map<String,String> doctorList=new HashMap<>();
int addDoctorAppointmentDetails (DoctorAppointment doctorAppointment);
}
doctorappointmentdaoserviceIMp
package com.cts.das.service;
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import com.cts.das.bean.DoctorAppointment;
@Service
public class DoctorAppointmentDaoServiceImpl implements DoctorAppointmentDaoService{
public static Map<Integer,DoctorAppointment> appointmentList=new HashMap<>();
public DoctorAppointmentDaoServiceImpl() {
doctorList.put("Heart", "Dr. Brijesh Kumar");
doctorList.put("Gynecology", "Dr. Sharda Singh");
doctorList.put("Diabetes", "Dr. Uma Chandrashekar");
doctorList.put("ENT", "Dr. Preethi raj");
doctorList.put("Dermatology", "Dr. Renuka Kher");
doctorList.put("Bone", "Dr. Kanika Kapoor");
}
@Override
public int addDoctorAppointmentDetails(DoctorAppointment doctorAppointment) {
// add the code as per the requirement
int id = doctorAppointment.getAppointmentId();
appointmentList.put(id,doctorAppointment);
return id;
}
}
Quickappointmentserviceapplication
package com.cts.das;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan("com.*")
public class QuickAppointmentServiceApplication {
public static void main(String[] args) {
SpringApplication.run(QuickAppointmentServiceApplication.class, args);
}
}
Appointmentstatus
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Appointment Status</title>
</head>
<body>
<h2 id="appointmentStatus">
Your Doctor Appointment has been successfully registered</br>
Your appointment ID is: ${doctorAppointment.getAppointmentId()}</br>
Patient Name:${doctorAppointment.getPatientName()}</br>
Appointment Date:${doctorAppointment.getDateOfAappointment()}</br>
Doctor Name:${doctorAppointment.getDoctorName()}</br>
</h2>
</body>
</html>
Doctorappointment
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Good Health Appointment Service </h1>
</br>
<h2>Doctor's Appointment Form</h2>
<sf:form name="form" modelAttribute="doctorAppointment" method="post"
action="getAppointment">
<table>
<tr>
<td><label>Patient Name:</label></td>
<td><sf:input path="patientName" id="patientName"/></td>
</tr>
<tr>
<td><label>Phone Number:</label></td>
<td><sf:input path="phoneNumber" id="phoneNumber"/></td>
</tr>
<tr>
<td><label>Email:</label></td>
<td><sf:input path="email" id="Email"/></td>
</tr>
<tr>
<td><label>Age:</label></td>
<td><sf:input path="age" id="Age"/></td>
</tr>
<tr>
<td><label>Gender:</label></td>
<td><sf:radiobutton path="gender" value="Male" id="Gender"/>
Male
<sf:radiobutton path="gender" value="Female" id="Gender"/>
Female
</tr>
<tr>
<td><label>Problem Name:</label></td>
<td><sf:select path="problemName" items="${problemList}"/>
</td>
</tr>
<tr>
<td><input type="submit" name="bookAppointment" value="Book
Appointment"></td>
<td><input type="reset" value="Cancel"></td>
</tr>
</table>
</sf:form>
${message}
</body>
</html>
Pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cts</groupId>
<artifactId>QuickAppointmentServiceApplication</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>QuickAppointmentServiceApplication</name>
<description>Spring Boot Doctor Quick Appointment Service Application</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- JSTL tag lib -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- Tomcat for JSP rendering -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Comments
Post a Comment