Skip to content

Commit

Permalink
Merge pull request #34 from LabGraphTeam/fix/refactoring
Browse files Browse the repository at this point in the history
Fix/refactoring
  • Loading branch information
LeonardoMeireles55 authored Jan 26, 2025
2 parents f50dd75 + 6add72e commit 21cf1f8
Show file tree
Hide file tree
Showing 62 changed files with 704 additions and 720 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,29 +145,29 @@ docker-compose up --build --force-recreate

### CoagulationAnalyticsService

Handles analytics related to coagulation tests.
Handles analytic related to coagulation tests.

### BiochemistryAnalyticsService

Handles analytics related to biochemistry tests.
Handles analytic related to biochemistry tests.

### HematologyAnalyticsService

Handles analytics related to hematology tests.
Handles analytic related to hematology tests.

## Controllers

### CoagulationAnalyticsController

Manages endpoints for coagulation analytics.
Manages endpoints for coagulation analytic.

### BiochemistryAnalyticsController

Manages endpoints for biochemistry analytics.
Manages endpoints for biochemistry analytic.

### HematologyAnalyticsController

Manages endpoints for hematology analytics.
Manages endpoints for hematology analytic.

## React Recharts.js Front-end

Expand Down
25 changes: 0 additions & 25 deletions formatFiles.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
req.requestMatchers(HttpMethod.DELETE, "/users/**");

// All other endpoints require authentication
req.anyRequest().authenticated();
req.anyRequest().permitAll();
}).addFilterBefore(securityFilter, UsernamePasswordAuthenticationFilter.class)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package leonardo.labutilities.qualitylabpro.controllers.analytics;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import leonardo.labutilities.qualitylabpro.dtos.analytics.AnalyticsRecord;
import leonardo.labutilities.qualitylabpro.dtos.analytics.MeanAndStdDeviationRecord;
import leonardo.labutilities.qualitylabpro.services.analytics.AnalyticsHelperService;
import leonardo.labutilities.qualitylabpro.dtos.analytics.AnalyticsDTO;
import leonardo.labutilities.qualitylabpro.dtos.analytics.MeanAndStdDeviationDTO;
import leonardo.labutilities.qualitylabpro.services.analytics.AnalyticHelperService;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -28,35 +28,35 @@
@RestController()
public abstract class AnalyticsController extends AnalyticsHelperController {

public AnalyticsController(AnalyticsHelperService analyticsHelperService) {
super(analyticsHelperService);
public AnalyticsController(AnalyticHelperService analyticHelperService) {
super(analyticHelperService);
}

@GetMapping()
public abstract ResponseEntity<CollectionModel<EntityModel<AnalyticsRecord>>> getAllAnalytics(
public abstract ResponseEntity<CollectionModel<EntityModel<AnalyticsDTO>>> getAllAnalytics(
@PageableDefault(sort = "date",
direction = Sort.Direction.DESC) @ParameterObject Pageable pageable);


@GetMapping("/date-range")
public abstract ResponseEntity<Page<AnalyticsRecord>> getAnalyticsDateBetween(
public abstract ResponseEntity<Page<AnalyticsDTO>> getAnalyticsDateBetween(
@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate, @PageableDefault(sort = "date",
direction = Sort.Direction.DESC) @ParameterObject Pageable pageable);

@GetMapping("/level-date-range")
public abstract ResponseEntity<Page<AnalyticsRecord>> getAllAnalyticsByLevelDateRange(
public abstract ResponseEntity<Page<AnalyticsDTO>> getAllAnalyticsByLevelDateRange(
@RequestParam String level, @RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate, @ParameterObject Pageable pageable);

@GetMapping("/name-and-level-date-range")
public abstract ResponseEntity<List<AnalyticsRecord>> getAllAnalyticsByNameAndLevelDateRange(
public abstract ResponseEntity<List<AnalyticsDTO>> getAllAnalyticsByNameAndLevelDateRange(
@RequestParam String name, @RequestParam String level,
@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate);

@GetMapping("/mean-standard-deviation")
public abstract ResponseEntity<MeanAndStdDeviationRecord> getMeanAndStandardDeviation(
public abstract ResponseEntity<MeanAndStdDeviationDTO> getMeanAndStandardDeviation(
@RequestParam String name, @RequestParam String level,
@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package leonardo.labutilities.qualitylabpro.controllers.analytics;

import jakarta.validation.Valid;
import leonardo.labutilities.qualitylabpro.dtos.analytics.AnalyticsRecord;
import leonardo.labutilities.qualitylabpro.dtos.analytics.GroupedMeanAndStdRecordByLevel;
import leonardo.labutilities.qualitylabpro.dtos.analytics.GroupedResultsByLevel;
import leonardo.labutilities.qualitylabpro.dtos.analytics.UpdateAnalyticsMeanRecord;
import leonardo.labutilities.qualitylabpro.services.analytics.AnalyticsHelperService;
import leonardo.labutilities.qualitylabpro.dtos.analytics.AnalyticsDTO;
import leonardo.labutilities.qualitylabpro.dtos.analytics.GroupedMeanAndStdByLevelDTO;
import leonardo.labutilities.qualitylabpro.dtos.analytics.GroupedResultsByLevelDTO;
import leonardo.labutilities.qualitylabpro.dtos.analytics.UpdateAnalyticsMeanDTO;
import leonardo.labutilities.qualitylabpro.services.analytics.AnalyticHelperService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.hateoas.CollectionModel;
Expand All @@ -25,63 +25,63 @@
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

public class AnalyticsHelperController {
private final AnalyticsHelperService analyticsHelperService;
private final AnalyticHelperService analyticHelperService;

public AnalyticsHelperController(AnalyticsHelperService analyticsHelperService) {
this.analyticsHelperService = analyticsHelperService;
public AnalyticsHelperController(AnalyticHelperService analyticHelperService) {
this.analyticHelperService = analyticHelperService;
}

@GetMapping("/{id}")
public ResponseEntity<AnalyticsRecord> getAnalyticsById(@PathVariable Long id) {
return ResponseEntity.ok(analyticsHelperService.findOneById(id));
public ResponseEntity<AnalyticsDTO> getAnalyticsById(@PathVariable Long id) {
return ResponseEntity.ok(analyticHelperService.findOneById(id));
}

@DeleteMapping("/{id}")
@Transactional
public ResponseEntity<Void> deleteAnalyticsResultById(@PathVariable Long id) {
analyticsHelperService.deleteAnalyticsById(id);
analyticHelperService.deleteAnalyticsById(id);
return ResponseEntity.noContent().build();
}

@PostMapping
@Transactional
public ResponseEntity<List<AnalyticsRecord>> postAnalytics(
@Valid @RequestBody List<@Valid AnalyticsRecord> values) {
analyticsHelperService.saveNewAnalyticsRecords(values);
public ResponseEntity<List<AnalyticsDTO>> postAnalytics(
@Valid @RequestBody List<@Valid AnalyticsDTO> values) {
analyticHelperService.saveNewAnalyticsRecords(values);
return ResponseEntity.status(201).build();
}

@PatchMapping()
public ResponseEntity<Void> updateAnalyticsMean(
@Valid @RequestBody UpdateAnalyticsMeanRecord updateAnalyticsMeanRecord) {
analyticsHelperService.updateAnalyticsMeanByNameAndLevelAndLevelLot(
updateAnalyticsMeanRecord.name(), updateAnalyticsMeanRecord.level(),
updateAnalyticsMeanRecord.levelLot(), updateAnalyticsMeanRecord.mean());
@Valid @RequestBody UpdateAnalyticsMeanDTO updateAnalyticsMeanDTO) {
analyticHelperService.updateAnalyticsMeanByNameAndLevelAndLevelLot(
updateAnalyticsMeanDTO.name(), updateAnalyticsMeanDTO.level(),
updateAnalyticsMeanDTO.levelLot(), updateAnalyticsMeanDTO.mean());
return ResponseEntity.noContent().build();
}

@GetMapping("/grouped-by-level")
public ResponseEntity<List<GroupedResultsByLevel>> getGroupedByLevel(@RequestParam String name,
@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate) {
List<GroupedResultsByLevel> groupedData =
analyticsHelperService.findAnalyticsWithGroupedResults(name, startDate, endDate);
public ResponseEntity<List<GroupedResultsByLevelDTO>> getGroupedByLevel(@RequestParam String name,
@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate) {
List<GroupedResultsByLevelDTO> groupedData =
analyticHelperService.findAnalyticsWithGroupedResults(name, startDate, endDate);
return ResponseEntity.ok(groupedData);
}

@GetMapping("/grouped-by-level/mean-deviation")
public ResponseEntity<List<GroupedMeanAndStdRecordByLevel>> getMeanAndDeviationGrouped(
public ResponseEntity<List<GroupedMeanAndStdByLevelDTO>> getMeanAndDeviationGrouped(
@RequestParam String name, @RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate) {
List<GroupedMeanAndStdRecordByLevel> groupedData = analyticsHelperService
List<GroupedMeanAndStdByLevelDTO> groupedData = analyticHelperService
.calculateGroupedMeanAndStandardDeviation(name, startDate, endDate);
return ResponseEntity.ok(groupedData);
}

public ResponseEntity<CollectionModel<EntityModel<AnalyticsRecord>>> getAllAnalyticsWithLinks(
public ResponseEntity<CollectionModel<EntityModel<AnalyticsDTO>>> getAllAnalyticsWithLinks(
List<String> names, Pageable pageable) {
Page<AnalyticsRecord> resultsList =
analyticsHelperService.findAnalyticsPagedByNameIn(names, pageable);
Page<AnalyticsDTO> resultsList =
analyticHelperService.findAnalyticsPagedByNameIn(names, pageable);

var entityModels = resultsList.getContent().stream()
.map(record -> createEntityModel(record, pageable)).collect(Collectors.toList());
Expand All @@ -90,10 +90,10 @@ public ResponseEntity<CollectionModel<EntityModel<AnalyticsRecord>>> getAllAnaly
return ResponseEntity.ok(result);
}

public ResponseEntity<CollectionModel<EntityModel<AnalyticsRecord>>> getAnalyticsByDateBetweenWithLinks(
public ResponseEntity<CollectionModel<EntityModel<AnalyticsDTO>>> getAnalyticsByDateBetweenWithLinks(
List<String> names, LocalDateTime startDate, LocalDateTime endDate, Pageable pageable) {

Page<AnalyticsRecord> analyticsRecordPaged = analyticsHelperService
Page<AnalyticsDTO> analyticsRecordPaged = analyticHelperService
.findAnalyticsByNameInAndDateBetweenWithLinks(names, startDate, endDate, pageable);

if (analyticsRecordPaged == null) {
Expand All @@ -109,16 +109,16 @@ public ResponseEntity<CollectionModel<EntityModel<AnalyticsRecord>>> getAnalytic
return ResponseEntity.ok(result);
}

EntityModel<AnalyticsRecord> createEntityModel(AnalyticsRecord record, Pageable pageable) {
EntityModel<AnalyticsDTO> createEntityModel(AnalyticsDTO record, Pageable pageable) {
return EntityModel.of(record, Link.of(ServletUriComponentsBuilder.fromCurrentContextPath()
.path("/backend-api")
.path(linkTo(methodOn(getClass()).getAnalyticsById(record.id())).toUri().getPath())
.toUriString()).withSelfRel());
}

private CollectionModel<EntityModel<AnalyticsRecord>> addPaginationLinks(
CollectionModel<EntityModel<AnalyticsRecord>> collectionModel,
Page<AnalyticsRecord> page, Pageable pageable) {
private CollectionModel<EntityModel<AnalyticsDTO>> addPaginationLinks(
CollectionModel<EntityModel<AnalyticsDTO>> collectionModel,
Page<AnalyticsDTO> page, Pageable pageable) {

UriComponentsBuilder uriBuilder =
ServletUriComponentsBuilder.fromCurrentRequest().replacePath("/backend-api"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package leonardo.labutilities.qualitylabpro.controllers.analytics;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import leonardo.labutilities.qualitylabpro.dtos.analytics.AnalyticsRecord;
import leonardo.labutilities.qualitylabpro.dtos.analytics.MeanAndStdDeviationRecord;
import leonardo.labutilities.qualitylabpro.services.analytics.BiochemistryAnalyticsService;
import leonardo.labutilities.qualitylabpro.dtos.analytics.AnalyticsDTO;
import leonardo.labutilities.qualitylabpro.dtos.analytics.MeanAndStdDeviationDTO;
import leonardo.labutilities.qualitylabpro.services.analytics.BiochemistryAnalyticService;
import leonardo.labutilities.qualitylabpro.utils.constants.AvailableBiochemistryAnalytics;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Page;
Expand All @@ -30,25 +30,25 @@ public class BiochemistryAnalyticsController extends AnalyticsController {

private static final List<String> names =
new AvailableBiochemistryAnalytics().availableBioAnalytics();
private final BiochemistryAnalyticsService biochemistryAnalyticsService;
private final BiochemistryAnalyticService biochemistryAnalyticsService;

public BiochemistryAnalyticsController(
BiochemistryAnalyticsService biochemistryAnalyticsService) {
BiochemistryAnalyticService biochemistryAnalyticsService) {
super(biochemistryAnalyticsService);
this.biochemistryAnalyticsService = biochemistryAnalyticsService;
}

@Override
@GetMapping()
public ResponseEntity<CollectionModel<EntityModel<AnalyticsRecord>>> getAllAnalytics(
public ResponseEntity<CollectionModel<EntityModel<AnalyticsDTO>>> getAllAnalytics(
@PageableDefault(sort = "date",
direction = Sort.Direction.DESC) @ParameterObject Pageable pageable) {
return this.getAllAnalyticsWithLinks(names, pageable);
}

@Override
@GetMapping("/date-range")
public ResponseEntity<Page<AnalyticsRecord>> getAnalyticsDateBetween(
public ResponseEntity<Page<AnalyticsDTO>> getAnalyticsDateBetween(
@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate, @PageableDefault(sort = "date",
direction = Sort.Direction.DESC) @ParameterObject Pageable pageable) {
Expand All @@ -58,7 +58,7 @@ public ResponseEntity<Page<AnalyticsRecord>> getAnalyticsDateBetween(

@Override
@GetMapping("/level-date-range")
public ResponseEntity<Page<AnalyticsRecord>> getAllAnalyticsByLevelDateRange(
public ResponseEntity<Page<AnalyticsDTO>> getAllAnalyticsByLevelDateRange(
@RequestParam String level, @RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate, @ParameterObject Pageable pageable) {
return ResponseEntity.ok(biochemistryAnalyticsService.findAnalyticsByNameInByLevel(names,
Expand All @@ -67,7 +67,7 @@ public ResponseEntity<Page<AnalyticsRecord>> getAllAnalyticsByLevelDateRange(

@Override
@GetMapping("/name-and-level-date-range")
public ResponseEntity<List<AnalyticsRecord>> getAllAnalyticsByNameAndLevelDateRange(
public ResponseEntity<List<AnalyticsDTO>> getAllAnalyticsByNameAndLevelDateRange(
@RequestParam String name, @RequestParam String level,
@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate) {
Expand All @@ -78,7 +78,7 @@ public ResponseEntity<List<AnalyticsRecord>> getAllAnalyticsByNameAndLevelDateRa

@Override
@GetMapping("/mean-standard-deviation")
public ResponseEntity<MeanAndStdDeviationRecord> getMeanAndStandardDeviation(
public ResponseEntity<MeanAndStdDeviationDTO> getMeanAndStandardDeviation(
@RequestParam String name, @RequestParam String level,
@RequestParam("startDate") LocalDateTime startDate,
@RequestParam("endDate") LocalDateTime endDate) {
Expand Down
Loading

0 comments on commit 21cf1f8

Please sign in to comment.