-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: medications and diagnostic reports issue
- Loading branch information
1 parent
8901ca2
commit f40a3c3
Showing
23 changed files
with
567 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
services/EHR/prisma/migrations/20240502021834_unique_patient_email/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.