@@ -66,11 +66,13 @@ describe('AwsBedrockService', () => {
6666
6767 // Create service instance
6868 service = new AwsBedrockService ( mockConfigService ) ;
69-
69+
7070 // Mock private methods directly
71- vi . spyOn ( service as any , 'invokeBedrock' ) . mockImplementation ( ( ) => Promise . resolve ( {
72- body : Buffer . from ( '{"mock": "response"}' ) ,
73- } ) ) ;
71+ vi . spyOn ( service as any , 'invokeBedrock' ) . mockImplementation ( ( ) =>
72+ Promise . resolve ( {
73+ body : Buffer . from ( '{"mock": "response"}' ) ,
74+ } ) ,
75+ ) ;
7476 } ) ;
7577
7678 describe ( 'initialization' , ( ) => {
@@ -93,10 +95,20 @@ describe('AwsBedrockService', () => {
9395 { term : 'Hemoglobin' , definition : 'Protein in red blood cells that carries oxygen' } ,
9496 ] ,
9597 labValues : [
96- { name : 'Hemoglobin' , value : '14.5' , unit : 'g/dL' , normalRange : '12.0-15.5' , isAbnormal : false } ,
98+ {
99+ name : 'Hemoglobin' ,
100+ value : '14.5' ,
101+ unit : 'g/dL' ,
102+ normalRange : '12.0-15.5' ,
103+ isAbnormal : false ,
104+ } ,
97105 ] ,
98106 diagnoses : [
99- { condition : 'Normal Blood Count' , details : 'All values within normal range' , recommendations : 'Continue monitoring' } ,
107+ {
108+ condition : 'Normal Blood Count' ,
109+ details : 'All values within normal range' ,
110+ recommendations : 'Continue monitoring' ,
111+ } ,
100112 ] ,
101113 metadata : {
102114 isMedicalReport : true ,
@@ -117,14 +129,16 @@ describe('AwsBedrockService', () => {
117129
118130 it ( 'should successfully extract medical information from image/png' , async ( ) => {
119131 const mockMedicalInfo = {
120- keyMedicalTerms : [
121- { term : 'Glucose' , definition : 'Blood sugar level' } ,
122- ] ,
132+ keyMedicalTerms : [ { term : 'Glucose' , definition : 'Blood sugar level' } ] ,
123133 labValues : [
124134 { name : 'Glucose' , value : '90' , unit : 'mg/dL' , normalRange : '70-100' , isAbnormal : false } ,
125135 ] ,
126136 diagnoses : [
127- { condition : 'Normal Glucose' , details : 'Normal blood sugar' , recommendations : 'Continue healthy diet' } ,
137+ {
138+ condition : 'Normal Glucose' ,
139+ details : 'Normal blood sugar' ,
140+ recommendations : 'Continue healthy diet' ,
141+ } ,
128142 ] ,
129143 metadata : {
130144 isMedicalReport : true ,
@@ -149,14 +163,24 @@ describe('AwsBedrockService', () => {
149163 { term : 'Cholesterol' , definition : 'Lipid molecule found in cell membranes' } ,
150164 ] ,
151165 labValues : [
152- { name : 'Cholesterol' , value : '180' , unit : 'mg/dL' , normalRange : '< 200' , isAbnormal : false } ,
166+ {
167+ name : 'Cholesterol' ,
168+ value : '180' ,
169+ unit : 'mg/dL' ,
170+ normalRange : '< 200' ,
171+ isAbnormal : false ,
172+ } ,
153173 ] ,
154174 diagnoses : [
155- { condition : 'Normal Cholesterol' , details : 'Within healthy range' , recommendations : 'Continue heart-healthy diet' } ,
175+ {
176+ condition : 'Normal Cholesterol' ,
177+ details : 'Within healthy range' ,
178+ recommendations : 'Continue heart-healthy diet' ,
179+ } ,
156180 ] ,
157181 metadata : {
158182 isMedicalReport : true ,
159- confidence : 0.90 ,
183+ confidence : 0.9 ,
160184 missingInformation : [ ] ,
161185 } ,
162186 } ;
@@ -173,14 +197,22 @@ describe('AwsBedrockService', () => {
173197
174198 it ( 'should successfully extract medical information from image/heif' , async ( ) => {
175199 const mockMedicalInfo = {
176- keyMedicalTerms : [
177- { term : 'Triglycerides' , definition : 'Type of fat found in blood' } ,
178- ] ,
200+ keyMedicalTerms : [ { term : 'Triglycerides' , definition : 'Type of fat found in blood' } ] ,
179201 labValues : [
180- { name : 'Triglycerides' , value : '120' , unit : 'mg/dL' , normalRange : '< 150' , isAbnormal : false } ,
202+ {
203+ name : 'Triglycerides' ,
204+ value : '120' ,
205+ unit : 'mg/dL' ,
206+ normalRange : '< 150' ,
207+ isAbnormal : false ,
208+ } ,
181209 ] ,
182210 diagnoses : [
183- { condition : 'Normal Triglycerides' , details : 'Within healthy range' , recommendations : 'Continue heart-healthy diet' } ,
211+ {
212+ condition : 'Normal Triglycerides' ,
213+ details : 'Within healthy range' ,
214+ recommendations : 'Continue heart-healthy diet' ,
215+ } ,
184216 ] ,
185217 metadata : {
186218 isMedicalReport : true ,
@@ -216,7 +248,9 @@ describe('AwsBedrockService', () => {
216248
217249 const result = await service . extractMedicalInfo ( mockImageBuffer , 'image/jpeg' ) ;
218250 expect ( result . metadata . isMedicalReport ) . toBe ( false ) ;
219- expect ( result . metadata . missingInformation ) . toContain ( 'The image was not clearly identified as a medical document. Results may be limited.' ) ;
251+ expect ( result . metadata . missingInformation ) . toContain (
252+ 'The image was not clearly identified as a medical document. Results may be limited.' ,
253+ ) ;
220254 } ) ;
221255
222256 it ( 'should handle low quality or unclear images' , async ( ) => {
@@ -236,7 +270,9 @@ describe('AwsBedrockService', () => {
236270
237271 const result = await service . extractMedicalInfo ( mockImageBuffer , 'image/jpeg' ) ;
238272 expect ( result . metadata . confidence ) . toBeLessThan ( 0.5 ) ;
239- expect ( result . metadata . missingInformation ) . toContain ( 'Low confidence in the analysis. Please verify results or try a clearer image.' ) ;
273+ expect ( result . metadata . missingInformation ) . toContain (
274+ 'Low confidence in the analysis. Please verify results or try a clearer image.' ,
275+ ) ;
240276 } ) ;
241277
242278 it ( 'should handle partially visible information in images' , async ( ) => {
@@ -255,14 +291,14 @@ describe('AwsBedrockService', () => {
255291 vi . spyOn ( service as any , 'parseBedrockResponse' ) . mockReturnValueOnce ( partialInfo ) ;
256292
257293 const result = await service . extractMedicalInfo ( mockImageBuffer , 'image/jpeg' ) ;
258-
294+
259295 expect ( result . metadata . missingInformation ) . toContain ( 'Partial document visible' ) ;
260296 expect ( result . keyMedicalTerms [ 0 ] . term ) . toBe ( 'Partial term' ) ;
261297 } ) ;
262298
263299 it ( 'should reject unsupported file types' , async ( ) => {
264300 await expect ( service . extractMedicalInfo ( mockImageBuffer , 'image/gif' ) ) . rejects . toThrow (
265- 'Only JPEG, PNG, and HEIC/HEIF images are allowed'
301+ 'Only JPEG, PNG, and HEIC/HEIF images are allowed' ,
266302 ) ;
267303 } ) ;
268304
@@ -275,7 +311,11 @@ describe('AwsBedrockService', () => {
275311 { name : 'BUN' , value : '15' , unit : 'mg/dL' , normalRange : '7-20' , isAbnormal : false } ,
276312 ] ,
277313 diagnoses : [
278- { condition : 'Normal Kidney Function' , details : 'BUN within normal limits' , recommendations : 'Routine follow-up' } ,
314+ {
315+ condition : 'Normal Kidney Function' ,
316+ details : 'BUN within normal limits' ,
317+ recommendations : 'Routine follow-up' ,
318+ } ,
279319 ] ,
280320 metadata : {
281321 isMedicalReport : true ,
@@ -296,14 +336,22 @@ describe('AwsBedrockService', () => {
296336
297337 it ( 'should accept HEIC/HEIF images from mobile phones' , async ( ) => {
298338 const mockMedicalInfo = {
299- keyMedicalTerms : [
300- { term : 'Creatinine' , definition : 'Waste product filtered by kidneys' } ,
301- ] ,
339+ keyMedicalTerms : [ { term : 'Creatinine' , definition : 'Waste product filtered by kidneys' } ] ,
302340 labValues : [
303- { name : 'Creatinine' , value : '0.9' , unit : 'mg/dL' , normalRange : '0.7-1.3' , isAbnormal : false } ,
341+ {
342+ name : 'Creatinine' ,
343+ value : '0.9' ,
344+ unit : 'mg/dL' ,
345+ normalRange : '0.7-1.3' ,
346+ isAbnormal : false ,
347+ } ,
304348 ] ,
305349 diagnoses : [
306- { condition : 'Normal Kidney Function' , details : 'Creatinine within normal limits' , recommendations : 'Routine follow-up' } ,
350+ {
351+ condition : 'Normal Kidney Function' ,
352+ details : 'Creatinine within normal limits' ,
353+ recommendations : 'Routine follow-up' ,
354+ } ,
307355 ] ,
308356 metadata : {
309357 isMedicalReport : true ,
@@ -327,7 +375,7 @@ describe('AwsBedrockService', () => {
327375 vi . spyOn ( service as any , 'invokeBedrock' ) . mockRejectedValueOnce ( error ) ;
328376
329377 await expect ( service . extractMedicalInfo ( mockImageBuffer , 'image/jpeg' ) ) . rejects . toThrow (
330- / F a i l e d t o e x t r a c t m e d i c a l i n f o r m a t i o n f r o m i m a g e : I m a g e p r o c e s s i n g f a i l e d /
378+ / F a i l e d t o e x t r a c t m e d i c a l i n f o r m a t i o n f r o m i m a g e : I m a g e p r o c e s s i n g f a i l e d / ,
331379 ) ;
332380 } ) ;
333381
@@ -337,7 +385,7 @@ describe('AwsBedrockService', () => {
337385 } ) ;
338386
339387 await expect ( service . extractMedicalInfo ( mockImageBuffer , 'image/jpeg' ) ) . rejects . toThrow (
340- / F a i l e d t o e x t r a c t m e d i c a l i n f o r m a t i o n f r o m i m a g e : I n v a l i d r e s p o n s e f o r m a t /
388+ / F a i l e d t o e x t r a c t m e d i c a l i n f o r m a t i o n f r o m i m a g e : I n v a l i d r e s p o n s e f o r m a t / ,
341389 ) ;
342390 } ) ;
343391 } ) ;
0 commit comments