Skip to content

Commit

Permalink
poc for using a json view for public device data
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSass authored and emyl3 committed Dec 3, 2024
1 parent a5afa4c commit d587d5c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package gov.cdc.usds.simplereport.api.devicetype;

import com.fasterxml.jackson.annotation.JsonView;
import gov.cdc.usds.simplereport.api.model.errors.DryRunException;
import gov.cdc.usds.simplereport.db.model.DeviceType;
import gov.cdc.usds.simplereport.service.DeviceTypeService;
import gov.cdc.usds.simplereport.service.DeviceTypeSyncService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequiredArgsConstructor
public class DeviceTypeController {
@Autowired private DeviceTypeSyncService deviceTypeSyncService;
private final DeviceTypeSyncService deviceTypeSyncService;
private final DeviceTypeService deviceTypeService;

@GetMapping("/devices/sync")
public void syncDevices(@RequestParam boolean dryRun) {
Expand All @@ -21,4 +27,14 @@ public void syncDevices(@RequestParam boolean dryRun) {
log.info("Dry run");
}
}

@GetMapping("/devices")
@JsonView(PublicDeviceType.class)
public List<DeviceType> getDevices() {
try {
return deviceTypeService.fetchDeviceTypes();
} catch (Exception e) {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package gov.cdc.usds.simplereport.api.devicetype;

public interface PublicDeviceType {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gov.cdc.usds.simplereport.db.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;
import gov.cdc.usds.simplereport.api.devicetype.PublicDeviceType;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -23,26 +24,32 @@
public class DeviceType extends EternalAuditedEntity {

@Column(nullable = false)
@JsonView(PublicDeviceType.class)
private String name;

@Column(nullable = false)
@JsonView(PublicDeviceType.class)
private String manufacturer;

@Column(nullable = false)
@JsonView(PublicDeviceType.class)
private String model;

@JoinTable(
name = "device_specimen_type",
joinColumns = @JoinColumn(name = "device_type_id"),
inverseJoinColumns = @JoinColumn(name = "specimen_type_id"))
@OneToMany(fetch = FetchType.LAZY)
@JsonView(PublicDeviceType.class)
private List<SpecimenType> swabTypes;

@Column(nullable = false)
@JsonView(PublicDeviceType.class)
private int testLength;

@JsonIgnore
// @JsonIgnore
@OneToMany(mappedBy = "deviceTypeId", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonView(PublicDeviceType.class)
List<DeviceTypeDisease> supportedDiseaseTestPerformed = new ArrayList<>();

protected DeviceType() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gov.cdc.usds.simplereport.db.model;

import com.fasterxml.jackson.annotation.JsonView;
import gov.cdc.usds.simplereport.api.devicetype.PublicDeviceType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
Expand All @@ -19,19 +21,40 @@
public class DeviceTypeDisease extends IdentifiedEntity {

@Column(name = "device_type_id")
@JsonView(PublicDeviceType.class)
private UUID deviceTypeId;

@ManyToOne
@JoinColumn(name = "supported_disease_id")
private SupportedDisease supportedDisease;

@Column private String testPerformedLoincCode;
@Column private String testPerformedLoincLongName;
@Column private String equipmentUid;
@Column private String equipmentUidType;
@Column private String testkitNameId;
@Column private String testOrderedLoincCode;
@Column private String testOrderedLoincLongName;
@Column
@JsonView(PublicDeviceType.class)
private String testPerformedLoincCode;

@Column
@JsonView(PublicDeviceType.class)
private String testPerformedLoincLongName;

@Column
@JsonView(PublicDeviceType.class)
private String equipmentUid;

@Column
@JsonView(PublicDeviceType.class)
private String equipmentUidType;

@Column
@JsonView(PublicDeviceType.class)
private String testkitNameId;

@Column
@JsonView(PublicDeviceType.class)
private String testOrderedLoincCode;

@Column
@JsonView(PublicDeviceType.class)
private String testOrderedLoincLongName;

@Override
public boolean equals(Object o) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gov.cdc.usds.simplereport.db.model;

import com.fasterxml.jackson.annotation.JsonView;
import gov.cdc.usds.simplereport.api.devicetype.PublicDeviceType;
import gov.cdc.usds.simplereport.validators.NumericCode;
import gov.cdc.usds.simplereport.validators.RequiredNumericCode;
import jakarta.persistence.Column;
Expand All @@ -12,16 +14,23 @@
public class SpecimenType extends EternalAuditedEntity {

@Column(nullable = false)
@JsonView(PublicDeviceType.class)
private String name;

@Column(nullable = false, updatable = false)
@RequiredNumericCode
@NaturalId
@JsonView(PublicDeviceType.class)
private String typeCode;

@Column private String collectionLocationName;
@Column
@JsonView(PublicDeviceType.class)
private String collectionLocationName;

@Column @NumericCode private String collectionLocationCode;
@Column
@NumericCode
@JsonView(PublicDeviceType.class)
private String collectionLocationCode;

protected SpecimenType() {} // for hibernate

Expand Down

0 comments on commit d587d5c

Please sign in to comment.