Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read SQL Server #2956

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e9b2a9c
Read from SQL Server
JNygaard-Skylight Nov 22, 2024
5c2e5ed
Remove copied files
JNygaard-Skylight Nov 22, 2024
5c3b797
Merge branch 'main' into josh/read-sqlserver
JNygaard-Skylight Nov 25, 2024
d1e57c7
Fix listecrdata reference
JNygaard-Skylight Nov 25, 2024
abc6124
Merge branch 'josh/read-sqlserver' of github.com-jnygaard-skylight:CD…
joshnygaard Nov 25, 2024
17c6e70
Fix listecrdataservice route
JNygaard-Skylight Nov 25, 2024
561cbde
Update listecrdataservice
JNygaard-Skylight Nov 25, 2024
b9338a8
Remove moved file
JNygaard-Skylight Nov 25, 2024
5a538be
Merge branch 'main' into josh/read-sqlserver
JNygaard-Skylight Nov 25, 2024
da20c24
Revert removing all of my changes becasuse I'm a big idiot.
JNygaard-Skylight Nov 25, 2024
8024cad
Fixing tests
JNygaard-Skylight Nov 25, 2024
8b017f9
Merge branch 'josh/read-sqlserver' of github.com-jnygaard-skylight:CD…
joshnygaard Nov 25, 2024
f4e6629
Add getTotalEcrCountBack back
JNygaard-Skylight Nov 25, 2024
1e27831
Merge branch 'main' into josh/read-sqlserver
JNygaard-Skylight Nov 25, 2024
8d96200
Merge branch 'main' into josh/read-sqlserver
joshnygaard Nov 25, 2024
7764f61
Remove duplicated mock
JNygaard-Skylight Nov 25, 2024
1bbe891
change types to interfaces
JNygaard-Skylight Nov 25, 2024
72816a4
Add mssql import
JNygaard-Skylight Nov 25, 2024
670848f
Fix Jest config
JNygaard-Skylight Nov 25, 2024
962b02c
SQL Server ecr table sorting and offset
JNygaard-Skylight Nov 26, 2024
fcc60ae
Removed moved file
JNygaard-Skylight Nov 26, 2024
b5ff766
SQL Server where statement
JNygaard-Skylight Nov 26, 2024
aa7529d
Revert type change
JNygaard-Skylight Nov 26, 2024
4be9211
Remove console.logs
JNygaard-Skylight Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion containers/ecr-viewer/sql/extended.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ CREATE TABLE ECR_DATA
encounter_end_date DATE,
encounter_end_time TIME,
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 @@ -280,7 +280,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_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) 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)",
);

if (metadata.labs) {
Expand Down
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