@@ -36,11 +36,13 @@ router.post('/', async (req: Request, res: Response) => {
3636 await handleRxFill ( message , res ) ;
3737 } else {
3838 logger . error ( 'Unknown NCPDP message type' ) ;
39+ res . type ( 'application/xml' ) ;
3940 res . status ( 400 ) . send ( buildErrorResponse ( 'Unknown message type' ) ) ;
4041 }
4142 } catch ( error : any ) {
4243 logger . error ( `ERROR processing NCPDP message: ${ error . message } ` ) ;
4344 logger . error ( `Stack: ${ error . stack } ` ) ;
45+ res . type ( 'application/xml' ) ;
4446 res . status ( 500 ) . send ( buildErrorResponse ( 'Internal server error' ) ) ;
4547 }
4648} ) ;
@@ -59,6 +61,7 @@ const handleRemsRequest = async (message: any, res: Response) => {
5961
6062 if ( ! caseId ) {
6163 logger . error ( 'Case ID not provided in request' ) ;
64+ res . type ( 'application/xml' ) ;
6265 return res . status ( 200 ) . send ( buildDeniedResponse ( header , remsRequest , 'EC' , 'Case ID not provided' ) ) ;
6366 }
6467
@@ -68,6 +71,7 @@ const handleRemsRequest = async (message: any, res: Response) => {
6871
6972 if ( ! remsCase ) {
7073 logger . error ( `Case not found: ${ caseId } ` ) ;
74+ res . type ( 'application/xml' ) ;
7175 return res . status ( 200 ) . send ( buildDeniedResponse ( header , remsRequest , 'EC' , 'Case not found' ) ) ;
7276 }
7377
@@ -86,6 +90,7 @@ const handleRemsRequest = async (message: any, res: Response) => {
8690
8791 if ( ! medication ) {
8892 logger . error ( `Medication configuration not found for NDC: ${ remsCase . drugNdcCode } ` ) ;
93+ res . type ( 'application/xml' ) ;
8994 return res . status ( 200 ) . send ( buildDeniedResponse ( header , remsRequest , 'ER' , 'Medication configuration error' ) ) ;
9095 }
9196
@@ -135,6 +140,7 @@ const handleRemsRequest = async (message: any, res: Response) => {
135140 } ;
136141 logger . info ( `Authorization details: ${ JSON . stringify ( authDetails ) } ` ) ;
137142
143+ res . type ( 'application/xml' ) ;
138144 return res . status ( 200 ) . send ( buildApprovedResponse (
139145 header ,
140146 remsRequest ,
@@ -167,11 +173,13 @@ const handleRemsRequest = async (message: any, res: Response) => {
167173 }
168174
169175 logger . info ( 'Sending DENIED response' ) ;
176+ res . type ( 'application/xml' ) ;
170177 return res . status ( 200 ) . send ( buildDeniedResponse ( header , remsRequest , reasonCodes . join ( ',' ) , reasonText ) ) ;
171178
172179 } catch ( error : any ) {
173180 logger . error ( `ERROR in handleRemsRequest: ${ error . message } ` ) ;
174181 logger . error ( `Stack trace: ${ error . stack } ` ) ;
182+ res . type ( 'application/xml' ) ;
175183 return res . status ( 500 ) . send ( buildErrorResponse ( error . message ) ) ;
176184 }
177185} ;
@@ -202,6 +210,7 @@ const handleRemsInitiation = async (message: any, res: Response) => {
202210
203211 if ( ! remsCase ) {
204212 logger . info ( 'No case exists - patient must enroll' ) ;
213+ res . type ( 'application/xml' ) ;
205214 return res . status ( 200 ) . send ( buildInitiationClosedResponse (
206215 header ,
207216 initRequest ,
@@ -217,6 +226,7 @@ const handleRemsInitiation = async (message: any, res: Response) => {
217226
218227 if ( ! medication ) {
219228 logger . error ( `Medication not found for NDC: ${ drugNdcCode } ` ) ;
229+ res . type ( 'application/xml' ) ;
220230 return res . status ( 200 ) . send ( buildInitiationClosedResponse (
221231 header ,
222232 initRequest ,
@@ -247,6 +257,7 @@ const handleRemsInitiation = async (message: any, res: Response) => {
247257 const reasonText = buildReasonText ( outstandingRequirements ) ;
248258
249259 logger . info ( `Requirements not met - closing with: ${ reasonCodes . join ( ',' ) } ` ) ;
260+ res . type ( 'application/xml' ) ;
250261 return res . status ( 200 ) . send ( buildInitiationClosedResponse (
251262 header ,
252263 initRequest ,
@@ -257,10 +268,12 @@ const handleRemsInitiation = async (message: any, res: Response) => {
257268
258269 // All requirements met - return success with patient ID
259270 logger . info ( 'All requirements met - returning success' ) ;
271+ res . type ( 'application/xml' ) ;
260272 return res . status ( 200 ) . send ( buildInitiationSuccessResponse ( header , initRequest , remsCase ) ) ;
261273
262274 } catch ( error : any ) {
263275 logger . error ( `ERROR in handleRemsInitiation: ${ error . message } ` ) ;
276+ res . type ( 'application/xml' ) ;
264277 return res . status ( 500 ) . send ( buildErrorResponse ( error . message ) ) ;
265278 }
266279} ;
@@ -292,9 +305,11 @@ const handleRxFill = async (message: any, res: Response) => {
292305 logger . warn ( 'Case not found for RxFill notification' ) ;
293306 }
294307
308+ res . type ( 'application/xml' ) ;
295309 return res . status ( 200 ) . send ( buildRxFillResponse ( header , rxFill ) ) ;
296310 } catch ( error : any ) {
297311 logger . error ( `ERROR in handleRxFill: ${ error . message } ` ) ;
312+ res . type ( 'application/xml' ) ;
298313 return res . status ( 500 ) . send ( buildErrorResponse ( error . message ) ) ;
299314 }
300315} ;
0 commit comments