PageSourceSearch

https://gravitate-health.github.io/assets/js/1bc7bfa2.77305a5f.js

js gravitate-health.github.io collected 2026-10-03 09:18:18 UTC 7,272 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[9661],{7375:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>r,default:()=>u,frontMatter:()=>o,metadata:()=>i,toc:()=>c});const i=JSON.parse('{"id":"tutorial-Lens/Implementation strategies","title":"Basic lens structure","description":"Functions interface","source":"@site/docs/tutorial-Lens/3 - Implementation strategies.md","sourceDirName":"tutorial-Lens","slug":"/tutorial-Lens/Implementation strategies","permalink":"/docs/tutorial-Lens/Implementation strategies","draft":false,"unlisted":false,"editUrl":"https://github.com/gravitate-health/gravitate-health.github.io/tree/main/docs/tutorial-Lens/3 - Implementation strategies.md","tags":[],"version":"current","sidebarPosition":3,"frontMatter":{},"sidebar":"tutorialSidebar","previous":{"title":"FHIR Metadata","permalink":"/docs/tutorial-Lens/FHIR metadata"},"next":{"title":"Deploying your Lens","permalink":"/docs/tutorial-Lens/Deploying your lens"}}');var a=t(4848),s=t(8453);const o={},r="Basic lens structure",l={},c=[{value:"Functions interface",id:"functions-interface",level:2},{value:"Required and Optional Functions",id:"required-and-optional-functions",level:3},{value:"Example Structure",id:"example-structure",level:3},{value:"Implementation strategies",id:"implementation-strategies",level:2},{value:"Use of Regular Expressions",id:"use-of-regular-expressions",level:3},{value:"DOM Manipulation",id:"dom-manipulation",level:3},{value:"Performance Considerations",id:"performance-considerations",level:3},{value:"Testing and Validation",id:"testing-and-validation",level:3}];function d(e){const n={admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.header,{children:(0,a.jsx)(n.h1,{id:"basic-lens-structure",children:"Basic lens structure"})}),"\n",(0,a.jsx)(n.h2,{id:"functions-interface",children:"Functions interface"}),"\n",(0,a.jsx)(n.p,{children:"A Lens is a JavaScript program that defines how to transform an ePI document. The basic structure of a Lens includes:"}),"\n",(0,a.jsx)(n.h3,{id:"required-and-optional-functions",children:"Required and Optional Functions"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsxs)(n.strong,{children:[(0,a.jsx)(n.code,{children:"enhance"})," function (mandatory)"]}),": This function takes the original ePI content as input and returns the transformed content. It is where you define how to modify the ePI."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsxs)(n.strong,{children:[(0,a.jsx)(n.code,{children:"explanation"})," function (optional)"]}),": This function provides a human-readable explanation of the changes made by the enhance function. It can be useful for users to understand what modifications were applied."]}),"\n"]}),"\n",(0,a.jsx)(n.h3,{id:"example-structure",children:"Example Structure"}),"\n",(0,a.jsx)(n.p,{children:"Here is a simple example of a Lens structure:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:'/*\n  Input data\n    These variables are automatically populated by the lens execution environment.\n*/\n// ePI data\nlet epiData = epi;\n// IPS data\nlet ipsData = ips;\n// PV data (for future use)\nlet pvData = pv;\n// Original HTML content to be transformed\nlet htmlData = html;\n\n\n/* \n    Enhance function: Transforms the original content to highlight specific sections.\n    Input: htmlData (string) - The original text content.\n           ipsData (object) - The IPS resource data.\n           pvData (object) - The PV resource data.\n           epiData (object) - The ePI resource data.\n    Output: transformedContent (string) - The modified text content with highlights.\n*/\nfunction enhance() { \n    // Your transformation logic here\n    transformedContent = htmlData; // Placeholder\n    return transformedContent;\n}\n\n/* \n    Explanation function: Provides an explanation for the lens\'s behavior.\n    Output: explanationText (string) - A textual explanation.\n*/\nfunction explanation() {\
1n    // Your explanation logic here\n    var explanationText = "This lens highlights relevant sections for your health condition beacuse...";\n    return explanationText;\n}\n\nreturn {\n    enhance: enhance,\n    explanation: explanation\n};\n'})}),"\n",(0,a.jsx)(n.hr,{}),"\n",(0,a.jsx)(n.h2,{id:"implementation-strategies",children:"Implementation strategies"}),"\n",(0,a.jsx)(n.p,{children:"When implementing a Lens, consider the following strategies to ensure it is effective and efficient:"}),"\n",(0,a.jsx)(n.h3,{id:"use-of-regular-expressions",children:"Use of Regular Expressions"}),"\n",(0,a.jsxs)(n.p,{children:[(0,a.jsx)(n.strong,{children:"Regular expressions"})," are powerful tools for pattern matching and text manipulation. They can be used to identify specific sections of the ePI that need to be modified."]}),"\n",(0,a.jsx)(n.admonition,{title:"Example Use Case",type:"note",children:(0,a.jsx)(n.p,{children:"You can use regular expressions to find all instances of a particular term or phrase and replace them with a highlighted version."})}),"\n",(0,a.jsx)(n.h3,{id:"dom-manipulation",children:"DOM Manipulation"}),"\n",(0,a.jsxs)(n.p,{children:["If the ePI content is structured as HTML, you can use ",(0,a.jsx)(n.strong,{children:"DOM manipulation techniques"})," to traverse and modify the document. This allows for more precise control over the elements being changed, such as adding classes or attributes to specific tags."]}),"\n",(0,a.jsx)(n.admonition,{title:"Precision Control",type:"tip",children:(0,a.jsx)(n.p,{children:"DOM manipulation provides fine-grained control over HTML elements, making it ideal for targeted modifications."})}),"\n",(0,a.jsx)(n.h3,{id:"performance-considerations",children:"Performance Considerations"}),"\n",(0,a.jsx)(n.admonition,{title:"Efficiency Requirements",type:"warning",children:(0,a.jsx)(n.p,{children:"Lenses should be designed to run efficiently, especially if they are executed on client devices with limited resources. Avoid complex computations and ensure that the enhance function executes quickly."})}),"\n",(0,a.jsx)(n.admonition,{title:"Offload Heavy Tasks",type:"tip",children:(0,a.jsx)(n.p,{children:"Consider using pre-processors for any heavy computational tasks that can be done before the Lens is applied."})}),"\n",(0,a.jsx)(n.h3,{id:"testing-and-validation",children:"Testing and Validation"}),"\n",(0,a.jsx)(n.admonition,{title:"Coming Soon",type:"caution",children:(0,a.jsx)(n.p,{children:"Testing and validation guidelines will be added in a future version of this documentation."})})]})}function u(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(d,{...e})}):d(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>o,x:()=>r});var i=t(6540);const a={},s=i.createContext(a);function o(e){const n=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),i.createElement(s.Provider,{value:n},e.children)}}}]);

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.