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

fix: patient general data refactoring #193

Merged
merged 30 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
07223d2
fix: Refactored collaborator endpoint
ElrohirGT Aug 23, 2024
bfd7a76
chore: Formatting and linting
ElrohirGT Aug 23, 2024
2f71995
feat: Added security checks to update collaborator data
ElrohirGT Aug 23, 2024
59f6d37
fix: update collaborator and student data
ElrohirGT Aug 23, 2024
bacf9b6
fix: tests
ElrohirGT Aug 23, 2024
adfef55
fix: update patient redundancy
ElrohirGT Aug 23, 2024
6a49a32
fix: Seguros field
ElrohirGT Aug 23, 2024
0799342
fix: backend behaviour and insurance
ElrohirGT Aug 23, 2024
c6bf5bc
fix: Removed zombi code
ElrohirGT Aug 24, 2024
7a385b7
feat: Added collapsable component
ElrohirGT Aug 24, 2024
1e5179a
fix: Endpoints
ElrohirGT Aug 25, 2024
0f789fe
fix: Changed to default devenv
ElrohirGT Aug 25, 2024
609729f
fix: Added temporal nixpkgs version for samcli
ElrohirGT Aug 25, 2024
062c24b
fix: Removed redundancy
ElrohirGT Aug 25, 2024
514e071
feat: Added contact information
ElrohirGT Aug 25, 2024
c519697
Merge branch 'develop' into fix/patient-general-data-refactoring
ElrohirGT Aug 25, 2024
6d5d363
fix: tests
ElrohirGT Aug 25, 2024
729fb7a
fix: integration tests and backend
ElrohirGT Aug 26, 2024
34c266a
fix: UI
ElrohirGT Aug 26, 2024
388faaf
fix: Big general loading
ElrohirGT Aug 26, 2024
060e856
fix: Suspense bug
ElrohirGT Aug 26, 2024
14796be
fix: tests
ElrohirGT Aug 26, 2024
b2d11d6
Merge branch 'develop' into fix/patient-general-data-refactoring
ElrohirGT Aug 27, 2024
0d0d69d
fix: main data styles
ElrohirGT Aug 27, 2024
63fde43
fix: general styles
ElrohirGT Aug 27, 2024
19b98bd
fix: gapping
ElrohirGT Aug 27, 2024
9a6a013
fix: Section padding
ElrohirGT Aug 27, 2024
e2264b9
fix: Stiling
ElrohirGT Aug 28, 2024
51017d2
Merge branch 'develop' into fix/patient-general-data-refactoring
ElrohirGT Aug 28, 2024
6133106
fix: deleted zombi code
ElrohirGT Aug 28, 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
10 changes: 3 additions & 7 deletions database/inserts.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
INSERT INTO SEGURO (NOMBRE, ESTADO_ACTIVO) VALUES
('Seguro Vida', TRUE),
('Seguro Salud', TRUE);

INSERT INTO USUARIO (EMAIL, TIPO) VALUES
('[email protected]', 'Administrador'),
('[email protected]', 'Doctor'),
Expand All @@ -25,7 +21,7 @@ INSERT INTO PACIENTE (
TELEFONO_CONTACTO2,
TIPO_SANGRE,
DIRECCION,
ID_SEGURO,
SEGURO,
FECHA_NACIMIENTO,
TELEFONO
) VALUES
Expand All @@ -43,7 +39,7 @@ INSERT INTO PACIENTE (
'987650123',
'O+',
'Calle Falsa 123, Ciudad',
1,
'El Roble',
'1990-01-01',
'1234567890'
),
Expand All @@ -61,7 +57,7 @@ INSERT INTO PACIENTE (
'876540123',
'A-',
'Avenida Siempre Viva 456, Ciudad',
2,
'IGSS',
'1992-02-02',
'2345678901'
);
Expand Down
16 changes: 5 additions & 11 deletions database/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ CREATE TABLE USUARIO (
TIPO VARCHAR(20) NOT NULL
);


CREATE TABLE SEGURO (
ID SERIAL PRIMARY KEY NOT NULL,
NOMBRE VARCHAR(50) NOT NULL,
ESTADO_ACTIVO BOOLEAN NOT NULL
);

CREATE TABLE PACIENTE (
ID SERIAL PRIMARY KEY,
CUI VARCHAR(24) UNIQUE NOT NULL,
Expand All @@ -25,11 +18,12 @@ CREATE TABLE PACIENTE (
TELEFONO_CONTACTO2 VARCHAR(20),
TIPO_SANGRE VARCHAR(3),
DIRECCION VARCHAR(100),
ID_SEGURO INTEGER,
SEGURO VARCHAR(30),
FECHA_NACIMIENTO DATE NOT NULL,
TELEFONO VARCHAR(20),
FOREIGN KEY (ID_SEGURO) REFERENCES SEGURO (ID)
TELEFONO VARCHAR(20)
);
COMMENT ON TABLE PACIENTE IS
'This table is used to save general information about a patient.';

CREATE TABLE DOCTOR (
EMAIL VARCHAR(100) NOT NULL PRIMARY KEY
Expand All @@ -39,7 +33,7 @@ COMMENT ON TABLE DOCTOR IS


CREATE TABLE ESTUDIANTE (
CARNET VARCHAR(20),
CARNET VARCHAR(20) PRIMARY KEY NOT NULL,
CARRERA VARCHAR(50),
ID_PACIENTE INTEGER NOT NULL UNIQUE,
FOREIGN KEY (ID_PACIENTE) REFERENCES PACIENTE (ID)
Expand Down
34 changes: 25 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
samcliPkgs.url = "github:nixos/nixpkgs/42c5e250a8a9162c3e962c78a4c393c5ac369093";
systems.url = "github:nix-systems/default";
devenv = {
url = "github:ElrohirGT/devenv/feat-add-custom-pg-hba-conf";
url = "github:cachix/devenv";
inputs.nixpkgs.follows = "nixpkgs";
};
};
Expand All @@ -20,6 +21,7 @@
nixpkgs,
systems,
devenv,
samcliPkgs,
...
} @ inputs: let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
Expand Down Expand Up @@ -78,16 +80,17 @@

devShells = forEachSystem (system: let
pkgs = import nixpkgs {inherit system;};
samcli = (import samcliPkgs {inherit system;}).aws-sam-cli;
requiredPkgs = with pkgs; [
jq
];
frontendRequiredPkgs = with pkgs; [
nodejs_20
yarn-berry
];
backendRequiredPkgs = with pkgs; [
awscli2
aws-sam-cli
backendRequiredPkgs = [
pkgs.awscli2
samcli
];
strFromDBFile = file: builtins.readFile ./database/${file};
dbInitFile = builtins.concatStringsSep "\n" [(strFromDBFile "init.sql") (strFromDBFile "tables.sql") (strFromDBFile "inserts.sql")];
Expand All @@ -103,14 +106,14 @@
inherit pkgs inputs;
modules = [
{
packages = with pkgs;
packages =
[
# General
nodePackages.jsdoc
pkgs.nodePackages.jsdoc

# Database
postgresql
sqlfluff # SQL linter and formatter
pkgs.postgresql
pkgs.sqlfluff # SQL linter and formatter
]
++ requiredPkgs
++ frontendRequiredPkgs
Expand All @@ -127,7 +130,7 @@
listen_addresses = postgresHost;
port = postgresPort;
initialScript = dbInitFile;
customPgHbaFile = ./pg_hba.conf;
hbaConf = builtins.readFile ./pg_hba.conf;
settings = {
log_connections = true;
log_statement = "all";
Expand Down
42 changes: 24 additions & 18 deletions sanitas_backend/layers/utils/utils/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ export function decodeJWT(jwt) {
*
* @property {string|null} tipo_sangre
* @property {string|null} direccion
* @property {number | null} id_seguro
* @property {string | null} seguro
* @property {string} fecha_nacimiento
* @property {string|null} telefono
*/

/**
* @typedef {Object} APIPatient
* @property {number} id
* @property {number} patientId
* @property {string} cui
* @property {boolean} isWoman
* @property {string|null} email
Expand All @@ -57,7 +57,7 @@ export function decodeJWT(jwt) {
*
* @property {string|null} bloodType
* @property {string|null} address
* @property {number | undefined} insuranceId
* @property {string | undefined} insurance
* @property {string} birthdate
* @property {string|null} phone
*/
Expand All @@ -83,7 +83,7 @@ export function decodeJWT(jwt) {
*/
export function mapToAPIPatient(dbPatient) {
const {
id,
id: patientId,
cui,
es_mujer: isWoman,
correo: email,
Expand All @@ -100,13 +100,13 @@ export function mapToAPIPatient(dbPatient) {

tipo_sangre: bloodType,
direccion: address,
id_seguro: insuranceId,
seguro: insurance,
fecha_nacimiento: birthdate,
telefono: phone,
} = dbPatient;

return {
id,
patientId,
cui,
email,
isWoman,
Expand All @@ -123,7 +123,7 @@ export function mapToAPIPatient(dbPatient) {

bloodType,
address,
insuranceId,
insurance,
birthdate,
phone,
};
Expand Down Expand Up @@ -205,7 +205,7 @@ export function createResponse() {

/**
* @typedef {Object} APIStudentInfo
* @property {string} patientId
* @property {string} idPatient
* @property {string} carnet
* @property {string} career
*/
Expand All @@ -216,29 +216,27 @@ export function createResponse() {
* @returns {APIStudentInfo} The API formatted student information.
*/
export function mapToAPIStudentInfo(dbStudentInfo) {
const { id_paciente: patientId, carnet, carrera: career } = dbStudentInfo;
const { id_paciente: idPatient, carnet, carrera: career } = dbStudentInfo;

return {
patientId,
idPatient,
carnet,
career,
};
}

/**
* @typedef {Object} DBCollaborator
* @property {number} id
* @property {string} codigo
* @property {string} area
* @property {number} id_paciente
*/

/**
* @typedef {Object} APICollaborator
* @property {number} id
* @property {string} codigo
* @property {string} code
* @property {string} area
* @property {number} patientId
* @property {number} idPatient
*/

/**
Expand All @@ -247,16 +245,24 @@ export function mapToAPIStudentInfo(dbStudentInfo) {
* @returns {APICollaborator} The collaborator object the API must return.
*/
export function mapToAPICollaboratorInfo(dbCollaborator) {
const { id, codigo: code, area, id_paciente: patientId } = dbCollaborator;

const { codigo: code, area, id_paciente: idPatient } = dbCollaborator;
return {
id,
code,
area,
patientId,
idPatient,
};
}

/**
* Maps an APICollaborator into a DBCollaborator
* @param {APICollaborator} apiCollaborator
* @returns {DBCollaborator}
*/
export function mapToDBCollaborator(apiCollaborator) {
const { code: codigo, area, idPatient: id_paciente } = apiCollaborator;
return { codigo, area, id_paciente };
}

/**
* @typedef {Object} MedicalConditionData
* @property {number} version - The version of the data format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("Collaborator Handler", () => {
expect(collaborator).toBeDefined();
expect(collaborator.code).toBe("C001");
expect(collaborator.area).toBe("Administración");
expect(collaborator.patientId).toBe(2);
expect(collaborator.idPatient).toBe(2);
});

it("should return default data", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getPgClient } from "db-conn";
import { logger, withRequest } from "logging";
import { createResponse, mapToAPICollaboratorInfo } from "utils";
import { createResponse, mapToAPICollaboratorInfo } from "utils/index.mjs";

/**
* Get the collaborator information endpoint handler.
Expand Down Expand Up @@ -52,7 +52,7 @@ export const getCollaboratorHandler = async (event, context) => {
return createResponse()
.setStatusCode(200)
.addCORSHeaders()
.setBody({ patientId: id, code: "", area: "" })
.setBody({ idPatient: id, code: "", area: "" })
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Get patient integration tests", () => {

const user = response.data;
expect(user).toBeDefined();
expect(user.id).toBe(patientId);
expect(user.patientId).toBe(patientId);
expect(user.cui).toBe(cui);
expect(user.isWoman).toBe(false);
expect(user.names).toBe("Flabio André");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getPgClient } from "db-conn";
import { logger, withRequest } from "logging";
import { mapToAPIPatient } from "utils";
import { mapToAPIPatient } from "utils/index.mjs";

/**
* Get the general patient information endpoint handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("Student Handler", () => {
expect(user).toBeDefined();
expect(user.carnet).toBe("A01234567");
expect(user.career).toBe("Ingeniería en CC y TI");
expect(user.patientId).toBe(1);
expect(user.idPatient).toBe(1);
});

it("should not found a patiend", async () => {
Expand Down
Loading