diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/AuditController.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/AuditController.java index 120aacbf..e49b55e9 100644 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/AuditController.java +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/AuditController.java @@ -29,9 +29,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.nimbusds.oauth2.sdk.util.StringUtils; - import ca.bc.gov.hlth.hnweb.model.rest.StatusEnum; +import ca.bc.gov.hlth.hnweb.model.rest.auditreport.AuditOrganization; import ca.bc.gov.hlth.hnweb.model.rest.auditreport.AuditRecord; import ca.bc.gov.hlth.hnweb.model.rest.auditreport.AuditReportRequest; import ca.bc.gov.hlth.hnweb.model.rest.auditreport.AuditReportResponse; @@ -89,10 +88,13 @@ public ResponseEntity getAuditReport(@Valid @RequestBody Au * @return list of organization */ @GetMapping("/organizations") - public ResponseEntity> getOrganizations() { - List organizations = convertOrganization(auditService.getOrganizations()); - ResponseEntity> responseEntity = ResponseEntity.ok(organizations); - return responseEntity; + public ResponseEntity> getOrganizations() { + List organizations = auditService.getOrganizations(); + List auditOrganizations = organizations.stream() + .map(o -> new AuditOrganization(o.getOrganization(), o.getOrganizationName())) + .collect(Collectors.toList()); + + return ResponseEntity.ok(auditOrganizations); } /** @@ -130,6 +132,7 @@ private List convertReport(List affectedParties) { affectedParties.forEach(affectedParty -> { AuditRecord model = new AuditRecord(); model.setOrganization(affectedParty.getTransaction().getOrganization()); + model.setOrganizationName(affectedParty.getTransaction().getOrganizationName()); model.setSpgRole(affectedParty.getTransaction().getSpgRole()); model.setTransactionId(affectedParty.getTransaction().getTransactionId().toString()); model.setType(affectedParty.getTransaction().getType()); @@ -144,11 +147,6 @@ private List convertReport(List affectedParties) { return auditReportResponse; } - private List convertOrganization(List organizations) { - return organizations.stream().filter(org -> StringUtils.isNotBlank(org.getOrganization())) - .map(org -> org.getOrganization()).collect(Collectors.toList()); - } - private LocalDateTime convertDate(Date date) { return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime(); } diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/auditreport/AuditOrganization.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/auditreport/AuditOrganization.java new file mode 100644 index 00000000..6096bb2a --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/auditreport/AuditOrganization.java @@ -0,0 +1,31 @@ +package ca.bc.gov.hlth.hnweb.model.rest.auditreport; + +public class AuditOrganization { + + private String id; + + private String name; + + public AuditOrganization(String id, String name) { + super(); + this.id = id; + this.name = name; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/auditreport/AuditRecord.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/auditreport/AuditRecord.java index 07d5de2e..b1a1b3f3 100644 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/auditreport/AuditRecord.java +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/auditreport/AuditRecord.java @@ -8,6 +8,8 @@ public class AuditRecord { private String organization; + private String organizationName; + private String userId; private LocalDateTime transactionStartTime; @@ -44,6 +46,14 @@ public void setOrganization(String organization) { this.organization = organization; } + public String getOrganizationName() { + return organizationName; + } + + public void setOrganizationName(String organizationName) { + this.organizationName = organizationName; + } + public String getUserId() { return userId; } diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/Organization.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/Organization.java index 40700de0..e05d5cee 100644 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/Organization.java +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/Organization.java @@ -1,5 +1,7 @@ package ca.bc.gov.hlth.hnweb.persistence.entity; +import javax.persistence.Basic; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @@ -7,8 +9,13 @@ public class Organization { @Id + @Column(name = "organization") private String organization; + @Basic + @Column(name = "organization_name") + private String organizationName; + public String getOrganization() { return organization; } @@ -17,11 +24,20 @@ public void setOrganization(String organizationId) { this.organization = organizationId; } + public String getOrganizationName() { + return organizationName; + } + + public void setOrganizationName(String organizationName) { + this.organizationName = organizationName; + } + @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((organization == null) ? 0 : organization.hashCode()); + result = prime * result + ((organizationName == null) ? 0 : organizationName.hashCode()); return result; } @@ -39,7 +55,11 @@ public boolean equals(Object obj) { return false; } else if (!organization.equals(other.organization)) return false; - + if (organizationName == null) { + if (other.organizationName != null) + return false; + } else if (!organizationName.equals(other.organizationName)) + return false; return true; } diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/Transaction.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/Transaction.java index 4da13eab..75faed91 100644 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/Transaction.java +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/Transaction.java @@ -62,6 +62,13 @@ public class Transaction { @Column(name = "organization") private String organization; + /** + * Organization Name of the user that initiated the transaction + */ + @Basic + @Column(name = "organization_name") + private String organizationName; + /** * SPG of the user performing the transaction */ @@ -69,14 +76,6 @@ public class Transaction { @Column(name = "spg_role") private String spgRole; - public String getSpgRole() { - return spgRole; - } - - public void setSpgRole(String spgRole) { - this.spgRole = spgRole; - } - /** * ID of the user that initiated the transaction */ @@ -139,6 +138,22 @@ public void setOrganization(String organization) { this.organization = organization; } + public String getOrganizationName() { + return organizationName; + } + + public void setOrganizationName(String organizationName) { + this.organizationName = organizationName; + } + + public String getSpgRole() { + return spgRole; + } + + public void setSpgRole(String spgRole) { + this.spgRole = spgRole; + } + public String getUserId() { return userId; } diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/repository/OrganizationRepository.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/repository/OrganizationRepository.java index 0b9a33eb..b323e9b4 100644 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/repository/OrganizationRepository.java +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/repository/OrganizationRepository.java @@ -1,5 +1,7 @@ package ca.bc.gov.hlth.hnweb.persistence.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -11,5 +13,10 @@ public interface OrganizationRepository extends JpaRepository findUnique(); } diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/security/SecurityUtil.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/security/SecurityUtil.java index 11b920c2..d8ed7384 100644 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/security/SecurityUtil.java +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/security/SecurityUtil.java @@ -31,6 +31,8 @@ public class SecurityUtil { private static final String ORGANIZATION_ID = "id"; + private static final String ORGANIZATION_NAME = "name"; + private static final String USER_ROLES = "roles"; private static final String UNKNOWN_ROLE = "UNKNOWN"; @@ -54,7 +56,7 @@ public static UserInfo loadUserInfo() { Jwt jwt = (Jwt) auth.getPrincipal(); UserInfo userInfo = new UserInfo(); - userInfo.setOrganization(extractOrganization(jwt)); + extractOrganization(jwt, userInfo); List roles = loadRoles(jwt); userInfo.setRoles(roles); @@ -111,15 +113,16 @@ public static String loadSPGBasedOnTransactionType(UserInfo userInfo, Transactio } return UNKNOWN_ROLE; } - - private static String extractOrganization(Jwt jwt) { + + + private static void extractOrganization(Jwt jwt, UserInfo userInfo) { try { ObjectMapper mapper = new ObjectMapper(); - JsonNode node = mapper.readTree((String) jwt.getClaim(CLAIM_ORGANIZATION)); - return node.get(ORGANIZATION_ID).asText(); + JsonNode node = mapper.readTree((String)jwt.getClaim(CLAIM_ORGANIZATION)); + userInfo.setOrganization(node.get(ORGANIZATION_ID).asText()); + userInfo.setOrganizationName(node.get(ORGANIZATION_NAME).asText()); } catch (Exception e) { logger.warn("User {} does not have claim {} set", jwt.getClaim(CLAIM_USERNAME), CLAIM_ORGANIZATION); - return null; } } diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/security/UserInfo.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/security/UserInfo.java index c2740eee..41610cc4 100644 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/security/UserInfo.java +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/security/UserInfo.java @@ -11,6 +11,7 @@ public class UserInfo { private String username; private String userId; private String organization; + private String organizationName; private String role; private String sessionState; private List roles; @@ -19,18 +20,20 @@ public UserInfo() { super(); } - public UserInfo(String username, String organization, String role) { + public UserInfo(String username, String organization, String organizationName, String role) { super(); this.username = username; this.organization = organization; + this.organizationName = organizationName; this.role = role; } - public UserInfo(String username, String userId, String organization, String role, String sessionState) { + public UserInfo(String username, String userId, String organization, String organizationName, String role, String sessionState) { super(); this.username = username; this.userId = userId; this.organization = organization; + this.organizationName = organizationName; this.role = role; this.sessionState = sessionState; } @@ -59,6 +62,14 @@ public void setOrganization(String organization) { this.organization = organization; } + public String getOrganizationName() { + return organizationName; + } + + public void setOrganizationName(String organizationName) { + this.organizationName = organizationName; + } + public String getRole() { return StringUtils.join(this.roles, " "); } @@ -81,8 +92,8 @@ public void setSessionState(String sessionState) { @Override public String toString() { - return "UserInfo [username=" + username + ", userId=" + userId + ", organization=" + organization + ", role=" - + role + ", sessionState=" + sessionState + "]"; + return "UserInfo [username=" + username + ", userId=" + userId + ", organization=" + organization + ", organizationName=" + + organizationName + ", role=" + role + ", sessionState=" + sessionState + "]"; } } \ No newline at end of file diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/service/AuditService.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/service/AuditService.java index f8e0840c..bab091b0 100644 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/service/AuditService.java +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/service/AuditService.java @@ -65,7 +65,7 @@ public class AuditService { public static final String DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; - private static final String[] HEADERS = { "Type", "Organization", "SPG", "User ID", "Transaction Start Time", + private static final String[] HEADERS = { "Type", "Organization", "Organization Name", "SPG", "User ID", "Transaction Start Time", "Affected Party ID", "Affected Party ID Type", "Transaction ID" }; private static final CSVFormat FORMAT = CSVFormat.DEFAULT.withHeader(HEADERS); @@ -95,6 +95,7 @@ public class AuditService { sortMap.put("affectedPartyId", "identifier"); sortMap.put("affectedPartyType", "identifierType"); sortMap.put("organization", "transaction.organization"); + sortMap.put("organizationName", "transaction.organizationName"); sortMap.put("spgRole", "transaction.spgRole"); sortMap.put("transactionStartTime", "transaction.startTime"); sortMap.put("type", "transaction.type"); @@ -118,15 +119,16 @@ public Transaction createTransaction(String sourceIP, TransactionType type) { } catch (Exception e) { // Ignore } - transaction.setOrganization(userInfo != null ? userInfo.getOrganization() : null); + transaction.setOrganization(userInfo != null ? userInfo.getOrganization(): null); + transaction.setOrganizationName(userInfo != null ? userInfo.getOrganizationName(): null); transaction.setServer(getServer()); transaction.setSessionId(userInfo != null ? userInfo.getSessionState() : null); transaction.setSourceIp(sourceIP); + transaction.setSpgRole(SecurityUtil.loadSPGBasedOnTransactionType(userInfo, type)); transaction.setStartTime(new Date()); transaction.setTransactionId(UUID.randomUUID()); transaction.setType(type.getValue()); transaction.setUserId(userInfo != null ? userInfo.getUsername() : null); - transaction.setSpgRole(SecurityUtil.loadSPGBasedOnTransactionType(userInfo, type)); return transactionRepository.save(transaction); } @@ -239,7 +241,7 @@ public AffectedParty createAffectedParty(Transaction transaction, IdentifierType * @return list of organization. */ public List getOrganizations() { - return organizationRepository.findAll(Sort.by("organization")); + return organizationRepository.findUnique(); } /** @@ -302,8 +304,8 @@ private ByteArrayInputStream writeDataToCsv(final List auditReports try (ByteArrayOutputStream stream = new ByteArrayOutputStream(); CSVPrinter printer = new CSVPrinter(new PrintWriter(stream), FORMAT)) { for (AuditRecord auditRecord : auditReports) { - List auditData = Arrays.asList(String.valueOf(auditRecord.getType()), - auditRecord.getOrganization(), auditRecord.getSpgRole(), auditRecord.getUserId(), + List auditData = Arrays.asList(String.valueOf(auditRecord.getType()), + auditRecord.getOrganization(), auditRecord.getOrganizationName(), auditRecord.getSpgRole(), auditRecord.getUserId(), convertLocalDateTime(auditRecord.getTransactionStartTime()), auditRecord.getAffectedPartyId(), auditRecord.getAffectedPartyType(), auditRecord.getTransactionId()); diff --git a/backend/src/main/resources/database/audit_report_mat_view.sql b/backend/src/main/resources/database/audit_report_mat_view.sql index 05fd0be1..b4e358be 100644 --- a/backend/src/main/resources/database/audit_report_mat_view.sql +++ b/backend/src/main/resources/database/audit_report_mat_view.sql @@ -6,7 +6,8 @@ DROP MATERIALIZED VIEW mspdirect.organization; CREATE MATERIALIZED VIEW mspdirect.organization AS select DISTINCT - t.organization as organization + t.organization as organization, + t.organization_name as organization_name from mspdirect.transaction t where organization is not null diff --git a/backend/src/test/java/ca/bc/gov/hlth/hnweb/BaseControllerTest.java b/backend/src/test/java/ca/bc/gov/hlth/hnweb/BaseControllerTest.java index 77242cb1..b5fdf133 100644 --- a/backend/src/test/java/ca/bc/gov/hlth/hnweb/BaseControllerTest.java +++ b/backend/src/test/java/ca/bc/gov/hlth/hnweb/BaseControllerTest.java @@ -53,7 +53,7 @@ static void setUp() throws IOException { mockBackEnd.start(0); mockStatic = Mockito.mockStatic(SecurityUtil.class); - mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "3c0fc3b5-45f8-4745-afa9-b7b04978023d", "00000010", "hnweb-user", UUID.randomUUID().toString())); + mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "3c0fc3b5-45f8-4745-afa9-b7b04978023d", "00000010", "Ministry of Health", "hnweb-user", UUID.randomUUID().toString())); } @AfterAll diff --git a/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/AuditControllerTest.java b/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/AuditControllerTest.java index 0250b4ca..0381a1b2 100644 --- a/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/AuditControllerTest.java +++ b/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/AuditControllerTest.java @@ -1,6 +1,7 @@ package ca.bc.gov.hlth.hnweb.controller; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; @@ -19,6 +20,7 @@ import org.springframework.http.ResponseEntity; import ca.bc.gov.hlth.hnweb.BaseControllerTest; +import ca.bc.gov.hlth.hnweb.model.rest.auditreport.AuditOrganization; import ca.bc.gov.hlth.hnweb.model.rest.auditreport.AuditRecord; import ca.bc.gov.hlth.hnweb.model.rest.auditreport.AuditReportRequest; import ca.bc.gov.hlth.hnweb.model.rest.auditreport.AuditReportResponse; @@ -49,15 +51,49 @@ public class AuditControllerTest extends BaseControllerTest { @Test public void testGetOrganization() throws Exception { createOrganization(); - ResponseEntity> organization = auditReportController.getOrganizations(); + ResponseEntity> response = auditReportController.getOrganizations(); - assertEquals(HttpStatus.OK, organization.getStatusCode()); - List orgs = organization.getBody(); + assertEquals(HttpStatus.OK, response.getStatusCode()); + List orgs = response.getBody(); assertNotNull(orgs); // Check the number of valid records assertEquals(1, orgs.size()); + + AuditOrganization org = orgs.get(0); + + assertEquals("00000010", org.getId()); + assertEquals("Ministry of Health", org.getName()); + } + + @Test + public void testGetOrganization_multiple() throws Exception { + createOrganization(); + + // Create an additional "older" organization without the Name captured + Organization orgNoName = new Organization(); + orgNoName.setOrganization("00000020"); + orgNoName.setOrganizationName(null); + organizationRepository.save(orgNoName); + + ResponseEntity> response = auditReportController.getOrganizations(); + assertEquals(HttpStatus.OK, response.getStatusCode()); + List orgs = response.getBody(); + + assertNotNull(orgs); + // Check the number of valid records + assertEquals(2, orgs.size()); + + AuditOrganization org1 = orgs.get(0); + + assertEquals("00000010", org1.getId()); + assertEquals("Ministry of Health", org1.getName()); + + AuditOrganization org2 = orgs.get(1); + + assertEquals("00000020", org2.getId()); + assertNull(org2.getName()); } @Test @@ -287,34 +323,40 @@ public void testGetAuditReport_downloadCSV() throws IOException { ResponseEntity downloadReport = auditReportController.downloadAuditReport(auditReportRequest, createHttpServletRequest()); - - List reportData = new ArrayList(); - InputStream downloadData = downloadReport.getBody().getInputStream(); - read(downloadData, reportData); - - assertEquals(HttpStatus.OK, downloadReport.getStatusCode()); - - // Check csv headers and data - assertEquals("Type", reportData.get(0)); - assertEquals("Organization", reportData.get(1)); - assertEquals("SPG", reportData.get(2)); - assertEquals("User ID", reportData.get(3)); - assertEquals("Transaction Start Time", reportData.get(4)); - assertEquals("Affected Party ID", reportData.get(5)); - assertEquals("Affected Party ID Type", reportData.get(6)); - assertEquals("Transaction ID\r\n" + "CHECK_ELIGIBILITY", reportData.get(7)); - assertEquals("00000010", reportData.get(8)); - assertEquals("TRAININGHEALTHAUTH", reportData.get(9)); - assertEquals("hnweb1", reportData.get(10)); - assertEquals("2022-08-05T00:00:00", reportData.get(11)); - assertEquals("PHN", reportData.get(12)); - - // Check the last (40th) record - assertEquals("00000010", reportData.get(239)); - assertEquals("TRAININGHEALTHAUTH", reportData.get(240)); - assertEquals("hnweb1", reportData.get(241)); - assertEquals("2022-08-05T00:00:00", reportData.get(242)); - assertEquals("PHN", reportData.get(243)); + + List reportData = new ArrayList(); + InputStream downloadData = downloadReport.getBody().getInputStream(); + read(downloadData, reportData); + + assertEquals(HttpStatus.OK, downloadReport.getStatusCode()); + + //Check csv headers and data + assertEquals("Type", reportData.get(0)); + assertEquals("Organization", reportData.get(1)); + assertEquals("Organization Name", reportData.get(2)); + assertEquals("SPG", reportData.get(3)); + assertEquals("User ID", reportData.get(4)); + assertEquals("Transaction Start Time", reportData.get(5)); + assertEquals("Affected Party ID", reportData.get(6)); + assertEquals("Affected Party ID Type", reportData.get(7)); + assertEquals("Transaction ID\r\n" + + "CHECK_ELIGIBILITY", reportData.get(8)); + assertEquals("00000010", reportData.get(9)); + assertEquals("Ministry of Health", reportData.get(10)); + assertEquals("TRAININGHEALTHAUTH", reportData.get(11)); + assertEquals("hnweb1", reportData.get(12)); + assertEquals("2022-08-05T00:00:00", reportData.get(13)); + assertEquals("800000001", reportData.get(14)); + assertEquals("PHN", reportData.get(15)); + + //Check the last (40th) record + assertEquals("00000010", reportData.get(321)); + assertEquals("Ministry of Health", reportData.get(322)); + assertEquals("TRAININGHEALTHAUTH", reportData.get(323)); + assertEquals("hnweb1", reportData.get(324)); + assertEquals("2022-08-05T00:00:00", reportData.get(325)); + assertEquals("800000001", reportData.get(326)); + assertEquals("PHN", reportData.get(327)); } @Test @@ -340,34 +382,41 @@ public void testGetAuditReport_downloadCSV_sortDesc() throws IOException { ResponseEntity downloadReport = auditReportController.downloadAuditReport(auditReportRequest, createHttpServletRequest()); + + List reportData = new ArrayList(); + InputStream downloadData = downloadReport.getBody().getInputStream(); + read(downloadData, reportData); + + assertEquals(HttpStatus.OK, downloadReport.getStatusCode()); + + //Check csv headers and data + assertEquals("Type", reportData.get(0)); + assertEquals("Organization", reportData.get(1)); + assertEquals("Organization Name", reportData.get(2)); + assertEquals("SPG", reportData.get(3)); + assertEquals("User ID", reportData.get(4)); + assertEquals("Transaction Start Time", reportData.get(5)); + assertEquals("Affected Party ID", reportData.get(6)); + assertEquals("Affected Party ID Type", reportData.get(7)); + assertEquals("Transaction ID\r\n" + + "PHN_INQUIRY", reportData.get(8)); + assertEquals("00000010", reportData.get(9)); + assertEquals("Ministry of Health", reportData.get(10)); + assertEquals("TRAININGHEALTHAUTH", reportData.get(11)); + assertEquals("hnweb1", reportData.get(12)); + assertEquals("2022-08-05T00:00:00", reportData.get(13)); + assertEquals("800000001", reportData.get(14)); + assertEquals("PHN", reportData.get(15)); + + //Check the last (40th) record + assertEquals("00000010", reportData.get(321)); + assertEquals("Ministry of Health", reportData.get(322)); + assertEquals("TRAININGHEALTHAUTH", reportData.get(323)); + assertEquals("hnweb1", reportData.get(324)); + assertEquals("2022-08-05T00:00:00", reportData.get(325)); + assertEquals("800000001", reportData.get(326)); + assertEquals("PHN", reportData.get(327)); - List reportData = new ArrayList(); - InputStream downloadData = downloadReport.getBody().getInputStream(); - read(downloadData, reportData); - - assertEquals(HttpStatus.OK, downloadReport.getStatusCode()); - - // Check csv headers and data - assertEquals("Type", reportData.get(0)); - assertEquals("Organization", reportData.get(1)); - assertEquals("SPG", reportData.get(2)); - assertEquals("User ID", reportData.get(3)); - assertEquals("Transaction Start Time", reportData.get(4)); - assertEquals("Affected Party ID", reportData.get(5)); - assertEquals("Affected Party ID Type", reportData.get(6)); - assertEquals("Transaction ID\r\n" + "PHN_INQUIRY", reportData.get(7)); - assertEquals("00000010", reportData.get(8)); - assertEquals("TRAININGHEALTHAUTH", reportData.get(9)); - assertEquals("hnweb1", reportData.get(10)); - assertEquals("2022-08-05T00:00:00", reportData.get(11)); - assertEquals("PHN", reportData.get(12)); - - // Check the last (40th) record - assertEquals("00000010", reportData.get(239)); - assertEquals("TRAININGHEALTHAUTH", reportData.get(240)); - assertEquals("hnweb1", reportData.get(241)); - assertEquals("2022-08-05T00:00:00", reportData.get(242)); - assertEquals("PHN", reportData.get(243)); } private void read(InputStream input, List reportData) throws IOException { @@ -390,6 +439,7 @@ private void read(InputStream input, List reportData) throws IOException private void createOrganization() { Organization org = new Organization(); org.setOrganization("00000010"); + org.setOrganizationName("Ministry of Health"); organizationRepository.save(org); } @@ -399,6 +449,7 @@ private void createAuditReports(int count, TransactionType transactionType) { Transaction transaction = new Transaction(); transaction.setOrganization("00000010"); + transaction.setOrganizationName("Ministry of Health"); transaction.setSpgRole("TRAININGHEALTHAUTH"); transaction.setServer("server1"); transaction.setSessionId("123456"); @@ -411,7 +462,7 @@ private void createAuditReports(int count, TransactionType transactionType) { transactionRepository.save(transaction); AffectedParty affectedParty = new AffectedParty(); - affectedParty.setIdentifier(IdentifierType.PHN.name()); + affectedParty.setIdentifier("800000001"); affectedParty.setIdentifierType(IdentifierType.PHN.getValue()); affectedParty.setDirection(AffectedPartyDirection.INBOUND.getValue()); affectedParty.setTransaction(transaction); diff --git a/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/PatientRegistrationControllerTest.java b/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/PatientRegistrationControllerTest.java index 6455b4b9..d0fbfce3 100644 --- a/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/PatientRegistrationControllerTest.java +++ b/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/PatientRegistrationControllerTest.java @@ -59,7 +59,7 @@ public void testRegistrationHistory_success_payeeWithinGroup_DemoRecord() throws .addHeader(CONTENT_TYPE, MediaType.TEXT_XML_VALUE.toString())); //Override the base setup of the user to ensure we return the User with the User ID mapped to the this Payee Number - mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "3c0fc3b5-45f8-4745-afa9-b7b04978023d", "00000010", "hnweb-user", UUID.randomUUID().toString())); + mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "3c0fc3b5-45f8-4745-afa9-b7b04978023d", "00000010", "Ministry of Health", "hnweb-user", UUID.randomUUID().toString())); PatientRegistrationRequest viewPatientRegisterRequest = new PatientRegistrationRequest(); viewPatientRegisterRequest.setPhn("9879869673"); @@ -88,7 +88,7 @@ public void testRegistrationHistory_success_payeeWithinGroup_NoDemoRecord() thro .addHeader(CONTENT_TYPE, MediaType.TEXT_XML_VALUE.toString())); //Override the base setup of the user to ensure we return the User with the User ID mapped to the this Payee Number - mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "3c0fc3b5-45f8-4745-afa9-b7b04978023d", "00000010", "hnweb-user", UUID.randomUUID().toString())); + mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "3c0fc3b5-45f8-4745-afa9-b7b04978023d", "00000010", "Ministry of Health", "hnweb-user", UUID.randomUUID().toString())); PatientRegistrationRequest viewPatientRegisterRequest = new PatientRegistrationRequest(); viewPatientRegisterRequest.setPhn("9879869673"); @@ -118,7 +118,7 @@ public void testRegistrationHistory_success_diffPayeeWithinGroup() throws Except .addHeader(CONTENT_TYPE, MediaType.TEXT_XML_VALUE.toString())); //Override the base setup of the user to ensure we return the User with the User ID mapped to the this Payee Number - mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "e4414a89-8974-4cff-9677-d9d2df6f9cfb", "00000010", "hnweb-user", UUID.randomUUID().toString())); + mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "e4414a89-8974-4cff-9677-d9d2df6f9cfb", "00000010", "Ministry of Health", "hnweb-user", UUID.randomUUID().toString())); PatientRegistrationRequest viewPatientRegisterRequest = new PatientRegistrationRequest(); viewPatientRegisterRequest.setPhn("9879869673"); @@ -148,7 +148,7 @@ public void testRegistrationHistory_success_diffPayeeOutsideGroup() throws Excep .addHeader(CONTENT_TYPE, MediaType.TEXT_XML_VALUE.toString())); //Override the base setup of the user to ensure we return the User with the User ID mapped to the this Payee Number - mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "e4414a89-8974-4cff-9677-d9d2df6f9cfb", "00000010", "hnweb-user", UUID.randomUUID().toString())); + mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "e4414a89-8974-4cff-9677-d9d2df6f9cfb", "00000010", "Ministry of Health", "hnweb-user", UUID.randomUUID().toString())); PatientRegistrationRequest viewPatientRegisterRequest = new PatientRegistrationRequest(); viewPatientRegisterRequest.setPhn("7363117301"); @@ -178,7 +178,7 @@ public void testRegistrationHistory_warning_NoPBFAndDemographicsRecord() throws .addHeader(CONTENT_TYPE, MediaType.TEXT_XML_VALUE.toString())); //Override the base setup of the user to ensure we return the User with the User ID mapped to the this Payee Number - mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "924917e3-970a-482d-88b5-244be4c19d70", "00000010", "hnweb-user", UUID.randomUUID().toString())); + mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "924917e3-970a-482d-88b5-244be4c19d70", "00000010", "Ministry of Health", "hnweb-user", UUID.randomUUID().toString())); PatientRegistrationRequest viewPatientRegisterRequest = new PatientRegistrationRequest(); viewPatientRegisterRequest.setPhn("7363117302"); @@ -203,7 +203,7 @@ public void testRegistrationHistory_failure_no_payee_mapping_found() { //Note, don't enqueue a response as it is never requested and so will remain queued for next test when they are run together. //Override the base setup of the user to ensure we return the User with the User ID mapped to the this Payee Number - mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "1b85225b-58cc-4430-9dc9-0199057afdff", "00000010", "hnweb-user", UUID.randomUUID().toString())); + mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "1b85225b-58cc-4430-9dc9-0199057afdff", "00000010", "Ministry of Health", "hnweb-user", UUID.randomUUID().toString())); PatientRegistrationRequest viewPatientRegisterRequest = new PatientRegistrationRequest(); viewPatientRegisterRequest.setPhn("9879869673"); @@ -222,7 +222,7 @@ public void testRegistrationHistory_failure_incorrect_payee_mapping_found() thro //Note, don't enqueue a response as it is never requested and so will remain queued for next test when they are run together. //Override the base setup of the user to ensure we return the User with the User ID mapped to the this Payee Number - mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "3c0fc3b5-45f8-4745-afa9-b7b04978023d", "00000010", "hnweb-user", UUID.randomUUID().toString())); + mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "3c0fc3b5-45f8-4745-afa9-b7b04978023d", "00000010", "Ministry of Health", "hnweb-user", UUID.randomUUID().toString())); PatientRegistrationRequest viewPatientRegisterRequest = new PatientRegistrationRequest(); viewPatientRegisterRequest.setPhn("9879869673"); diff --git a/backend/src/test/java/ca/bc/gov/hlth/hnweb/serialization/HL7SerializerTest.java b/backend/src/test/java/ca/bc/gov/hlth/hnweb/serialization/HL7SerializerTest.java index 627b9bf5..3b7ec191 100644 --- a/backend/src/test/java/ca/bc/gov/hlth/hnweb/serialization/HL7SerializerTest.java +++ b/backend/src/test/java/ca/bc/gov/hlth/hnweb/serialization/HL7SerializerTest.java @@ -30,7 +30,7 @@ public class HL7SerializerTest { static void setUp() throws IOException { mockStatic = Mockito.mockStatic(SecurityUtil.class); - mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "00000010", "hnweb-user")); + mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "00000010", "Ministry of Health", "hnweb-user")); } private static MockedStatic mockStatic; diff --git a/backend/src/test/java/ca/bc/gov/hlth/hnweb/service/AuditServiceTest.java b/backend/src/test/java/ca/bc/gov/hlth/hnweb/service/AuditServiceTest.java index 7d7a4cc2..e65d317c 100644 --- a/backend/src/test/java/ca/bc/gov/hlth/hnweb/service/AuditServiceTest.java +++ b/backend/src/test/java/ca/bc/gov/hlth/hnweb/service/AuditServiceTest.java @@ -58,7 +58,7 @@ public class AuditServiceTest { @BeforeAll static void setUp() { mockStatic = Mockito.mockStatic(SecurityUtil.class); - mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "14100f9b-7daa-4938-a833-c8c56a5988e9", "00000010", "hnweb-user", UUID.randomUUID().toString())); + mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "14100f9b-7daa-4938-a833-c8c56a5988e9", "00000010", "Ministry of Health", "hnweb-user", UUID.randomUUID().toString())); } @AfterAll diff --git a/frontend/src/views/reports/AuditReporting.vue b/frontend/src/views/reports/AuditReporting.vue index c8cd5afd..65b62cd6 100644 --- a/frontend/src/views/reports/AuditReporting.vue +++ b/frontend/src/views/reports/AuditReporting.vue @@ -10,9 +10,9 @@ Organization
-
@@ -85,6 +85,7 @@ > + @@ -169,7 +170,7 @@ export default { 'UpdateContractAddress', 'UpdateNumberAndDept', ], - spgOptions: ['AUDITUSER', 'E45', 'ELIGIBILITY', 'MANAGEMSPPAYEENUMBER', 'PBFUSER', 'PREMIUMADMIN', 'PREMIUMADMINPLUS', 'SOCIALSECTOR', 'TRAININGHEALTHAUTH', 'VISARESIDENT'], + spgOptions: ['AUDITUSER', 'E45', 'ELIGIBILITY', 'HELPDESK', 'MANAGEMSPPAYEENUMBER', 'PBFUSER', 'PREMIUMADMIN', 'PREMIUMADMINPLUS', 'SOCIALSECTOR', 'TRAININGHEALTHAUTH', 'VISARESIDENT'], } }, mounted() {