Skip to content

Commit

Permalink
fix: medications and diagnostic reports issue
Browse files Browse the repository at this point in the history
  • Loading branch information
aliakkas006 committed May 2, 2024
1 parent 8901ca2 commit f40a3c3
Show file tree
Hide file tree
Showing 23 changed files with 567 additions and 27 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ jobs:
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/appointment:latest

- name: Build and push EHR service
uses: docker/build-push-action@v5
with:
context: ./services/EHR
file: ./services/EHR/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/EHR:latest

- name: Build and push user service
uses: docker/build-push-action@v5
with:
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Healthcare Appointment Scheduling System

## About

Building Microservices Architecture using Docker, implementing CI/CD pipelines using GitHub Actions, incorporating asynchronous communication using RabbitMQ and caching with Redis. Additionally, implementing rate limiting, creating a custom API gateway or reverse proxy, and documenting system architecture.

## [Basic System Architecture](https://ali-akkas.notion.site/Healthcare-Appointment-Scheduling-System-cf67ead3bb1947f58f505c18fb886280?pvs=4)
Expand Down Expand Up @@ -82,6 +83,22 @@ Healthcare-Appointment-Scheduling-System/
├── app.ts
├── index.ts
├── config.ts
├── queue.ts
├── redis.ts
├── tests
├── package.json
├── Dockerfile
├── EHR
├── prisma
├── src/
├── controllers
├── lib
├── routes
├── app.ts
├── index.ts
├── config.ts
├── queue.ts
├── redis.ts
├── tests
├── package.json
├── Dockerfile
Expand Down Expand Up @@ -124,6 +141,7 @@ When push the code in the GitHub automatic run the actions
```

### Postman `API Testing`

```bash
https://api.postman.com/collections/22653708-df253a8d-6b26-4e83-9673-793d1d6c04d5?access_key=PMAT-01HWT700T6H22BASWVF2E3HK9R
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- A unique constraint covering the columns `[patientEmail]` on the table `EHR` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "EHR_patientEmail_key" ON "EHR"("patientEmail");
8 changes: 5 additions & 3 deletions services/EHR/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ enum Gender {
}

model EHR {
id String @id @default(cuid())
id String @id @default(cuid())
patientId String
patientEmail String
patientEmail String @unique
medicalHistories String[]
allergies String[]
medications Medication[]
diagnosticReports DiagnosticReport[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
patient Patient @relation(fields: [patientId], references: [id])
patient Patient @relation(fields: [patientId], references: [id])
}

model Patient {
Expand Down
33 changes: 33 additions & 0 deletions services/EHR/src/controllers/createDiagnosticReport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Request, Response, NextFunction } from 'express';
import { DiagnosticReportCreateSchema } from '@/schemas';
import ehrService from '@/lib/EHRService';

const createDiagnosticReport = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
// Validate the request body
const parsedBody = DiagnosticReportCreateSchema.safeParse(req.body);
if (!parsedBody.success) {
return res.status(400).json({ message: parsedBody.error.errors });
}

// Create the DiagnosticReport
const diagnosticReport = await ehrService.createDiagnosticReport(
parsedBody.data
);

return res
.status(201)
.json({
message: 'Diagnostic Report created successfully!',
diagnosticReport,
});
} catch (err) {
next(err);
}
};

export default createDiagnosticReport;
9 changes: 8 additions & 1 deletion services/EHR/src/controllers/createEHR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import { EHRCreateSchema } from '@/schemas';
import ehrService from '@/lib/EHRService';

const createEHR = async (req: Request, res: Response, next: NextFunction) => {
console.log('Creating EHR...');
try {
// Validate the request body
const parsedBody = EHRCreateSchema.safeParse(req.body);
if (!parsedBody.success) {
return res.status(400).json({ message: parsedBody.error.errors });
}

// Check if the patient already has an EHR by patient email
const existingEHR = await ehrService.checkExistingEHR(
parsedBody.data.patientEmail
);
if (existingEHR) {
return res.status(400).json({ message: 'Patient already has an EHR' });
}

// Create the EHR
const ehr = await ehrService.createEHR(parsedBody.data);

Expand Down
28 changes: 28 additions & 0 deletions services/EHR/src/controllers/createMedication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Request, Response, NextFunction } from 'express';
import { MedicationCreateSchema } from '@/schemas';
import ehrService from '@/lib/EHRService';

const createMedication = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
// Validate the request body
const parsedBody = MedicationCreateSchema.safeParse(req.body);
if (!parsedBody.success) {
return res.status(400).json({ message: parsedBody.error.errors });
}

// Create the Medications
const medication = await ehrService.createMedication(parsedBody.data);

return res
.status(201)
.json({ message: 'Medication created successfully!', medication });
} catch (err) {
next(err);
}
};

export default createMedication;
35 changes: 35 additions & 0 deletions services/EHR/src/controllers/createPatient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Request, Response, NextFunction } from 'express';
import { PatientCreateSchema } from '@/schemas';
import ehrService from '@/lib/EHRService';

const createPatient = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
// Validate the request body
const parsedBody = PatientCreateSchema.safeParse(req.body);

if (!parsedBody.success) {
return res.status(400).json({ message: parsedBody.error.errors });
}

const { userId } = parsedBody.data;
const existingPatient = await ehrService.checkExistingPatient(userId);

if (existingPatient) {
return res.status(400).json({ message: 'Patient already exists!' });
}

const patient = await ehrService.createPatient(parsedBody.data);

return res
.status(201)
.json({ message: 'Patient created successfully!', patient });
} catch (err) {
next(err);
}
};

export default createPatient;
21 changes: 21 additions & 0 deletions services/EHR/src/controllers/deleteEHRById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Request, Response, NextFunction } from 'express';
import ehrService from '@/lib/EHRService';

const deleteEHRById = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const { id } = req.params;

// Delete EHR by id
await ehrService.deleteEHRById(id);

return res.status(204).send();
} catch (err) {
next(err);
}
};

export default deleteEHRById;
19 changes: 19 additions & 0 deletions services/EHR/src/controllers/getDiagnosticReports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Request, Response, NextFunction } from 'express';
import ehrService from '@/lib/EHRService';

const getDiagnosticReports = async (
_req: Request,
res: Response,
next: NextFunction
) => {
try {
// Get all Diagnostic Reports
const diagnosticReports = await ehrService.getDiagnosticReports();

return res.status(200).json(diagnosticReports);
} catch (err) {
next(err);
}
};

export default getDiagnosticReports;
19 changes: 19 additions & 0 deletions services/EHR/src/controllers/getEHRById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Request, Response, NextFunction } from 'express';
import ehrService from '@/lib/EHRService';

const getEHRById = async (req: Request, res: Response, next: NextFunction) => {
try {
const { id } = req.params;

const EHR = await ehrService.getEHRById(id);
if (!EHR) {
return res.status(404).json({ message: 'EHR not found' });
}

return res.status(200).json({ message: 'EHR fetched successfully', EHR });
} catch (err) {
next(err);
}
};

export default getEHRById;
24 changes: 24 additions & 0 deletions services/EHR/src/controllers/getEHRByPatientId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Request, Response, NextFunction } from 'express';
import ehrService from '@/lib/EHRService';

const getEHRByPatientId = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const { patientId } = req.params;

const EHR = await ehrService.getEHRByPatientId(patientId);

if (!EHR) {
return res.status(404).json({ message: 'EHR not found' });
}

res.status(200).json({ message: 'EHR fetched successfully', EHR });
} catch (err) {
next(err);
}
};

export default getEHRByPatientId;
2 changes: 1 addition & 1 deletion services/EHR/src/controllers/getEHRs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ehrService from '@/lib/EHRService';
import { Request, Response, NextFunction } from 'express';
import ehrService from '@/lib/EHRService';

const getEHRs = async (_req: Request, res: Response, next: NextFunction) => {
try {
Expand Down
19 changes: 19 additions & 0 deletions services/EHR/src/controllers/getMedications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Request, Response, NextFunction } from 'express';
import ehrService from '@/lib/EHRService';

const getMedications = async (
_req: Request,
res: Response,
next: NextFunction
) => {
try {
// Get all Medications
const medications = await ehrService.getMedications();

return res.status(200).json(medications);
} catch (err) {
next(err);
}
};

export default getMedications;
9 changes: 9 additions & 0 deletions services/EHR/src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
export { default as createEHR } from './createEHR';
export { default as getEHRs } from './getEHRs';
export { default as getEHRById } from './getEHRById';
export { default as getEHRByPatientId } from './getEHRByPatientId';
export { default as updateEHRById } from './updateEHRById';
export { default as deleteEHRById } from './deleteEHRById';
export { default as createPatient } from './createPatient';
export { default as createMedication } from './createMedication';
export { default as createDiagnosticReport } from './createDiagnosticReport';
export { default as getMedications } from './getMedications';
export { default as getDiagnosticReports } from './getDiagnosticReports';
31 changes: 31 additions & 0 deletions services/EHR/src/controllers/updateEHRById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Request, Response, NextFunction } from 'express';
import ehrService from '@/lib/EHRService';
import { EHRUpdateSchema } from '@/schemas';

const updateEHRById = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
// Validate the request body
const parsedBody = EHRUpdateSchema.safeParse(req.body);
if (!parsedBody.success) {
return res.status(400).json({ message: parsedBody.error.errors });
}

const { id } = req.params;

// Update EHR by id
const updatedEHR = await ehrService.updateEHRById(id, parsedBody.data);
if (!updatedEHR) {
return res.status(404).json({ message: 'EHR not found' });
}

return res.json({ message: 'EHR updated successfully', updatedEHR });
} catch (err) {
next(err);
}
};

export default updateEHRById;
Loading

0 comments on commit f40a3c3

Please sign in to comment.