11import Patient from '../models/patient.js' ;
2- < << << << HEAD
32import { createPatientPortalAccount } from '../services/patientPortal.service.js' ;
4- = === ===
5- import User from '../models/User.js' ;
6- import bcrypt from 'bcrypt' ;
7- import * as emailService from '../services/email.service.js' ;
8- > >>> >>> recovery - branch
93
104const createPatient = async ( req , res , next ) => {
115 try {
126 const { name, email, phno, paymentMode } = req . body ;
7+
138 console . log ( `Creating patient: ${ name } , Email: ${ email } , PaymentMode: ${ paymentMode } ` ) ;
149
15- // Create the patient record
1610 const patient = new Patient ( req . body ) ;
1711 await patient . save ( ) ;
1812
19- < << << << HEAD
20- const { email , paymentMethod } = req . body ;
21-
22- if ( paymentMethod === "online" && email ) {
13+ if ( paymentMode === "online" && email ) {
2314 await createPatientPortalAccount ( email ) ;
2415 }
2516
@@ -28,42 +19,6 @@ const createPatient = async (req, res, next) => {
2819 patient
2920 } ) ;
3021
31- = === ===
32- // If online payment, create a patient portal account
33- if ( paymentMode === 'online' ) {
34- console . log ( `Online payment mode detected for ${ email } . Processing portal creation...` ) ;
35- const existingUser = await User . findOne ( { email } ) ;
36- if ( ! existingUser ) {
37- // Use phone number as default password
38- const password = phno ; // Plain text for the email
39- const hashedPassword = await bcrypt . hash ( password , 10 ) ;
40-
41- await User . create ( {
42- name,
43- email,
44- password : hashedPassword ,
45- role : 'patient' ,
46- status : 'Active' ,
47- phno
48- } ) ;
49- console . log ( `Patient portal User record created for: ${ email } ` ) ;
50-
51- // Send credentials email
52- try {
53- await emailService . sendPortalCredentials ( email , name , password ) ;
54- console . log ( `Portal credentials email sent to: ${ email } ` ) ;
55- } catch ( mailErr ) {
56- console . error ( `Failed to send portal credentials email: ${ mailErr . message } ` ) ;
57- }
58- } else {
59- console . log ( `User account already exists for: ${ email } . Skipping portal creation.` ) ;
60- }
61- } else {
62- console . log ( `Payment mode is '${ paymentMode } '. Skipping portal creation.` ) ;
63- }
64-
65- res . status ( 201 ) . json ( patient ) ;
66- > >>> >>> recovery - branch
6722 } catch ( err ) {
6823 console . error ( `Error in createPatient: ${ err . message } ` ) ;
6924 next ( err ) ;
0 commit comments