1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4816,5557],{14816:(e,t,a)=>{a.d(t,{downloadProfessionalMedicalPDF:()=>s,generateMedicalPDFWithPdfMake:()=>c});var n=a(60480),i=a(22959),o=a(45557),l=a(77621);let r={nombre_completo:"Profesional de la salud",especialidad:"Especialidad no disponible",cedula:"N/A",mpps:"N/A",colegio_medico:"N/A",telefono:"N/A",telefono2:"",email:"N/A",instagram:"",institucion:"Centro de salud",direccion:"N/A",logo:null,tenantLogo:null,firma:null},c=async({pdfType:e="consultation",patientData:t={},consultationData:c={},doctorData:s={},date:d=new Date().toLocaleDateString("es-ES"),documentType:m=null})=>{let u=(({pdfType:e,patientData:t={},consultationData:a={},doctorData:n={},date:i="",documentType:o=null})=>JSON.stringify({pdfType:e||"consultation",documentType:o||null,date:i||null,patient:{nombre_completo:t?.nombre_completo||"",numero_historial:t?.numero_historial||"",fecha_nacimiento:t?.fecha_nacimiento||"",sexo:t?.sexo||""},consultation:{fecha:a?.fecha||"",customText:a?.customText||"",motivo_consulta:a?.motivo_consulta||"",enfermedad_actual:a?.enfermedad_actual||"",diagnostico:a?.diagnostico||"",plan_tratamiento:a?.plan_tratamiento||"",recipeCount:a?.recipeData?.medicamentos?.length||0,fieldsCount:a?.fields?.length||0},doctor:{nombre_completo:n?.nombre_completo||"",especialidad:n?.especialidad||"",institucion:n?.institucion||""}}))({pdfType:e,patientData:t,consultationData:c,doctorData:s,date:d,documentType:m});return(0,o.runCachedGeneration)(u,async()=>{let u=await (0,o.initializePdfMakeSingleton)(),g=((e={})=>{let t=e;if(!t||0===Object.keys(t).length){let e=(0,i.kC)();e&&Object.keys(e).length>0?t=e:console.warn("sanitizeDoctorData - No cached data available, will use defaults")}let a={...r};return Object.entries(t||{}).forEach(([e,t])=>{null!=t&&""!==t&&(a[e]="string"==typeof t?t.replace(/[\r\n]+/g," "):t)}),a})(s),f=await (0,o.loadLogoToVFS)(u,g?.logo,g?.tenantLogo),h=await (0,o.loadSocialMediaIconsToVFS)(u),{getPDFConfig:y}=await Promise.resolve().then(a.bind(a,22959)),p=y(e),b=c.fields?(0,n.Iy)(c):c,x=[{label:"Paciente",value:t.nombre_completo||"N/A"},{label:"Historia",value:t.numero_historial||"N/A"},t.fecha_nacimiento?{label:"Edad",value:(0,l.Cb)(t.fecha_nacimiento)}:null,t.sexo?{label:"Sexo",value:t.sexo}:null,t.ciudad_nombre?{label:"Ciudad",value:t.ciudad_nombre}:null,b.fecha?{label:"Fecha Cons.",value:(0,n.Lw)(b.fecha).toLocaleDateString("es-ES")+(b.hora?` ${String(b.hora).substring(0,5)}`:"")}:null].filter(Boolean),C=p.includeVitalSigns?[{key:"peso_kg",label:"Peso",unit:"kg"},{key:"talla_cm",label:"Talla",unit:"cm"},{key:"temperatura_c",label:"Temperatura",unit:"\xb0C"},{key:"circunferencia_cefalica_cm",label:"Circ. Cef\xe1lica",unit:"cm"},{key:"saturacion_oxigeno_porcentaje",label:"Sat. Oâ",unit:"%"},{key:"frecuencia_cardiaca_bpm",label:"Frec. Card\xedaca",unit:"bpm"},{key:"frecuencia_respiratoria_rpm",label:"Frec. Respiratoria",unit:"rpm"},{key:"tension_arterial_sistolica_mmhg",label:"TA Sist\xf3lica",unit:"mmHg"},{key:"tension_arterial_diastolica_mmhg",label:"TA Diast\xf3lica",unit:"mmHg"},{key:"cbi",label:"CBI",unit:"cm"},{key:"km",label:"KM",unit:""},{key:"sc",label:"SC",unit:""},{key:"imc",label:"IMC",unit:""}].filter(e=>null!==b[e.key]&&void 0!==b[e.key]&&""!==b[e.key]).map(e=>({label:e.label,value:b[e.key],unit:e.unit})):[],{sections:S,enfermedadActualContent:_,diagnosticoContent:k}=((e,t)=>{let a=(0,i.getPDFConfig)(e),n=e=>{let a=i.a3[e];if(!a)return"";if(a.replaceKey)return t[a.replaceKey];if(!a.directKey)return t[a.dataKey]||"";{let e,n,i=t[a.dataKey],o=t[a.directKey];return e="","string"==typeof i?e=i.trim():i&&"object"==typeof i&&(e=Array.isArray(i)?i.filter(e=>e&&(e.nombre||"string"==typeof e)).map(e=>"string"==typeof e?`⢠${e}`:`⢠${e.nombre}`).join("\n"):Object.values(i).filter(e=>e&&(e.nombre||"string"==typeof e)).map(e=>"string"==typeof e?`⢠${e}`:`⢠${e.nombre}`).join("\n")),n=o?o.trim():"",e&&n?`${e} 2 3${n}`:e||n||""}};if("long_medical_report"===e)return{sections:["motivo_consulta","examenes_fisico","plan_tratamiento"].map(e=>{let t=i.a3[e];
3if(!t)return null;let a=n(e);return a&&0!==a.trim().length?{title:t.title,content:a.trim(),key:e}:null}).filter(Boolean),enfermedadActualContent:t.enfermedad_actual,diagnosticoContent:t.diagnostico};let o=[];return o=e.includes("certificate")&&t.customText?[]:a.sections.filter(e=>"enfermedad_actual"!==e).map(e=>{let t=i.a3[e];if(!t)return null;let a=n(e);return a&&0!==a.trim().length?{title:t.title,content:a.trim(),key:e}:null}).filter(Boolean),{sections:o,enfermedadActualContent:"custom_medical_report"===e||e.includes("certificate")?null:t.enfermedad_actual,diagnosticoContent:"custom_medical_report"===e||"reference"===e||"prescription"===e?null:t.diagnostico}})(e,b),w=S.some(e=>"plan_tratamiento"===e.key),T="long_medical_report"===e,v=()=>T?"sectionHeaderCompact":"sectionHeader",L=()=>T?"sectionContentCompact":"sectionContent",A=()=>T?"vitalSignsTitleCompact":"vitalSignsTitle",M=()=>T?"vitalSignTextCompact":"vitalSignText",D=()=>T?[10,4]:[10,8],I=()=>T?[0,0,0,5]:[0,0,0,15],N={pageSize:"A4",pageMargins:[30,140,30,90],header:{margin:[30,10,30,0],stack:[{table:{widths:["*"],body:[[{stack:[{columns:[((e=!1,t=!1,a=!1)=>a?{image:"tenant-logo.png",width:80,margin:[0,0,10,0]}:t?{image:"user-logo.png",width:80,margin:[0,0,10,0]}:e?{image:"logo.png",width:80,margin:[0,0,10,0]}:{stack:[{text:"âï¸",fontSize:32,alignment:"center",margin:[0,8,0,3],color:"#2c5aa0"},{text:"MEDICINA",fontSize:8,alignment:"center",bold:!0,color:"#1a4287",margin:[0,0,0,5]}]})(f.hasDefaultLogo,f.hasUserLogo,f.hasTenantLogo),{stack:[{text:g.institucion||g.nombre_completo||"Dr. N/A",style:"headerTitle"},{text:g.especialidad||"Especialidad no configurada",style:"headerSubtitle"}],alignment:"center",margin:[10,2,0,2]}]},{columns:[{text:`Paciente: ${t.nombre_completo||"N/A"}`,style:"headerText",width:"50%",alignment:"center"},{text:`Historia: ${x[1]?x[1].value:"N/A"}`,style:"headerText",width:"50%",alignment:"center"}],margin:[0,4,0,1]},{text:`Fecha: ${d}`,style:"headerDate",alignment:"right"}],margin:[10,5]}]]},layout:"headerDashLayout"},..."reference"===e?[{margin:[0,10,0,0],table:{widths:["*"],body:[[{stack:[{text:"Referencia",style:"referenceTitle"},{text:`Referido a: ${g.institucion||"Centro de salud"}${g.telefono?` - ${g.telefono}`:""}`,style:"referenceText",bold:!0},{text:g.nombre_completo||"M\xe9dico",style:"referenceText"},{text:g.especialidad||"Especialidad",style:"referenceText"},{text:g.direccion||"Direcci\xf3n",style:"referenceText"},...g.telefono2?[{text:g.telefono2,style:"referenceText"}]:[]],margin:D()}]]},layout:o.dashLayout}]:[],..."prescription"===e?[{margin:[0,10,0,0],table:{widths:["*"],body:[[{stack:[{text:"RECIPE M\xc9DICO",style:"referenceTitle"}],margin:D()}]]},layout:o.dashLayout}]:[]]},footer:(t,a)=>"long_medical_report"===e?null:{margin:[30,10,30,15],stack:[{canvas:[{type:"line",x1:0,y1:0,x2:515,y2:0,lineWidth:1,lineColor:"#2c5aa0"}]},{columns:[{width:"*",stack:[{text:`${g.institucion||"Instituci\xf3n no configurada"}. ${g.direccion||"N/A"}`,style:"footerClinic"},{text:`Tel\xe9fonos: ${g.telefono||"N/A"}`,style:"footerContact"},{text:g.telefono2||"",style:"footerContact"},...g.instagram&&h.hasInstagramIcon?[{columns:[{image:"instagram-icon.png",width:12},{width:4,text:""},{text:g.instagram,style:"footerContact"}],columnGap:0}]:g.instagram?[{text:`ð· ${g.instagram}`,style:"footerContact"}]:[],...g.email&&h.hasEmailIcon?[{columns:[{image:"email-icon.png",width:12},{width:4,text:""},{text:g.email,style:"footerContact"}],columnGap:0}]:g.email?[{text:`ð§ ${g.email}`,style:"footerContact"}]:[]]},{width:"*",stack:[{text:`${g.nombre_completo||"Dr. N/A"}`,style:"footerDoctorName"},{text:`C.I.: ${g.cedula||"N/A"}`,style:"footerCredentials"},{text:`Reg MPPS ${g.mpps||"N/A"}`,style:"footerCredentials"},{text:`Colegio M\xe9dico: ${g.colegio_medico||"N/A"}`,style:"footerCredentials"}]}],margin:[0,5,0,0]},{text:`P\xe1gina ${t} de ${a}`,style:"pageNumber",alignment:"center",margin:[0,8,0,0]}]},content:[..."long_medical_report"===e&&S.find(e=>"motivo_consulta"===e.key)?[{table:{widths:["*"],body:[[{stack:[{text:S.find(e=>"motivo_consulta"===e.key).title||"MOTIVO DE CONSULTA",style:v()},{text:S.find(e=>"motivo_consulta"===e.key).content||"",style:L()}],margin:D()}]]},layout:o.dashLayout,margin:[0,0,0,0],unbreakable:!0}]:[],...C.length>0&&"long_medical_report"!==e?[{table:{widths:["*"],body:[[{stack:[{text:"SIGNOS VITALES Y MEDIDAS ANTROPOM\xc9TRICAS",style:A()},{table:{widths:["*","*","*","*"],body:[...Array.from({length:Math.ceil(C.length/4)},(e,t)=>{let a=4*t,n=C.slice(a,a+4);for(;n.length<4;)n.push({label:"",value:"",unit:""});return n.map(e=>({text:e.label?`${e.label}: ${e.value}${e.unit}`:"",style:M()}))})]},layout:"noBorders"}],margin:D()}]]},layout:o.dashLayout,margin:I()}]:[],...b.customText?[{table:{widths:["*"],body:[[{stack:[{text:m?m.toUpperCase():"reference"===e?"REFERENCIA M\xc9DICA":"rest_certificate"===e?"CERTIFICADO DE REPOSO":"visit_certificate"===e?"CONSTANCIA M\xc9DICA":"INFORME M\xc9DICO",style:v()},"reference"===e?{text:((e,t="bodyText")=>{let a;if(!e)return[];let n=[],i=/\*\*([^*]+)\*\*/g,o=0;for(;null!==(a=i.exec(e));){if(a.index>o){let i=e.substring(o,a.index);i&&n.push({text:i,style:t})}n.push({text:a[1],style:t,bold:!0}),o=a.index+a[0].length}if(o<e.length){let a=e.substring(o);a&&n.push({text:a,style:t})}return n.length>0?n:[{text:e,style:t}]})(b.customText,L())}:{text:b.customText,style:L()}],margin:D()}]]},layout:o.dashLayout,margin:I()}]:[],..."prescription"===e&&b.recipeData?.medicamentos?[{table:{widths:["50%","50%"],body:[[{stack:[{text:"Recipe",style:"recipeColumnHeader",margin:[0,0,0,10]}
3,{ul:b.recipeData.medicamentos.map(e=>({stack:[{text:`${e.nombre_comercial}: ${e.concentracion||0} mg/cc`,style:"recipeMedicineTitle",margin:[0,0,0,2]},{text:e.nombre_generico||"",style:"recipeMedicineGeneric",margin:[0,0,0,8]}]}))}],margin:D()},{stack:[{text:"Indicaciones",style:"recipeColumnHeader",margin:[0,0,0,10]},{ul:b.recipeData.medicamentos.map(e=>({stack:[{text:`${e.nombre_comercial}: ${e.concentracion||0} mg/cc`,style:"recipeMedicineTitle",margin:[0,0,0,2]},{text:e.nombre_generico||"",style:"recipeMedicineGeneric",margin:[0,0,0,2]},{text:e.indicaciones||"Seguir indicaciones m\xe9dicas",style:"sectionContent",margin:[0,0,0,8]}]}))}],margin:D()}]]},layout:o.dashLayout,margin:I()}]:[],..._&&"prescription"!==e&&"reference"!==e&&"ultrasound_request"!==e?[{table:{widths:["*"],body:[[{stack:[{text:"ENFERMEDAD ACTUAL",style:v()},{text:_,style:T?"enfermedadActualContentCompact":"enfermedadActualContent"}],margin:D()}]]},layout:o.dashLayout,margin:I()}]:[],..."long_medical_report"===e&&C.length>0?[{table:{widths:["*"],body:[[{stack:[{text:"SIGNOS VITALES Y MEDIDAS ANTROPOM\xc9TRICAS",style:A()},{table:{widths:["*","*","*","*"],body:[...Array.from({length:Math.ceil(C.length/4)},(e,t)=>{let a=4*t,n=C.slice(a,a+4);for(;n.length<4;)n.push({label:"",value:"",unit:""});return n.map(e=>({text:e.label?`${e.label}: ${e.value}${e.unit}`:"",style:M()}))})]},layout:"noBorders"}],margin:D()}]]},layout:o.dashLayout,margin:[0,0,0,8]}]:[],..."prescription"!==e?S.filter(t=>"long_medical_report"!==e||"motivo_consulta"!==t.key).flatMap(e=>"plan_tratamiento"===e.key&&k&&k.length>0?[{table:{widths:["*"],body:[[{stack:[{text:"DIAGN\xd3STICO",style:v()},{text:k,style:L()}],margin:D()}]]},layout:o.dashLayout,margin:[0,0,0,0],unbreakable:!0},{table:{widths:["*"],body:[[{stack:[{text:e.title||"Sin t\xedtulo",style:v()},{text:e.content||"Sin contenido",style:L()}],margin:D()}]]},layout:o.dashLayout,margin:[0,0,0,0],unbreakable:!0}]:[{table:{widths:["*"],body:[[{stack:[{text:e.title||"Sin t\xedtulo",style:v()},{text:e.content||"Sin contenido",style:L()}],margin:D()}]]},layout:o.dashLayout,margin:[0,0,0,0],unbreakable:!0}]):[],...k&&k.length>0&&!w&&"ultrasound_request"!==e&&"rest_certificate"!==e&&"visit_certificate"!==e?[{table:{widths:["*"],body:[[{stack:[{text:"DIAGN\xd3STICO",style:"sectionHeader"},{text:k,style:"sectionContent"}],margin:D()}]]},layout:o.dashLayout,margin:[0,0,0,0],unbreakable:!0}]:[]],styles:{headerTitle:{fontSize:17,bold:!0,color:"#1a4287",margin:[0,0,0,2]},headerSubtitle:{fontSize:12,bold:!0,color:"#1a4287",margin:[0,0,0,4]},headerText:{fontSize:12,color:"#333",bold:!0,margin:[0,0,0,2]},headerDate:{fontSize:10,color:"#666",margin:[0,0,0,4]},headerContact:{fontSize:9,color:"#555",italics:!0,margin:[0,0,0,1]},headerCompact:{fontSize:9,color:"#666",margin:[0,0,0,0]},referenceTitle:{fontSize:14,bold:!0,color:"#1a4287",alignment:"center",margin:[0,0,0,8]},referenceText:{fontSize:10,color:"#333",margin:[0,0,0,2]},patientTitle:{fontSize:13,bold:!0,color:"#1a4287",alignment:"center",margin:[0,0,0,10]},patientInfoText:{fontSize:10,color:"#333",margin:[5,3]},patientInfoInline:{fontSize:9,color:"#333",margin:[0,2],alignment:"left"},vitalSignsTitle:{fontSize:13,bold:!0,color:"#1a4287",alignment:"center",margin:[0,0,0,10]},vitalSignText:{fontSize:10,color:"#333",margin:[5,3]},vitalSignsTitleCompact:{fontSize:10,bold:!0,color:"#111",alignment:"center",margin:[0,0,0,4]},vitalSignTextCompact:{fontSize:10,color:"#333",margin:[5,1]},enfermedadActualLabel:{fontSize:12,bold:!0,color:"#1a4287"},enfermedadActualContent:{fontSize:10,color:"#333",lineHeight:1.4},enfermedadActualContentCompact:{fontSize:10,color:"#333",lineHeight:1.2},sectionHeader:{fontSize:12,bold:!0,color:"#1a4287",alignment:"center",margin:[0,0,0,8]},sectionContent:{fontSize:10,lineHeight:1.5,color:"#333",alignment:"justify",margin:[0,0,0,0]},sectionHeaderCompact:{fontSize:10,bold:!0,color:"#111",alignment:"center",margin:[0,0,0,4]},sectionContentCompact:{fontSize:10,lineHeight:1.2,color:"#333",alignment:"justify",margin:[0,0,0,0]},recipeColumnHeader:{fontSize:13,bold:!0,color:"#1a4287",alignment:"center"},recipeMedicineTitle:{fontSize:11,bold:!0,color:"#333"}
3,recipeMedicineGeneric:{fontSize:10,color:"#666",italics:!0},footerDoctorName:{fontSize:12,bold:!0,color:"#1a4287",margin:[0,0,0,2]},footerCredentials:{fontSize:9,color:"#333",margin:[0,0,0,1]},footerClinic:{fontSize:9,color:"#333",margin:[0,3,0,1]},footerContact:{fontSize:8,color:"#555",margin:[0,0,0,1]},pageNumber:{fontSize:9,color:"#333",bold:!0}},defaultStyle:{fontSize:10,lineHeight:1.3}};return new Promise((e,t)=>{let a=setTimeout(()=>t(Error("PDF generation timed out")),5e3);try{u.createPdf(N).getBuffer(t=>{clearTimeout(a),e(t)})}catch(e){clearTimeout(a),t(e)}})})},s=async(e,t="informe-medico.pdf")=>{try{let a=await c(e),n=new Blob([a],{type:"application/pdf"}),i=URL.createObjectURL(n),o=document.createElement("a");o.href=i,o.download=t,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i)}catch(e){throw console.error("ProfessionalMedicalPDF:downloadProfessionalMedicalPDF - Error:",e),e}}},45557:(e,t,a)=>{a.r(t),a.d(t,{GENERATION_CACHE_TTL_MS:()=>r,dashLayout:()=>d,downscalePngToJpegDataUrl:()=>s,generationCache:()=>l,headerDashLayout:()=>m,imageBase64Cache:()=>o,initializePdfMakeSingleton:()=>u,loadImageCached:()=>g,loadLogoToVFS:()=>f,loadSocialMediaIconsToVFS:()=>h,runCachedGeneration:()=>y,sanitizeString:()=>c});let n=null,i=null,o=new Map,l=new Map,r=3e4,c=e=>"string"==typeof e?e.replace(/[\r\n]+/g," "):e,s=(e,t=1400,a=.9)=>new Promise(n=>{try{let i=new(0,window.Image);i.crossOrigin="anonymous",i.onload=()=>{let o=i.naturalWidth||i.width,l=i.naturalHeight||i.height,r=Math.min(1,t/Math.max(o,l)),c=Math.max(1,Math.round(o*r)),s=Math.max(1,Math.round(l*r)),d=document.createElement("canvas");d.width=c,d.height=s,d.getContext("2d").drawImage(i,0,0,c,s);let m=a,u=d.toDataURL("image/jpeg",m),g=()=>{u&&u.length>3670016&&m>.5&&(m=m>.75?.75:.6,u=d.toDataURL("image/jpeg",m),g())};g(),n(u||e)},i.onerror=()=>n(e),i.src=e}catch{n(e)}}),d={fillColor:()=>"#fff",hLineWidth:()=>0,vLineWidth:()=>0,hLineColor:()=>"#2c5aa0",vLineColor:()=>"#2c5aa0",hLineStyle:()=>({dash:{length:3,space:5}}),vLineStyle:()=>({dash:{length:2,space:2}})},m={fillColor:()=>"#fff",hLineWidth:(e,t)=>0,vLineWidth:(e,t)=>0,hLineColor:(e,t)=>"#2c5aa0",vLineColor:(e,t)=>"#2c5aa0",hLineStyle:(e,t)=>({dash:{length:8,space:4}}),vLineStyle:(e,t)=>({dash:{length:8,space:4}})},u=async()=>{if(n)return n;if(i)return i;i=(async()=>{let e=await a.e(6953).then(a.t.bind(a,61980,23)),t=await a.e(2423).then(a.bind(a,62423));return n=e.default||e,t.default&&t.default.pdfMake&&t.default.pdfMake.vfs?n.vfs=t.default.pdfMake.vfs:t.default?n.vfs=t.default:t.pdfMake&&t.pdfMake.vfs?n.vfs=t.pdfMake.vfs:n.vfs=t,n.tableLayouts={...n.tableLayouts,dashLayout:d,headerDashLayout:m},n})();try{return await i}catch(e){throw i=null,e}},g=async e=>{if(o.has(e))return o.get(e);try{let t=await fetch(e);if(!t.ok)return null;let a=await t.blob(),n=new Promise(e=>{let t=new FileReader;t.onload=()=>{let a=t.result.split(",")[1];e(a||null)},t.onerror=()=>e(null),t.readAsDataURL(a)});o.set(e,n);let i=await n;return i?o.set(e,i):o.delete(e),i}catch(t){return o.delete(e),null}},f=async(e,t=null,a=null)=>{let n={hasDefaultLogo:!1,hasUserLogo:!1,hasTenantLogo:!1};try{let t=await g("/assets/logo.png");t&&(e.vfs["logo.png"]=t,n.hasDefaultLogo=!0)}catch(e){}if(t)try{let a=t.includes(",")?t.split(",")[1]:t;e.vfs["user-logo.png"]=a,n.hasUserLogo=!0}catch(e){}if(a)try{let t=a.includes(",")?a.split(",")[1]:a;e.vfs["tenant-logo.png"]=t,n.hasTenantLogo=!0}
3catch(e){}return n},h=async e=>{let t={hasInstagramIcon:!1,hasEmailIcon:!1},a=await g("/assets/instagram.png");a&&(e.vfs["instagram-icon.png"]=a,t.hasInstagramIcon=!0);let n=await g("/assets/email-icon.png");return n&&(e.vfs["email-icon.png"]=n,t.hasEmailIcon=!0),t},y=async(e,t)=>{let a=l.get(e),n=Date.now();if(a){if(a.promise)return a.promise;if(a.buffer&&n-a.timestamp<r)return a.buffer}let i=Promise.resolve().then(t);l.set(e,{promise:i,timestamp:n});try{let t=await i;return l.set(e,{buffer:t,timestamp:Date.now()}),t}catch(t){throw l.delete(e),t}}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.