├── settings.gradle ├── src ├── main │ ├── java │ │ └── com │ │ │ └── medizine │ │ │ └── backend │ │ │ ├── dto │ │ │ ├── Status.java │ │ │ ├── StatusType.java │ │ │ ├── ZoomMeetingStatus.java │ │ │ ├── BaseEntity.java │ │ │ ├── MedicalHistory.java │ │ │ ├── UserBookingDetail.java │ │ │ ├── MultiLingual.java │ │ │ ├── Appointment.java │ │ │ ├── ZoomMeeting.java │ │ │ ├── Slot.java │ │ │ ├── BaseModel.java │ │ │ ├── Doctor.java │ │ │ └── User.java │ │ │ ├── exchanges │ │ │ ├── BaseResponse.java │ │ │ ├── ZoomMeetingResponse.java │ │ │ ├── DoctorListResponse.java │ │ │ ├── UserListResponse.java │ │ │ ├── AppointmentResponse.java │ │ │ ├── SlotResponse.java │ │ │ ├── SlotStatusRequest.java │ │ │ ├── UploadMediaResponse.java │ │ │ ├── Response.java │ │ │ ├── ZoomMeetingRequest.java │ │ │ ├── SlotBookingRequest.java │ │ │ ├── DoctorPatchRequest.java │ │ │ ├── UserPatchRequest.java │ │ │ └── PatchHelper.java │ │ │ ├── exceptions │ │ │ ├── MedizineAppException.java │ │ │ ├── StorageException.java │ │ │ ├── DocumentStorageException.java │ │ │ ├── StorageFileNotFoundException.java │ │ │ └── RestExceptionHandler.java │ │ │ ├── repositories │ │ │ ├── MediaRepository.java │ │ │ ├── SlotRepository.java │ │ │ ├── UserRepository.java │ │ │ ├── DoctorRepository.java │ │ │ ├── ZoomRepository.java │ │ │ └── AppointmentRepository.java │ │ │ ├── controller │ │ │ ├── BaseController.java │ │ │ ├── ApiCrudController.java │ │ │ ├── MediaController.java │ │ │ ├── ZoomController.java │ │ │ ├── AppointmentController.java │ │ │ ├── SlotController.java │ │ │ ├── DoctorController.java │ │ │ └── UserController.java │ │ │ ├── config │ │ │ ├── StorageProperties.java │ │ │ └── SwaggerConfiguration.java │ │ │ ├── services │ │ │ ├── BaseService.java │ │ │ ├── MediaStorageService.java │ │ │ ├── DoctorService.java │ │ │ ├── UserService.java │ │ │ ├── ZoomMeetingService.java │ │ │ ├── MediaStorageServiceImpl.java │ │ │ └── MediaService.java │ │ │ ├── models │ │ │ ├── DoctorEntity.java │ │ │ └── Media.java │ │ │ ├── repositoryservices │ │ │ ├── MeetingRepositoryService.java │ │ │ ├── UserRepositoryService.java │ │ │ ├── DoctorRepositoryService.java │ │ │ ├── MediaRepositoryService.java │ │ │ ├── MeetingRepositoryServiceImpl.java │ │ │ ├── AppointmentRepositoryService.java │ │ │ ├── UserRepositoryServiceImpl.java │ │ │ ├── DoctorRepositoryServiceImpl.java │ │ │ └── SlotRepositoryService.java │ │ │ ├── utils │ │ │ ├── ApiSubError.java │ │ │ └── ApiError.java │ │ │ ├── log │ │ │ └── UncaughtExceptionHandler.java │ │ │ └── MedizineBackendApplication.java │ └── resources │ │ ├── META-INF │ │ └── additional-spring-configuration-metadata.json │ │ ├── slots.json │ │ ├── application.properties │ │ ├── static │ │ └── style.css │ │ └── templates │ │ └── ApiHome.html └── test │ └── java │ └── com │ └── medizine │ └── backend │ └── MedizineBackendApplicationTests.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradlew.bat ├── README.md └── gradlew /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'backend' 2 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/dto/Status.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.dto; 2 | 3 | public enum Status { 4 | ACTIVE, INACTIVE 5 | } 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aakashsankritya/Doctors-Appointment-Booking-App-backend/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/dto/StatusType.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.dto; 2 | 3 | public enum StatusType { 4 | ACTIVE, INACTIVE 5 | 6 | } 7 | 8 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/dto/ZoomMeetingStatus.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.dto; 2 | 3 | public enum ZoomMeetingStatus { 4 | COMPLETED, LIVE, UPCOMING, UNKNOWN 5 | 6 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/test/java/com/medizine/backend/MedizineBackendApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | //@SpringBootTest 6 | class MedizineBackendApplicationTests { 7 | 8 | @Test 9 | void contextLoads() { 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/dto/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.dto; 2 | 3 | import org.springframework.data.annotation.Id; 4 | 5 | import java.io.Serializable; 6 | 7 | public class BaseEntity implements Serializable { 8 | 9 | @Id 10 | public String id; 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/BaseResponse.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | 6 | @AllArgsConstructor 7 | public class BaseResponse { 8 | @Getter 9 | private final T data; 10 | 11 | @Getter 12 | private final String message; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/dto/MedicalHistory.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class MedicalHistory { 11 | private String problem; 12 | private String consultedWith; 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exceptions/MedizineAppException.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exceptions; 2 | 3 | abstract class MedizineAppException extends RuntimeException { 4 | 5 | MedizineAppException() { 6 | } 7 | 8 | MedizineAppException(String message) { 9 | super(message); 10 | } 11 | 12 | public abstract int getErrorType(); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exceptions/StorageException.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exceptions; 2 | 3 | public class StorageException extends RuntimeException { 4 | 5 | public StorageException(String message) { 6 | super(message); 7 | } 8 | 9 | public StorageException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/ZoomMeetingResponse.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import com.medizine.backend.dto.ZoomMeeting; 4 | import lombok.Builder; 5 | 6 | public class ZoomMeetingResponse extends Response { 7 | 8 | @Builder 9 | public ZoomMeetingResponse(ZoomMeeting data) { 10 | super(data); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/dto/UserBookingDetail.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class UserBookingDetail { 13 | private String userId; 14 | private Date date; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/DoctorListResponse.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import com.medizine.backend.dto.Doctor; 4 | 5 | import java.util.List; 6 | 7 | public class DoctorListResponse extends BaseResponse> { 8 | 9 | public DoctorListResponse(List data, String message) { 10 | super(data, message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/UserListResponse.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import com.medizine.backend.dto.User; 4 | import lombok.Builder; 5 | 6 | import java.util.List; 7 | 8 | public class UserListResponse extends Response> { 9 | 10 | @Builder 11 | public UserListResponse(List users) { 12 | super(users); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exceptions/DocumentStorageException.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exceptions; 2 | 3 | 4 | public class DocumentStorageException extends RuntimeException { 5 | public DocumentStorageException(String message) { 6 | super(message); 7 | } 8 | 9 | public DocumentStorageException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/AppointmentResponse.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import com.medizine.backend.dto.Appointment; 4 | 5 | import java.util.List; 6 | 7 | public class AppointmentResponse extends BaseResponse> { 8 | 9 | public AppointmentResponse(List data, String message) { 10 | super(data, message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exceptions/StorageFileNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exceptions; 2 | 3 | public class StorageFileNotFoundException extends StorageException { 4 | 5 | public StorageFileNotFoundException(String message) { 6 | super(message); 7 | } 8 | 9 | public StorageFileNotFoundException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "com.mongodb.WriteConcern", 5 | "type": "java.lang.String", 6 | "description": "Description for com.mongodb.WriteConcern." 7 | }, 8 | { 9 | "name": "file.upload-dir", 10 | "type": "java.lang.String", 11 | "description": "Description for file.upload-dir." 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositories/MediaRepository.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositories; 2 | 3 | import com.medizine.backend.models.Media; 4 | import org.bson.types.ObjectId; 5 | import org.springframework.data.mongodb.repository.MongoRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | 9 | @Repository 10 | public interface MediaRepository extends MongoRepository { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositories/SlotRepository.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositories; 2 | 3 | import com.medizine.backend.dto.Slot; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | 9 | @Repository 10 | public interface SlotRepository extends MongoRepository { 11 | 12 | List getAllByDoctorId(String doctorId); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/SlotResponse.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.medizine.backend.dto.Slot; 5 | 6 | import java.util.List; 7 | 8 | public class SlotResponse extends BaseResponse> { 9 | 10 | @JsonIgnoreProperties(ignoreUnknown = true) 11 | public SlotResponse(List data, String message) { 12 | super(data, message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/resources/slots.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "startTime": "10.00", 4 | "endTime": "10.30", 5 | "docId": "5f6dc987645cghf789ba5f77f95ea1e1f", 6 | "isBooked": "No" 7 | }, 8 | { 9 | "startTime": "11.00", 10 | "endTime": "11.30", 11 | "docId": "5f6dcf72345689ba5f77f95ea1e1f", 12 | "isBooked": "No" 13 | }, 14 | { 15 | "startTime": "12.00", 16 | "endTime": "12.30", 17 | "docId": "5f6dcf734589ba5f77f95ea1e1f", 18 | "isBooked": "No" 19 | } 20 | ] -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/SlotStatusRequest.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | import javax.validation.constraints.NotNull; 7 | import java.util.Date; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | public class SlotStatusRequest { 12 | 13 | @NotNull 14 | private String doctorId; 15 | 16 | @NotNull 17 | private String userId; 18 | 19 | @NotNull 20 | private Date currentDate; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositories/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositories; 2 | 3 | import com.medizine.backend.dto.User; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import javax.validation.constraints.NotNull; 8 | 9 | @Repository 10 | public interface UserRepository extends MongoRepository { 11 | 12 | User findUserByPhoneNumber(@NotNull String phoneNumber); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositories/DoctorRepository.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositories; 2 | 3 | import com.medizine.backend.dto.Doctor; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import javax.validation.constraints.NotNull; 8 | 9 | @Repository 10 | public interface DoctorRepository extends MongoRepository { 11 | Doctor findDoctorByPhoneNumber(@NotNull String phoneNumber); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/controller/BaseController.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.controller; 2 | 3 | import lombok.extern.log4j.Log4j2; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.validation.annotation.Validated; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | 8 | @Controller 9 | @Validated 10 | @Log4j2 11 | public class BaseController { 12 | 13 | @GetMapping("/") 14 | public String getHomepage() { 15 | return "ApiHome"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | !**/src/main/**/out/ 24 | !**/src/test/**/out/ 25 | 26 | ### NetBeans ### 27 | /nbproject/private/ 28 | /nbbuild/ 29 | /dist/ 30 | /nbdist/ 31 | /.nb-gradle/ 32 | 33 | ### VS Code ### 34 | .vscode/ 35 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/config/StorageProperties.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | @ConfigurationProperties("storage") 6 | public class StorageProperties { 7 | 8 | /** 9 | * Folder location for storing files 10 | */ 11 | private String location = "upload-dir"; 12 | 13 | public String getLocation() { 14 | return location; 15 | } 16 | 17 | public void setLocation(String location) { 18 | this.location = location; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/UploadMediaResponse.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @JsonIgnoreProperties(ignoreUnknown = true) 12 | public class UploadMediaResponse { 13 | 14 | private String fileName; 15 | 16 | private String fileDownloadURI; 17 | 18 | private String fileType; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/services/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.services; 2 | 3 | import com.medizine.backend.exchanges.DoctorListResponse; 4 | import org.springframework.http.ResponseEntity; 5 | 6 | public interface BaseService { 7 | 8 | DoctorListResponse getAvailableDoctors(); 9 | 10 | ResponseEntity findEntityById(String id); 11 | 12 | ResponseEntity deleteEntity(String id); 13 | 14 | ResponseEntity restoreEntity(String id); 15 | 16 | ResponseEntity findEntityByPhone(String countryCode, String phoneNumber); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/services/MediaStorageService.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.services; 2 | 3 | import org.springframework.core.io.Resource; 4 | import org.springframework.web.multipart.MultipartFile; 5 | 6 | import java.nio.file.Path; 7 | import java.util.stream.Stream; 8 | 9 | public interface MediaStorageService { 10 | 11 | void init(); 12 | 13 | void store(MultipartFile file); 14 | 15 | Stream loadAll(); 16 | 17 | Path load(String filename); 18 | 19 | Resource loadAsResource(String filename); 20 | 21 | void deleteAll(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/models/DoctorEntity.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.models; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | import org.bson.types.ObjectId; 6 | import org.springframework.data.annotation.Id; 7 | import org.springframework.data.mongodb.core.mapping.Document; 8 | 9 | @Data 10 | @Document(collection = "doctors") 11 | @NoArgsConstructor 12 | public class DoctorEntity { 13 | @Id 14 | private ObjectId id; 15 | 16 | private String name; 17 | 18 | private String speciality; 19 | 20 | private String[] language; 21 | 22 | private String location; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositories/ZoomRepository.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositories; 2 | 3 | import com.medizine.backend.dto.ZoomMeeting; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | 9 | @Repository 10 | public interface ZoomRepository extends MongoRepository { 11 | 12 | ZoomMeeting findByHostId(String hostId); 13 | 14 | ZoomMeeting findByAppointmentId(String appointmentId); 15 | 16 | List findAllByAppointmentId(String appointmentId); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/Response.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | 8 | 9 | @Data 10 | @AllArgsConstructor 11 | public abstract class Response { 12 | 13 | private T data; 14 | 15 | public JsonNode toJson() { 16 | ObjectMapper mapper = new ObjectMapper(); 17 | try { 18 | return mapper.valueToTree(data); 19 | } catch (Exception e) { 20 | throw new RuntimeException(e); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositoryservices/MeetingRepositoryService.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositoryservices; 2 | 3 | import com.medizine.backend.dto.ZoomMeeting; 4 | import com.medizine.backend.exchanges.ZoomMeetingRequest; 5 | 6 | public interface MeetingRepositoryService { 7 | 8 | ZoomMeeting getById(String id); 9 | 10 | ZoomMeeting getByHostId(String hostId); 11 | 12 | ZoomMeeting createMeeting(ZoomMeeting zoomMeeting); 13 | 14 | ZoomMeeting patchMeeting(ZoomMeetingRequest zoomMeetingRequest, String id); 15 | 16 | ZoomMeeting getZoomMeetingByAppointmentId(String appointmentId); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/utils/ApiSubError.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.utils; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | abstract class ApiSubError { 8 | 9 | } 10 | 11 | @Data 12 | @EqualsAndHashCode(callSuper = false) 13 | @AllArgsConstructor 14 | class ApiValidationError extends ApiSubError { 15 | private String object; 16 | private String field; 17 | private Object rejectedValue; 18 | private String message; 19 | 20 | ApiValidationError(String object, String message) { 21 | this.object = object; 22 | this.message = message; 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/ZoomMeetingRequest.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import com.medizine.backend.dto.ZoomMeeting; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | @Data 8 | @EqualsAndHashCode(callSuper = true) 9 | public class ZoomMeetingRequest extends ZoomMeeting { 10 | 11 | public static final String REQUEST_MODULE_TYPE = "moduleType"; 12 | public static final String REQUEST_MODULE_ID = "moduleId"; 13 | public static final String REQUEST_MEETING_STATUS = "meetingStatus"; 14 | public static final String REQUEST_MEETING_NUMBER = "meetingNumber"; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/dto/MultiLingual.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.dto; 2 | 3 | import io.swagger.annotations.ApiModelProperty; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | public class MultiLingual { 10 | 11 | @ApiModelProperty(example = "Lorem Ipsum") 12 | private String en; //english 13 | 14 | @ApiModelProperty(example = "लोरम इप्सम") 15 | private String hi; //hindi 16 | 17 | @ApiModelProperty(hidden = true) 18 | private String gu; //gujarati 19 | 20 | @ApiModelProperty(hidden = true) 21 | private String mr; //marathi 22 | 23 | @ApiModelProperty(hidden = true) 24 | private String kn; //kannada 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/models/Media.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.models; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | import org.bson.types.ObjectId; 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | import org.springframework.data.annotation.Id; 8 | import org.springframework.data.mongodb.core.mapping.Document; 9 | 10 | 11 | @Data 12 | @NoArgsConstructor 13 | @Document(collection = "mediaStorage") 14 | @ConfigurationProperties(prefix = "file") 15 | public class Media { 16 | 17 | @Id 18 | private ObjectId id; 19 | 20 | private String userId; 21 | 22 | private String fileName; 23 | 24 | private String fileFormat; 25 | 26 | private String uploadDir; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/dto/Appointment.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.dto; 2 | 3 | import lombok.*; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | import javax.validation.constraints.NotNull; 7 | import java.util.Date; 8 | 9 | @EqualsAndHashCode(callSuper = true) 10 | @Data 11 | @Builder 12 | @Document(collection = "appointment") 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class Appointment extends BaseEntity { 16 | 17 | @NotNull 18 | private String doctorId; 19 | 20 | @NotNull 21 | private String userId; 22 | 23 | @NotNull 24 | private String slotId; 25 | 26 | @NotNull 27 | private Date appointmentDate; 28 | 29 | @NotNull 30 | private Status STATUS; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/controller/ApiCrudController.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.controller; 2 | 3 | import com.medizine.backend.exchanges.BaseResponse; 4 | import org.springframework.web.bind.annotation.DeleteMapping; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PutMapping; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | 9 | 10 | abstract class ApiCrudController { 11 | 12 | @GetMapping("/getById") 13 | public abstract BaseResponse getById(@RequestParam String id); 14 | 15 | @DeleteMapping("/deleteById") 16 | public abstract BaseResponse deleteById(@RequestParam String id); 17 | 18 | @PutMapping("/restoreById") 19 | public abstract BaseResponse restoreById(@RequestParam String id); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/SlotBookingRequest.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import javax.validation.Valid; 9 | import javax.validation.constraints.NotNull; 10 | import java.util.Date; 11 | 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | @JsonIgnoreProperties(ignoreUnknown = true) 16 | @Valid 17 | public class SlotBookingRequest { 18 | 19 | @NotNull 20 | private String DoctorId; 21 | 22 | @NotNull 23 | private String slotId; 24 | 25 | @NotNull 26 | private Date bookingDate; // Parse only the Date not the time. 27 | 28 | @NotNull 29 | private String userId; // User for reference to the user. 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositoryservices/UserRepositoryService.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositoryservices; 2 | 3 | import com.medizine.backend.dto.User; 4 | import com.medizine.backend.exchanges.UserPatchRequest; 5 | import org.springframework.http.ResponseEntity; 6 | 7 | import java.util.List; 8 | 9 | public interface UserRepositoryService { 10 | 11 | ResponseEntity createUser(User userToSave); 12 | 13 | List getAll(); 14 | 15 | ResponseEntity getUserById(String id); 16 | 17 | ResponseEntity updateUserById(String id, User userToUpdate); 18 | 19 | ResponseEntity patchUser(String id, UserPatchRequest changes); 20 | 21 | ResponseEntity deleteUserById(String id); 22 | 23 | ResponseEntity restoreUserById(String id); 24 | 25 | ResponseEntity findUserByPhone(String countryCode, String phoneNumber); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/dto/ZoomMeeting.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.dto; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.validation.constraints.NotNull; 8 | import java.util.LinkedHashMap; 9 | 10 | @Data 11 | @NoArgsConstructor 12 | @EqualsAndHashCode(callSuper = true) 13 | public class ZoomMeeting extends BaseEntity { 14 | 15 | private MultiLingual meetingTitle; 16 | 17 | @NotNull 18 | private String hostId; 19 | 20 | @NotNull 21 | private String appointmentId; 22 | 23 | @NotNull 24 | private String meetingNumber; 25 | 26 | private String meetingPassword; 27 | 28 | private String meetingStartTime; 29 | private String meetingDuration; 30 | 31 | private ZoomMeetingStatus meetingStatus; 32 | 33 | private LinkedHashMap meetingMetaData; 34 | } -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/dto/Slot.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.dto; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.EqualsAndHashCode; 7 | import lombok.NoArgsConstructor; 8 | import org.springframework.data.mongodb.core.mapping.Document; 9 | 10 | import javax.validation.constraints.NotNull; 11 | import java.util.Date; 12 | 13 | @Data 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | @Document(collection = "slots") 17 | @JsonIgnoreProperties(ignoreUnknown = true) 18 | @EqualsAndHashCode(callSuper = true) 19 | public class Slot extends BaseEntity { 20 | 21 | @NotNull 22 | private Date startTime; // 24hr format. 23 | 24 | @NotNull 25 | private Date endTime; 26 | 27 | @NotNull 28 | private String doctorId; 29 | 30 | private boolean isBooked; 31 | 32 | private boolean isBookedBySameUser; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositoryservices/DoctorRepositoryService.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositoryservices; 2 | 3 | import com.medizine.backend.dto.Doctor; 4 | import com.medizine.backend.exchanges.DoctorPatchRequest; 5 | import org.springframework.http.ResponseEntity; 6 | 7 | import java.util.List; 8 | 9 | public interface DoctorRepositoryService { 10 | 11 | ResponseEntity createDoctor(Doctor doctorToSave); 12 | 13 | ResponseEntity updateDoctorById(String id, Doctor doctorToUpdate); 14 | 15 | ResponseEntity patchDoctor(String id, DoctorPatchRequest doctorPatchRequest); 16 | 17 | List getAllDoctorsCloseBy(); 18 | 19 | ResponseEntity getDoctorById(String id); 20 | 21 | ResponseEntity deleteDoctorById(String id); 22 | 23 | ResponseEntity restoreDoctorById(String id); 24 | 25 | ResponseEntity getDoctorByPhone(String countryCode, String phoneNumber); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/dto/BaseModel.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.dto; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import org.bson.types.ObjectId; 8 | import org.springframework.data.annotation.Id; 9 | 10 | @Data 11 | @NoArgsConstructor 12 | public abstract class BaseModel implements Cloneable { 13 | 14 | @Id 15 | @ApiModelProperty(example = "5cdd81f49981f6a1b2578c7", dataType = "string") 16 | private ObjectId id; 17 | 18 | @JsonIgnore 19 | private StatusType status; 20 | 21 | @Override 22 | public boolean equals(Object o) { 23 | if (this == o) return true; 24 | if (o == null || getClass() != o.getClass()) return false; 25 | BaseModel baseModel = (BaseModel) o; 26 | return getId().equals(baseModel.getId()) && getStatus() == baseModel.getStatus(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/config/SwaggerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.PathSelectors; 6 | import springfox.documentation.builders.RequestHandlerSelectors; 7 | import springfox.documentation.spi.DocumentationType; 8 | import springfox.documentation.spring.web.plugins.Docket; 9 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 10 | 11 | @EnableSwagger2 12 | @Configuration 13 | public class SwaggerConfiguration { 14 | /** 15 | * Swagger Implementation 16 | */ 17 | @Bean 18 | public Docket medizineApi() { 19 | return new Docket(DocumentationType.SWAGGER_2) 20 | .select() 21 | .apis(RequestHandlerSelectors.any()) 22 | .paths(PathSelectors.any()) 23 | .build() 24 | .forCodeGeneration(true); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositories/AppointmentRepository.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositories; 2 | 3 | import com.medizine.backend.dto.Appointment; 4 | import com.medizine.backend.dto.Status; 5 | import org.springframework.data.mongodb.repository.MongoRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | @Repository 11 | public interface AppointmentRepository extends MongoRepository { 12 | 13 | List findAllBySlotIdAndDoctorIdAndUserIdAndSTATUS(String slotId, String doctorId, String userId, 14 | Status status); 15 | 16 | List findAllBySlotIdAndDoctorIdAndSTATUS(String slotId, String doctorId, Status status); 17 | 18 | List findAllByDoctorIdAndSTATUS(String doctorId, Status status); 19 | 20 | List findAllByUserIdAndSTATUS(String userId, Status status); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/DoctorPatchRequest.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import javax.validation.constraints.Pattern; 9 | import java.time.LocalDate; 10 | 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | @JsonIgnoreProperties(ignoreUnknown = true) 15 | public class DoctorPatchRequest { 16 | 17 | // NOTE: The phoneNumber, countryCode should not be modified. 18 | 19 | // @Size(max = 100) 20 | private String name; 21 | 22 | @Pattern(regexp = "\\S+@\\S+\\.\\S+") 23 | private String emailAddress; 24 | 25 | private LocalDate dob; 26 | 27 | private String gender; 28 | 29 | private String speciality; 30 | 31 | private int experience; 32 | 33 | private String about; 34 | 35 | private String[] language; 36 | 37 | private String location; 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/UserPatchRequest.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.medizine.backend.dto.MedicalHistory; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.validation.constraints.Pattern; 10 | import java.time.LocalDate; 11 | 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | @JsonIgnoreProperties(ignoreUnknown = true) 16 | public class UserPatchRequest { 17 | 18 | // NOTE: The phoneNumber, countryCode should not be modified. 19 | 20 | // @Size(max = 100) 21 | private String name; 22 | 23 | @Pattern(regexp = "\\S+@\\S+\\.\\S+") 24 | private String emailAddress; 25 | 26 | private String[] problems; 27 | 28 | private LocalDate dob; 29 | 30 | private String gender; 31 | 32 | private MedicalHistory medicalHistory; 33 | 34 | private String bloodGroup; 35 | 36 | private int weight; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositoryservices/MediaRepositoryService.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositoryservices; 2 | 3 | import com.medizine.backend.models.Media; 4 | import com.medizine.backend.repositories.MediaRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | @Service 11 | public class MediaRepositoryService { 12 | 13 | @Autowired 14 | private MediaRepository mediaRepository; 15 | 16 | public Media findMediaStorageByUserId(String userId) { 17 | List mediaList = mediaRepository.findAll(); 18 | 19 | for (Media media : mediaList) { 20 | if (media.getUserId().equalsIgnoreCase(userId)) 21 | return media; 22 | } 23 | 24 | return null; 25 | } 26 | 27 | public void save(Media mediaToSave) { 28 | mediaRepository.save(mediaToSave); 29 | } 30 | 31 | public String getUploadMediaPath(String userId, String docType) { 32 | return userId + "_" + docType + "." + docType; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) Medizine 2020. All rights reserved 2 | # Run the server on port 8081. 3 | server.port=8081 4 | # Mongo 5 | spring.data.mongodb.uri= # Enter the mongodb URI 6 | spring.data.mongodb.username= # Login user of the mongo server. 7 | spring.data.mongodb.database= # Enter the database name 8 | logging.level.org.springframework.boot.autoconfigure.mongo.embedded=INFO 9 | logging.level.org.mongodb=INFO 10 | # TIP:Uncomment the following to debug Spring Issues. 11 | debug=true 12 | ## MULTIPART (MultipartProperties) 13 | # Enable multipart uploads 14 | spring.servlet.multipart.enabled=true 15 | # Threshold after which files are written to disk. 16 | spring.servlet.multipart.file-size-threshold=200KB 17 | # Max file size. 18 | spring.servlet.multipart.max-file-size=5MB 19 | # Max Request Size 20 | spring.servlet.multipart.max-request-size=215MB 21 | # All files uploaded through the REST API will be stored in this directory 22 | file.upload-dir= # Enter directory path for media uploads 23 | logging.file.name=medizine_logfile.log 24 | spring.devtools.livereload.enabled=false 25 | 26 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/dto/Doctor.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.dto; 2 | 3 | import lombok.*; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | import javax.validation.constraints.NotNull; 7 | import javax.validation.constraints.Pattern; 8 | import javax.validation.constraints.Size; 9 | import java.time.LocalDate; 10 | 11 | 12 | @Data 13 | @Builder 14 | @Document(collection = "doctors") 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | @EqualsAndHashCode(callSuper = true) 18 | public class Doctor extends BaseEntity { 19 | 20 | @Size(max = 100) 21 | private String name; 22 | 23 | @NotNull 24 | private String phoneNumber; // Not Modifiable 25 | 26 | @NotNull 27 | private String countryCode; // // Not Modifiable 28 | 29 | @Pattern(regexp = "\\S+@\\S+\\.\\S+") 30 | private String emailAddress; 31 | 32 | private LocalDate dob; 33 | 34 | private String gender; 35 | 36 | private String speciality; 37 | 38 | private int experience; 39 | 40 | private String about; 41 | 42 | private String[] language; 43 | 44 | private String location; 45 | 46 | private Status status; 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/dto/User.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.dto; 2 | 3 | import lombok.*; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | import javax.validation.constraints.NotNull; 7 | import javax.validation.constraints.Pattern; 8 | import javax.validation.constraints.Size; 9 | import java.time.LocalDate; 10 | 11 | /** 12 | * At signup user can be created using 13 | * CountryCode and PhoneNumber only. 14 | */ 15 | @Data 16 | @Builder 17 | @Document(collection = "users") 18 | @AllArgsConstructor 19 | @NoArgsConstructor 20 | @EqualsAndHashCode(callSuper = true) 21 | public class User extends BaseEntity { 22 | 23 | @Size(max = 100) 24 | private String name; 25 | 26 | @Pattern(regexp = "\\S+@\\S+\\.\\S+") 27 | private String emailAddress; 28 | 29 | @NotNull 30 | private String phoneNumber; // Not Modifiable 31 | 32 | @NotNull 33 | private String countryCode; // Not Modifiable 34 | 35 | private LocalDate dob; 36 | 37 | private String gender; 38 | 39 | private MedicalHistory medicalHistory; 40 | 41 | private String bloodGroup; 42 | 43 | private int weight; 44 | 45 | private String[] problems; 46 | 47 | private Status status; 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/utils/ApiError.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.utils; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.Data; 5 | import org.springframework.http.HttpStatus; 6 | 7 | import java.time.LocalDateTime; 8 | import java.util.List; 9 | 10 | @Data 11 | public class ApiError { 12 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss") 13 | private final LocalDateTime timeStamp; 14 | private HttpStatus httpStatus; 15 | private String message; 16 | private String debugMessage; 17 | private List subErrors; 18 | 19 | private ApiError() { 20 | timeStamp = LocalDateTime.now(); 21 | } 22 | 23 | ApiError(HttpStatus status) { 24 | this(); 25 | this.httpStatus = status; 26 | } 27 | 28 | ApiError(HttpStatus status, Throwable ex) { 29 | this(); 30 | this.httpStatus = status; 31 | this.message = "Unexpected error"; 32 | this.debugMessage = ex.getLocalizedMessage(); 33 | } 34 | 35 | public ApiError(HttpStatus status, String message, Throwable ex) { 36 | this(); 37 | this.httpStatus = status; 38 | this.message = message; 39 | this.debugMessage = ex.getLocalizedMessage(); 40 | } 41 | 42 | public HttpStatus getStatus() { 43 | return httpStatus; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/log/UncaughtExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.log; 2 | 3 | 4 | import com.fasterxml.jackson.databind.node.ArrayNode; 5 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; 6 | import com.fasterxml.jackson.databind.node.ObjectNode; 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | 10 | public class UncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { 11 | 12 | private static final Logger log = LogManager.getLogger(UncaughtExceptionHandler.class); 13 | 14 | @Override 15 | public void uncaughtException(Thread thread, Throwable throwable) { 16 | ObjectNode logEventJsonObjNode = JsonNodeFactory.instance.objectNode(); 17 | 18 | if (throwable.getStackTrace() != null && throwable.getStackTrace().length > 0) { 19 | ArrayNode logStacktraceJsonArrNode = JsonNodeFactory.instance.arrayNode(); 20 | 21 | for (StackTraceElement stackTraceElement : throwable.getStackTrace()) { 22 | logStacktraceJsonArrNode.add(stackTraceElement.toString()); 23 | } 24 | 25 | logEventJsonObjNode.set("stacktrace", logStacktraceJsonArrNode); 26 | } 27 | 28 | logEventJsonObjNode.put("cause", throwable.toString()); 29 | 30 | log.error(logEventJsonObjNode.toString(), throwable); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exceptions/RestExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exceptions; 2 | 3 | import com.medizine.backend.utils.ApiError; 4 | import org.springframework.core.Ordered; 5 | import org.springframework.core.annotation.Order; 6 | import org.springframework.http.HttpHeaders; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.http.converter.HttpMessageNotReadableException; 10 | import org.springframework.web.bind.annotation.ControllerAdvice; 11 | import org.springframework.web.context.request.WebRequest; 12 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 13 | 14 | @Order(Ordered.HIGHEST_PRECEDENCE) 15 | @ControllerAdvice 16 | public class RestExceptionHandler extends ResponseEntityExceptionHandler { 17 | 18 | @Override 19 | protected ResponseEntity handleHttpMessageNotReadable(HttpMessageNotReadableException ex, 20 | HttpHeaders headers, HttpStatus status, 21 | WebRequest request) { 22 | String error = "Malformed JSON request"; 23 | return buildResponseEntity(new ApiError(HttpStatus.BAD_REQUEST, error, ex)); 24 | } 25 | 26 | private ResponseEntity buildResponseEntity(ApiError apiError) { 27 | return new ResponseEntity<>(apiError, apiError.getStatus()); 28 | } 29 | 30 | //other exception handlers below 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/exchanges/PatchHelper.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.exchanges; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import com.fasterxml.jackson.databind.DeserializationFeature; 5 | import com.fasterxml.jackson.databind.MapperFeature; 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | import com.fasterxml.jackson.databind.SerializationFeature; 8 | import org.springframework.stereotype.Component; 9 | 10 | import javax.json.JsonMergePatch; 11 | import javax.json.JsonValue; 12 | 13 | @Component 14 | public class PatchHelper { 15 | 16 | private final ObjectMapper mapper; 17 | 18 | public PatchHelper() { 19 | this.mapper = new ObjectMapper() 20 | .setDefaultPropertyInclusion(JsonInclude.Include.NON_NULL) 21 | .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) 22 | .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) 23 | .findAndRegisterModules() 24 | .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); 25 | } 26 | 27 | public T mergePatch(JsonMergePatch mergePatch, T targetBean, Class beanClass) { 28 | JsonValue target = mapper.convertValue(targetBean, JsonValue.class); 29 | JsonValue patched = applyMergePatch(mergePatch, target); 30 | return convertAndValidate(patched, beanClass); 31 | } 32 | 33 | private JsonValue applyMergePatch(JsonMergePatch mergePatch, JsonValue target) { 34 | try { 35 | return mergePatch.apply(target); 36 | } catch (Exception e) { 37 | throw new RuntimeException(e); 38 | } 39 | } 40 | 41 | private T convertAndValidate(JsonValue jsonValue, Class beanClass) { 42 | return mapper.convertValue(jsonValue, beanClass); 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/MedizineBackendApplication.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend; 2 | 3 | import com.medizine.backend.config.StorageProperties; 4 | import com.medizine.backend.models.Media; 5 | import com.medizine.backend.services.MediaStorageService; 6 | import com.mongodb.WriteConcern; 7 | import lombok.extern.log4j.Log4j2; 8 | import org.modelmapper.ModelMapper; 9 | import org.springframework.boot.CommandLineRunner; 10 | import org.springframework.boot.SpringApplication; 11 | import org.springframework.boot.autoconfigure.SpringBootApplication; 12 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 13 | import org.springframework.context.annotation.Bean; 14 | import org.springframework.context.annotation.Scope; 15 | import org.springframework.data.mongodb.core.WriteConcernResolver; 16 | 17 | @Log4j2 18 | @SpringBootApplication 19 | @EnableConfigurationProperties({StorageProperties.class, Media.class}) 20 | public class MedizineBackendApplication { 21 | 22 | public static void main(String[] args) { 23 | SpringApplication.run(MedizineBackendApplication.class, args); 24 | } 25 | 26 | /** 27 | * Acknowledging Write Concern in MongoDB. 28 | * 29 | * @return WriteConcern 30 | */ 31 | @Bean 32 | public WriteConcernResolver writeConcernResolver() { 33 | return action -> { 34 | System.out.println("Using Write Concern of Acknowledged"); 35 | return WriteConcern.ACKNOWLEDGED; 36 | }; 37 | } 38 | 39 | 40 | /** 41 | * Fetches a ModelMapper instance. 42 | * 43 | * @return ModelMapper 44 | */ 45 | 46 | @Bean 47 | @Scope("prototype") 48 | public ModelMapper modelMapper() { 49 | return new ModelMapper(); 50 | } 51 | 52 | @Bean 53 | CommandLineRunner init(MediaStorageService mediaStorageService) { 54 | return (args) -> { 55 | mediaStorageService.deleteAll(); 56 | mediaStorageService.init(); 57 | }; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/services/DoctorService.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.services; 2 | 3 | import com.medizine.backend.dto.Doctor; 4 | import com.medizine.backend.exchanges.DoctorListResponse; 5 | import com.medizine.backend.exchanges.DoctorPatchRequest; 6 | import com.medizine.backend.repositoryservices.DoctorRepositoryService; 7 | import lombok.extern.log4j.Log4j2; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.List; 13 | 14 | @Service 15 | @Log4j2 16 | public class DoctorService implements BaseService { 17 | 18 | @Autowired 19 | private DoctorRepositoryService doctorRepositoryService; 20 | 21 | public ResponseEntity createDoctor(Doctor doctor) { 22 | return doctorRepositoryService.createDoctor(doctor); 23 | } 24 | 25 | public ResponseEntity patchDoctor(String id, DoctorPatchRequest patchRequest) { 26 | return doctorRepositoryService.patchDoctor(id, patchRequest); 27 | } 28 | 29 | public ResponseEntity updateDoctorById(String id, Doctor doctorToUpdate) { 30 | return doctorRepositoryService.updateDoctorById(id, doctorToUpdate); 31 | } 32 | 33 | @Override 34 | public DoctorListResponse getAvailableDoctors() { 35 | List doctorList = doctorRepositoryService.getAllDoctorsCloseBy(); 36 | return new DoctorListResponse(doctorList, ""); 37 | } 38 | 39 | @Override 40 | public ResponseEntity findEntityById(String id) { 41 | return doctorRepositoryService.getDoctorById(id); 42 | } 43 | 44 | @Override 45 | public ResponseEntity deleteEntity(String id) { 46 | return doctorRepositoryService.deleteDoctorById(id); 47 | } 48 | 49 | @Override 50 | public ResponseEntity restoreEntity(String id) { 51 | return doctorRepositoryService.restoreDoctorById(id); 52 | } 53 | 54 | @Override 55 | public ResponseEntity findEntityByPhone(String countryCode, String phoneNumber) { 56 | return doctorRepositoryService.getDoctorByPhone(countryCode, phoneNumber); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/services/UserService.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.services; 2 | 3 | import com.medizine.backend.dto.Doctor; 4 | import com.medizine.backend.dto.User; 5 | import com.medizine.backend.exchanges.DoctorListResponse; 6 | import com.medizine.backend.exchanges.UserPatchRequest; 7 | import com.medizine.backend.repositoryservices.DoctorRepositoryService; 8 | import com.medizine.backend.repositoryservices.UserRepositoryService; 9 | import lombok.extern.log4j.Log4j2; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.stereotype.Service; 13 | 14 | import java.util.List; 15 | 16 | @Service 17 | @Log4j2 18 | public class UserService implements BaseService { 19 | 20 | @Autowired 21 | private DoctorRepositoryService doctorRepositoryService; 22 | 23 | @Autowired 24 | private UserRepositoryService userRepositoryService; 25 | 26 | public ResponseEntity updateEntityById(String id, User userToUpdate) { 27 | return userRepositoryService.updateUserById(id, userToUpdate); 28 | } 29 | 30 | @Override 31 | public DoctorListResponse getAvailableDoctors() { 32 | List doctorList = doctorRepositoryService.getAllDoctorsCloseBy(); 33 | return new DoctorListResponse(doctorList, ""); 34 | } 35 | 36 | public ResponseEntity createUser(User newUser) { 37 | return userRepositoryService.createUser(newUser); 38 | } 39 | 40 | public List getAllUser() { 41 | return userRepositoryService.getAll(); 42 | } 43 | 44 | @Override 45 | public ResponseEntity findEntityById(String id) { 46 | return userRepositoryService.getUserById(id); 47 | } 48 | 49 | public ResponseEntity patchEntityById(String id, UserPatchRequest changes) { 50 | return userRepositoryService.patchUser(id, changes); 51 | } 52 | 53 | @Override 54 | public ResponseEntity deleteEntity(String id) { 55 | return userRepositoryService.deleteUserById(id); 56 | } 57 | 58 | @Override 59 | public ResponseEntity restoreEntity(String id) { 60 | return userRepositoryService.restoreUserById(id); 61 | } 62 | 63 | @Override 64 | public ResponseEntity findEntityByPhone(String countryCode, String phoneNumber) { 65 | return userRepositoryService.findUserByPhone(countryCode, phoneNumber); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/resources/static/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #FFF; 3 | font-family: 'Ubuntu', sans-serif; 4 | } 5 | 6 | .main { 7 | background-color: #FFFFFF; 8 | width: 400px; 9 | height: 400px; 10 | margin: 7em auto; 11 | border-radius: 1.5em; 12 | box-shadow: 0px 11px 35px 2px rgba(0, 0, 0, 0.14); 13 | } 14 | 15 | .sign { 16 | padding-top: 40px; 17 | color: #8C55AA; 18 | font-family: 'Ubuntu', sans-serif; 19 | font-weight: bold; 20 | font-size: 23px; 21 | } 22 | 23 | .un { 24 | width: 76%; 25 | color: rgb(38, 50, 56); 26 | font-weight: 700; 27 | font-size: 14px; 28 | letter-spacing: 1px; 29 | background: rgba(136, 126, 126, 0.04); 30 | padding: 10px 20px; 31 | border: none; 32 | border-radius: 20px; 33 | outline: none; 34 | box-sizing: border-box; 35 | border: 2px solid rgba(0, 0, 0, 0.02); 36 | margin-bottom: 50px; 37 | margin-left: 46px; 38 | text-align: center; 39 | margin-bottom: 27px; 40 | font-family: 'Ubuntu', sans-serif; 41 | } 42 | 43 | form.form1 { 44 | padding-top: 40px; 45 | } 46 | 47 | .pass { 48 | width: 76%; 49 | color: rgb(38, 50, 56); 50 | font-weight: 700; 51 | font-size: 14px; 52 | letter-spacing: 1px; 53 | background: rgba(136, 126, 126, 0.04); 54 | padding: 10px 20px; 55 | border: none; 56 | border-radius: 20px; 57 | outline: none; 58 | box-sizing: border-box; 59 | border: 2px solid rgba(0, 0, 0, 0.02); 60 | margin-bottom: 50px; 61 | margin-left: 46px; 62 | text-align: center; 63 | margin-bottom: 27px; 64 | font-family: 'Ubuntu', sans-serif; 65 | } 66 | 67 | 68 | .un:focus, .pass:focus { 69 | border: 2px solid rgba(0, 0, 0, 0.18) !important; 70 | 71 | } 72 | 73 | .submit { 74 | cursor: pointer; 75 | border-radius: 5em; 76 | color: #ffff; 77 | background: linear-gradient(to right, #9C27B0, #E040FB); 78 | border: 0; 79 | padding-left: 40px; 80 | padding-right: 40px; 81 | padding-bottom: 10px; 82 | padding-top: 10px; 83 | font-family: 'Ubuntu', sans-serif; 84 | margin-left: 5%; 85 | font-size: 13px; 86 | box-shadow: 0 0 20px 1px rgba(0, 0, 0, 0.04); 87 | } 88 | 89 | .button { 90 | background-color: #4CAF50; /* Green */ 91 | border: none; 92 | color: white; 93 | padding: 15px 32px; 94 | text-align: center; 95 | text-decoration: none; 96 | display: inline-block; 97 | font-size: 16px; 98 | } 99 | 100 | .forgot { 101 | text-shadow: 0px 0px 3px rgba(117, 117, 117, 0.12); 102 | color: #E1BEE7; 103 | padding-top: 15px; 104 | } 105 | 106 | a { 107 | text-shadow: 0px 0px 3px rgba(117, 117, 117, 0.12); 108 | color: #E1BEE7; 109 | text-decoration: none 110 | } 111 | 112 | @media (max-width: 600px) { 113 | .main { 114 | border-radius: 0px; 115 | } 116 | } 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/services/ZoomMeetingService.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.services; 2 | 3 | import com.medizine.backend.dto.ZoomMeeting; 4 | import com.medizine.backend.exchanges.ZoomMeetingRequest; 5 | import com.medizine.backend.repositoryservices.DoctorRepositoryService; 6 | import com.medizine.backend.repositoryservices.MeetingRepositoryService; 7 | import lombok.extern.log4j.Log4j2; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.stereotype.Service; 11 | import org.thymeleaf.util.StringUtils; 12 | 13 | @Service 14 | @Log4j2 15 | public class ZoomMeetingService { 16 | 17 | @Autowired 18 | private MeetingRepositoryService meetingRepositoryService; 19 | 20 | @Autowired 21 | private DoctorRepositoryService doctorRepositoryService; 22 | 23 | 24 | public ResponseEntity getById(String id) { 25 | if (StringUtils.isEmpty(id)) { 26 | return ResponseEntity.badRequest().body("Not Processable"); 27 | } 28 | 29 | ZoomMeeting zoomMeeting = meetingRepositoryService.getById(id); 30 | 31 | if (zoomMeeting == null) { 32 | return ResponseEntity.notFound().build(); 33 | } else { 34 | return ResponseEntity.ok(zoomMeeting); 35 | } 36 | } 37 | 38 | public ResponseEntity getLiveMeetingByHostId(String hostId) { 39 | if (StringUtils.isEmpty(hostId)) { 40 | return ResponseEntity.badRequest().body("Not Processable"); 41 | } 42 | 43 | ZoomMeeting zoomMeeting = meetingRepositoryService.getByHostId(hostId); 44 | 45 | if (zoomMeeting == null) { 46 | return ResponseEntity.notFound().build(); 47 | } else { 48 | return ResponseEntity.ok(zoomMeeting); 49 | } 50 | } 51 | 52 | public ResponseEntity create(ZoomMeeting zoomMeeting) { 53 | 54 | ZoomMeeting savedMeeting = meetingRepositoryService.createMeeting(zoomMeeting); 55 | 56 | if (savedMeeting == null) { 57 | return ResponseEntity.unprocessableEntity().body("Not Processed"); 58 | } else { 59 | return ResponseEntity.ok(savedMeeting); 60 | } 61 | } 62 | 63 | public ResponseEntity patch(String id, ZoomMeetingRequest zoomMeetingRequest) { 64 | 65 | ZoomMeeting patchedMeeting = meetingRepositoryService.patchMeeting(zoomMeetingRequest, id); 66 | 67 | if (patchedMeeting == null) { 68 | return ResponseEntity.unprocessableEntity().build(); 69 | } else { 70 | return ResponseEntity.ok(patchedMeeting); 71 | } 72 | } 73 | 74 | public ResponseEntity getByAppointmentId(String appointmentId) { 75 | if (appointmentId.isEmpty()) { 76 | return ResponseEntity.badRequest().body("Appointment id is not valid"); 77 | } 78 | 79 | ZoomMeeting fetchedMeeting = meetingRepositoryService.getZoomMeetingByAppointmentId(appointmentId); 80 | 81 | if (fetchedMeeting != null) { 82 | return ResponseEntity.ok(fetchedMeeting); 83 | } else { 84 | return ResponseEntity.badRequest().body("Meeting not found"); 85 | } 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/controller/MediaController.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.controller; 2 | 3 | import com.medizine.backend.exchanges.UploadMediaResponse; 4 | import com.medizine.backend.services.MediaService; 5 | import lombok.extern.log4j.Log4j2; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.core.io.Resource; 8 | import org.springframework.http.HttpHeaders; 9 | import org.springframework.http.MediaType; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.stereotype.Controller; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.PostMapping; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RequestParam; 16 | import org.springframework.web.multipart.MultipartFile; 17 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; 18 | 19 | import javax.servlet.http.HttpServletRequest; 20 | import java.io.IOException; 21 | 22 | @Log4j2 23 | @Controller 24 | @RequestMapping(UserController.BASE_API_ENDPOINT + "/media") 25 | public class MediaController { 26 | 27 | @Autowired 28 | private MediaService mediaService; 29 | 30 | @PostMapping("/uploadFile") 31 | public ResponseEntity uploadFile(@RequestParam("file") MultipartFile file, 32 | @RequestParam("userId") String UserId, 33 | @RequestParam("docType") String docType) { 34 | 35 | String fileName = mediaService.storeFile(file, UserId, docType); 36 | 37 | String fileDownloadUri = ServletUriComponentsBuilder.fromCurrentContextPath() 38 | .path("/downloadFile/").path(fileName) 39 | .toUriString(); 40 | 41 | UploadMediaResponse response = new UploadMediaResponse(fileName, fileDownloadUri, file.getContentType()); 42 | return ResponseEntity.ok(response); 43 | } 44 | 45 | @GetMapping("/downloadFile") 46 | public ResponseEntity downloadFile(@RequestParam("userId") String userId, 47 | @RequestParam("docType") String docType, 48 | HttpServletRequest request) { 49 | 50 | String fileName = mediaService.getDocumentName(userId, docType); 51 | 52 | Resource resource = null; 53 | 54 | if (fileName != null && !fileName.isEmpty()) { 55 | 56 | try { 57 | resource = mediaService.loadFileAsResource(fileName); 58 | } catch (Exception e) { 59 | e.printStackTrace(); 60 | } 61 | 62 | // Try to determine file's content type 63 | String contentType = null; 64 | try { 65 | assert resource != null; 66 | contentType = request.getServletContext().getMimeType(resource.getFile().getAbsolutePath()); 67 | 68 | } catch (IOException ex) { 69 | //logger.info("Could not determine file type."); 70 | } 71 | 72 | // Fallback to the default content type if type could not be determined 73 | 74 | if (contentType == null) { 75 | 76 | contentType = "application/octet-stream"; 77 | } 78 | return ResponseEntity.ok() 79 | .contentType(MediaType.parseMediaType(contentType)) 80 | .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"") 81 | .body(resource); 82 | } else { 83 | return ResponseEntity.notFound().build(); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/services/MediaStorageServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.services; 2 | 3 | import com.medizine.backend.config.StorageProperties; 4 | import com.medizine.backend.exceptions.StorageException; 5 | import com.medizine.backend.exceptions.StorageFileNotFoundException; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.core.io.Resource; 8 | import org.springframework.core.io.UrlResource; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.util.FileSystemUtils; 11 | import org.springframework.util.StringUtils; 12 | import org.springframework.web.multipart.MultipartFile; 13 | 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import java.net.MalformedURLException; 17 | import java.nio.file.Files; 18 | import java.nio.file.Path; 19 | import java.nio.file.Paths; 20 | import java.nio.file.StandardCopyOption; 21 | import java.util.Objects; 22 | import java.util.stream.Stream; 23 | 24 | @Service 25 | public class MediaStorageServiceImpl implements MediaStorageService { 26 | 27 | private final Path rootLocation; 28 | 29 | @Autowired 30 | public MediaStorageServiceImpl(StorageProperties properties) { 31 | this.rootLocation = Paths.get(properties.getLocation()); 32 | } 33 | 34 | @Override 35 | public void store(MultipartFile file) { 36 | String filename = StringUtils.cleanPath(Objects.requireNonNull(file.getOriginalFilename())); 37 | try { 38 | if (file.isEmpty()) { 39 | throw new StorageException("Failed to store empty file " + filename); 40 | } 41 | if (filename.contains("..")) { 42 | // This is a security check 43 | throw new StorageException( 44 | "Cannot store file with relative path outside current directory " 45 | + filename); 46 | } 47 | try (InputStream inputStream = file.getInputStream()) { 48 | Files.copy(inputStream, this.rootLocation.resolve(filename), 49 | StandardCopyOption.REPLACE_EXISTING); 50 | } 51 | } catch (IOException e) { 52 | throw new StorageException("Failed to store file " + filename, e); 53 | } 54 | } 55 | 56 | @Override 57 | public Stream loadAll() { 58 | try { 59 | return Files.walk(this.rootLocation, 1) 60 | .filter(path -> !path.equals(this.rootLocation)) 61 | .map(this.rootLocation::relativize); 62 | } catch (IOException e) { 63 | throw new StorageException("Failed to read stored files", e); 64 | } 65 | 66 | } 67 | 68 | @Override 69 | public Path load(String filename) { 70 | return rootLocation.resolve(filename); 71 | } 72 | 73 | @Override 74 | public Resource loadAsResource(String filename) { 75 | try { 76 | Path file = load(filename); 77 | Resource resource = new UrlResource(file.toUri()); 78 | if (resource.exists() || resource.isReadable()) { 79 | return resource; 80 | } else { 81 | throw new StorageFileNotFoundException( 82 | "Could not read file: " + filename); 83 | 84 | } 85 | } catch (MalformedURLException e) { 86 | throw new StorageFileNotFoundException("Could not read file: " + filename, e); 87 | } 88 | } 89 | 90 | @Override 91 | public void deleteAll() { 92 | FileSystemUtils.deleteRecursively(rootLocation.toFile()); 93 | } 94 | 95 | @Override 96 | public void init() { 97 | try { 98 | Files.createDirectories(rootLocation); 99 | } catch (IOException e) { 100 | throw new StorageException("Could not initialize storage", e); 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Medizine - aims to connect users to healthcare services 2 | 3 | **Tech Stack** 4 | 5 | JAVA, Spring Boot, Gradle, Swagger Documentation, MongoDB, AWS Elastic Beanstalk 6 | 7 | ## Local installation 8 | - Clone the repo. 9 | - Change the directory 10 | - Update the file `src/main/resources/application.properties`. 11 | - There you need to declare your database configurations and since the backend is using MongoDB as its database. 12 | - Try to use mongo's configuration (either local or MongoDB Atlas). 13 | - Also update property `file.upload-dir` in the same file pointing to some local directory, **it should not be null**. 14 | 15 | - Run the command `gralde bootrun` 16 | - Server would be up at http://localhost:8081/ 17 | - API documentation can be viewed at http://localhost:8081/swagger-ui/index.html 18 | 19 | ## **Features** 20 | 21 | **Types of User:** 22 | 23 | * Patients - Patients are users with necessary permissions who can request online consultation with a doctor 24 | * Doctors - Users who provide online consultation to patients, view patients’ profiles, lab reports, and schedule appointments 25 | 26 | 27 | **Patient’s Dashboard:** 28 | 29 | If you log in as a patient (normal user), you can find the following components in your app: 30 | 31 | ### Profile 32 | 33 | Patients can create profiles by entering their essential information: 34 | 35 | Name 36 | Email address 37 | Phone number 38 | Age 39 | Gender 40 | Medical history 41 | Problems they are suffering from 42 | 43 | They can update their profile information anytime 44 | 45 | ### Find a Doctor 46 | 47 | Find doctors using filters such as: 48 | Specialty 49 | Language 50 | 51 | It would help patients to find a physician that meets their situation and needs 52 | 53 | ### Appointment Scheduling 54 | 55 | Patients can browse doctors’ profiles on the app and 56 | book an appointment with a doctor by looking at their availability via the calendar 57 | 58 | ### Real-time Visits 59 | 60 | Patients can interact with doctors via video and audio calling 61 | Video conferencing should be smooth and high-quality 62 | 63 | ### Payments and billing (expected in future) 64 | 65 | Patients can pay online for their visits 66 | The app should be able to provide multiple payment options so that users can choose the convenient method 67 | 68 | ### Messages/Instant Chat (expected in future) 69 | 70 | Patients can also send messages to the doctors related to their problems or chat with them instantly 71 | 72 | ### Previous Medical Records (expected in future) 73 | 74 | Patients and doctors can access their past medical records from the application 75 | 76 | 77 | ### Notifications (expected in future) 78 | Remind patients about upcoming visits a few minutes before the scheduled time 79 | 80 | 81 | **Doctor’s Dashboard:** 82 | 83 | ### Doctor Profile 84 | 85 | Doctors should be able to create profiles so patients can check their backgrounds, certifications and hospital affiliation 86 | 87 | ### Appointment Schedule Management 88 | 89 | Doctors should be able to make changes to their schedules and manage their day-to-day availability 90 | They should be able to accept and reject appointments 91 | Provide Digital Prescriptions 92 | 93 | ### Messages (expected in future) 94 | 95 | Doctors can chat with patients in real-time using instant messaging 96 | Doctors can respond to the patients’ queries and prescribe them medicines and treatment through messages 97 | 98 | ### Calls 99 | 100 | Face-to-face video consultations 101 | 102 | ### Visit Patients’ Medical History (expected in future) 103 | 104 | The option of viewing the patients’ medical history 105 | 106 | ### Notifications (expected in future) 107 | 108 | Alert doctors about their appointment a few minutes before it gets started 109 | Also, notify doctors when a patient requests for an appointment 110 | 111 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/services/MediaService.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.services; 2 | 3 | import com.medizine.backend.exceptions.DocumentStorageException; 4 | import com.medizine.backend.models.Media; 5 | import com.medizine.backend.repositoryservices.MediaRepositoryService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.core.io.Resource; 8 | import org.springframework.core.io.UrlResource; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.util.StringUtils; 11 | import org.springframework.web.multipart.MultipartFile; 12 | 13 | import java.io.FileNotFoundException; 14 | import java.io.IOException; 15 | import java.net.MalformedURLException; 16 | import java.nio.file.Files; 17 | import java.nio.file.Path; 18 | import java.nio.file.Paths; 19 | import java.nio.file.StandardCopyOption; 20 | import java.util.Objects; 21 | 22 | @Service 23 | public class MediaService { 24 | 25 | private final Path fileStorageLocation; 26 | 27 | @Autowired 28 | MediaRepositoryService mediaRepositoryService; 29 | 30 | @Autowired 31 | public MediaService(Media media) { 32 | this.fileStorageLocation = Paths.get(media.getUploadDir()) 33 | .toAbsolutePath().normalize(); 34 | 35 | try { 36 | Files.createDirectories(this.fileStorageLocation); 37 | } catch (Exception ex) { 38 | throw new DocumentStorageException("Could not create directory to upload media!!"); 39 | } 40 | } 41 | 42 | public String storeFile(MultipartFile file, String userId, String docType) { 43 | // Clear out the file name 44 | String originalFileName = StringUtils.cleanPath(Objects.requireNonNull(file.getOriginalFilename())); 45 | String fileName = ""; 46 | 47 | try { 48 | // Check if the file's name contains invalid characters 49 | if (originalFileName.contains("..")) { 50 | throw new DocumentStorageException("Sorry! Filename contains invalid path sequence " 51 | + originalFileName); 52 | } 53 | 54 | String fileExtension = ""; 55 | try { 56 | fileExtension = originalFileName.substring(originalFileName.lastIndexOf(".")); 57 | } catch (Exception e) { 58 | fileExtension = ""; 59 | } 60 | fileName = userId + "_" + docType + fileExtension; 61 | // Copy file to the target location (Replacing existing file with the same name) 62 | Path targetLocation = this.fileStorageLocation.resolve(fileName); 63 | Files.copy(file.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING); 64 | 65 | Media doc = mediaRepositoryService.findMediaStorageByUserId(userId); 66 | if (doc != null) { 67 | doc.setFileFormat(file.getContentType()); 68 | doc.setFileName(fileName); 69 | mediaRepositoryService.save(doc); 70 | 71 | } else { 72 | Media newDoc = new Media(); 73 | newDoc.setUserId(userId); 74 | newDoc.setFileFormat(file.getContentType()); 75 | newDoc.setFileName(fileName); 76 | mediaRepositoryService.save(newDoc); 77 | } 78 | return fileName; 79 | 80 | } catch (IOException ex) { 81 | throw new DocumentStorageException("Could not store file " + fileName + " Please try again!", ex); 82 | } 83 | } 84 | 85 | public Resource loadFileAsResource(String fileName) throws Exception { 86 | try { 87 | Path filePath = this.fileStorageLocation.resolve(fileName).normalize(); 88 | Resource resource = new UrlResource(filePath.toUri()); 89 | if (resource.exists()) { 90 | return resource; 91 | } else { 92 | throw new FileNotFoundException("File not found " + fileName); 93 | } 94 | } catch (MalformedURLException ex) { 95 | throw new FileNotFoundException("File not found " + fileName); 96 | } 97 | } 98 | 99 | public String getDocumentName(String userId, String docType) { 100 | return mediaRepositoryService.getUploadMediaPath(userId, docType); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/resources/templates/ApiHome.html: -------------------------------------------------------------------------------- 1 | 2 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | Medizine API Server 127 | 128 | 129 | 130 |
131 |

Medizine API Server

132 |

API Server for Medizine App

133 |
134 |
API Documentation
135 | Swagger UI 136 |
137 |
138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositoryservices/MeetingRepositoryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositoryservices; 2 | 3 | import com.medizine.backend.dto.ZoomMeeting; 4 | import com.medizine.backend.exchanges.ZoomMeetingRequest; 5 | import com.medizine.backend.repositories.ZoomRepository; 6 | import lombok.extern.log4j.Log4j2; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | 12 | @Service 13 | @Log4j2 14 | public class MeetingRepositoryServiceImpl implements MeetingRepositoryService { 15 | 16 | @Autowired 17 | private ZoomRepository zoomRepository; 18 | 19 | @Override 20 | public ZoomMeeting getById(String id) { 21 | ZoomMeeting zoomMeeting = null; 22 | 23 | if (zoomRepository.findById(id).isPresent()) { 24 | zoomMeeting = zoomRepository.findById(id).get(); 25 | } 26 | 27 | return zoomMeeting; 28 | } 29 | 30 | @Override 31 | public ZoomMeeting getByHostId(String hostId) { 32 | 33 | ZoomMeeting zoomMeeting; 34 | 35 | zoomMeeting = zoomRepository.findByHostId(hostId); 36 | 37 | return zoomMeeting; 38 | } 39 | 40 | @Override 41 | public ZoomMeeting createMeeting(ZoomMeeting zoomMeeting) { 42 | 43 | if (zoomMeeting == null) { 44 | return null; 45 | } 46 | 47 | // If meeting exist for a particular appointment id 48 | // then delete them. 49 | List meetingList = zoomRepository.findAllByAppointmentId(zoomMeeting.getAppointmentId()); 50 | 51 | log.info("Zoom Meeting Creation in Progress!!"); 52 | for (ZoomMeeting meeting : meetingList) { 53 | log.info("Deleting the previous meeting history {}", meeting); 54 | zoomRepository.deleteById(meeting.id); 55 | } 56 | 57 | ZoomMeeting savedMeeting; 58 | 59 | savedMeeting = zoomRepository.save(zoomMeeting); 60 | 61 | return savedMeeting; 62 | } 63 | 64 | @Override 65 | public ZoomMeeting patchMeeting(ZoomMeetingRequest meetingRequest, String id) { 66 | 67 | ZoomMeeting existingMeeting = getById(id); 68 | 69 | if (existingMeeting != null) { 70 | if (meetingRequest.getMeetingTitle() != null) { 71 | existingMeeting.setMeetingTitle(meetingRequest.getMeetingTitle()); 72 | } 73 | 74 | if (meetingRequest.getHostId() != null) { 75 | existingMeeting.setHostId(meetingRequest.getHostId()); 76 | } 77 | 78 | if (meetingRequest.getMeetingNumber() != null) { 79 | existingMeeting.setMeetingNumber(meetingRequest.getMeetingNumber()); 80 | } 81 | 82 | if (meetingRequest.getAppointmentId() != null && !meetingRequest.getAppointmentId().isEmpty()) { 83 | existingMeeting.setAppointmentId(meetingRequest.getAppointmentId()); 84 | } 85 | 86 | if (meetingRequest.getMeetingPassword() != null) { 87 | existingMeeting.setMeetingPassword(meetingRequest.getMeetingPassword()); 88 | } 89 | 90 | if (meetingRequest.getMeetingStartTime() != null) { 91 | existingMeeting.setMeetingStartTime(meetingRequest.getMeetingStartTime()); 92 | } 93 | 94 | if (meetingRequest.getMeetingDuration() != null) { 95 | existingMeeting.setMeetingDuration(meetingRequest.getMeetingDuration()); 96 | } 97 | 98 | if (meetingRequest.getMeetingStatus() != null) { 99 | existingMeeting.setMeetingStatus(meetingRequest.getMeetingStatus()); 100 | } 101 | 102 | zoomRepository.save(existingMeeting); 103 | return existingMeeting; 104 | 105 | } else { 106 | return null; 107 | } 108 | } 109 | 110 | @Override 111 | public ZoomMeeting getZoomMeetingByAppointmentId(String appointmentId) { 112 | return zoomRepository.findByAppointmentId(appointmentId); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositoryservices/AppointmentRepositoryService.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositoryservices; 2 | 3 | import com.medizine.backend.dto.Appointment; 4 | import com.medizine.backend.dto.Slot; 5 | import com.medizine.backend.dto.Status; 6 | import com.medizine.backend.exchanges.SlotBookingRequest; 7 | import com.medizine.backend.repositories.AppointmentRepository; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.List; 13 | 14 | @Service 15 | public class AppointmentRepositoryService { 16 | 17 | @Autowired 18 | private AppointmentRepository appointmentRepository; 19 | 20 | public Appointment createAppointment(SlotBookingRequest slotRequest) { 21 | Appointment appointment = Appointment.builder() 22 | .appointmentDate(slotRequest.getBookingDate()) 23 | .doctorId(slotRequest.getDoctorId()) 24 | .userId(slotRequest.getUserId()) 25 | .slotId(slotRequest.getSlotId()) 26 | .STATUS(Status.ACTIVE).build(); 27 | 28 | appointmentRepository.save(appointment); 29 | 30 | return null; 31 | } 32 | 33 | public List findAppointmentBySlot(Slot currentSlot, String userId) { 34 | return appointmentRepository.findAllBySlotIdAndDoctorIdAndUserIdAndSTATUS( 35 | currentSlot.id, 36 | currentSlot.getDoctorId(), userId, 37 | Status.ACTIVE); 38 | } 39 | 40 | public List findBookedAppointment(Slot currentSlot) { 41 | return appointmentRepository.findAllBySlotIdAndDoctorIdAndSTATUS( 42 | currentSlot.id, 43 | currentSlot.getDoctorId(), 44 | Status.ACTIVE); 45 | } 46 | 47 | public boolean alreadyExist(SlotBookingRequest slotRequest, Long epochRequestedDate) { 48 | 49 | List appointmentList = appointmentRepository 50 | .findAllBySlotIdAndDoctorIdAndUserIdAndSTATUS(slotRequest.getSlotId(), 51 | slotRequest.getDoctorId(), slotRequest.getUserId(), Status.ACTIVE); 52 | 53 | for (Appointment appointment : appointmentList) { 54 | Long epochBookedDate = SlotRepositoryService.getLocalDate(appointment.getAppointmentDate()) 55 | .toEpochDay(); 56 | 57 | if (epochBookedDate.equals(epochRequestedDate)) { 58 | return true; 59 | } 60 | } 61 | 62 | return false; 63 | } 64 | 65 | public Appointment findById(String id) { 66 | if (appointmentRepository.findById(id).isPresent()) { 67 | Appointment appointment = appointmentRepository.findById(id).get(); 68 | if (appointment.getSTATUS().equals(Status.ACTIVE)) { 69 | return appointment; 70 | } 71 | } 72 | return null; 73 | } 74 | 75 | public Appointment deleteById(String id) { 76 | Appointment fetchedAppointment = findById(id); 77 | if (fetchedAppointment != null) { 78 | fetchedAppointment.setSTATUS(Status.INACTIVE); 79 | 80 | appointmentRepository.save(fetchedAppointment); 81 | return fetchedAppointment; 82 | } 83 | return null; 84 | } 85 | 86 | public ResponseEntity restoreById(String id) { 87 | if (appointmentRepository.findById(id).isPresent()) { 88 | Appointment fetchedAppointment = appointmentRepository.findById(id).get(); 89 | if (fetchedAppointment.getSTATUS().equals(Status.ACTIVE)) { 90 | return ResponseEntity.badRequest().body("Already ACTIVE"); 91 | } else { 92 | fetchedAppointment.setSTATUS(Status.ACTIVE); 93 | appointmentRepository.save(fetchedAppointment); 94 | return ResponseEntity.ok(fetchedAppointment); 95 | } 96 | } 97 | return null; 98 | } 99 | 100 | public List findAllByUserId(String userId) { 101 | return appointmentRepository.findAllByUserIdAndSTATUS(userId, Status.ACTIVE); 102 | } 103 | 104 | public List findAllByDoctorId(String doctorId) { 105 | return appointmentRepository.findAllByDoctorIdAndSTATUS(doctorId, Status.ACTIVE); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/controller/ZoomController.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.controller; 2 | 3 | import com.medizine.backend.dto.ZoomMeeting; 4 | import com.medizine.backend.exchanges.BaseResponse; 5 | import com.medizine.backend.exchanges.ZoomMeetingRequest; 6 | import com.medizine.backend.services.ZoomMeetingService; 7 | import io.swagger.annotations.ApiOperation; 8 | import io.swagger.annotations.ApiResponse; 9 | import io.swagger.annotations.ApiResponses; 10 | import lombok.extern.log4j.Log4j2; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.validation.annotation.Validated; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | @RestController 17 | @Validated 18 | @RequestMapping(UserController.BASE_API_ENDPOINT + "/meet") 19 | @Log4j2 20 | public class ZoomController { 21 | 22 | @Autowired 23 | private ZoomMeetingService zoomMeetingService; 24 | 25 | 26 | @ApiOperation(value = "get by id", response = ZoomMeeting.class) 27 | @ApiResponses({ 28 | @ApiResponse(code = 200, message = "OK"), 29 | @ApiResponse(code = 400, message = "VALIDATION_ERROR"), 30 | @ApiResponse(code = 500, message = "SERVER_ERROR") 31 | }) 32 | @GetMapping("/getById") 33 | public ZoomMeeting getById(String id) { 34 | ResponseEntity responseEntity = zoomMeetingService.getById(id); 35 | 36 | if (responseEntity.getStatusCode().is2xxSuccessful()) { 37 | return (ZoomMeeting) responseEntity.getBody(); 38 | } else { 39 | return null; 40 | } 41 | } 42 | 43 | @ApiOperation(value = "get meeting by Host id", response = ZoomMeeting.class) 44 | @ApiResponses({ 45 | @ApiResponse(code = 200, message = "OK"), 46 | @ApiResponse(code = 400, message = "VALIDATION_ERROR"), 47 | @ApiResponse(code = 500, message = "SERVER_ERROR") 48 | }) 49 | @GetMapping("/getByHostId") 50 | public BaseResponse getLiveMeetingByHostId(String hostId) { 51 | ResponseEntity response = zoomMeetingService.getLiveMeetingByHostId(hostId); 52 | 53 | if (response.getStatusCode().is2xxSuccessful()) { 54 | return new BaseResponse<>((ZoomMeeting) response.getBody(), response.getStatusCode().toString()); 55 | } else { 56 | return new BaseResponse<>(null, response.getStatusCode().toString()); 57 | } 58 | } 59 | 60 | @ApiOperation(value = "create a zoom meeting", response = ZoomMeeting.class) 61 | @ApiResponses({ 62 | @ApiResponse(code = 200, message = "OK"), 63 | @ApiResponse(code = 400, message = "VALIDATION_ERROR"), 64 | @ApiResponse(code = 500, message = "SERVER_ERROR") 65 | }) 66 | @PostMapping("/create") 67 | public ZoomMeeting create(@RequestBody ZoomMeeting zoomMeeting) { 68 | ResponseEntity response = zoomMeetingService.create(zoomMeeting); 69 | if (response.getStatusCode().is2xxSuccessful()) { 70 | return (ZoomMeeting) response.getBody(); 71 | } else { 72 | return null; 73 | } 74 | } 75 | 76 | @ApiOperation(value = "patch meeting by id", response = ZoomMeeting.class) 77 | @ApiResponses({ 78 | @ApiResponse(code = 200, message = "OK"), 79 | @ApiResponse(code = 400, message = "VALIDATION_ERROR"), 80 | @ApiResponse(code = 500, message = "SERVER_ERROR") 81 | }) 82 | @PatchMapping("/patchById") 83 | public BaseResponse patchById(String id, @RequestBody ZoomMeetingRequest zoomMeetingRequest) { 84 | 85 | ResponseEntity response = zoomMeetingService.patch(id, zoomMeetingRequest); 86 | if (response.getStatusCode().is2xxSuccessful()) { 87 | return new BaseResponse<>((ZoomMeeting) response.getBody(), response.getStatusCode().toString()); 88 | } else { 89 | return new BaseResponse<>(null, response.getStatusCode().toString()); 90 | } 91 | } 92 | 93 | @ApiOperation(value = "Get meeting by appointment id", response = ZoomMeeting.class) 94 | @ApiResponses({ 95 | @ApiResponse(code = 200, message = "OK"), 96 | @ApiResponse(code = 400, message = "BAD REQUEST"), 97 | @ApiResponse(code = 500, message = "SERVER_ERROR") 98 | }) 99 | @GetMapping("/getByAppointmentId") 100 | public BaseResponse patchById(@RequestParam String appointmentId) { 101 | 102 | ResponseEntity response = zoomMeetingService.getByAppointmentId(appointmentId); 103 | if (response.getStatusCode().is2xxSuccessful()) { 104 | return new BaseResponse<>((ZoomMeeting) response.getBody(), response.getStatusCode().toString()); 105 | } else { 106 | return new BaseResponse<>(null, response.getStatusCode().toString()); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/controller/AppointmentController.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.controller; 2 | 3 | import com.medizine.backend.dto.Appointment; 4 | import com.medizine.backend.exchanges.AppointmentResponse; 5 | import com.medizine.backend.exchanges.BaseResponse; 6 | import com.medizine.backend.repositoryservices.AppointmentRepositoryService; 7 | import io.swagger.annotations.ApiOperation; 8 | import io.swagger.annotations.ApiResponse; 9 | import io.swagger.annotations.ApiResponses; 10 | import lombok.extern.log4j.Log4j2; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RequestParam; 16 | import org.springframework.web.bind.annotation.RestController; 17 | 18 | import java.util.List; 19 | import java.util.Objects; 20 | 21 | @RestController 22 | @RequestMapping(UserController.BASE_API_ENDPOINT + "/appointment") 23 | @Log4j2 24 | public class AppointmentController extends ApiCrudController { 25 | 26 | @Autowired 27 | private AppointmentRepositoryService appointmentService; 28 | 29 | 30 | @ApiOperation(value = "Get appointment by id", response = Appointment.class) 31 | @ApiResponses({ 32 | @ApiResponse(code = 200, message = "OK"), 33 | @ApiResponse(code = 400, message = "Bad Request"), 34 | @ApiResponse(code = 500, message = "Server Error") 35 | }) 36 | @Override 37 | public BaseResponse getById(String id) { 38 | Appointment appointment = appointmentService.findById(id); 39 | if (appointment != null) { 40 | return new BaseResponse<>(appointment, "FETCHED"); 41 | } else { 42 | return new BaseResponse<>(null, "NOT FOUND"); 43 | } 44 | } 45 | 46 | @ApiOperation(value = "Delete appointment by id", response = Appointment.class) 47 | @ApiResponses({ 48 | @ApiResponse(code = 200, message = "OK"), 49 | @ApiResponse(code = 400, message = "Bad Request"), 50 | @ApiResponse(code = 500, message = "Server Error") 51 | }) 52 | @Override 53 | public BaseResponse deleteById(String id) { 54 | Appointment appointment = appointmentService.deleteById(id); 55 | if (appointment != null) { 56 | return new BaseResponse<>(appointment, "DELETED"); 57 | } else { 58 | return new BaseResponse<>(null, "NOT FOUND"); 59 | } 60 | } 61 | 62 | @ApiOperation(value = "Restore appointment by id", response = Appointment.class) 63 | @ApiResponses({ 64 | @ApiResponse(code = 200, message = "OK"), 65 | @ApiResponse(code = 400, message = "Bad Request"), 66 | @ApiResponse(code = 500, message = "Server Error") 67 | }) 68 | @Override 69 | public BaseResponse restoreById(String id) { 70 | ResponseEntity responseEntity = appointmentService.restoreById(id); 71 | if (responseEntity != null) { 72 | if (responseEntity.getStatusCode().is2xxSuccessful()) { 73 | return new BaseResponse<>((Appointment) responseEntity.getBody(), "RESTORED"); 74 | } else if (responseEntity.getStatusCode().is4xxClientError()) { 75 | return new BaseResponse<>(null, Objects.requireNonNull(responseEntity.getBody()).toString()); 76 | } 77 | } 78 | return new BaseResponse<>(null, "NOT FOUND"); 79 | } 80 | 81 | 82 | @ApiOperation(value = "Get all appointment by user id", response = AppointmentResponse.class) 83 | @ApiResponses({ 84 | @ApiResponse(code = 200, message = "OK"), 85 | @ApiResponse(code = 400, message = "Bad Request"), 86 | @ApiResponse(code = 500, message = "Server Error") 87 | }) 88 | @GetMapping("/getAllByUserId") 89 | public AppointmentResponse getAllAppointmentByUserId(@RequestParam String userId) { 90 | List appointmentList = appointmentService.findAllByUserId(userId); 91 | 92 | if (appointmentList == null || appointmentList.size() == 0) { 93 | return new AppointmentResponse(null, "NOT AVAILABLE"); 94 | } else { 95 | return new AppointmentResponse(appointmentList, "FETCHED"); 96 | } 97 | } 98 | 99 | @ApiOperation(value = "Get all appointment by doctor id", response = AppointmentResponse.class) 100 | @ApiResponses({ 101 | @ApiResponse(code = 200, message = "OK"), 102 | @ApiResponse(code = 400, message = "Bad Request"), 103 | @ApiResponse(code = 500, message = "Server Error") 104 | }) 105 | @GetMapping("/getAllByDoctorId") 106 | public AppointmentResponse getAllAppointmentByDoctorId(@RequestParam String doctorId) { 107 | List appointmentList = appointmentService.findAllByDoctorId(doctorId); 108 | if (appointmentList == null || appointmentList.size() == 0) { 109 | return new AppointmentResponse(null, "NOT AVAILABLE"); 110 | } else { 111 | return new AppointmentResponse(appointmentList, "FETCHED"); 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/controller/SlotController.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.controller; 2 | 3 | import com.medizine.backend.dto.Appointment; 4 | import com.medizine.backend.dto.Slot; 5 | import com.medizine.backend.exchanges.BaseResponse; 6 | import com.medizine.backend.exchanges.SlotBookingRequest; 7 | import com.medizine.backend.exchanges.SlotResponse; 8 | import com.medizine.backend.exchanges.SlotStatusRequest; 9 | import com.medizine.backend.repositoryservices.SlotRepositoryService; 10 | import io.swagger.annotations.ApiOperation; 11 | import io.swagger.annotations.ApiResponse; 12 | import io.swagger.annotations.ApiResponses; 13 | import lombok.extern.log4j.Log4j2; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.format.annotation.DateTimeFormat; 16 | import org.springframework.http.ResponseEntity; 17 | import org.springframework.validation.annotation.Validated; 18 | import org.springframework.web.bind.annotation.*; 19 | 20 | import javax.validation.Valid; 21 | import java.util.Date; 22 | import java.util.List; 23 | 24 | @RestController 25 | @RequestMapping(UserController.BASE_API_ENDPOINT + "/slot") 26 | @Log4j2 27 | @Validated 28 | public class SlotController { 29 | 30 | @Autowired 31 | private SlotRepositoryService slotService; 32 | 33 | @ApiOperation(value = "Create new slot", response = Slot.class) 34 | @ApiResponses({ 35 | @ApiResponse(code = 200, message = "OK"), 36 | @ApiResponse(code = 400, message = "Bad Request"), 37 | @ApiResponse(code = 500, message = "Server Error") 38 | }) 39 | @PutMapping("/create") 40 | public BaseResponse createNewSlot(@Valid @RequestBody Slot slot) { 41 | ResponseEntity response = slotService.createSlot(slot); 42 | if (response.getStatusCode().is2xxSuccessful()) { 43 | return new BaseResponse<>((Slot) response.getBody(), 44 | response.getStatusCode().toString()); 45 | } else if (response.getStatusCode().is4xxClientError() && response.getBody() != null) { 46 | return new BaseResponse<>(null, response.getBody().toString()); 47 | } else { 48 | return new BaseResponse<>(null, response.getStatusCode().toString()); 49 | } 50 | } 51 | 52 | @ApiOperation(value = "Get all slots by doctor Id", response = SlotResponse.class) 53 | @ApiResponses({ 54 | @ApiResponse(code = 200, message = "OK"), 55 | @ApiResponse(code = 400, message = "Bad Request"), 56 | @ApiResponse(code = 500, message = "Server Error") 57 | }) 58 | @GetMapping("/getAllByDocId") 59 | public SlotResponse getAllSlotByDoctorId(@Valid @RequestParam String doctorId) { 60 | List slots = slotService.getAllByDoctorId(doctorId); 61 | if (slots == null || slots.size() == 0) { 62 | return new SlotResponse(null, "NOT FOUND"); 63 | } else { 64 | return new SlotResponse(slots, "FOUND"); 65 | } 66 | } 67 | 68 | @ApiOperation(value = "Get Slot Live Status", response = SlotResponse.class) 69 | @ApiResponses({ 70 | @ApiResponse(code = 200, message = "OK"), 71 | @ApiResponse(code = 400, message = "Bad Request"), 72 | @ApiResponse(code = 500, message = "Server Error") 73 | }) 74 | @GetMapping("/liveSlotStatus") 75 | public SlotResponse getSlotLiveStatus(@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date date, 76 | @RequestParam String doctorId, 77 | @RequestParam String userId) { 78 | 79 | SlotStatusRequest slotStatusRequest = new SlotStatusRequest(doctorId, userId, date); 80 | return slotService.getLiveSlotStatus(slotStatusRequest); 81 | } 82 | 83 | @ApiOperation(value = "Get all the slots", response = SlotResponse.class) 84 | @ApiResponses({ 85 | @ApiResponse(code = 200, message = "OK"), 86 | @ApiResponse(code = 400, message = "Bad Request"), 87 | @ApiResponse(code = 500, message = "Server Error") 88 | }) 89 | @GetMapping("/getAll") 90 | public SlotResponse getAllSlot() { 91 | List slotList = slotService.getAll(); 92 | return new SlotResponse(slotList, "DONE"); 93 | } 94 | 95 | @ApiOperation(value = "Book slot for a given date", response = Appointment.class) 96 | @ApiResponses({ 97 | @ApiResponse(code = 200, message = "OK"), 98 | @ApiResponse(code = 400, message = "Bad Request"), 99 | @ApiResponse(code = 500, message = "Server Error") 100 | }) 101 | @PatchMapping("/book") 102 | public BaseResponse bookSlotByPatientId(@Valid @RequestBody SlotBookingRequest slotRequest) { 103 | 104 | ResponseEntity response = slotService.bookSlot(slotRequest); 105 | if (response.getStatusCode().is2xxSuccessful()) { 106 | return new BaseResponse<>((Appointment) response.getBody(), 107 | response.getStatusCode().toString()); 108 | } else { 109 | return new BaseResponse<>(null, response.getStatusCode().toString()); 110 | } 111 | } 112 | 113 | @ApiOperation(value = "Delete Slot by id", response = SlotResponse.class) 114 | @ApiResponses({ 115 | @ApiResponse(code = 200, message = "OK"), 116 | @ApiResponse(code = 400, message = "Bad Request"), 117 | @ApiResponse(code = 500, message = "Server Error") 118 | }) 119 | @DeleteMapping("/deleteById") 120 | public BaseResponse deleteSlotById(@RequestParam String slotId) { 121 | 122 | Slot deletedSlot = slotService.deleteSlotById(slotId); 123 | if (deletedSlot == null) { 124 | return new BaseResponse<>(null, "Bad Request"); 125 | } else { 126 | return new BaseResponse<>(deletedSlot, "OK"); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/controller/DoctorController.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.controller; 2 | 3 | import com.medizine.backend.dto.Doctor; 4 | import com.medizine.backend.exchanges.BaseResponse; 5 | import com.medizine.backend.exchanges.DoctorListResponse; 6 | import com.medizine.backend.exchanges.DoctorPatchRequest; 7 | import com.medizine.backend.services.DoctorService; 8 | import io.swagger.annotations.ApiOperation; 9 | import io.swagger.annotations.ApiResponse; 10 | import io.swagger.annotations.ApiResponses; 11 | import lombok.extern.log4j.Log4j2; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.http.ResponseEntity; 14 | import org.springframework.validation.annotation.Validated; 15 | import org.springframework.web.bind.annotation.*; 16 | 17 | import javax.validation.Valid; 18 | 19 | @RestController 20 | @Log4j2 21 | @Validated 22 | @RequestMapping(UserController.BASE_API_ENDPOINT + "/doctor") 23 | public class DoctorController extends ApiCrudController { 24 | 25 | @Autowired 26 | private DoctorService doctorService; 27 | 28 | @ApiResponses({ 29 | @ApiResponse(code = 200, message = "OK", response = Doctor.class), 30 | @ApiResponse(code = 400, message = "Validation Error"), 31 | @ApiResponse(code = 500, message = "Server Error") 32 | }) 33 | @PostMapping("/create") 34 | public BaseResponse create(@Valid @RequestBody Doctor newDoctor) { 35 | log.info("doctor create method called {}", newDoctor); 36 | ResponseEntity responseEntity = doctorService.createDoctor(newDoctor); 37 | if (responseEntity.getStatusCode().is2xxSuccessful()) { 38 | return new BaseResponse<>((Doctor) responseEntity.getBody(), responseEntity.getStatusCode().toString()); 39 | } else { 40 | return new BaseResponse<>(null, responseEntity.getStatusCode().toString()); 41 | } 42 | } 43 | 44 | @ApiResponses({ 45 | @ApiResponse(code = 200, message = "OK", response = Doctor.class), 46 | @ApiResponse(code = 400, message = "Validation Error"), 47 | @ApiResponse(code = 500, message = "Server Error") 48 | }) 49 | @PatchMapping("/patchById") 50 | public BaseResponse patchById(String id, @Valid @RequestBody DoctorPatchRequest patchRequest) { 51 | ResponseEntity responseEntity = doctorService.patchDoctor(id, patchRequest); 52 | if (responseEntity.getStatusCode().is2xxSuccessful()) { 53 | return new BaseResponse<>((Doctor) responseEntity.getBody(), responseEntity.getStatusCode().toString()); 54 | } else { 55 | return new BaseResponse<>(null, responseEntity.getStatusCode().toString()); 56 | } 57 | } 58 | 59 | 60 | @ApiResponses({ 61 | @ApiResponse(code = 200, message = "OK", response = Doctor.class), 62 | @ApiResponse(code = 400, message = "Validation Error"), 63 | @ApiResponse(code = 500, message = "Server Error") 64 | }) 65 | @PutMapping("/updateById") 66 | public BaseResponse updateById(String id, @Valid @RequestBody Doctor doctorToUpdate) { 67 | ResponseEntity responseEntity = doctorService.updateDoctorById(id, doctorToUpdate); 68 | if (responseEntity.getStatusCode().is2xxSuccessful()) { 69 | return new BaseResponse<>((Doctor) responseEntity.getBody(), responseEntity.getStatusCode().toString()); 70 | } else { 71 | return new BaseResponse<>(null, responseEntity.getStatusCode().toString()); 72 | } 73 | } 74 | 75 | @ApiOperation(value = "Get the list of all active doctor", response = DoctorListResponse.class) 76 | @ApiResponses({ 77 | @ApiResponse(code = 200, message = "OK"), 78 | @ApiResponse(code = 400, message = "Bad Request"), 79 | @ApiResponse(code = 500, message = "Server Error") 80 | }) 81 | @GetMapping("/getMany") 82 | public DoctorListResponse getMany() { 83 | return doctorService.getAvailableDoctors(); 84 | } 85 | 86 | 87 | @ApiResponses({ 88 | @ApiResponse(code = 200, message = "OK", response = Doctor.class), 89 | @ApiResponse(code = 400, message = "Validation Error"), 90 | @ApiResponse(code = 500, message = "Server Error") 91 | }) 92 | @Override 93 | public BaseResponse getById(String id) { 94 | ResponseEntity responseEntity = doctorService.findEntityById(id); 95 | if (responseEntity.getStatusCode().is2xxSuccessful()) { 96 | return new BaseResponse<>((Doctor) responseEntity.getBody(), responseEntity.getStatusCode().toString()); 97 | } else { 98 | return new BaseResponse<>(null, responseEntity.getStatusCode().toString()); 99 | } 100 | } 101 | 102 | @ApiResponses({ 103 | @ApiResponse(code = 200, message = "OK", response = Doctor.class), 104 | @ApiResponse(code = 400, message = "Bad Request"), 105 | @ApiResponse(code = 500, message = "Server Error") 106 | }) 107 | @GetMapping("/existByPhone") 108 | public BaseResponse findByPhoneNumber(String countryCode, String phoneNumber) { 109 | ResponseEntity responseEntity = doctorService.findEntityByPhone(countryCode, phoneNumber); 110 | if (responseEntity.getStatusCode().is2xxSuccessful()) { 111 | return new BaseResponse<>((Doctor) responseEntity.getBody(), responseEntity.getStatusCode().toString()); 112 | } else { 113 | return new BaseResponse<>(null, responseEntity.getStatusCode().toString()); 114 | } 115 | } 116 | 117 | @ApiResponses({ 118 | @ApiResponse(code = 200, message = "OK", response = Doctor.class), 119 | @ApiResponse(code = 400, message = "Bad Request"), 120 | @ApiResponse(code = 500, message = "Server Error") 121 | }) 122 | @Override 123 | public BaseResponse deleteById(String id) { 124 | ResponseEntity responseEntity = doctorService.deleteEntity(id); 125 | if (responseEntity.getStatusCode().is2xxSuccessful()) { 126 | return new BaseResponse<>((Doctor) responseEntity.getBody(), responseEntity.getStatusCode().toString()); 127 | } else { 128 | return new BaseResponse<>(null, responseEntity.getStatusCode().toString()); 129 | } 130 | } 131 | 132 | @ApiResponses({ 133 | @ApiResponse(code = 200, message = "OK", response = Doctor.class), 134 | @ApiResponse(code = 400, message = "Bad Request"), 135 | @ApiResponse(code = 500, message = "Server Error") 136 | }) 137 | @Override 138 | public BaseResponse restoreById(String id) { 139 | ResponseEntity responseEntity = doctorService.restoreEntity(id); 140 | if (responseEntity.getStatusCode().is2xxSuccessful()) { 141 | return new BaseResponse<>((Doctor) responseEntity.getBody(), responseEntity.getStatusCode().toString()); 142 | } else { 143 | return new BaseResponse<>(null, responseEntity.getStatusCode().toString()); 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositoryservices/UserRepositoryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositoryservices; 2 | 3 | import com.medizine.backend.dto.Status; 4 | import com.medizine.backend.dto.User; 5 | import com.medizine.backend.exchanges.UserPatchRequest; 6 | import com.medizine.backend.repositories.UserRepository; 7 | import lombok.extern.log4j.Log4j2; 8 | import org.modelmapper.ModelMapper; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.data.mongodb.core.MongoTemplate; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.stereotype.Service; 13 | 14 | import javax.inject.Provider; 15 | import java.util.List; 16 | import java.util.NoSuchElementException; 17 | import java.util.stream.Collectors; 18 | 19 | @Service 20 | @Log4j2 21 | public class UserRepositoryServiceImpl implements UserRepositoryService { 22 | 23 | @Autowired 24 | private UserRepository userRepository; 25 | 26 | @Autowired 27 | private Provider modelMapperProvider; 28 | 29 | @Autowired 30 | private MongoTemplate mongoTemplate; 31 | 32 | @Override 33 | public ResponseEntity createUser(User userToBeSaved) { 34 | 35 | if (isUserAlreadyExist(userToBeSaved)) { 36 | return ResponseEntity.badRequest().body("User with same detail already exist"); 37 | } else { 38 | userToBeSaved.setStatus(Status.ACTIVE); 39 | userRepository.save(userToBeSaved); 40 | return ResponseEntity.ok(userToBeSaved); 41 | } 42 | } 43 | 44 | @Override 45 | public List getAll() { 46 | return userRepository.findAll().stream() 47 | .filter(user -> user.getStatus() == Status.ACTIVE) 48 | .collect(Collectors.toList()); 49 | } 50 | 51 | @Override 52 | public ResponseEntity getUserById(String id) { 53 | 54 | if (userRepository.findById(id).isPresent() && 55 | userRepository.findById(id).get().getStatus() == Status.ACTIVE) { 56 | 57 | User user; 58 | try { 59 | user = userRepository.findById(id).get(); 60 | } catch (NoSuchElementException noSuchElementException) { 61 | return ResponseEntity.notFound().build(); 62 | } 63 | 64 | log.info("user found with id {} {}", id, user); 65 | return ResponseEntity.ok(user); 66 | 67 | } else { 68 | return ResponseEntity.notFound().build(); 69 | } 70 | } 71 | 72 | @Override 73 | public ResponseEntity updateUserById(String id, User userToUpdate) { 74 | ResponseEntity response = getUserById(id); 75 | 76 | if (response.getBody() != null) { 77 | User currentUser = (User) response.getBody(); 78 | // The name, phoneNumber, countryCode should not be modified. 79 | User toSave = User.builder().name(currentUser.getName()) 80 | .emailAddress(userToUpdate.getEmailAddress()) 81 | .phoneNumber(currentUser.getPhoneNumber()) 82 | .countryCode(currentUser.getCountryCode()) 83 | .dob(userToUpdate.getDob()) 84 | .gender(userToUpdate.getGender()) 85 | .medicalHistory(userToUpdate.getMedicalHistory()) 86 | .bloodGroup(userToUpdate.getBloodGroup()) 87 | .weight(userToUpdate.getWeight()) 88 | .problems(userToUpdate.getProblems()) 89 | .status(Status.ACTIVE).build(); 90 | 91 | toSave.id = currentUser.id; 92 | userRepository.save(toSave); 93 | 94 | return ResponseEntity.ok(toSave); 95 | 96 | } else { 97 | return ResponseEntity.notFound().build(); 98 | } 99 | } 100 | 101 | @Override 102 | public ResponseEntity patchUser(String id, UserPatchRequest changes) { 103 | 104 | User initialUser = (User) getUserById(id).getBody(); 105 | 106 | if (initialUser == null) { 107 | return ResponseEntity.notFound().build(); 108 | } 109 | 110 | if (changes.getName() != null) { 111 | initialUser.setName(changes.getName()); 112 | } 113 | 114 | if (changes.getEmailAddress() != null) { 115 | initialUser.setEmailAddress(changes.getEmailAddress()); 116 | } 117 | 118 | if (changes.getProblems() != null) { 119 | initialUser.setProblems(changes.getProblems()); 120 | } 121 | 122 | if (changes.getDob() != null) { 123 | initialUser.setDob(changes.getDob()); 124 | } 125 | 126 | if (changes.getGender() != null) { 127 | initialUser.setGender(changes.getGender()); 128 | } 129 | 130 | if (changes.getMedicalHistory() != null) { 131 | initialUser.setMedicalHistory(changes.getMedicalHistory()); 132 | } 133 | 134 | if (changes.getBloodGroup() != null) { 135 | initialUser.setBloodGroup(changes.getBloodGroup()); 136 | } 137 | 138 | if (changes.getWeight() >= 10 && changes.getWeight() <= 150) { 139 | initialUser.setWeight(changes.getWeight()); 140 | } 141 | 142 | userRepository.save(initialUser); 143 | 144 | return ResponseEntity.ok(initialUser); 145 | } 146 | 147 | @Override 148 | public ResponseEntity deleteUserById(String id) { 149 | if (userRepository.findById(id).isEmpty()) { 150 | return ResponseEntity.notFound().build(); 151 | } else { 152 | 153 | // NOTE: WE ARE JUST UPDATING STATUS OF ENTITY. 154 | User userToDelete = (User) getUserById(id).getBody(); 155 | userToDelete.setStatus(Status.INACTIVE); 156 | userRepository.save(userToDelete); 157 | return ResponseEntity.ok(userToDelete); 158 | } 159 | } 160 | 161 | @Override 162 | public ResponseEntity restoreUserById(String id) { 163 | if (userRepository.findById(id).isPresent()) { 164 | User restoredUser = userRepository.findById(id).get(); 165 | if (restoredUser.getStatus() == Status.ACTIVE) 166 | return ResponseEntity.badRequest().body("Already Exist"); 167 | 168 | restoredUser.setStatus(Status.ACTIVE); 169 | userRepository.save(restoredUser); 170 | return ResponseEntity.ok(restoredUser); 171 | } 172 | return ResponseEntity.badRequest().body("User not found by given id"); 173 | } 174 | 175 | @Override 176 | public ResponseEntity findUserByPhone(String countryCode, String phoneNumber) { 177 | User foundUser = userRepository.findUserByPhoneNumber(phoneNumber); 178 | 179 | if (foundUser != null && foundUser.getCountryCode().equals(countryCode) 180 | && foundUser.getStatus().equals(Status.ACTIVE)) { 181 | log.info("Found User Phone is {} and countryCode is {}", 182 | foundUser.getPhoneNumber(), foundUser.getCountryCode()); 183 | 184 | return ResponseEntity.ok(foundUser); 185 | } else { 186 | 187 | log.info("User not found by countryCode and phone {} {}", countryCode, phoneNumber); 188 | return ResponseEntity.notFound().build(); 189 | } 190 | } 191 | 192 | private boolean isUserAlreadyExist(User userToSave) { 193 | List savedUserList = userRepository.findAll(); 194 | for (User u : savedUserList) { 195 | if (u.getPhoneNumber().equals(userToSave.getPhoneNumber()) 196 | && u.getCountryCode().equals(userToSave.getCountryCode()) 197 | && u.getStatus() == Status.ACTIVE) { 198 | return true; 199 | } 200 | } 201 | return false; 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositoryservices/DoctorRepositoryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositoryservices; 2 | 3 | import com.medizine.backend.dto.Doctor; 4 | import com.medizine.backend.dto.Status; 5 | import com.medizine.backend.exchanges.DoctorPatchRequest; 6 | import com.medizine.backend.repositories.DoctorRepository; 7 | import lombok.extern.log4j.Log4j2; 8 | import org.modelmapper.ModelMapper; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.stereotype.Service; 12 | 13 | import javax.inject.Provider; 14 | import java.util.List; 15 | import java.util.stream.Collectors; 16 | 17 | @Log4j2 18 | @Service 19 | public class DoctorRepositoryServiceImpl implements DoctorRepositoryService { 20 | 21 | @Autowired 22 | private DoctorRepository doctorRepository; 23 | 24 | @Autowired 25 | private Provider modelMapperProvider; 26 | 27 | @Override 28 | public ResponseEntity createDoctor(Doctor doctorToSave) { 29 | if (isDoctorAlreadyExist(doctorToSave)) { 30 | return ResponseEntity.badRequest().body("Doctor with same info already exist"); 31 | 32 | } else { 33 | doctorToSave.setStatus(Status.ACTIVE); 34 | doctorRepository.save(doctorToSave); 35 | return ResponseEntity.ok(doctorToSave); 36 | } 37 | } 38 | 39 | @Override 40 | public ResponseEntity updateDoctorById(String id, Doctor doctorToUpdate) { 41 | ResponseEntity response = getDoctorById(id); 42 | 43 | if (response.getBody() != null) { 44 | Doctor currentDoctor = (Doctor) response.getBody(); 45 | // The name, phoneNumber, countryCode should not be modified. 46 | Doctor toSave = Doctor.builder().name(currentDoctor.getName()) 47 | .emailAddress(doctorToUpdate.getEmailAddress()) 48 | .phoneNumber(currentDoctor.getPhoneNumber()) 49 | .countryCode(currentDoctor.getCountryCode()) 50 | .dob(doctorToUpdate.getDob()) 51 | .gender(doctorToUpdate.getGender()) 52 | .speciality(doctorToUpdate.getSpeciality()) 53 | .experience(doctorToUpdate.getExperience()) 54 | .about(doctorToUpdate.getAbout()) 55 | .language(doctorToUpdate.getLanguage()) 56 | .location(doctorToUpdate.getLocation()) 57 | .status(Status.ACTIVE).build(); 58 | 59 | toSave.id = currentDoctor.id; 60 | doctorRepository.save(toSave); 61 | 62 | return ResponseEntity.ok(toSave); 63 | } else { 64 | return ResponseEntity.notFound().build(); 65 | } 66 | } 67 | 68 | @Override 69 | public ResponseEntity patchDoctor(String id, DoctorPatchRequest changes) { 70 | Doctor initialDoctor = (Doctor) getDoctorById(id).getBody(); 71 | 72 | if (initialDoctor == null) { 73 | return ResponseEntity.notFound().build(); 74 | } 75 | 76 | if (changes.getName() != null) { 77 | initialDoctor.setName(changes.getName()); 78 | } 79 | 80 | if (changes.getEmailAddress() != null) { 81 | initialDoctor.setEmailAddress(changes.getEmailAddress()); 82 | } 83 | 84 | if (changes.getDob() != null) { 85 | initialDoctor.setDob(changes.getDob()); 86 | } 87 | 88 | if (changes.getGender() != null) { 89 | initialDoctor.setGender(changes.getGender()); 90 | } 91 | 92 | if (changes.getSpeciality() != null) { 93 | initialDoctor.setSpeciality(changes.getSpeciality()); 94 | } 95 | 96 | if (changes.getExperience() >= 0 && changes.getExperience() <= 20) { 97 | initialDoctor.setExperience(changes.getExperience()); 98 | } 99 | 100 | if (changes.getAbout() != null) { 101 | initialDoctor.setAbout(changes.getAbout()); 102 | } 103 | 104 | if (changes.getLanguage() != null) { 105 | initialDoctor.setLanguage(changes.getLanguage()); 106 | } 107 | 108 | if (changes.getLocation() != null) { 109 | initialDoctor.setLanguage(changes.getLanguage()); 110 | } 111 | 112 | doctorRepository.save(initialDoctor); 113 | 114 | return ResponseEntity.ok(initialDoctor); 115 | } 116 | 117 | @Override 118 | public List getAllDoctorsCloseBy() { 119 | return doctorRepository.findAll().stream() 120 | .filter(doctor -> doctor.getStatus() == Status.ACTIVE) 121 | .collect(Collectors.toList()); 122 | } 123 | 124 | @Override 125 | public ResponseEntity getDoctorById(String id) { 126 | 127 | if (doctorRepository.findById(id).isPresent() && 128 | doctorRepository.findById(id).get().getStatus() == Status.ACTIVE) { 129 | Doctor doctor = doctorRepository.findById(id).get(); 130 | return ResponseEntity.ok(doctor); 131 | } else { 132 | return ResponseEntity.noContent().build(); 133 | } 134 | } 135 | 136 | @Override 137 | public ResponseEntity deleteDoctorById(String id) { 138 | if (doctorRepository.findById(id).isEmpty()) { 139 | return ResponseEntity.notFound().build(); 140 | } else { 141 | // NOTE: WE ARE JUST UPDATING STATUS OF ENTITY. 142 | Doctor doctorToDelete = (Doctor) getDoctorById(id).getBody(); 143 | doctorToDelete.setStatus(Status.INACTIVE); 144 | doctorRepository.save(doctorToDelete); 145 | return ResponseEntity.ok().build(); 146 | } 147 | } 148 | 149 | @Override 150 | public ResponseEntity restoreDoctorById(String id) { 151 | if (doctorRepository.findById(id).isPresent()) { 152 | Doctor restoredDoctor = doctorRepository.findById(id).get(); 153 | if (restoredDoctor.getStatus() == Status.ACTIVE) 154 | return ResponseEntity.badRequest().body("Already Exist"); 155 | 156 | restoredDoctor.setStatus(Status.ACTIVE); 157 | doctorRepository.save(restoredDoctor); 158 | 159 | return ResponseEntity.ok(restoredDoctor); 160 | } 161 | return ResponseEntity.badRequest().body("Doctor not found by given id"); 162 | } 163 | 164 | @Override 165 | public ResponseEntity getDoctorByPhone(String countryCode, String phoneNumber) { 166 | Doctor foundDoctor = doctorRepository.findDoctorByPhoneNumber(phoneNumber); 167 | 168 | log.info("Method Called to find Doctor by countryCode {} and phoneNumber {}", 169 | countryCode, phoneNumber); 170 | 171 | if (foundDoctor != null && foundDoctor.getCountryCode().equals(countryCode) 172 | && foundDoctor.getStatus().equals(Status.ACTIVE)) { 173 | log.info("Found Doctor Phone is {} and countryCode is {}", 174 | foundDoctor.getPhoneNumber(), foundDoctor.getCountryCode()); 175 | return ResponseEntity.ok(foundDoctor); 176 | } else { 177 | log.info("Doctor not found by countryCode and phone {} {}", countryCode, phoneNumber); 178 | return ResponseEntity.notFound().build(); 179 | } 180 | } 181 | 182 | private boolean isDoctorAlreadyExist(Doctor doctorToSave) { 183 | List savedDoctorList = doctorRepository.findAll(); 184 | for (Doctor d : savedDoctorList) { 185 | if (d.getPhoneNumber() != null && d.getPhoneNumber().equals(doctorToSave.getPhoneNumber()) 186 | && d.getCountryCode().equals(doctorToSave.getCountryCode()) 187 | && d.getStatus() == Status.ACTIVE) { 188 | return true; 189 | } 190 | } 191 | return false; 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.controller; 2 | 3 | import com.medizine.backend.dto.User; 4 | import com.medizine.backend.exchanges.BaseResponse; 5 | import com.medizine.backend.exchanges.DoctorListResponse; 6 | import com.medizine.backend.exchanges.UserListResponse; 7 | import com.medizine.backend.exchanges.UserPatchRequest; 8 | import com.medizine.backend.services.BaseService; 9 | import com.medizine.backend.services.UserService; 10 | import io.swagger.annotations.ApiOperation; 11 | import io.swagger.annotations.ApiResponse; 12 | import io.swagger.annotations.ApiResponses; 13 | import lombok.extern.log4j.Log4j2; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.beans.factory.annotation.Qualifier; 16 | import org.springframework.http.ResponseEntity; 17 | import org.springframework.validation.annotation.Validated; 18 | import org.springframework.web.bind.annotation.*; 19 | 20 | import javax.validation.Valid; 21 | import java.util.List; 22 | import java.util.Objects; 23 | 24 | @RestController 25 | @Validated 26 | @RequestMapping(UserController.BASE_API_ENDPOINT + "/normalUser") 27 | @Log4j2 28 | public class UserController extends ApiCrudController { 29 | 30 | public static final String BASE_API_ENDPOINT = "/medizine/v1"; 31 | public static final String GET_DOCTORS = "/getDoctors"; 32 | 33 | @Autowired 34 | private UserService userService; 35 | 36 | @Autowired 37 | @Qualifier("doctorService") 38 | private BaseService baseService; 39 | 40 | 41 | @ApiOperation(value = "Get the list of available doctors", response = DoctorListResponse.class) 42 | @ApiResponses({ 43 | @ApiResponse(code = 200, message = "OK"), 44 | @ApiResponse(code = 400, message = "Bad Request"), 45 | @ApiResponse(code = 500, message = "Server Error") 46 | }) 47 | @GetMapping(GET_DOCTORS) 48 | public DoctorListResponse getAvailableDoctors() { 49 | log.info("getAvailableDoctors called by user"); 50 | DoctorListResponse availableDoctors = baseService.getAvailableDoctors(); 51 | return Objects.requireNonNullElseGet(availableDoctors, () -> new DoctorListResponse(null, "ERROR")); 52 | } 53 | 54 | @ApiResponses({ 55 | @ApiResponse(code = 200, message = "OK", response = BaseResponse.class), 56 | @ApiResponse(code = 400, message = "Validation Error"), 57 | @ApiResponse(code = 500, message = "Server Error") 58 | }) 59 | @PostMapping("/create") 60 | public BaseResponse create(@Valid @RequestBody User newUser) { 61 | log.info("user create method called {}", newUser); 62 | ResponseEntity responseEntity = userService.createUser(newUser); 63 | if (responseEntity.getStatusCodeValue() == 400) { 64 | return new BaseResponse<>(null, "Already Exist"); 65 | } else { 66 | return new BaseResponse<>((User) responseEntity.getBody(), responseEntity.getStatusCode().toString()); 67 | } 68 | 69 | } 70 | 71 | @ApiResponses({ 72 | @ApiResponse(code = 200, message = "OK", response = BaseResponse.class), 73 | @ApiResponse(code = 400, message = "Validation Error"), 74 | @ApiResponse(code = 500, message = "Server Error") 75 | }) 76 | @PatchMapping("/patchById") 77 | public BaseResponse patchById(String id, @Valid @RequestBody UserPatchRequest patchRequest) { 78 | ResponseEntity responseEntity = userService.patchEntityById(id, patchRequest); 79 | if (responseEntity.getStatusCode().is2xxSuccessful()) { 80 | return new BaseResponse<>((User) responseEntity.getBody(), responseEntity.getStatusCode().toString()); 81 | } else { 82 | return new BaseResponse<>(null, responseEntity.getStatusCode().toString()); 83 | } 84 | } 85 | 86 | @ApiResponses({ 87 | @ApiResponse(code = 200, message = "OK", response = BaseResponse.class), 88 | @ApiResponse(code = 400, message = "Validation Error"), 89 | @ApiResponse(code = 500, message = "Server Error") 90 | }) 91 | @PutMapping("/updateById") 92 | public BaseResponse updateById(String id, @Valid @RequestBody User userToUpdate) { 93 | ResponseEntity responseEntity = userService.updateEntityById(id, userToUpdate); 94 | if (responseEntity.getStatusCode().is2xxSuccessful()) { 95 | return new BaseResponse<>((User) responseEntity.getBody(), responseEntity.getStatusCode().toString()); 96 | } else { 97 | return new BaseResponse<>(null, responseEntity.getStatusCode().toString()); 98 | } 99 | } 100 | 101 | @ApiOperation(value = "Get the list of all users", response = UserListResponse.class) 102 | @ApiResponses({ 103 | @ApiResponse(code = 200, message = "OK"), 104 | @ApiResponse(code = 400, message = "Bad Request"), 105 | @ApiResponse(code = 500, message = "Server Error") 106 | }) 107 | @GetMapping("/getMany") 108 | public UserListResponse getMany() { 109 | List userList = userService.getAllUser(); 110 | return new UserListResponse(userList); 111 | } 112 | 113 | @ApiResponses({ 114 | @ApiResponse(code = 200, message = "OK", response = BaseResponse.class), 115 | @ApiResponse(code = 400, message = "Bad Request"), 116 | @ApiResponse(code = 500, message = "Server Error") 117 | }) 118 | @Override 119 | public BaseResponse getById(String id) { 120 | ResponseEntity response = userService.findEntityById(id); 121 | if (response.getStatusCode().is2xxSuccessful()) { 122 | return new BaseResponse<>((User) response.getBody(), response.getStatusCode().toString()); 123 | } else { 124 | return new BaseResponse<>(null, response.getStatusCode().toString()); 125 | } 126 | } 127 | 128 | @ApiResponses({ 129 | @ApiResponse(code = 200, message = "OK", response = BaseResponse.class), 130 | @ApiResponse(code = 400, message = "Bad Request"), 131 | @ApiResponse(code = 500, message = "Server Error") 132 | }) 133 | @GetMapping("/existByPhone") 134 | public BaseResponse findByPhoneNumber(String countryCode, String phoneNumber) { 135 | ResponseEntity response = userService.findEntityByPhone(countryCode, phoneNumber); 136 | if (response.getStatusCode().is2xxSuccessful()) { 137 | return new BaseResponse<>((User) response.getBody(), response.getStatusCode().toString()); 138 | } else { 139 | return new BaseResponse<>(null, response.getStatusCode().toString()); 140 | } 141 | } 142 | 143 | 144 | @ApiResponses({ 145 | @ApiResponse(code = 200, message = "OK", response = BaseResponse.class), 146 | @ApiResponse(code = 400, message = "Bad Request"), 147 | @ApiResponse(code = 500, message = "Server Error") 148 | }) 149 | @Override 150 | public BaseResponse deleteById(String id) { 151 | 152 | ResponseEntity responseEntity = userService.deleteEntity(id); 153 | if (responseEntity.getStatusCode().is2xxSuccessful()) { 154 | return new BaseResponse<>((User) responseEntity.getBody(), responseEntity.getStatusCode().toString()); 155 | } else { 156 | return new BaseResponse<>(null, responseEntity.getStatusCode().toString()); 157 | } 158 | } 159 | 160 | 161 | @ApiResponses({ 162 | @ApiResponse(code = 200, message = "OK", response = BaseResponse.class), 163 | @ApiResponse(code = 400, message = "Bad Request"), 164 | @ApiResponse(code = 500, message = "Server Error") 165 | }) 166 | @Override 167 | public BaseResponse restoreById(String id) { 168 | ResponseEntity responseEntity = userService.restoreEntity(id); 169 | if (responseEntity.getStatusCode().is2xxSuccessful()) { 170 | return new BaseResponse<>((User) responseEntity.getBody(), responseEntity.getStatusCode().toString()); 171 | } else { 172 | return new BaseResponse<>(null, responseEntity.getStatusCode().toString()); 173 | } 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /src/main/java/com/medizine/backend/repositoryservices/SlotRepositoryService.java: -------------------------------------------------------------------------------- 1 | package com.medizine.backend.repositoryservices; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.databind.SerializationFeature; 5 | import com.medizine.backend.dto.Appointment; 6 | import com.medizine.backend.dto.Slot; 7 | import com.medizine.backend.exchanges.SlotBookingRequest; 8 | import com.medizine.backend.exchanges.SlotResponse; 9 | import com.medizine.backend.exchanges.SlotStatusRequest; 10 | import com.medizine.backend.repositories.SlotRepository; 11 | import lombok.extern.log4j.Log4j2; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.http.ResponseEntity; 14 | import org.springframework.stereotype.Service; 15 | import org.thymeleaf.util.StringUtils; 16 | 17 | import java.text.SimpleDateFormat; 18 | import java.time.LocalDate; 19 | import java.time.LocalTime; 20 | import java.time.ZoneId; 21 | import java.util.*; 22 | 23 | @Service 24 | @Log4j2 25 | public class SlotRepositoryService { 26 | 27 | public static final long MIN_SLOT_DURATION = 900000; 28 | public static final long MAX_SLOT_DURATION = 1800000; 29 | 30 | private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("UTC"); 31 | 32 | private static final SimpleDateFormat SIMPLE_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd-hh.mm.ss"); 33 | 34 | 35 | @Autowired 36 | private final ObjectMapper mapper = new ObjectMapper() 37 | .configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS, true); 38 | 39 | @Autowired 40 | private SlotRepository slotRepository; 41 | 42 | @Autowired 43 | private AppointmentRepositoryService appointmentService; 44 | 45 | /** 46 | * Utility method to check for overlapping slots. 47 | *

48 | * Time Complexity O(N log N) - n is number of intervals. 49 | * 50 | * @param timeSlots - all added time slot for specific doctor. 51 | * @param slot - new slot to be added. 52 | * @return - is current slot overlaps or not. 53 | */ 54 | private static boolean isSlotOverlap(List timeSlots, Slot slot) { 55 | 56 | timeSlots.add(new LocalTime[]{ 57 | getLocalTimeFromDate(slot.getStartTime()), 58 | getLocalTimeFromDate(slot.getEndTime()) 59 | }); 60 | 61 | timeSlots.sort(Comparator.comparing(time -> time[0])); 62 | 63 | // Now in the sorted timeSlots list, if start time of a slot 64 | // is less than end of previous slot, then there is an overlap. 65 | 66 | for (int i = 1; i < timeSlots.size(); i++) { 67 | if (timeSlots.get(i - 1)[1].compareTo(timeSlots.get(i)[0]) > 0) 68 | return true; 69 | } 70 | return false; 71 | } 72 | 73 | /** 74 | * Utility method to convert Date to LocalTime 75 | * 76 | * @param date - input Date Object. 77 | * @return - LocalTime. 78 | */ 79 | private static LocalTime getLocalTimeFromDate(Date date) { 80 | return date 81 | .toInstant() 82 | .atZone(ZoneId.of("UTC")) 83 | .toLocalTime(); 84 | } 85 | 86 | public static LocalDate getLocalDate(Date date) { 87 | return date 88 | .toInstant() 89 | .atZone(ZoneId.of("UTC")) 90 | .toLocalDate(); 91 | } 92 | 93 | public ResponseEntity createSlot(Slot slot) { 94 | 95 | // Start time must be less than the end time. 96 | if (slot.getStartTime().compareTo(slot.getEndTime()) >= 0) { 97 | return ResponseEntity.badRequest().body("End Time must be greater than Start time"); 98 | } 99 | 100 | // And Slot duration must be greater or equal to 15 minutes but less than 30 minutes. 101 | // i.e >= 900 seconds and <= 1800 seconds. 102 | 103 | long slotDuration = (slot.getEndTime().getTime() - slot.getStartTime().getTime()); 104 | 105 | if (slotDuration < MIN_SLOT_DURATION || slotDuration > MAX_SLOT_DURATION) { 106 | return ResponseEntity.badRequest().body("Time duration must lies between 15 to 30 min"); 107 | } 108 | 109 | String currentDoctorId = slot.getDoctorId(); 110 | List allSlotOfGivenDoctor = slotRepository.getAllByDoctorId(currentDoctorId); 111 | 112 | List timeSlots = new ArrayList<>(); 113 | 114 | // Now check the current slot must not clash with other already added slots. 115 | for (Slot currentSlot : allSlotOfGivenDoctor) { 116 | LocalTime localStartTime = getLocalTimeFromDate(currentSlot.getStartTime()); 117 | LocalTime localEndTime = getLocalTimeFromDate(currentSlot.getEndTime()); 118 | timeSlots.add(new LocalTime[]{localStartTime, localEndTime}); 119 | } 120 | 121 | 122 | if (isSlotOverlap(timeSlots, slot)) { 123 | return ResponseEntity.badRequest().body("Error, Overlapping Slot!"); 124 | } else { 125 | slotRepository.save(slot); 126 | return ResponseEntity.ok().body(slot); 127 | } 128 | } 129 | 130 | public List getAll() { 131 | return slotRepository.findAll(); 132 | } 133 | 134 | public List getAllByDoctorId(String doctorId) { 135 | return slotRepository.getAllByDoctorId(doctorId); 136 | } 137 | 138 | public ResponseEntity bookSlot(SlotBookingRequest slotRequest) { 139 | 140 | Slot requestedSlot = getAppointmentSlotById(slotRequest.getDoctorId(), slotRequest.getSlotId()); 141 | 142 | if (requestedSlot == null) { 143 | return ResponseEntity.badRequest().body("Requested slot not found"); 144 | } 145 | 146 | Long epochRequestedDate = getLocalDate(slotRequest.getBookingDate()).toEpochDay(); 147 | 148 | if (appointmentService.alreadyExist(slotRequest, epochRequestedDate)) { 149 | return ResponseEntity.badRequest().body("Appointment Already Exist"); 150 | } 151 | 152 | Appointment savedAppointment = appointmentService.createAppointment(slotRequest); 153 | 154 | return ResponseEntity.ok(savedAppointment); 155 | } 156 | 157 | public Slot getAppointmentSlotById(String doctorId, String slotId) { 158 | List slots = slotRepository.getAllByDoctorId(doctorId); 159 | for (Slot currentSlot : slots) { 160 | if (currentSlot.id.equals(slotId)) { 161 | return currentSlot; 162 | } 163 | } 164 | return null; 165 | } 166 | 167 | public SlotResponse getLiveSlotStatus(SlotStatusRequest slotStatusRequest) { 168 | 169 | String doctorId = slotStatusRequest.getDoctorId(); 170 | String userId = slotStatusRequest.getUserId(); 171 | Date currentDate = slotStatusRequest.getCurrentDate(); 172 | 173 | if (StringUtils.isEmpty(doctorId) || currentDate == null) return null; 174 | 175 | Long epochValueOfCurrDate = getLocalDate(currentDate).toEpochDay(); 176 | 177 | List slotList = slotRepository.getAllByDoctorId(doctorId); 178 | 179 | if (slotList == null || slotList.size() == 0) { 180 | return new SlotResponse(null, "No slots found"); 181 | } else { 182 | for (Slot currentSlot : slotList) { 183 | List savedAppointment = appointmentService.findAppointmentBySlot(currentSlot, userId); 184 | if (savedAppointment != null) { 185 | for (Appointment appointment : savedAppointment) { 186 | Long epochBookedDate = getLocalDate(appointment.getAppointmentDate()).toEpochDay(); 187 | if (epochBookedDate.equals(epochValueOfCurrDate)) { 188 | currentSlot.setBookedBySameUser(true); 189 | break; 190 | } 191 | } 192 | } 193 | List savedByOther = appointmentService.findBookedAppointment(currentSlot); 194 | if (savedByOther != null) { 195 | for (Appointment appointment : savedByOther) { 196 | Long epochBookedDate = getLocalDate(appointment.getAppointmentDate()).toEpochDay(); 197 | if (epochBookedDate.equals(epochValueOfCurrDate)) { 198 | currentSlot.setBooked(true); 199 | break; 200 | } 201 | } 202 | } 203 | } 204 | return new SlotResponse(slotList, "Fetched"); 205 | } 206 | } 207 | 208 | public Slot deleteSlotById(String slotId) { 209 | Slot deletedSlot; 210 | 211 | if (slotRepository.findById(slotId).isPresent()) { 212 | deletedSlot = slotRepository.findById(slotId).get(); 213 | } else { 214 | return null; 215 | } 216 | 217 | slotRepository.delete(deletedSlot); 218 | return deletedSlot; 219 | } 220 | } 221 | --------------------------------------------------------------------------------