temirlan100

Untitled

Nov 14th, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.11 KB | None | 0 0
  1. import com.fasterxml.jackson.annotation.JsonFormat;
  2. import com.fasterxml.jackson.databind.ObjectMapper;
  3. import com.fasterxml.jackson.databind.SerializationFeature;
  4. import java.io.IOException;
  5. import java.time.LocalDate;
  6.  
  7. public class PatientRecord {
  8.     private String recordId;
  9.     private String patientId;
  10.     private String name;
  11.     private int age;
  12.  
  13.     @JsonFormat(pattern = "yyyy-MM-dd")
  14.     private LocalDate appointmentDate;
  15.  
  16.     private String diagnosis;
  17.     private boolean followUpNeeded;
  18.     private String assignedDoctor;
  19.  
  20.     @JsonFormat(pattern = "yyyy-MM-dd")
  21.     private LocalDate nextAppointmentDate;
  22.  
  23.     public PatientRecord() {
  24.     }
  25.  
  26.     // Геттеры и сеттеры для всех полей
  27.     public String getRecordId() {
  28.         return recordId;
  29.     }
  30.  
  31.     public void setRecordId(String recordId) {
  32.         this.recordId = recordId;
  33.     }
  34.  
  35.     public String getPatientId() {
  36.         return patientId;
  37.     }
  38.  
  39.     public void setPatientId(String patientId) {
  40.         this.patientId = patientId;
  41.     }
  42.  
  43.     public String getName() {
  44.         return name;
  45.     }
  46.  
  47.     public void setName(String name) {
  48.         this.name = name;
  49.     }
  50.  
  51.     public int getAge() {
  52.         return age;
  53.     }
  54.  
  55.     public void setAge(int age) {
  56.         this.age = age;
  57.     }
  58.  
  59.     public LocalDate getAppointmentDate() {
  60.         return appointmentDate;
  61.     }
  62.  
  63.     public void setAppointmentDate(LocalDate appointmentDate) {
  64.         this.appointmentDate = appointmentDate;
  65.     }
  66.  
  67.     public String getDiagnosis() {
  68.         return diagnosis;
  69.     }
  70.  
  71.     public void setDiagnosis(String diagnosis) {
  72.         this.diagnosis = diagnosis;
  73.     }
  74.  
  75.     public boolean isFollowUpNeeded() {
  76.         return followUpNeeded;
  77.     }
  78.  
  79.     public void setFollowUpNeeded(boolean followUpNeeded) {
  80.         this.followUpNeeded = followUpNeeded;
  81.     }
  82.  
  83.     public String getAssignedDoctor() {
  84.         return assignedDoctor;
  85.     }
  86.  
  87.     public void setAssignedDoctor(String assignedDoctor) {
  88.         this.assignedDoctor = assignedDoctor;
  89.     }
  90.  
  91.     public LocalDate getNextAppointmentDate() {
  92.         return nextAppointmentDate;
  93.     }
  94.  
  95.     public void setNextAppointmentDate(LocalDate nextAppointmentDate) {
  96.         this.nextAppointmentDate = nextAppointmentDate;
  97.     }
  98.  
  99.     // Методы для сериализации и десериализации JSON
  100.     private static final ObjectMapper objectMapper = new ObjectMapper()
  101.             .findAndRegisterModules() // Регистрация модулей для работы с JavaTime
  102.             .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
  103.  
  104.     public static PatientRecord fromJson(String json) {
  105.         try {
  106.             return objectMapper.readValue(json, PatientRecord.class);
  107.         } catch (IOException e) {
  108.             e.printStackTrace();
  109.             return null;
  110.         }
  111.     }
  112.  
  113.     public String toJson() {
  114.         try {
  115.             return objectMapper.writeValueAsString(this);
  116.         } catch (IOException e) {
  117.             e.printStackTrace();
  118.             return null;
  119.         }
  120.     }
  121. }
  122.  
Advertisement
Add Comment
Please, Sign In to add comment