Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #278 from ImisDevelopers/feature/225-state-table
Browse files Browse the repository at this point in the history
Close #225
  • Loading branch information
LeonardKoll authored May 11, 2020
2 parents d4c2c05 + 746002e commit e28ee9a
Show file tree
Hide file tree
Showing 23 changed files with 640 additions and 13 deletions.
1 change: 1 addition & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'org.springframework.cloud:spring-cloud-gcp-starter-storage'
implementation 'org.postgresql:postgresql:42.2.11'
compile group: 'org.hibernate', name: 'hibernate-envers', version: '5.4.14.Final'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.coronavirus.imis.api.dto.RequestLabTestDTO;
import de.coronavirus.imis.domain.PatientEvent;
import de.coronavirus.imis.services.IncidentService;
import de.coronavirus.imis.services.PatientEventService;
import de.coronavirus.imis.services.PatientService;
import lombok.RequiredArgsConstructor;
Expand All @@ -18,10 +19,12 @@
public class DoctorController {
private final PatientEventService eventService;
private final PatientService patientService;
private final IncidentService incidentService;

@PostMapping("/create_appointment")
public PatientEvent addScheduledEvent(@RequestBody RequestLabTestDTO dto) {
var patient = patientService.findPatientById(dto.getPatientId()).orElseThrow();
incidentService.addIncident(patient, dto.getLaboratoryId(), dto.getDoctorId());
return eventService.createScheduledEvent(patient, dto.getLaboratoryId(), dto.getDoctorId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package de.coronavirus.imis.api;

/*
To ease migration, incidents are currently automatically created when
- Creating Tests
- Updating Tests
- Sending to Quarantine
- Creating Patients (equivalent to Initial Patient Event)
- Scheduling appointments (implemented, not tested. Could not find frontend feature)
*/

import de.coronavirus.imis.domain.Incident;
import de.coronavirus.imis.domain.IncidentType;
import de.coronavirus.imis.services.IncidentService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/incidents")
@AllArgsConstructor
public class IncidentController {

private final IncidentService incidentService;

@GetMapping("/{id}")
public Incident getIncident(@PathVariable("id") String incidentId) {
return incidentService.getCurrent(incidentId);
}

@GetMapping("/{id}/log")
public List<Incident> getLog(@PathVariable("id") String incidentId) {
return incidentService.getLog(incidentId, false);
}

@GetMapping("/patient/{id}")
public List<Incident> getPatientCurrent(@PathVariable("id") String patientId) {
return incidentService.getCurrentByPatient(patientId);
}

@GetMapping("/{type}/patient/{id}")
public List<Incident> getPatientCurrentByType(@PathVariable("type") IncidentType incidentType, @PathVariable("id") String patientId) {
return incidentService.getCurrentByPatient(patientId, incidentType);
}

@GetMapping("/patient/{id}/log")
public List<Incident> getPatientLog(@PathVariable("id") String patientId) {
return incidentService.getLog(patientId, true);
}

@GetMapping("/{type}/patient/{id}/log")
public List<Incident> getPatientLogByType(@PathVariable("type") IncidentType incidentType, @PathVariable("id") String patientId) {
return incidentService.getLog(incidentType.IMPLEMENTATION, patientId, true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.coronavirus.imis.api.dto.CreateLabTestDTO;
import de.coronavirus.imis.api.dto.UpdateTestStatusDTO;
import de.coronavirus.imis.domain.LabTest;
import de.coronavirus.imis.services.IncidentService;
import de.coronavirus.imis.services.LabTestService;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -17,9 +18,11 @@
public class LabTestController {

private final LabTestService service;
private final IncidentService incidentService;

@PostMapping
public ResponseEntity<LabTest> createTestForPatient(@RequestBody CreateLabTestDTO createLabTestRequest) {
incidentService.addIncident(createLabTestRequest);
return ResponseEntity.ok(
service.createLabTest(createLabTestRequest)
);
Expand All @@ -37,6 +40,7 @@ public Set<LabTest> getLabTestForPatient(@PathVariable("id") String patientId) {

@PutMapping("/{laboratoryId}")
public ResponseEntity<LabTest> updateTestStatus(@PathVariable("laboratoryId") String laboratoryId, @RequestBody UpdateTestStatusDTO statusDTO) {
incidentService.updateIncident(laboratoryId, statusDTO);
return ResponseEntity.ok(service.updateTestStatus(
laboratoryId, statusDTO
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import de.coronavirus.imis.api.dto.PatientSimpleSearchParamsDTO;
import de.coronavirus.imis.api.dto.SendToQuarantineDTO;
import de.coronavirus.imis.domain.Patient;
import de.coronavirus.imis.services.IncidentService;
import de.coronavirus.imis.domain.PatientEvent;
import de.coronavirus.imis.services.PatientEventService;
import de.coronavirus.imis.services.PatientService;
Expand All @@ -24,6 +25,7 @@
public class PatientController {

private final PatientService patientService;
private final IncidentService incidentService;
private final PatientEventService eventService;

@PostMapping
Expand Down Expand Up @@ -81,6 +83,7 @@ public Long countQueryPatients(@RequestBody final PatientSearchParamsDTO patient
@PostMapping("/quarantine/{id}")
@PreAuthorize("hasAnyRole('DEPARTMENT_OF_HEALTH')")
public ResponseEntity<Patient> sendToQuarantine(@PathVariable("id") String patientId, @RequestBody SendToQuarantineDTO statusDTO) {
incidentService.addOrUpdateIncident(patientId, statusDTO);
return ResponseEntity.ok(patientService.sendToQuaratine(patientId, statusDTO));
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package de.coronavirus.imis.config;

import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.persistence.EntityManagerFactory;


@Configuration
public class AuditConfiguration {

private final EntityManagerFactory entityManagerFactory;

AuditConfiguration(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}

@Bean
AuditReader auditReader() {
return AuditReaderFactory.get(entityManagerFactory.createEntityManager());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package de.coronavirus.imis.config;

import de.coronavirus.imis.config.domain.User;
import org.springframework.data.domain.AuditorAware;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Optional;

public class AuditorAwareImpl implements AuditorAware<User> {
@Override
public Optional<User> getCurrentAuditor() {

Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

if(authentication != null && SecurityContextHolder.getContext().getAuthentication().isAuthenticated())
{
var user = (User) authentication.getPrincipal();
Optional<User> opt = Optional.of(user);
return opt;
}

return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.coronavirus.imis.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import de.coronavirus.imis.config.domain.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement
@EnableJpaAuditing (auditorAwareRef = "auditorAware")
class PersistenceConfig {

@Bean
public AuditorAware<User> auditorAware() {
return new AuditorAwareImpl();
}

@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers(API_PREFIX + "/doctor/*").hasAnyRole(DEPARTMENT_OF_HEALTH, DOCTORS_OFFICE, CLINIC)
.mvcMatchers(POST, API_PREFIX + "/labtest").hasAnyRole(DEPARTMENT_OF_HEALTH, DOCTORS_OFFICE, CLINIC, TEST_SITE)
.antMatchers(API_PREFIX + "/labtest/patient/*").hasAnyRole(DEPARTMENT_OF_HEALTH, DOCTORS_OFFICE, CLINIC, TEST_SITE)
.antMatchers(API_PREFIX + "/incidents/*").hasAnyRole(DEPARTMENT_OF_HEALTH, DOCTORS_OFFICE, CLINIC, TEST_SITE)
.mvcMatchers(PUT, API_PREFIX + "/labtest/*").hasAnyRole(DEPARTMENT_OF_HEALTH, LABORATORY)
.antMatchers(API_PREFIX + "/stats").authenticated()
.antMatchers(API_PREFIX + "/auth/register").hasAuthority(UserRole.USER_ROLE_ADMIN.name())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.coronavirus.imis.domain;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.envers.Audited;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import java.time.LocalDate;

import static org.hibernate.envers.RelationTargetAuditMode.NOT_AUDITED;

@Entity
@Getter
@Setter
@Accessors(chain = true)
@Audited
public class AdministrativeIncident extends Incident {

private Illness illness;

private String comment;

@Audited(targetAuditMode = NOT_AUDITED)
@ManyToOne
private Doctor responsibleDoctor;

private LocalDate dateOfReporting;


public AdministrativeIncident() {
super(IncidentType.administrative);
}
}
54 changes: 54 additions & 0 deletions server/src/main/java/de/coronavirus/imis/domain/Incident.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package de.coronavirus.imis.domain;

import de.coronavirus.imis.config.domain.User;
import de.coronavirus.imis.services.RandomService;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.envers.Audited;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.UUID;

import static org.hibernate.envers.RelationTargetAuditMode.NOT_AUDITED;

@Getter
@Setter
@Accessors(chain = true)
@EntityListeners(AuditingEntityListener.class)
@Audited
@MappedSuperclass
public abstract class Incident {

protected Incident (IncidentType type)
{
id = type.toString() + "_" + UUID.randomUUID().toString().replace("-", "");
}

@Id
private String id;

@Audited(targetAuditMode = NOT_AUDITED)
@ManyToOne
private Patient patient;

private String caseId;

@Enumerated(EnumType.STRING)
private EventType eventType;

@LastModifiedDate
private LocalDateTime versionTimestamp;

@Audited(targetAuditMode = NOT_AUDITED)
@ManyToOne
@LastModifiedBy
private User versionUser;
}
17 changes: 17 additions & 0 deletions server/src/main/java/de/coronavirus/imis/domain/IncidentType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.coronavirus.imis.domain;

public enum IncidentType {

// lowercase to support direct casting from api route.

test(TestIncident.class),
quarantine(QuarantineIncident.class),
administrative(AdministrativeIncident.class);

public final Class IMPLEMENTATION;

IncidentType(Class implementation) {
this.IMPLEMENTATION = implementation;
}

}
13 changes: 13 additions & 0 deletions server/src/main/java/de/coronavirus/imis/domain/Presumtion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.coronavirus.imis.domain;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Presumtion {

private Illness illness;
private String comment;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.coronavirus.imis.domain;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.envers.Audited;

import javax.persistence.Entity;
import java.time.LocalDate;


@Entity
@Getter
@Setter
@Accessors(chain = true)
@Audited
public class QuarantineIncident extends Incident {

private LocalDate until;

private String comment;

public QuarantineIncident() {
super(IncidentType.quarantine);
}

}
Loading

0 comments on commit e28ee9a

Please sign in to comment.