This repository has been archived by the owner on Jun 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
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 #278 from ImisDevelopers/feature/225-state-table
Close #225
- Loading branch information
Showing
23 changed files
with
640 additions
and
13 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
59 changes: 59 additions & 0 deletions
59
server/src/main/java/de/coronavirus/imis/api/IncidentController.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,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); | ||
} | ||
|
||
} |
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
12 changes: 0 additions & 12 deletions
12
server/src/main/java/de/coronavirus/imis/api/dto/UpdateLabTestDTO.java
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
server/src/main/java/de/coronavirus/imis/config/AuditConfiguration.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,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()); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
server/src/main/java/de/coronavirus/imis/config/AuditorAwareImpl.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,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(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
server/src/main/java/de/coronavirus/imis/config/PersistanceConfig.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,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); | ||
} | ||
|
||
} |
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
35 changes: 35 additions & 0 deletions
35
server/src/main/java/de/coronavirus/imis/domain/AdministrativeIncident.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,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
54
server/src/main/java/de/coronavirus/imis/domain/Incident.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,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
17
server/src/main/java/de/coronavirus/imis/domain/IncidentType.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,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
13
server/src/main/java/de/coronavirus/imis/domain/Presumtion.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,13 @@ | ||
package de.coronavirus.imis.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class Presumtion { | ||
|
||
private Illness illness; | ||
private String comment; | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
server/src/main/java/de/coronavirus/imis/domain/QuarantineIncident.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,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); | ||
} | ||
|
||
} |
Oops, something went wrong.