-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from Incredible-Technologies/patient-documents
Patient documents
- Loading branch information
Showing
29 changed files
with
735 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
backend/src/main/java/com/personal/patient/account/controllers/PassportController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.personal.patient.account.controllers; | ||
|
||
import com.personal.patient.account.exceptions.ForbiddenException; | ||
import com.personal.patient.account.exceptions.NotFoundException; | ||
import com.personal.patient.account.models.CreatingPassportResponse; | ||
import com.personal.patient.account.models.DeletePassportFile; | ||
import com.personal.patient.account.service.PassportFileService; | ||
import com.personal.patient.account.service.PassportService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.dao.DataIntegrityViolationException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.security.Principal; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/documents") | ||
public class PassportController { | ||
|
||
@ExceptionHandler(NotFoundException.class) | ||
protected ResponseEntity<Object> handleNotFoundException(NotFoundException ex) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ex.getMessage()); | ||
} | ||
|
||
@ExceptionHandler(ForbiddenException.class) | ||
protected ResponseEntity<Object> handleForbiddenException(ForbiddenException ex) { | ||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(ex.getMessage()); | ||
} | ||
|
||
|
||
@ExceptionHandler(DataIntegrityViolationException.class) | ||
public ResponseEntity<String> handleDataIntegrityViolationException(DataIntegrityViolationException ex) { | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Ошибка валидации: поле user_id уже существует"); | ||
} | ||
private final PassportService passportService; | ||
|
||
private final PassportFileService passportFileService; | ||
|
||
|
||
@PostMapping("/passport") | ||
public ResponseEntity<?> creatingPassport(@RequestBody CreatingPassportResponse creatingPassportResponse, Principal principal){ | ||
return ResponseEntity.ok(passportService.createPassport(creatingPassportResponse, principal)); | ||
} | ||
|
||
@GetMapping("/passport") | ||
public ResponseEntity<?> getPassport(Principal principal){ | ||
return ResponseEntity.ok(passportService.getPassport(principal)); | ||
} | ||
|
||
@PutMapping("/passport") | ||
public ResponseEntity<?> changePassport(@RequestBody CreatingPassportResponse creatingPassportResponse, Principal principal) { | ||
return ResponseEntity.ok(passportService.changePassport(creatingPassportResponse, principal)); | ||
} | ||
|
||
|
||
@PostMapping("/passport/passport-file") | ||
public ResponseEntity<?> createPassportFile(@RequestParam("file") MultipartFile file, Principal principal) throws IOException { | ||
return ResponseEntity.ok(passportFileService.addPassportFileRepository(principal, file)); | ||
} | ||
|
||
|
||
@GetMapping("/passport/passport-file") | ||
public ResponseEntity<?> getPassportFiles(Principal principal){ | ||
return ResponseEntity.ok(passportFileService.getPassportFiles(principal)); | ||
} | ||
|
||
|
||
@DeleteMapping("/passport/passport-file/{deleteId}") | ||
public ResponseEntity<?> DeletePassportFile(Principal principal, @PathVariable Long deleteId){ | ||
DeletePassportFile deletePassportFile = passportFileService.deletePassportFile(deleteId, principal); | ||
return ResponseEntity.ok(deletePassportFile); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
backend/src/main/java/com/personal/patient/account/controllers/SnilsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.personal.patient.account.controllers; | ||
|
||
import com.personal.patient.account.exceptions.NotFoundException; | ||
import com.personal.patient.account.models.CreatingSnilsResponse; | ||
import com.personal.patient.account.service.SnilsService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.dao.DataIntegrityViolationException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.security.Principal; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/documents") | ||
public class SnilsController { | ||
|
||
@ExceptionHandler(NotFoundException.class) | ||
protected ResponseEntity<Object> handleNotFoundException(NotFoundException ex) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ex.getMessage()); | ||
} | ||
|
||
|
||
@ExceptionHandler(DataIntegrityViolationException.class) | ||
public ResponseEntity<String> handleDataIntegrityViolationException(DataIntegrityViolationException ex) { | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Ошибка валидации: поле user_id уже существует"); | ||
} | ||
private final SnilsService snilsService; | ||
|
||
@PostMapping("/snils") | ||
public ResponseEntity<?> creatingSnils(@RequestBody CreatingSnilsResponse creatingSnilsResponse, Principal principal){ | ||
return ResponseEntity.ok(snilsService.createSnils(creatingSnilsResponse, principal)); | ||
} | ||
|
||
@GetMapping("/snils") | ||
public ResponseEntity<?> getSnils(Principal principal){ | ||
return ResponseEntity.ok(snilsService.getSnils(principal)); | ||
} | ||
|
||
@PutMapping("/snils") | ||
public ResponseEntity<?> changeSnils(@RequestBody CreatingSnilsResponse creatingSnilsResponse, Principal principal){ | ||
return ResponseEntity.ok(snilsService.changeSnils(creatingSnilsResponse,principal)); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
backend/src/main/java/com/personal/patient/account/entities/Passport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.personal.patient.account.entities; | ||
|
||
|
||
import com.personal.patient.account.models.enums.PassportGender; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Table( | ||
name="passport", | ||
uniqueConstraints = { | ||
@UniqueConstraint(columnNames = "user_id") | ||
} | ||
) | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Passport { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name="id") | ||
private Long id; | ||
|
||
@Column(name="full_name") | ||
private String fullName; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private PassportGender passportGender; | ||
|
||
@Column(name="date_of_birt") | ||
@Temporal(TemporalType.DATE) | ||
@DateTimeFormat(pattern = "dd-MM-yyyy") | ||
private Date dateOfBirth; | ||
|
||
@Column(name="place_of_birth") | ||
private String placeOfBirth; | ||
|
||
@Column(name="series") | ||
private Integer series; | ||
|
||
@Column(name="number") | ||
private Integer number; | ||
|
||
@Column(name="date_of_issue") | ||
@Temporal(TemporalType.DATE) | ||
@DateTimeFormat(pattern = "dd-MM-yyyy") | ||
private Date dateOfIssue; | ||
|
||
@Column(name="division_code") | ||
private Integer divisionCode; | ||
|
||
@Column(name="issued_by") | ||
private String issuedBy; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "passport") | ||
private List<PassportFile> passportFiles = new ArrayList<>(); | ||
|
||
@Override | ||
public String toString() { | ||
return "Passport"; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
backend/src/main/java/com/personal/patient/account/entities/PassportFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.personal.patient.account.entities; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Table(name="passport_file") | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class PassportFile { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name="id") | ||
private Long id; | ||
|
||
@Column(name="name") | ||
private String name; | ||
|
||
@Column(name = "originalFileName") | ||
private String originalFileName; | ||
|
||
@Column(name="size") | ||
private Long size; | ||
|
||
@Column(name="contentType") | ||
private String contentType; | ||
|
||
@Lob | ||
private byte[] bytes; | ||
|
||
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) | ||
@JoinColumn(name="passport_id") | ||
private Passport passport; | ||
|
||
@Override | ||
public String toString() { | ||
return "PassportFile"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
backend/src/main/java/com/personal/patient/account/entities/Snils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.personal.patient.account.entities; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Table( | ||
name="snils", | ||
uniqueConstraints = { | ||
@UniqueConstraint(columnNames = "user_id") | ||
} | ||
) | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Snils { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name="id") | ||
private Long id; | ||
|
||
@Column(name="number") | ||
private Long number; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
@Override | ||
public String toString(){ | ||
return "snils"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.