Skip to content

Commit

Permalink
Read SQL Server (#2956)
Browse files Browse the repository at this point in the history
* Read from SQL Server

* Remove copied files

* Fix listecrdata reference

* Fix  listecrdataservice route

* Update listecrdataservice

* Remove moved file

* Revert removing all of my changes becasuse I'm a big idiot.

* Fixing tests

* Add getTotalEcrCountBack back

* Remove duplicated mock

* change types to interfaces

* Add mssql import

* Fix Jest config

* SQL Server ecr table sorting and offset

* Removed moved file

* SQL Server where statement

* Revert type change

* Remove console.logs

* SQL Server listEcrDataService tests, use sqlserver_db, %like$, gettotalecrcount sql server

* Reset after SQL Server tests

* Update containers/ecr-viewer/src/app/services/listEcrDataService.ts

Co-authored-by: austin-hall-skylight <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit hooks

* Get time from SQL Server

* SQL use datetime

---------

Co-authored-by: Josh Nygaard <[email protected]>
Co-authored-by: austin-hall-skylight <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 3, 2024
1 parent 2909ae4 commit 2cfbeda
Show file tree
Hide file tree
Showing 17 changed files with 608 additions and 281 deletions.
5 changes: 2 additions & 3 deletions containers/ecr-viewer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ services:
- ./sql/core.sql:/docker-entrypoint-initdb.d/core.sql
- ./seed-scripts/sql/.pgpass/:/usr/local/lib/.pgpass
- db:/var/lib/postgresql/data
- ./sql/extended.sql:/var/opt/mssql/scripts/extended.sql
environment:
- POSTGRES_USER=postgres
- PGUSER=postgres
Expand All @@ -55,11 +54,11 @@ services:
image: mcr.microsoft.com/mssql/server:2022-latest
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=Password1!
- MSSQL_SA_PASSWORD=${SQL_SERVER_PASSWORD}
ports:
- "1433:1433"
volumes:
- ./seed-scripts/sql/entrypoint.sh:/var/opt/mssql/scripts/entrypoint.sh
- ./sql/entrypoint.sh:/var/opt/mssql/scripts/entrypoint.sh
- ./sql/extended.sql:/var/opt/mssql/scripts/extended.sql
entrypoint: /bin/bash -c "/var/opt/mssql/scripts/entrypoint.sh"
healthcheck:
Expand Down
4 changes: 4 additions & 0 deletions containers/ecr-viewer/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const createJestConfig = nextJest({
const customJestConfig = {
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
testEnvironment: "jest-environment-jsdom",
moduleNameMapper: {
"^mssql$": "<rootDir>/src/app/tests/__mocks__/mssql.js",
"^tedious$": "<rootDir>/src/app/tests/__mocks__/mssql.js",
},
};

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
Expand Down
File renamed without changes.
12 changes: 5 additions & 7 deletions containers/ecr-viewer/sql/extended.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@ CREATE TABLE ECR_DATA
rr_id VARCHAR(255),
processing_status VARCHAR(255),
eicr_version_number VARCHAR(50),
authoring_date DATE,
authoring_time TIME,
authoring_date DATETIME,
authoring_provider VARCHAR(255),
provider_id VARCHAR(255),
facility_id VARCHAR(255),
facility_name VARCHAR(255),
encounter_type VARCHAR(255),
encounter_start_date DATE,
encounter_start_time TIME,
encounter_end_date DATE,
encounter_end_time TIME,
encounter_start_date DATETIME,
encounter_end_date DATETIME,
reason_for_visit VARCHAR(MAX),
active_problems VARCHAR(MAX)
active_problems VARCHAR(MAX),
date_created DATETIMEOFFSET NOT NULL DEFAULT SYSDATETIMEOFFSET(),
);

CREATE TABLE ecr_rr_conditions
Expand Down
5 changes: 3 additions & 2 deletions containers/ecr-viewer/src/app/api/conditions/service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { NextResponse } from "next/server";
import pgPromise from "pg-promise";
import { database } from "../services/postgres_db";
import { NextResponse } from "next/server";
import sql from "mssql";
import { get_pool } from "../services/sqlserver_db";
import sql from "mssql";

/**
* Retrieves all unique conditions from the ecr_rr_conditions table in the PostgreSQL database.
* @returns A promise resolving to a NextResponse object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export const saveMetadataToSqlServer = async (
.input("eicr_set_id", sql.VarChar(255), metadata.eicr_set_id)
.input("fhir_reference_link", sql.VarChar(255), null) // Not implemented
.input("last_name", sql.VarChar(255), metadata.last_name)
.input("first_name", sql.VarChar(255), metadata.last_name)
.input("first_name", sql.VarChar(255), metadata.first_name)
.input("birth_date", sql.Date, metadata.birth_date)
.input("gender", sql.VarChar(50), metadata.gender)
.input("birth_sex", sql.VarChar(50), metadata.birth_sex)
Expand Down Expand Up @@ -254,21 +254,18 @@ export const saveMetadataToSqlServer = async (
sql.VarChar(50),
metadata.eicr_version_number,
)
.input("authoring_date", sql.Date, metadata.authoring_datetime)
.input("authoring_time", sql.Time(7), metadata.authoring_datetime)
.input("authoring_date", sql.DateTime, metadata.authoring_datetime)
.input("authoring_provider", sql.VarChar(255), metadata.provider_id)
.input("provider_id", sql.VarChar(255), metadata.provider_id)
.input("facility_id", sql.VarChar(255), metadata.facility_id_number)
.input("facility_name", sql.VarChar(255), metadata.facility_name)
.input("encounter_type", sql.VarChar(255), metadata.encounter_type)
.input("encounter_start_date", sql.Date, metadata.encounter_start_date)
.input(
"encounter_start_time",
sql.Time(7),
"encounter_start_date",
sql.DateTime,
metadata.encounter_start_date,
)
.input("encounter_end_date", sql.Date, metadata.encounter_end_date)
.input("encounter_end_time", sql.Time(7), metadata.encounter_end_date)
.input("encounter_end_date", sql.DateTime, metadata.encounter_end_date)
.input(
"reason_for_visit",
sql.VarChar(sql.MAX),
Expand All @@ -280,7 +277,7 @@ export const saveMetadataToSqlServer = async (
metadata.active_problems,
)
.query(
"INSERT INTO dbo.ECR_DATA VALUES (@eICR_ID, @eicr_set_id, @fhir_reference_link, @last_name, @first_name, @birth_date, @gender, @birth_sex, @gender_identity, @race, @ethnicity, @street_address1, @street_address2, @state, @zip_code, @latitude, @longitude, @homelessness_status, @disabilities, @tribal_affiliation, @tribal_enrollment_status, @current_job_title, @current_job_industry, @usual_occupation, @usual_industry, @preferred_language, @pregnancy_status, @rr_id, @processing_status, @eicr_version_number, @authoring_date, @authoring_time, @authoring_provider, @provider_id, @facility_id, @facility_name, @encounter_type, @encounter_start_date, @encounter_start_time, @encounter_end_date, @encounter_end_time, @reason_for_visit, @active_problems)",
"INSERT INTO dbo.ECR_DATA (eICR_ID, set_id, fhir_reference_link, last_name, first_name, birth_date, gender, birth_sex, gender_identity, race, ethnicity, street_address_1, street_address_2, state, zip_code, latitude, longitude, homelessness_status, disabilities, tribal_affiliation, tribal_enrollment_status, current_job_title, current_job_industry, usual_occupation, usual_industry, preferred_language, pregnancy_status, rr_id, processing_status, eicr_version_number, authoring_date, authoring_provider, provider_id, facility_id, facility_name, encounter_type, encounter_start_date, encounter_end_date, reason_for_visit, active_problems) VALUES (@eICR_ID, @eicr_set_id, @fhir_reference_link, @last_name, @first_name, @birth_date, @gender, @birth_sex, @gender_identity, @race, @ethnicity, @street_address1, @street_address2, @state, @zip_code, @latitude, @longitude, @homelessness_status, @disabilities, @tribal_affiliation, @tribal_enrollment_status, @current_job_title, @current_job_industry, @usual_occupation, @usual_industry, @preferred_language, @pregnancy_status, @rr_id, @processing_status, @eicr_version_number, @authoring_date, @authoring_provider, @provider_id, @facility_id, @facility_name, @encounter_type, @encounter_start_date, @encounter_end_date, @reason_for_visit, @active_problems)",
);

if (metadata.labs) {
Expand Down Expand Up @@ -344,7 +341,7 @@ export const saveMetadataToSqlServer = async (
.input("specimen_type", sql.VarChar(255), lab.specimen_type)
.input(
"specimen_collection_date",
sql.Date,
sql.DateTime,
lab.specimen_collection_date,
)
.input("performing_lab", sql.VarChar(255), lab.performing_lab)
Expand Down
217 changes: 0 additions & 217 deletions containers/ecr-viewer/src/app/api/services/listEcrDataService.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ import {
import { database } from "@/app/api/services/postgres_db";
import { NextResponse } from "next/server";

jest.mock("mssql", () => ({})); // Mock the mssql module

jest.mock("mssql", () => {
const mssql = {
connect: jest.fn(),
Transaction: jest.fn(),
Request: jest.fn(),
// You can add other mocks if needed
};
return mssql;
});
// Mock dependencies
jest.mock("mssql", () => ({
connect: jest.fn(),
Transaction: jest.fn(),
Request: jest.fn(),
}));

jest.mock("../services/postgres_db", () => ({
database: {
Expand Down
2 changes: 1 addition & 1 deletion containers/ecr-viewer/src/app/components/EcrTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { listEcrData } from "@/app/api/services/listEcrDataService";
import { listEcrData } from "@/app/services/listEcrDataService";

import { EcrTableClient } from "@/app/components/EcrTableClient";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useEffect, useState } from "react";
import { Table } from "@trussworks/react-uswds";
import { SortButton } from "@/app/components/SortButton";
import { EcrDisplay } from "@/app/api/services/listEcrDataService";
import { EcrDisplay } from "@/app/services/listEcrDataService";
import { toSentenceCase } from "@/app/services/formatService";
import { usePathname, useSearchParams, useRouter } from "next/navigation";

Expand Down
2 changes: 1 addition & 1 deletion containers/ecr-viewer/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import Header from "./Header";
import { getTotalEcrCount } from "@/app/api/services/listEcrDataService";
import { getTotalEcrCount } from "@/app/services/listEcrDataService";
import EcrPaginationWrapper from "@/app/components/EcrPaginationWrapper";
import EcrTable from "@/app/components/EcrTable";
import LibrarySearch from "./components/LibrarySearch";
Expand Down
Loading

0 comments on commit 2cfbeda

Please sign in to comment.