@oystehr/sdk 4.3.9 → 4.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/client.cjs +12 -5
- package/dist/cjs/client/client.cjs.map +1 -1
- package/dist/cjs/client/client.d.ts +5 -0
- package/dist/cjs/index.min.cjs +1 -1
- package/dist/cjs/index.min.cjs.map +1 -1
- package/dist/cjs/resources/classes/fhir-ext.cjs +196 -4
- package/dist/cjs/resources/classes/fhir-ext.cjs.map +1 -1
- package/dist/cjs/resources/classes/fhir-ext.d.ts +70 -3
- package/dist/cjs/resources/classes/fhir.cjs +14 -3
- package/dist/cjs/resources/classes/fhir.cjs.map +1 -1
- package/dist/cjs/resources/classes/fhir.d.ts +14 -3
- package/dist/cjs/resources/types/FaxSendParams.d.ts +1 -1
- package/dist/cjs/resources/types/ZambdaCreateParams.d.ts +1 -1
- package/dist/cjs/resources/types/ZambdaUpdateParams.d.ts +1 -1
- package/dist/cjs/resources/types/fhir.d.ts +20 -0
- package/dist/esm/client/client.d.ts +5 -0
- package/dist/esm/client/client.js +12 -5
- package/dist/esm/client/client.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/esm/resources/classes/fhir-ext.d.ts +70 -3
- package/dist/esm/resources/classes/fhir-ext.js +194 -5
- package/dist/esm/resources/classes/fhir-ext.js.map +1 -1
- package/dist/esm/resources/classes/fhir.d.ts +14 -3
- package/dist/esm/resources/classes/fhir.js +15 -4
- package/dist/esm/resources/classes/fhir.js.map +1 -1
- package/dist/esm/resources/types/FaxSendParams.d.ts +1 -1
- package/dist/esm/resources/types/ZambdaCreateParams.d.ts +1 -1
- package/dist/esm/resources/types/ZambdaUpdateParams.d.ts +1 -1
- package/dist/esm/resources/types/fhir.d.ts +20 -0
- package/package.json +1 -1
- package/src/client/client.ts +22 -8
- package/src/resources/classes/fhir-ext.ts +257 -7
- package/src/resources/classes/fhir.ts +14 -3
- package/src/resources/types/FaxSendParams.ts +1 -1
- package/src/resources/types/ZambdaCreateParams.ts +1 -1
- package/src/resources/types/ZambdaUpdateParams.ts +1 -1
- package/src/resources/types/fhir.ts +22 -0
package/dist/esm/index.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{v4 as e,validate as t}from"uuid";class s extends Error{code;constructor({message:e,code:t,cause:r}){super(e,{cause:r}),Object.setPrototypeOf(this,s.prototype),this.code=t,this.name="OystehrSdkError"}toString(){return`${this.name}: ${this.message} (code: ${this.code})`}toJSON(){return{name:this.name,message:this.message,code:this.code,cause:this.cause}}}function r(e){const t=[];for(const s of e.issue??[])s.details&&s.details.text&&t.push(s.details.text);return t.length||t.push("Unknown FHIR error"),t.join(",")}class i extends s{cause;constructor({error:e,code:t}){super({message:r(e),code:t}),Object.setPrototypeOf(this,i.prototype),this.cause=e,this.name="OystehrFHIRError"}toJSON(){return{name:this.name,message:this.message,code:this.code,cause:this.cause}}}class n{_level;constructor({level:e}){this._level=e}error(e,t={}){this._level&&["error","info","debug"].includes(this._level)&&console.error(JSON.stringify({message:e,...t}))}info(e,t={}){this._level&&["info","debug"].includes(this._level)&&console.info(JSON.stringify({message:e,...t}))}debug(e,t={}){this._level&&["debug"].includes(this._level)&&console.debug(JSON.stringify({message:e,...t}))}time(e,t={}){this._level&&["debug"].includes(this._level)&&console.time(JSON.stringify({message:e,...t}))}timeEnd(e,t={}){this._level&&["debug"].includes(this._level)&&console.timeEnd(JSON.stringify({message:e,...t}))}}const o=[408,429,500,502,503,504],a=["ECONNRESET","ECONNREFUSED","EPIPE","ETIMEDOUT","UND_ERR_CONNECT_TIMEOUT","UND_ERR_HEADERS_TIMEOUT","UND_ERR_HEADERS_TIMEOUT","UND_ERR_SOCKET"];class u{config;logger;constructor(e){this.config=e,this.logger=new n({level:this.config.logLevel})}request(e,t,r){return async(i,n)=>{const o=()=>this.config,a=()=>this.logger;try{return await h(r,o,a,e,t)(i,n)}catch(e){const t=e;throw this.logger.error(t.message,{code:t.code,cause:t.cause}),new s({message:t.message,code:t.code,cause:t.cause})}}}fhirRequest(e,t){return async(r,n,o)=>{try{const s=()=>this.config.services?.fhirApiUrl??"https://fhir-api.zapehr.com",i=()=>this.config,a=()=>this.logger;return await h(s,i,a,e,t)(r,n,o)}catch(e){const t=e;if("string"==typeof t.message)throw new s({message:t.message,code:t.code,cause:t.cause});throw new i({error:t.message,code:t.code})}}}async startAsyncJob(e,t,r,i,n){const o="async-bulk"===i?"bulk":"bundle",a="async-bulk"===i?this.appendBulkOutputFormat(e):e,u=await this.fhirRequest(a,t)(r,{...n,rawResponse:!0},i);if(202!==u.status)throw new s({message:`Expected start async job to return 202 Accepted, received ${u.status}`,code:u.status});const c=this.readHeader(u.headers,"content-location");if(!c)throw new s({message:"Start Async job response missing Content-Location header",code:500});const h=this.parseAsyncJobId(c);if(!h)throw new s({message:`Could not parse async job id from Content-Location: ${c}`,code:500});return{jobId:h,contentLocation:c,mode:o}}async fetchAsyncJobStatus(e,t){const s=await this.fhirRequest(`/async-job/${e}`,"GET")({},{...t,rawResponse:!0});if(202===s.status)return{status:202,xProgress:this.readHeader(s.headers,"x-progress"),retryAfter:this.readHeader(s.headers,"retry-after")};if(410===s.status)return{status:410};if(404===s.status)return{status:404};if(200===s.status){if(this.isBulkManifest(s.body))return{status:200,mode:"bulk",manifest:s.body};const e=s.body;if("Bundle"===e?.resourceType&&"batch-response"===e?.type){const t=e.entry?.[0],s=t?.response?.status,r=t?.resource,i=t?.response?.outcome;return{status:200,mode:"bundle",bundle:e,interactionStatus:s,resource:r,outcome:i}}return{status:200,body:s.body}}return{status:s.status,body:s.body}}readHeader(e,t){const s=e[t];if(null!=s)return s;const r=t.toLowerCase(),i=Object.keys(e).find((e=>e.toLowerCase()===r));return i?e[i]:void 0}parseAsyncJobId(e){const t=e.split("/").filter(Boolean),s=t.lastIndexOf("async-job");if(!(s<0||s+1>=t.length))return t[s+1]}appendBulkOutputFormat(e){const t=e.includes("?")?"&":"?";return`${e}${t}_outputFormat=${encodeURIComponent("application/fhir+ndjson")}`}isBulkManifest(e){if(null==e||"object"!=typeof e)return!1;const t=e;return"string"==typeof t.transactionTime&&"string"==typeof t.request&&"boolean"==typeof t.requiresAccessToken&&Array.isArray(t.output)&&Array.isArray(t.error)}}function c(e){return"accessToken"in e||"projectId"in e&&t(e.projectId)||"contentType"in e&&2===e.contentType?.split("/").length||"requestId"in e||"ifMatch"in e&&e.ifMatch.startsWith('W/"')||"mode"in e||"rawResponse"in e}function h(t,r,i,n,u){return async(h,l,p)=>{let[b,m]=function(e,t){const s=e&&!t&&!Array.isArray(e)&&c(e)?{}:e??{},r=e&&!t&&!Array.isArray(e)&&c(e)?e:t;return[s,r]}(h,l);m??={},m.requestId??=e();const g=r(),f=i(),T=u.toLowerCase();f.debug("Beginning fetch",{method:T,path:n,requestId:m?.requestId});const y=g.fetch??fetch,k=m?.accessToken??g.accessToken,U=m?.projectId??g.projectId;let q=n,w=b;if(!Array.isArray(b)){const[e,t]=function(e,t){const r={...t},i=e.replace(/\{([^}]+)\}/g,((e,i)=>{if(delete r[i],i.match(/^.*\+$/))return t[i]+"";if(!t[i]||""===t[i])throw new s({message:`Required path parameter is an empty string: ${i}`,code:400});return t[i]?encodeURIComponent(t[i]+""):""})),n=Object.keys(r),o=n.length?n.reduce(((e,t)=>({...e,[t]:r[t]})),{}):{};return[i,o]}(n,b);q=e,w=t}f.debug("Substituted parameters in path",{method:T,path:n,requestId:m?.requestId}),q=q.replace(/^\//,"");const v=t(),j=v.endsWith("/")?v:v+"/",A=new URL(q,j);let I;if(Array.isArray(w))I=JSON.stringify(w);else if(Object.keys(w).length)if("get"===T)d(w,A.searchParams);else if("application/x-www-form-urlencoded"===m?.contentType){const e=new URLSearchParams;d(w,e),I=e.toString()}else I=JSON.stringify(w);else"application/x-www-form-urlencoded"!==m?.contentType&&"post"===T&&(I="{}");f.debug("Prepared request body",{method:T,path:n,requestId:m?.requestId});const E=function(e){if("async-bundle"===e||"async-bulk"===e)return"respond-async"}(p),x=Object.assign(U?{"x-zapehr-project-id":U,"x-oystehr-project-id":U}:{},{"content-type":m?.contentType??"application/json"},E?{Prefer:E}:{},k?{Authorization:`Bearer ${k}`}:{},m?.ifMatch?{"If-Match":m.ifMatch}:{},{"x-oystehr-request-id":m?.requestId}),z={retries:g.retry?.retries??3,jitter:g.retry?.jitter??20,delay:g.retry?.delay??100,onRetry:g.retry?.onRetry,retryOn:[...g.retry?.retryOn??[],...o]};return z.retryOn.push(...o),async function(e,t){let s;for(const r of Array.from({length:(t.retries??0)+1},((e,t)=>t)))try{return await e(r)}catch(e){let i=!1;if("response"in e){const r=e;i=t.retryOn.includes(r.code),s={message:e.message,code:e.code}}else if(s=e,"code"in e&&"string"==typeof e.code){const t=e;i=a.includes(t.code)}if(!i)break;const n=Math.floor(Math.random()*(t.jitter+1));await new Promise((e=>setTimeout(e,t.delay+n))),t.onRetry&&r!==(t.retries??0)&&t.onRetry(r+1)}throw s}((async()=>{f.info("Request start",{method:T,url:A,requestId:m?.requestId});const e=Date.now(),t=await y(new Request(A,{method:T.toUpperCase(),body:I,headers:x}));f.info("Request end",{method:T,url:A,duration:Date.now()-e,requestId:m?.requestId});const s=t.body?await t.text():null;let r;const i=t.headers.get("content-type");try{s&&(i?.includes("application/json")||i?.includes("application/fhir+json"))?(f.time("Deserialized JSON response",{method:T,url:A,requestId:m?.requestId}),r=JSON.parse(s),f.timeEnd("Deserialized JSON response",{method:T,url:A,requestId:m?.requestId})):s&&(i?.includes("application/xml")||i?.includes("text/xml"))?(f.time("Deserialized XML response",{method:T,url:A,requestId:m?.requestId}),r=function(e){try{const t=e.match(/<status>(\d+)<\/status>/),s=t?parseInt(t[1],10):null,r=e.match(/<output>([\s\S]*?)<\/output>/),i=r?r[1]:null;return null===s||null===i?null:{status:s,output:i}}catch(e){return null}}(s),f.timeEnd("Deserialized XML response",{method:T,url:A,requestId:m?.requestId})):r=null}catch(e){r=null}if(f.debug("Deserialized response",{method:T,url:A,requestId:m?.requestId}),m?.rawResponse){const e={};return t.headers.forEach(((t,s)=>{e[s]=t})),{status:t.status,headers:e,body:r??s}}if(!t.ok||t.status>=400){throw{message:("string"==typeof r?.output?r.output:r?.output?.message)??r?.message??r??s??t.statusText,code:r?.output?.code??r?.code??t.status,response:t}}return r}),z)}}function d(e,t){for(const[s,r]of Object.entries(e))Array.isArray(r)?r.forEach((e=>null!=e&&t.append(s,e))):null!=r&&t.append(s,r)}class l extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}list(e){return this.request("/application","get",this.#e.bind(this))(e)}create(e,t){return this.request("/application","post",this.#e.bind(this))(e,t)}get(e,t){return this.request("/application/{id}","get",this.#e.bind(this))(e,t)}update(e,t){return this.request("/application/{id}","patch",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/application/{id}","delete",this.#e.bind(this))(e,t)}rotateSecret(e,t){return this.request("/application/{id}/rotate-secret","post",this.#e.bind(this))(e,t)}revokeRefreshToken(e,t){return this.request("/application/{id}/revoke-refresh-token","post",this.#e.bind(this))(e,t)}revokeAccessToken(e,t){return this.request("/application/{id}/revoke-access-token","post",this.#e.bind(this))(e,t)}}class p extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}issue(e,t){return this.request("/payment/charge/issue","post",this.#e.bind(this))(e,t)}status(e,t){return this.request("/payment/charge/status","post",this.#e.bind(this))(e,t)}}const b="https://extensions.fhir.zapehr.com/encounter-virtual-service-pre-release",m="addressString";function g(e){if(function(e){return Object.hasOwn(e,"virtualService")}(e)){const t=e.virtualService?.find((e=>"https://fhir.zapehr.com/virtual-service-type"===e.channelType?.system));return t?.addressString}if(!e.extension)return;const t=e.extension.find((e=>e.url===b));if(!t?.extension)return;const s=t.extension?.find((e=>e.url===m))?.valueString;return s}class f extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}ENCOUNTER_VS_EXTENSION_URL=b;ENCOUNTER_VS_EXTENSION_RELATIVE_URL=m;getConversationIdFromEncounter=g;create(e,t){return this.request("/messaging/conversation","post",this.#e.bind(this))(e,t)}getToken(e){return this.request("/messaging/conversation/token","get",this.#e.bind(this))(e)}addParticipant(e,t){return this.request("/messaging/conversation/{conversationId}/participant","post",this.#e.bind(this))(e,t)}removeParticipant(e,t){return this.request("/messaging/conversation/{conversationId}/participant","delete",this.#e.bind(this))(e,t)}message(e,t){return this.request("/messaging/conversation/{conversationId}/message","post",this.#e.bind(this))(e,t)}}class T extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}get(e,t){return this.request("/developer/{id}","get",this.#e.bind(this))(e,t)}update(e,t){return this.request("/developer/{id}","patch",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/developer/{id}","delete",this.#e.bind(this))(e,t)}invite(e,t){return this.request("/developer/invite","post",this.#e.bind(this))(e,t)}list(e){return this.request("/developer","get",this.#e.bind(this))(e)}listV2(e,t){return this.request("/developer/v2/list","get",this.#e.bind(this))(e,t)}}class y extends u{constructor(e){super(e)}#e(){return this.config.services?.erxApiUrl??"https://erx-api.zapehr.com/v3"}searchAllergens(e,t){return this.request("/allergen","get",this.#e.bind(this))(e,t)}searchMedications(e,t){return this.request("/medication","get",this.#e.bind(this))(e,t)}getMedication(e,t){return this.request("/medication/details","get",this.#e.bind(this))(e,t)}getConfiguration(e){return this.request("/config","get",this.#e.bind(this))(e)}checkAllergyInteractions(e,t){return this.request("/patient/{patientId}/interactions/allergy","get",this.#e.bind(this))(e,t)}checkMedicationInteractions(e,t){return this.request("/patient/{patientId}/interactions/medication","get",this.#e.bind(this))(e,t)}checkPrecheckInteractions(e,t){return this.request("/patient/{patientId}/interactions/precheck/{drugId}","get",this.#e.bind(this))(e,t)}getMedicationHistory(e,t){return this.request("/patient/{patientId}/medication-history","get",this.#e.bind(this))(e,t)}addPatientPharmacy(e,t){return this.request("/patient/{patientId}/pharmacies","post",this.#e.bind(this))(e,t)}cancelPrescription(e,t){return this.request("/patient/{patientId}/prescriptions/{medicationRequestId}","delete",this.#e.bind(this))(e,t)}syncPatient(e,t){return this.request("/patient/{patientId}/sync","post",this.#e.bind(this))(e,t)}searchPharmacies(e,t){return this.request("/pharmacy","get",this.#e.bind(this))(e,t)}connectPractitioner(e,t){return this.request("/practitioner/connect","get",this.#e.bind(this))(e,t)}checkPractitionerEnrollment(e,t){return this.request("/practitioner/{practitionerId}","get",this.#e.bind(this))(e,t)}enrollPractitioner(e,t){return this.request("/practitioner/{practitionerId}","post",this.#e.bind(this))(e,t)}unenrollPractitioner(e,t){return this.request("/practitioner/{practitionerId}","delete",this.#e.bind(this))(e,t)}}class k extends u{constructor(e){super(e)}#e(){return this.config.services?.faxApiUrl??"https://fax-api.zapehr.com/v1"}offboard(e){return this.request("/offboard","post",this.#e.bind(this))(e)}onboard(e){return this.request("/onboard","post",this.#e.bind(this))(e)}getConfiguration(e){return this.request("/config","get",this.#e.bind(this))(e)}send(e,t){return this.request("/send","post",this.#e.bind(this))(e,t)}}const U=65535;function q(e){const t=(new globalThis.TextEncoder).encode(e);let s="";for(let e=0;e<t.length;e+=U){const r=t.subarray(e,e+U);s+=globalThis.btoa(String.fromCodePoint.apply(void 0,r))}return s}function w(e){return e.system?`${e.system}|${e.code??""}`:e.code??""}function v(e,t){return(e.system??"")===(t.system??"")&&(e.code??"")===(t.code??"")}function j(e,t){const r=t;if(e.ignoreTags?.length){const i=r.meta?.tag??[];for(const t of e.ignoreTags)if(i.some((e=>v(e,t))))throw new s({message:`Resource has an ignored tag (system: "${t.system??""}", code: "${t.code??""}") and cannot be mutated in ignoreTags mode`,code:400});return t}if(e.workspaceTag){const s=e.workspaceTag,i=r.meta?.tag??[];if(!i.some((e=>v(e,s))))return{...t,meta:{...r.meta,tag:[...i,s]}}}return t}function A(e,t){if(e.ignoreTags?.length){for(const r of t)if("add"===r.op||"replace"===r.op||"test"===r.op){const t=r.value;if(null!=t&&"object"==typeof t){const r=t;if(void 0!==r.code)for(const t of e.ignoreTags)if(v(r,t))throw new s({message:`Patch operation contains an ignored tag (system: "${t.system??""}", code: "${t.code??""}") and cannot be applied in ignoreTags mode`,code:400})}}return t}if(e.workspaceTag){const s=e.workspaceTag;return t.reduce(((e,t)=>{if("remove"===t.op&&"/meta/tag"===t.path)return e.push(t),e.push({op:"add",path:"/meta/tag",value:[s]}),e;if("remove"===t.op&&"/meta"===t.path)return e.push(t),e.push({op:"add",path:"/meta",value:{tag:[s]}}),e;if(("add"===t.op||"replace"===t.op)&&"/meta/tag"===t.path){const r=Array.isArray(t.value)?t.value:[];return r.some((e=>v(e,s)))?e.push(t):e.push({...t,value:[...r,s]}),e}if(("add"===t.op||"replace"===t.op)&&"/meta"===t.path){const r=null!=t.value&&"object"==typeof t.value?t.value:{},i=r.tag??[];return i.some((e=>v(e,s)))?e.push(t):e.push({...t,value:{...r,tag:[...i,s]}}),e}return e.push(t),e}),[])}return t}function I(e,t){const s=t,r=s.meta?.tag??[];if(e.workspaceTag){const t=e.workspaceTag;if(!r.some((e=>v(e,t))))throw new i({error:{resourceType:"OperationOutcome",id:"not-found",issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},code:404})}else if(e.ignoreTags?.length)for(const t of e.ignoreTags)if(r.some((e=>v(e,t))))throw new i({error:{resourceType:"OperationOutcome",id:"not-found",issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},code:404})}function E(e){return"async-bundle"===e||"async-bulk"===e}async function x(e,t){const{resourceType:s}=e,r=function(e,t){const s=t?[...t]:[];if(e.workspaceTag)s.push({name:"_tag",value:w(e.workspaceTag)});else if(e.ignoreTags?.length)for(const t of e.ignoreTags)s.push({name:"_tag:not",value:w(t)});return s}(this.config,e.params);let i;r.length&&(i=r.reduce(((e,t)=>(e[t.name]||(e[t.name]=[]),e[t.name].push(t.value),e)),{}));const n=t?.mode;if(E(n))return await this.startAsyncJob(`/${s}/_search`,"POST",i??{},n,{...t,contentType:"application/x-www-form-urlencoded"});const o=await this.fhirRequest(`/${s}/_search`,"POST")(i,{...t,contentType:"application/x-www-form-urlencoded"});return{...o,entry:o.entry,unbundle:function(){return this.entry?.map((e=>e.resource)).filter((e=>void 0!==e))??[]}}}async function z(e,t){const s=j(this.config,e),{resourceType:r}=s,i=t?.mode;return E(i)?await this.startAsyncJob(`/${r}`,"POST",s,i,t):await this.fhirRequest(`/${r}`,"POST")(s,t)}async function S({resourceType:e,id:t},s){const r=s?.mode;if(E(r))return await this.startAsyncJob(`/${e}/${t}`,"GET",{},r,s);const i=await this.fhirRequest(`/${e}/${t}`,"GET")({},s);return I(this.config,i),i}async function P(e,t){const s=j(this.config,e),{id:r,resourceType:i}=s,n=t?.mode,o={...t,ifMatch:t?.optimisticLockingVersionId?`W/"${t.optimisticLockingVersionId}"`:void 0};return E(n)?await this.startAsyncJob(`/${i}/${r}`,"PUT",s,n,o):await this.fhirRequest(`/${i}/${r}`,"PUT")(s,o)}async function O({resourceType:e,id:t,operations:s},r){const i=A(this.config,s),n=r?.mode,o={...r,ifMatch:r?.optimisticLockingVersionId?`W/"${r.optimisticLockingVersionId}"`:void 0};return E(n)?await this.startAsyncJob(`/${e}/${t}`,"PATCH",i,n,{...o,contentType:"application/json-patch+json"}):this.fhirRequest(`/${e}/${t}`,"PATCH")(i,{...o,contentType:"application/json-patch+json"})}async function $({resourceType:e,id:t},s){const r=s?.mode;return E(r)?await this.startAsyncJob(`/${e}/${t}`,"DELETE",{},r,s):await this.fhirRequest(`/${e}/${t}`,"DELETE")({},s)}function R(e,t){if(!e)return t;const s=Number(e);if(Number.isFinite(s)&&s>=0)return Math.max(0,Math.floor(1e3*s));const r=Date.parse(e);return Number.isFinite(r)?Math.max(0,r-Date.now()):t}async function N(e,t){return await this.fetchAsyncJobStatus(e,t)}async function _(e,t,r){const i=t?.pollIntervalMs??5e3,n=t?.timeoutMs??9e5,o=Math.max(1,Math.ceil(n/i));for(let t=0;t<o;t++){const s=await this.fetchAsyncJobStatus(e,r);if(202!==s.status)return s;if(t<o-1){const e="retryAfter"in s?s.retryAfter:void 0;await new Promise((t=>setTimeout(t,R(e,i))))}}throw new s({message:`Async job ${e} did not complete within ${n} ms`,code:408})}async function M(e,t){await this.fhirRequest(`/async-job/${e}`,"DELETE")({},t)}async function C({resourceType:e,id:t,versionId:s,count:r,offset:i},n){const o=n?.mode;return E(o)?s?await this.startAsyncJob(`/${e}/${t}/_history/${s}`,"GET",{},o,n):await this.startAsyncJob(`/${e}/${t}/_history`,"GET",{},o,n):s?this.fhirRequest(`/${e}/${t}/_history/${s}`,"GET")({},n):r?this.fhirRequest(`/${e}/${t}/_history?_total=accurate&_count=${r}\n ${i?`&_offset=${i}`:""}`,"GET")({},n):this.fhirRequest(`/${e}/${t}/_history?_total=accurate`,"GET")({},n)}function J(e){const t=e.split("?")[0].split("/").filter(Boolean);return t.length<=1||t[1].startsWith("_")}function L(e){return e.split("?")[0].endsWith("/_search")}function D(e,t){const{method:s}=e;let r=e.url;if((("GET"===s||"HEAD"===s)&&J(r)||"POST"===s&&L(r))&&(t.workspaceTag&&(r+=(r.includes("?")?"&":"?")+`_tag=${w(t.workspaceTag)}`),t.ignoreTags?.length))for(const e of t.ignoreTags)r+=(r.includes("?")?"&":"?")+`_tag:not=${w(e)}`;const i={request:{method:s,url:r}};if(r.split("?").length>1){const[e,t]=r.split("?"),s=t.split("&").map((e=>{const[t,s]=e.split("=");return{name:t,value:s}})).reduce(((e,{name:t,value:s})=>t?(e[t]||(e[t]=[]),e[t].push(s),e):e),{}),n=new URLSearchParams;d(s,n),i.request.url=`${e}?${n.toString()}`}if(["GET","DELETE","HEAD"].includes(s))return i;if("PUT"===s){const s=j(t,e.resource);return{request:{...i.request,ifMatch:e.ifMatch},resource:s}}if("PATCH"===s){if("resource"in e){let s=e.resource;const r=s.data;if(r){const e=A(t,JSON.parse(function(e){const t=globalThis.atob(e),s=new Uint8Array(t.length);for(let e=0;e<t.length;e++)s[e]=t.charCodeAt(e);return(new globalThis.TextDecoder).decode(s)}(r)));s={...s,data:q(JSON.stringify(e))}}return{request:{...i.request,ifMatch:e.ifMatch},resource:s}}const s=A(t,e.operations),r=q(JSON.stringify(s));return{...i,resource:{resourceType:"Binary",contentType:"application/json-patch+json",data:r}}}if("POST"===s&&L(r))return i;if("POST"===s&&"resource"in e){const s=j(t,e.resource),{fullUrl:r}=e;return{...i,resource:s,fullUrl:r}}throw new Error("Unrecognized method")}async function F(e,t){const s={resourceType:"Bundle",type:"batch",entry:e.requests.map((e=>D(e,this.config)))},r=t?.mode;if(E(r))return await this.startAsyncJob("/","POST",s,r,t);const n=await this.fhirRequest("/","POST")(s,t),o=n.entry,a=this.config.workspaceTag||this.config.ignoreTags?.length?o?.map(((t,s)=>{const r=e.requests[s];if(!r||!t?.resource)return t;if(("GET"===r.method||"HEAD"===r.method)&&!J(r.url))try{I(this.config,t.resource)}catch(e){if(!(e instanceof i))throw e;return{request:t.request,response:{status:"404",outcome:e.cause}}}return t})):o;return{...n,entry:a,unbundle:function(){return this.entry?.map((e=>e.resource)).filter((e=>void 0!==e))??[]},errors:function(){return this.entry?.filter((e=>e.response?.status?.startsWith("4")||e.response?.status?.startsWith("5"))).map((e=>e.response?.outcome)).filter((e=>void 0!==e))}}}async function B(e,t){const s={resourceType:"Bundle",type:"transaction",entry:e.requests.map((e=>D(e,this.config)))},r=t?.mode;if(E(r))return await this.startAsyncJob("/","POST",s,r,t);const i=await this.fhirRequest("/","POST")(s,t);(this.config.workspaceTag||this.config.ignoreTags?.length)&&i.entry?.forEach(((t,s)=>{const r=e.requests[s];r&&t?.resource&&("GET"!==r.method&&"HEAD"!==r.method||J(r.url)||I(this.config,t.resource))}));return{...i,entry:i.entry,unbundle:function(){return this.entry?.map((e=>e.resource)).filter((e=>void 0!==e))??[]}}}async function G({id:e},t){return this.fhirRequest(`/Patient/${e}/$generate-friendly-patient-id`,"POST")({},t)}function H(e,t){const s=[];if(e.line&&s.push(...e.line),e.city||e.state||e.postalCode){const t=[];e.city&&t.push(e.city),e.state&&t.push(e.state),e.postalCode&&t.push(e.postalCode),s.push(t.join(", "))}return e.use&&(t?.all||t?.use)&&s.push("["+e.use+"]"),s.join(t?.lineSeparator||", ").trim()}function V(e,t){const s=[];return e.prefix&&!1!==t?.prefix&&s.push(...e.prefix),e.given&&s.push(...e.given),e.family&&s.push(e.family),e.suffix&&!1!==t?.suffix&&s.push(...e.suffix),e.use&&(t?.all||t?.use)&&s.push("["+e.use+"]"),s.join(" ").trim()}class W extends u{constructor(e){super(e)}#e(){return this.config.services?.fhirApiUrl??"https://fhir-api.zapehr.com"}search=x;create=z;get=S;getAsyncJob=N;waitForAsyncJob=_;cancelAsyncJob=M;update=P;patch=O;delete=$;history=C;batch=F;transaction=B;generateFriendlyPatientId=G;formatAddress=H;formatHumanName=V}class X extends u{constructor(e){super(e)}#e(){return this.config.services?.labApiUrl??"https://labs-api.zapehr.com/v1"}routeList(e){return this.request("/route","get",this.#e.bind(this))(e)}routeCreate(e,t){return this.request("/route","post",this.#e.bind(this))(e,t)}routeGet(e,t){return this.request("/route/{routeGuid}","get",this.#e.bind(this))(e,t)}routeDelete(e,t){return this.request("/route/{routeGuid}","delete",this.#e.bind(this))(e,t)}orderableItemList(e,t){return this.request("/orderableItem","get",this.#e.bind(this))(e,t)}orderableItemQuestionnaireGet(e,t){return this.request("/canonical-questionnaire/lab/{labGuid}/compendium/{compendiumVersion}/item/{itemCode}/questionnaire","get",this.#e.bind(this))(e,t)}orderSubmit(e,t){return this.request("/submit","post",this.#e.bind(this))(e,t)}}class Z extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}list(e){return this.request("/m2m","get",this.#e.bind(this))(e)}create(e,t){return this.request("/m2m","post",this.#e.bind(this))(e,t)}me(e){return this.request("/m2m/me","get",this.#e.bind(this))(e)}get(e,t){return this.request("/m2m/{id}","get",this.#e.bind(this))(e,t)}update(e,t){return this.request("/m2m/{id}","patch",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/m2m/{id}","delete",this.#e.bind(this))(e,t)}rotateSecret(e,t){return this.request("/m2m/{id}/rotate-secret","post",this.#e.bind(this))(e,t)}listV2(e,t){return this.request("/m2m/v2/list","get",this.#e.bind(this))(e,t)}}class K extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}getMessagingConfig(e){return this.request("/messaging/config","get",this.#e.bind(this))(e)}}class Q extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}setUp(e,t){return this.request("/payment/payment-method/setup","post",this.#e.bind(this))(e,t)}setDefault(e,t){return this.request("/payment/payment-method/set-default","post",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/payment/payment-method","delete",this.#e.bind(this))(e,t)}list(e,t){return this.request("/payment/payment-method/list","post",this.#e.bind(this))(e,t)}}class Y extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}get(e){return this.request("/project","get",this.#e.bind(this))(e)}update(e,t){return this.request("/project","patch",this.#e.bind(this))(e,t)}}function ee(){return this.config.services?.rcmApiUrl??"https://rcm-api.zapehr.com/v1"}function te({id:e}){return`${ee.call(this)}/payer/${e}`}async function se({url:e},t){if(!e.startsWith(te.call(this,{id:""})))throw new s({code:400,message:"Invalid payer URL."});const r=new URL(e).pathname.split("/").filter(Boolean),i=r[r.length-1];return this.request("/payer/{id}","get",ee.bind(this))({id:i},t)}class re extends u{constructor(e){super(e)}#e(){return this.config.services?.rcmApiUrl??"https://rcm-api.zapehr.com/v1"}constructPayerUrl=te;getPayerByUrl=se;eligibilityCheck(e,t){return this.request("/eligibility-check","post",this.#e.bind(this))(e,t)}submitClaim(e,t){return this.request("/claim/{claimId}/submit","post",this.#e.bind(this))(e,t)}setClaimStatus(e,t){return this.request("/claim/{claimId}/status","post",this.#e.bind(this))(e,t)}listPayers(e,t){return this.request("/payer","get",this.#e.bind(this))(e,t)}getPayer(e,t){return this.request("/payer/{id}","get",this.#e.bind(this))(e,t)}}class ie extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}list(e){return this.request("/iam/role","get",this.#e.bind(this))(e)}create(e,t){return this.request("/iam/role","post",this.#e.bind(this))(e,t)}get(e,t){return this.request("/iam/role/{roleId}","get",this.#e.bind(this))(e,t)}update(e,t){return this.request("/iam/role/{roleId}","patch",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/iam/role/{roleId}","delete",this.#e.bind(this))(e,t)}}class ne extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}list(e){return this.request("/secret","get",this.#e.bind(this))(e)}set(e,t){return this.request("/secret","post",this.#e.bind(this))(e,t)}get(e,t){return this.request("/secret/{name}","get",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/secret/{name}","delete",this.#e.bind(this))(e,t)}}class oe extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}createMeeting(e,t){return this.request("/telemed/v2/meeting","post",this.#e.bind(this))(e,t)}joinMeeting(e,t){return this.request("/telemed/v2/meeting/{encounterId}/join","get",this.#e.bind(this))(e,t)}}class ae extends u{constructor(e){super(e)}#e(){return this.config.services?.terminologyApiUrl??"https://terminology-api.zapehr.com/v1"}searchCpt(e,t){return this.request("/cpt/search","get",this.#e.bind(this))(e,t)}searchHcpcs(e,t){return this.request("/hcpcs/search","get",this.#e.bind(this))(e,t)}}class ue extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}send(e,t){return this.request("/messaging/transactional-sms/send","post",this.#e.bind(this))(e,t)}}class ce extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}me(e){return this.request("/user/me","get",this.#e.bind(this))(e)}get(e,t){return this.request("/user/{id}","get",this.#e.bind(this))(e,t)}update(e,t){return this.request("/user/{id}","patch",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/user/{id}","delete",this.#e.bind(this))(e,t)}resetMfa(e,t){return this.request("/user/{id}/reset-mfa","post",this.#e.bind(this))(e,t)}resetPasswordLink(e,t){return this.request("/user/{id}/reset-password-link","post",this.#e.bind(this))(e,t)}changePassword(e,t){return this.request("/user/{id}/change-password","post",this.#e.bind(this))(e,t)}invite(e,t){return this.request("/user/invite","post",this.#e.bind(this))(e,t)}list(e){return this.request("/user","get",this.#e.bind(this))(e)}listV2(e,t){return this.request("/user/v2/list","get",this.#e.bind(this))(e,t)}}class he extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}get(e){return this.request("/version","get",this.#e.bind(this))(e)}}function de(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}async function le({bucketName:e,"objectPath+":t,file:s}){const r=await this.request("/z3/{bucketName}/{objectPath+}","post",de.bind(this))({action:"upload",bucketName:e,"objectPath+":t});await fetch(r.signedUrl,{method:"PUT",body:s})}async function pe({bucketName:e,"objectPath+":t}){const s=await this.request("/z3/{bucketName}/{objectPath+}","post",de.bind(this))({action:"download",bucketName:e,"objectPath+":t}),r=await fetch(s.signedUrl,{method:"GET"});if(!r.ok)throw new Error("Failed to download file");return r.arrayBuffer()}async function be(e){let t,r;const i=new URL(e.url);if("z3:"===i.protocol){const e=i.pathname.split("/").slice(1);t=i.hostname,r=e.join("/")}else{if(!i.href.startsWith(this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"))throw new s({message:"Invalid Z3 URL",code:400});{const e=i.pathname.split("/").slice(3);t=e[0],r=e.slice(1).join("/")}}const n={action:"upload",bucketName:t,"objectPath+":r};return this.request("/z3/{bucketName}/{objectPath+}","post",de.bind(this))(n)}class me extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}uploadFile=le;downloadFile=pe;getPresignedUrlForZ3Url=be;listBuckets(e){return this.request("/z3","get",this.#e.bind(this))(e)}createBucket(e,t){return this.request("/z3/{bucketName}","put",this.#e.bind(this))(e,t)}deleteBucket(e,t){return this.request("/z3/{bucketName}","delete",this.#e.bind(this))(e,t)}listObjects(e,t){return this.request("/z3/{bucketName}/{objectPath+}","get",this.#e.bind(this))(e,t)}getPresignedUrl(e,t){return this.request("/z3/{bucketName}/{objectPath+}","post",this.#e.bind(this))(e,t)}deleteObject(e,t){return this.request("/z3/{bucketName}/{objectPath+}","delete",this.#e.bind(this))(e,t)}}function ge(){return this.config.services?.zambdaApiUrl??"https://zambda-api.zapehr.com/v1"}async function fe({id:e,file:t,filename:r}){const i=await this.request("/zambda/{id}/presigned-url","post",ge.bind(this))({id:e,action:"upload",filename:r}),n=await fetch(i.signedUrl,{method:"PUT",body:t});if(!n.ok)throw new s({message:"Failed to upload file",code:n.status,cause:n.statusText})}async function Te({id:e}){const t=await this.request("/zambda/{id}/presigned-url","post",ge.bind(this))({id:e,action:"download"}),r=await fetch(t.signedUrl,{method:"GET"});if(!r.ok)throw new s({message:"Failed to download file",code:r.status,cause:r.statusText});return r.arrayBuffer()}class ye extends u{constructor(e){super(e)}#e(){return this.config.services?.zambdaApiUrl??"https://zambda-api.zapehr.com/v1"}uploadFile=fe;downloadFile=Te;list(e){return this.request("/zambda","get",this.#e.bind(this))(e)}create(e,t){return this.request("/zambda","post",this.#e.bind(this))(e,t)}get(e,t){return this.request("/zambda/{id}","get",this.#e.bind(this))(e,t)}update(e,t){return this.request("/zambda/{id}","patch",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/zambda/{id}","delete",this.#e.bind(this))(e,t)}execute(e,t){return this.request("/zambda/{id}/execute","post",this.#e.bind(this))(e,t)}executePublic(e,t){return this.request("/zambda/{id}/execute-public","post",this.#e.bind(this))(e,t)}s3Upload(e,t){return this.request("/zambda/{id}/s3-upload","post",this.#e.bind(this))(e,t)}getPresignedUrl(e,t){return this.request("/zambda/{id}/presigned-url","post",this.#e.bind(this))(e,t)}}class ke extends u{constructor(e){super(e)}#e(){return this.config.services?.zambdaApiUrl??"https://zambda-api.zapehr.com/v1"}list(e,t){return this.request("/zambda/{id}/logStream","post",this.#e.bind(this))(e,t)}search(e,t){return this.request("/zambda/{id}/logStream/search","post",this.#e.bind(this))(e,t)}get(e,t){return this.request("/zambda/{id}/logStream/{logStreamName}","post",this.#e.bind(this))(e,t)}}let Ue=class{config;application;developer;m2m;messaging;conversation;transactionalSMS;paymentMethod;charge;project;role;secret;telemed;user;version;z3;fax;lab;erx;terminology;zambda;zambdaLogStream;rcm;fhir;constructor(e){if(e.workspaceTag&&e.ignoreTags)throw new s({message:"workspaceTag and ignoreTags are mutually exclusive and cannot both be set in config",code:400});this.config=e,this.config.services??={},this.config.services.projectApiUrl??=e.projectApiUrl,this.config.services.fhirApiUrl??=e.fhirApiUrl,this.application=new l(e),this.developer=new T(e),this.m2m=new Z(e),this.messaging=new K(e),this.conversation=new f(e),this.transactionalSMS=new ue(e),this.paymentMethod=new Q(e),this.charge=new p(e),this.project=new Y(e),this.role=new ie(e),this.secret=new ne(e),this.telemed=new oe(e),this.user=new ce(e),this.version=new he(e),this.z3=new me(e),this.fax=new k(e),this.lab=new X(e),this.erx=new y(e),this.terminology=new ae(e),this.zambda=new ye(e),this.zambdaLogStream=new ke(e),this.rcm=new re(e),this.fhir=new W(e)}};class qe extends Ue{static OystehrFHIRError=i;static OystehrSdkError=s}export{qe as default};
|
|
1
|
+
import{v4 as e,validate as t}from"uuid";class s extends Error{code;constructor({message:e,code:t,cause:r}){super(e,{cause:r}),Object.setPrototypeOf(this,s.prototype),this.code=t,this.name="OystehrSdkError"}toString(){return`${this.name}: ${this.message} (code: ${this.code})`}toJSON(){return{name:this.name,message:this.message,code:this.code,cause:this.cause}}}function r(e){const t=[];for(const s of e.issue??[])s.details&&s.details.text&&t.push(s.details.text);return t.length||t.push("Unknown FHIR error"),t.join(",")}class i extends s{cause;constructor({error:e,code:t}){super({message:r(e),code:t}),Object.setPrototypeOf(this,i.prototype),this.cause=e,this.name="OystehrFHIRError"}toJSON(){return{name:this.name,message:this.message,code:this.code,cause:this.cause}}}class n{_level;constructor({level:e}){this._level=e}error(e,t={}){this._level&&["error","info","debug"].includes(this._level)&&console.error(JSON.stringify({message:e,...t}))}info(e,t={}){this._level&&["info","debug"].includes(this._level)&&console.info(JSON.stringify({message:e,...t}))}debug(e,t={}){this._level&&["debug"].includes(this._level)&&console.debug(JSON.stringify({message:e,...t}))}time(e,t={}){this._level&&["debug"].includes(this._level)&&console.time(JSON.stringify({message:e,...t}))}timeEnd(e,t={}){this._level&&["debug"].includes(this._level)&&console.timeEnd(JSON.stringify({message:e,...t}))}}const o=[408,429,500,502,503,504],a=["ECONNRESET","ECONNREFUSED","EPIPE","ETIMEDOUT","UND_ERR_CONNECT_TIMEOUT","UND_ERR_HEADERS_TIMEOUT","UND_ERR_HEADERS_TIMEOUT","UND_ERR_SOCKET"];class u{config;logger;constructor(e){this.config=e,this.logger=new n({level:this.config.logLevel})}request(e,t,r){return async(i,n)=>{const o=()=>this.config,a=()=>this.logger;try{return await c(r,o,a,e,t)(i,n)}catch(e){const t=e;throw this.logger.error(t.message,{code:t.code,cause:t.cause}),new s({message:t.message,code:t.code,cause:t.cause})}}}fhirRequest(e,t){return async(r,n,o)=>{try{const s=()=>this.config.services?.fhirApiUrl??"https://fhir-api.zapehr.com",i=()=>this.config,a=()=>this.logger;return await c(s,i,a,e,t)(r,n,o)}catch(e){const t=e;if("string"==typeof t.message)throw new s({message:t.message,code:t.code,cause:t.cause});throw new i({error:t.message,code:t.code})}}}async startAsyncJob(e,t,r,i,n){const o="async-bulk"===i?"bulk":"bundle",a="async-bulk"===i?this.appendBulkOutputFormat(e):e,u=await this.fhirRequest(a,t)(r,{...n,rawResponse:!0},i);if(202!==u.status)throw new s({message:`Expected start async job to return 202 Accepted, received ${u.status}`,code:u.status});const c=this.readHeader(u.headers,"content-location");if(!c)throw new s({message:"Start Async job response missing Content-Location header",code:500});const h=this.parseAsyncJobId(c);if(!h)throw new s({message:`Could not parse async job id from Content-Location: ${c}`,code:500});return{jobId:h,contentLocation:c,mode:o}}async fetchAsyncJobStatus(e,t){const s=await this.fhirRequest(`/async-job/${e}`,"GET")({},{...t,rawResponse:!0});if(202===s.status)return{status:202,xProgress:this.readHeader(s.headers,"x-progress"),retryAfter:this.readHeader(s.headers,"retry-after")};if(410===s.status)return{status:410};if(404===s.status)return{status:404};if(200===s.status){if(this.isBulkManifest(s.body))return{status:200,mode:"bulk",manifest:s.body};const e=s.body;if("Bundle"===e?.resourceType&&"batch-response"===e?.type){const t=e.entry?.[0],s=t?.response?.status,r=t?.resource,i=t?.response?.outcome;return{status:200,mode:"bundle",bundle:e,interactionStatus:s,resource:r,outcome:i}}return{status:200,body:s.body}}return{status:s.status,body:s.body}}readHeader(e,t){const s=e[t];if(null!=s)return s;const r=t.toLowerCase(),i=Object.keys(e).find((e=>e.toLowerCase()===r));return i?e[i]:void 0}parseAsyncJobId(e){const t=e.split("/").filter(Boolean),s=t.lastIndexOf("async-job");if(!(s<0||s+1>=t.length))return t[s+1]}appendBulkOutputFormat(e){const t=e.includes("?")?"&":"?";return`${e}${t}_outputFormat=${encodeURIComponent("application/fhir+ndjson")}`}isBulkManifest(e){if(null==e||"object"!=typeof e)return!1;const t=e;return"string"==typeof t.transactionTime&&"string"==typeof t.request&&"boolean"==typeof t.requiresAccessToken&&Array.isArray(t.output)&&Array.isArray(t.error)}}function c(r,i,n,u,c){return async(l,d,p)=>{let[b,f]=function(e,s){const r=!!e&&!s&&!Array.isArray(e)&&function(e){return"accessToken"in e||"projectId"in e&&t(e.projectId)||"contentType"in e&&2===e.contentType?.split("/").length||"requestId"in e||"ifMatch"in e&&e.ifMatch.startsWith('W/"')||"ifNoneExist"in e||"mode"in e||"rawResponse"in e}(e)&&!function(e){return"string"==typeof e.resourceType&&e.resourceType.length>0}(e),i=r?{}:e??{},n=r?e:s;return[i,n]}(l,d);f??={},f.requestId??=e();const m=i(),g=n(),y=c.toLowerCase();g.debug("Beginning fetch",{method:y,path:u,requestId:f?.requestId});const T=m.fetch??fetch,k=f?.accessToken??m.accessToken,U=f?.projectId??m.projectId;let q=u,w=b;if(!Array.isArray(b)){const[e,t]=function(e,t){const r={...t},i=e.replace(/\{([^}]+)\}/g,((e,i)=>{if(delete r[i],i.match(/^.*\+$/))return t[i]+"";if(!t[i]||""===t[i])throw new s({message:`Required path parameter is an empty string: ${i}`,code:400});return t[i]?encodeURIComponent(t[i]+""):""})),n=Object.keys(r),o=n.length?n.reduce(((e,t)=>({...e,[t]:r[t]})),{}):{};return[i,o]}(u,b);q=e,w=t}g.debug("Substituted parameters in path",{method:y,path:u,requestId:f?.requestId}),q=q.replace(/^\//,"");const v=r(),j=v.endsWith("/")?v:v+"/",A=new URL(q,j);let x;if(Array.isArray(w))x=JSON.stringify(w);else if(Object.keys(w).length)if("get"===y)h(w,A.searchParams);else if("application/x-www-form-urlencoded"===f?.contentType){const e=new URLSearchParams;h(w,e),x=e.toString()}else x=JSON.stringify(w);else"application/x-www-form-urlencoded"!==f?.contentType&&"post"===y&&(x="{}");g.debug("Prepared request body",{method:y,path:u,requestId:f?.requestId});const E=function(e){if("async-bundle"===e||"async-bulk"===e)return"respond-async"}(p),I=Object.assign(U?{"x-zapehr-project-id":U,"x-oystehr-project-id":U}:{},{"content-type":f?.contentType??"application/json"},E?{Prefer:E}:{},k?{Authorization:`Bearer ${k}`}:{},f?.ifMatch?{"If-Match":f.ifMatch}:{},f?.ifNoneExist?{"If-None-Exist":f.ifNoneExist}:{},{"x-oystehr-request-id":f?.requestId}),z={retries:m.retry?.retries??3,jitter:m.retry?.jitter??20,delay:m.retry?.delay??100,onRetry:m.retry?.onRetry,retryOn:[...m.retry?.retryOn??[],...o]};return z.retryOn.push(...o),async function(e,t){let s;for(const r of Array.from({length:(t.retries??0)+1},((e,t)=>t)))try{return await e(r)}catch(e){let i=!1;if("response"in e){const r=e;i=t.retryOn.includes(r.code),s={message:e.message,code:e.code}}else if(s=e,"code"in e&&"string"==typeof e.code){const t=e;i=a.includes(t.code)}if(!i)break;const n=Math.floor(Math.random()*(t.jitter+1));await new Promise((e=>setTimeout(e,t.delay+n))),t.onRetry&&r!==(t.retries??0)&&t.onRetry(r+1)}throw s}((async()=>{g.info("Request start",{method:y,url:A,requestId:f?.requestId});const e=Date.now(),t=await T(new Request(A,{method:y.toUpperCase(),body:x,headers:I}));g.info("Request end",{method:y,url:A,duration:Date.now()-e,requestId:f?.requestId});const s=t.body?await t.text():null;let r;const i=t.headers.get("content-type");try{s&&(i?.includes("application/json")||i?.includes("application/fhir+json"))?(g.time("Deserialized JSON response",{method:y,url:A,requestId:f?.requestId}),r=JSON.parse(s),g.timeEnd("Deserialized JSON response",{method:y,url:A,requestId:f?.requestId})):s&&(i?.includes("application/xml")||i?.includes("text/xml"))?(g.time("Deserialized XML response",{method:y,url:A,requestId:f?.requestId}),r=function(e){try{const t=e.match(/<status>(\d+)<\/status>/),s=t?parseInt(t[1],10):null,r=e.match(/<output>([\s\S]*?)<\/output>/),i=r?r[1]:null;return null===s||null===i?null:{status:s,output:i}}catch(e){return null}}(s),g.timeEnd("Deserialized XML response",{method:y,url:A,requestId:f?.requestId})):r=null}catch(e){r=null}if(g.debug("Deserialized response",{method:y,url:A,requestId:f?.requestId}),f?.rawResponse){const e={};return t.headers.forEach(((t,s)=>{e[s]=t})),{status:t.status,headers:e,body:r??s}}if(!t.ok||t.status>=400){throw{message:("string"==typeof r?.output?r.output:r?.output?.message)??r?.message??r??s??t.statusText,code:r?.output?.code??r?.code??t.status,response:t}}return r}),z)}}function h(e,t){for(const[s,r]of Object.entries(e))Array.isArray(r)?r.forEach((e=>null!=e&&t.append(s,e))):null!=r&&t.append(s,r)}class l extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}list(e){return this.request("/application","get",this.#e.bind(this))(e)}create(e,t){return this.request("/application","post",this.#e.bind(this))(e,t)}get(e,t){return this.request("/application/{id}","get",this.#e.bind(this))(e,t)}update(e,t){return this.request("/application/{id}","patch",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/application/{id}","delete",this.#e.bind(this))(e,t)}rotateSecret(e,t){return this.request("/application/{id}/rotate-secret","post",this.#e.bind(this))(e,t)}revokeRefreshToken(e,t){return this.request("/application/{id}/revoke-refresh-token","post",this.#e.bind(this))(e,t)}revokeAccessToken(e,t){return this.request("/application/{id}/revoke-access-token","post",this.#e.bind(this))(e,t)}}class d extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}issue(e,t){return this.request("/payment/charge/issue","post",this.#e.bind(this))(e,t)}status(e,t){return this.request("/payment/charge/status","post",this.#e.bind(this))(e,t)}}const p="https://extensions.fhir.zapehr.com/encounter-virtual-service-pre-release",b="addressString";function f(e){if(function(e){return Object.hasOwn(e,"virtualService")}(e)){const t=e.virtualService?.find((e=>"https://fhir.zapehr.com/virtual-service-type"===e.channelType?.system));return t?.addressString}if(!e.extension)return;const t=e.extension.find((e=>e.url===p));if(!t?.extension)return;const s=t.extension?.find((e=>e.url===b))?.valueString;return s}class m extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}ENCOUNTER_VS_EXTENSION_URL=p;ENCOUNTER_VS_EXTENSION_RELATIVE_URL=b;getConversationIdFromEncounter=f;create(e,t){return this.request("/messaging/conversation","post",this.#e.bind(this))(e,t)}getToken(e){return this.request("/messaging/conversation/token","get",this.#e.bind(this))(e)}addParticipant(e,t){return this.request("/messaging/conversation/{conversationId}/participant","post",this.#e.bind(this))(e,t)}removeParticipant(e,t){return this.request("/messaging/conversation/{conversationId}/participant","delete",this.#e.bind(this))(e,t)}message(e,t){return this.request("/messaging/conversation/{conversationId}/message","post",this.#e.bind(this))(e,t)}}class g extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}get(e,t){return this.request("/developer/{id}","get",this.#e.bind(this))(e,t)}update(e,t){return this.request("/developer/{id}","patch",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/developer/{id}","delete",this.#e.bind(this))(e,t)}invite(e,t){return this.request("/developer/invite","post",this.#e.bind(this))(e,t)}list(e){return this.request("/developer","get",this.#e.bind(this))(e)}listV2(e,t){return this.request("/developer/v2/list","get",this.#e.bind(this))(e,t)}}class y extends u{constructor(e){super(e)}#e(){return this.config.services?.erxApiUrl??"https://erx-api.zapehr.com/v3"}searchAllergens(e,t){return this.request("/allergen","get",this.#e.bind(this))(e,t)}searchMedications(e,t){return this.request("/medication","get",this.#e.bind(this))(e,t)}getMedication(e,t){return this.request("/medication/details","get",this.#e.bind(this))(e,t)}getConfiguration(e){return this.request("/config","get",this.#e.bind(this))(e)}checkAllergyInteractions(e,t){return this.request("/patient/{patientId}/interactions/allergy","get",this.#e.bind(this))(e,t)}checkMedicationInteractions(e,t){return this.request("/patient/{patientId}/interactions/medication","get",this.#e.bind(this))(e,t)}checkPrecheckInteractions(e,t){return this.request("/patient/{patientId}/interactions/precheck/{drugId}","get",this.#e.bind(this))(e,t)}getMedicationHistory(e,t){return this.request("/patient/{patientId}/medication-history","get",this.#e.bind(this))(e,t)}addPatientPharmacy(e,t){return this.request("/patient/{patientId}/pharmacies","post",this.#e.bind(this))(e,t)}cancelPrescription(e,t){return this.request("/patient/{patientId}/prescriptions/{medicationRequestId}","delete",this.#e.bind(this))(e,t)}syncPatient(e,t){return this.request("/patient/{patientId}/sync","post",this.#e.bind(this))(e,t)}searchPharmacies(e,t){return this.request("/pharmacy","get",this.#e.bind(this))(e,t)}connectPractitioner(e,t){return this.request("/practitioner/connect","get",this.#e.bind(this))(e,t)}checkPractitionerEnrollment(e,t){return this.request("/practitioner/{practitionerId}","get",this.#e.bind(this))(e,t)}enrollPractitioner(e,t){return this.request("/practitioner/{practitionerId}","post",this.#e.bind(this))(e,t)}unenrollPractitioner(e,t){return this.request("/practitioner/{practitionerId}","delete",this.#e.bind(this))(e,t)}}class T extends u{constructor(e){super(e)}#e(){return this.config.services?.faxApiUrl??"https://fax-api.zapehr.com/v1"}offboard(e){return this.request("/offboard","post",this.#e.bind(this))(e)}onboard(e){return this.request("/onboard","post",this.#e.bind(this))(e)}getConfiguration(e){return this.request("/config","get",this.#e.bind(this))(e)}send(e,t){return this.request("/send","post",this.#e.bind(this))(e,t)}}const k=65535;function U(e){const t=(new globalThis.TextEncoder).encode(e);let s="";for(let e=0;e<t.length;e+=k){const r=t.subarray(e,e+k);s+=globalThis.btoa(String.fromCodePoint.apply(void 0,r))}return s}function q(e){return e.system?`${e.system}|${e.code??""}`:e.code??""}function w(e,t){return(e.system??"")===(t.system??"")&&(e.code??"")===(t.code??"")}function v(e,t){const r=t;if(e.ignoreTags?.length){const i=r.meta?.tag??[];for(const t of e.ignoreTags)if(i.some((e=>w(e,t))))throw new s({message:`Resource has an ignored tag (system: "${t.system??""}", code: "${t.code??""}") and cannot be mutated in ignoreTags mode`,code:400});return t}if(e.workspaceTag){const s=e.workspaceTag,i=r.meta?.tag??[];if(!i.some((e=>w(e,s))))return{...t,meta:{...r.meta,tag:[...i,s]}}}return t}function j(e,t){if(e.ignoreTags?.length){for(const r of t)if("add"===r.op||"replace"===r.op||"test"===r.op){const t=r.value;if(null!=t&&"object"==typeof t){const r=t;if(void 0!==r.code)for(const t of e.ignoreTags)if(w(r,t))throw new s({message:`Patch operation contains an ignored tag (system: "${t.system??""}", code: "${t.code??""}") and cannot be applied in ignoreTags mode`,code:400})}}return t}if(e.workspaceTag){const s=e.workspaceTag;return t.reduce(((e,t)=>{if("remove"===t.op&&"/meta/tag"===t.path)return e.push(t),e.push({op:"add",path:"/meta/tag",value:[s]}),e;if("remove"===t.op&&"/meta"===t.path)return e.push(t),e.push({op:"add",path:"/meta",value:{tag:[s]}}),e;if(("add"===t.op||"replace"===t.op)&&"/meta/tag"===t.path){const r=Array.isArray(t.value)?t.value:[];return r.some((e=>w(e,s)))?e.push(t):e.push({...t,value:[...r,s]}),e}if(("add"===t.op||"replace"===t.op)&&"/meta"===t.path){const r=null!=t.value&&"object"==typeof t.value?t.value:{},i=r.tag??[];return i.some((e=>w(e,s)))?e.push(t):e.push({...t,value:{...r,tag:[...i,s]}}),e}return e.push(t),e}),[])}return t}function A(e,t){const s=t,r=s.meta?.tag??[];if(e.workspaceTag){const t=e.workspaceTag;if(!r.some((e=>w(e,t))))throw new i({error:{resourceType:"OperationOutcome",id:"not-found",issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},code:404})}else if(e.ignoreTags?.length)for(const t of e.ignoreTags)if(r.some((e=>w(e,t))))throw new i({error:{resourceType:"OperationOutcome",id:"not-found",issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},code:404})}function x(e){if("string"==typeof e)return e;const t=new URLSearchParams;for(const s of e)t.append(s.name,String(s.value));return t.toString()}function E(e){return"async-bundle"===e||"async-bulk"===e}async function I(e,t){const{resourceType:s}=e,r=function(e,t){const s=t?[...t]:[];if(e.workspaceTag)s.push({name:"_tag",value:q(e.workspaceTag)});else if(e.ignoreTags?.length)for(const t of e.ignoreTags)s.push({name:"_tag:not",value:q(t)});return s}(this.config,e.params);let i;r.length&&(i=r.reduce(((e,t)=>(e[t.name]||(e[t.name]=[]),e[t.name].push(t.value),e)),{}));const n=t?.mode;if(E(n))return await this.startAsyncJob(`/${s}/_search`,"POST",i??{},n,{...t,contentType:"application/x-www-form-urlencoded"});const o=await this.fhirRequest(`/${s}/_search`,"POST")(i,{...t,contentType:"application/x-www-form-urlencoded"});return{...o,entry:o.entry,unbundle:function(){return this.entry?.map((e=>e.resource)).filter((e=>void 0!==e))??[]}}}async function z(e,t){const{pageSize:s,...r}=e;let i=r;if(s){const e=(r.params??[]).filter((e=>"_count"!==e.name))??[];i={...r,params:[...e,{name:"_count",value:s}]}}const n=[],o=I;let a=await o.call(this,i,t);const u={...a,link:a.link?.filter((e=>"next"!==e.relation))};for(;;){const e=a.entry;e&&n.push(...e);const s=a.link?.find((e=>"next"===e.relation))?.url;if(!s)break;a=await this.fhirRequest(s,"GET")({},t)}return{...u,entry:n.length?n:void 0,unbundle:function(){return this.entry?.map((e=>e.resource)).filter((e=>void 0!==e))??[]}}}async function S(e,t){const s=v(this.config,e),{resourceType:r}=s,i=t?.mode,n={...t,ifNoneExist:void 0!==t?.ifNoneExist?x(t.ifNoneExist):void 0};return E(i)?await this.startAsyncJob(`/${r}`,"POST",s,i,n):await this.fhirRequest(`/${r}`,"POST")(s,n)}async function $({resourceType:e,id:t},s){const r=s?.mode;if(E(r))return await this.startAsyncJob(`/${e}/${t}`,"GET",{},r,s);const i=await this.fhirRequest(`/${e}/${t}`,"GET")({},s);return A(this.config,i),i}async function P(e,t){const s=v(this.config,e),{id:r,resourceType:i}=s,n=t?.mode,o={...t,ifMatch:t?.optimisticLockingVersionId?`W/"${t.optimisticLockingVersionId}"`:void 0};return E(n)?await this.startAsyncJob(`/${i}/${r}`,"PUT",s,n,o):await this.fhirRequest(`/${i}/${r}`,"PUT")(s,o)}async function O({resourceType:e,id:t,operations:s},r){const i=j(this.config,s),n=r?.mode,o={...r,ifMatch:r?.optimisticLockingVersionId?`W/"${r.optimisticLockingVersionId}"`:void 0};return E(n)?await this.startAsyncJob(`/${e}/${t}`,"PATCH",i,n,{...o,contentType:"application/json-patch+json"}):this.fhirRequest(`/${e}/${t}`,"PATCH")(i,{...o,contentType:"application/json-patch+json"})}async function N({resourceType:e,id:t},s){const r=s?.mode;return E(r)?await this.startAsyncJob(`/${e}/${t}`,"DELETE",{},r,s):await this.fhirRequest(`/${e}/${t}`,"DELETE")({},s)}function R(e,t){if(!e)return t;const s=Number(e);if(Number.isFinite(s)&&s>=0)return Math.max(0,Math.floor(1e3*s));const r=Date.parse(e);return Number.isFinite(r)?Math.max(0,r-Date.now()):t}async function _(e,t){return await this.fetchAsyncJobStatus(e,t)}async function M(e,t,r){const i=t?.pollIntervalMs??5e3,n=t?.timeoutMs??9e5,o=Math.max(1,Math.ceil(n/i));for(let t=0;t<o;t++){const s=await this.fetchAsyncJobStatus(e,r);if(202!==s.status)return s;if(t<o-1){const e="retryAfter"in s?s.retryAfter:void 0;await new Promise((t=>setTimeout(t,R(e,i))))}}throw new s({message:`Async job ${e} did not complete within ${n} ms`,code:408})}function J(e,t){const r=[],i=e.split("\n");for(let e=0;e<i.length;e++){const n=i[e].trim();if(0!==n.length)try{r.push(JSON.parse(n))}catch(r){throw new s({message:`Failed to parse NDJSON line ${e+1} from ${t}`,code:500,cause:r})}}return r}async function C(e,t,r){const i=await M.call(this,e,t,r);if(404===i.status)throw new s({message:`Async job ${e} not found`,code:404});if(410===i.status)throw new s({message:`Async job ${e} expired`,code:410});if(200!==i.status||!("mode"in i)||"bulk"!==i.mode)throw new s({message:`Async job ${e} did not complete in bulk mode`,code:i.status});const n=r?.accessToken??this.config.accessToken,o=r?.projectId??this.config.projectId;if(i.manifest.requiresAccessToken&&!n)throw new s({message:`Bulk output for async job ${e} requires an access token`,code:401});const a=this.config.fetch??fetch,u={};o&&(u["x-zapehr-project-id"]=o,u["x-oystehr-project-id"]=o),i.manifest.requiresAccessToken&&n&&(u.Authorization=`Bearer ${n}`);const c=Object.keys(u).length>0?u:void 0,h=await Promise.all(i.manifest.output.map((async e=>{const t=await a(new Request(e.url,{method:"GET",headers:c}));if(!t.ok)throw new s({message:`Failed to download bulk output (${e.type}): HTTP ${t.status}`,code:t.status});const r=await t.text();return{...e,resources:J(r,e.url)}})));return{manifest:i.manifest,output:h}}async function L(e,t,s){return{resourceType:"Bundle",type:"collection",entry:(await C.call(this,e,t,s)).output.flatMap((e=>e.resources)).map((e=>({resource:e}))),unbundle:function(){return this.entry?.map((e=>e.resource)).filter((e=>void 0!==e))??[]}}}async function D(e,t){await this.fhirRequest(`/async-job/${e}`,"DELETE")({},t)}async function B({resourceType:e,id:t,versionId:s,count:r,offset:i},n){const o=n?.mode;return E(o)?s?await this.startAsyncJob(`/${e}/${t}/_history/${s}`,"GET",{},o,n):await this.startAsyncJob(`/${e}/${t}/_history`,"GET",{},o,n):s?this.fhirRequest(`/${e}/${t}/_history/${s}`,"GET")({},n):r?this.fhirRequest(`/${e}/${t}/_history?_total=accurate&_count=${r}\n ${i?`&_offset=${i}`:""}`,"GET")({},n):this.fhirRequest(`/${e}/${t}/_history?_total=accurate`,"GET")({},n)}function F(e){const t=e.split("?")[0].split("/").filter(Boolean);return t.length<=1||t[1].startsWith("_")}function G(e){return e.split("?")[0].endsWith("/_search")}function H(e,t){const{method:s}=e;let r=e.url;if((("GET"===s||"HEAD"===s)&&F(r)||"POST"===s&&G(r))&&(t.workspaceTag&&(r+=(r.includes("?")?"&":"?")+`_tag=${q(t.workspaceTag)}`),t.ignoreTags?.length))for(const e of t.ignoreTags)r+=(r.includes("?")?"&":"?")+`_tag:not=${q(e)}`;const i={request:{method:s,url:r}};if(r.split("?").length>1){const[e,t]=r.split("?"),s=t.split("&").map((e=>{const[t,s]=e.split("=");return{name:t,value:s}})).reduce(((e,{name:t,value:s})=>t?(e[t]||(e[t]=[]),e[t].push(s),e):e),{}),n=new URLSearchParams;h(s,n),i.request.url=`${e}?${n.toString()}`}if(["GET","DELETE","HEAD"].includes(s))return i;if("PUT"===s){const s=v(t,e.resource);return{request:{...i.request,ifMatch:e.ifMatch},resource:s}}if("PATCH"===s){if("resource"in e){let s=e.resource;const r=s.data;if(r){const e=j(t,JSON.parse(function(e){const t=globalThis.atob(e),s=new Uint8Array(t.length);for(let e=0;e<t.length;e++)s[e]=t.charCodeAt(e);return(new globalThis.TextDecoder).decode(s)}(r)));s={...s,data:U(JSON.stringify(e))}}return{request:{...i.request,ifMatch:e.ifMatch},resource:s}}const s=j(t,e.operations),r=U(JSON.stringify(s));return{...i,resource:{resourceType:"Binary",contentType:"application/json-patch+json",data:r}}}if("POST"===s&&G(r))return i;if("POST"===s&&"resource"in e){const s=v(t,e.resource),{fullUrl:r,ifNoneExist:n}=e;return{request:{...i.request,ifNoneExist:void 0!==n?x(n):void 0},resource:s,fullUrl:r}}throw new Error("Unrecognized method")}async function V(e,t){const s={resourceType:"Bundle",type:"batch",entry:e.requests.map((e=>H(e,this.config)))},r=t?.mode;if(E(r))return await this.startAsyncJob("/","POST",s,r,t);const n=await this.fhirRequest("/","POST")(s,t),o=n.entry,a=this.config.workspaceTag||this.config.ignoreTags?.length?o?.map(((t,s)=>{const r=e.requests[s];if(!r||!t?.resource)return t;if(("GET"===r.method||"HEAD"===r.method)&&!F(r.url))try{A(this.config,t.resource)}catch(e){if(!(e instanceof i))throw e;return{request:t.request,response:{status:"404",outcome:e.cause}}}return t})):o;return{...n,entry:a,unbundle:function(){return this.entry?.map((e=>e.resource)).filter((e=>void 0!==e))??[]},errors:function(){return this.entry?.filter((e=>e.response?.status?.startsWith("4")||e.response?.status?.startsWith("5"))).map((e=>e.response?.outcome)).filter((e=>void 0!==e))}}}async function W(e,t){const s={resourceType:"Bundle",type:"transaction",entry:e.requests.map((e=>H(e,this.config)))},r=t?.mode;if(E(r))return await this.startAsyncJob("/","POST",s,r,t);const i=await this.fhirRequest("/","POST")(s,t);(this.config.workspaceTag||this.config.ignoreTags?.length)&&i.entry?.forEach(((t,s)=>{const r=e.requests[s];r&&t?.resource&&("GET"!==r.method&&"HEAD"!==r.method||F(r.url)||A(this.config,t.resource))}));return{...i,entry:i.entry,unbundle:function(){return this.entry?.map((e=>e.resource)).filter((e=>void 0!==e))??[]}}}async function X({id:e},t){return this.fhirRequest(`/Patient/${e}/$generate-friendly-patient-id`,"POST")({},t)}function Z(e,t){const s=[];if(e.line&&s.push(...e.line),e.city||e.state||e.postalCode){const t=[];e.city&&t.push(e.city),e.state&&t.push(e.state),e.postalCode&&t.push(e.postalCode),s.push(t.join(", "))}return e.use&&(t?.all||t?.use)&&s.push("["+e.use+"]"),s.join(t?.lineSeparator||", ").trim()}function K(e,t){const s=[];return e.prefix&&!1!==t?.prefix&&s.push(...e.prefix),e.given&&s.push(...e.given),e.family&&s.push(e.family),e.suffix&&!1!==t?.suffix&&s.push(...e.suffix),e.use&&(t?.all||t?.use)&&s.push("["+e.use+"]"),s.join(" ").trim()}class Q extends u{constructor(e){super(e)}#e(){return this.config.services?.fhirApiUrl??"https://fhir-api.zapehr.com"}search=I;searchAndGetAllPages=z;create=S;get=$;update=P;patch=O;delete=N;getAsyncJob=_;waitForAsyncJob=M;waitForAsyncBulkOutput=C;waitForAsyncBulkBundle=L;cancelAsyncJob=D;history=B;batch=V;transaction=W;generateFriendlyPatientId=X;formatAddress=Z;formatHumanName=K}class Y extends u{constructor(e){super(e)}#e(){return this.config.services?.labApiUrl??"https://labs-api.zapehr.com/v1"}routeList(e){return this.request("/route","get",this.#e.bind(this))(e)}routeCreate(e,t){return this.request("/route","post",this.#e.bind(this))(e,t)}routeGet(e,t){return this.request("/route/{routeGuid}","get",this.#e.bind(this))(e,t)}routeDelete(e,t){return this.request("/route/{routeGuid}","delete",this.#e.bind(this))(e,t)}orderableItemList(e,t){return this.request("/orderableItem","get",this.#e.bind(this))(e,t)}orderableItemQuestionnaireGet(e,t){return this.request("/canonical-questionnaire/lab/{labGuid}/compendium/{compendiumVersion}/item/{itemCode}/questionnaire","get",this.#e.bind(this))(e,t)}orderSubmit(e,t){return this.request("/submit","post",this.#e.bind(this))(e,t)}}class ee extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}list(e){return this.request("/m2m","get",this.#e.bind(this))(e)}create(e,t){return this.request("/m2m","post",this.#e.bind(this))(e,t)}me(e){return this.request("/m2m/me","get",this.#e.bind(this))(e)}get(e,t){return this.request("/m2m/{id}","get",this.#e.bind(this))(e,t)}update(e,t){return this.request("/m2m/{id}","patch",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/m2m/{id}","delete",this.#e.bind(this))(e,t)}rotateSecret(e,t){return this.request("/m2m/{id}/rotate-secret","post",this.#e.bind(this))(e,t)}listV2(e,t){return this.request("/m2m/v2/list","get",this.#e.bind(this))(e,t)}}class te extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}getMessagingConfig(e){return this.request("/messaging/config","get",this.#e.bind(this))(e)}}class se extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}setUp(e,t){return this.request("/payment/payment-method/setup","post",this.#e.bind(this))(e,t)}setDefault(e,t){return this.request("/payment/payment-method/set-default","post",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/payment/payment-method","delete",this.#e.bind(this))(e,t)}list(e,t){return this.request("/payment/payment-method/list","post",this.#e.bind(this))(e,t)}}class re extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}get(e){return this.request("/project","get",this.#e.bind(this))(e)}update(e,t){return this.request("/project","patch",this.#e.bind(this))(e,t)}}function ie(){return this.config.services?.rcmApiUrl??"https://rcm-api.zapehr.com/v1"}function ne({id:e}){return`${ie.call(this)}/payer/${e}`}async function oe({url:e},t){if(!e.startsWith(ne.call(this,{id:""})))throw new s({code:400,message:"Invalid payer URL."});const r=new URL(e).pathname.split("/").filter(Boolean),i=r[r.length-1];return this.request("/payer/{id}","get",ie.bind(this))({id:i},t)}class ae extends u{constructor(e){super(e)}#e(){return this.config.services?.rcmApiUrl??"https://rcm-api.zapehr.com/v1"}constructPayerUrl=ne;getPayerByUrl=oe;eligibilityCheck(e,t){return this.request("/eligibility-check","post",this.#e.bind(this))(e,t)}submitClaim(e,t){return this.request("/claim/{claimId}/submit","post",this.#e.bind(this))(e,t)}setClaimStatus(e,t){return this.request("/claim/{claimId}/status","post",this.#e.bind(this))(e,t)}listPayers(e,t){return this.request("/payer","get",this.#e.bind(this))(e,t)}getPayer(e,t){return this.request("/payer/{id}","get",this.#e.bind(this))(e,t)}}class ue extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}list(e){return this.request("/iam/role","get",this.#e.bind(this))(e)}create(e,t){return this.request("/iam/role","post",this.#e.bind(this))(e,t)}get(e,t){return this.request("/iam/role/{roleId}","get",this.#e.bind(this))(e,t)}update(e,t){return this.request("/iam/role/{roleId}","patch",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/iam/role/{roleId}","delete",this.#e.bind(this))(e,t)}}class ce extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}list(e){return this.request("/secret","get",this.#e.bind(this))(e)}set(e,t){return this.request("/secret","post",this.#e.bind(this))(e,t)}get(e,t){return this.request("/secret/{name}","get",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/secret/{name}","delete",this.#e.bind(this))(e,t)}}class he extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}createMeeting(e,t){return this.request("/telemed/v2/meeting","post",this.#e.bind(this))(e,t)}joinMeeting(e,t){return this.request("/telemed/v2/meeting/{encounterId}/join","get",this.#e.bind(this))(e,t)}}class le extends u{constructor(e){super(e)}#e(){return this.config.services?.terminologyApiUrl??"https://terminology-api.zapehr.com/v1"}searchCpt(e,t){return this.request("/cpt/search","get",this.#e.bind(this))(e,t)}searchHcpcs(e,t){return this.request("/hcpcs/search","get",this.#e.bind(this))(e,t)}}class de extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}send(e,t){return this.request("/messaging/transactional-sms/send","post",this.#e.bind(this))(e,t)}}class pe extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}me(e){return this.request("/user/me","get",this.#e.bind(this))(e)}get(e,t){return this.request("/user/{id}","get",this.#e.bind(this))(e,t)}update(e,t){return this.request("/user/{id}","patch",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/user/{id}","delete",this.#e.bind(this))(e,t)}resetMfa(e,t){return this.request("/user/{id}/reset-mfa","post",this.#e.bind(this))(e,t)}resetPasswordLink(e,t){return this.request("/user/{id}/reset-password-link","post",this.#e.bind(this))(e,t)}changePassword(e,t){return this.request("/user/{id}/change-password","post",this.#e.bind(this))(e,t)}invite(e,t){return this.request("/user/invite","post",this.#e.bind(this))(e,t)}list(e){return this.request("/user","get",this.#e.bind(this))(e)}listV2(e,t){return this.request("/user/v2/list","get",this.#e.bind(this))(e,t)}}class be extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}get(e){return this.request("/version","get",this.#e.bind(this))(e)}}function fe(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}async function me({bucketName:e,"objectPath+":t,file:s}){const r=await this.request("/z3/{bucketName}/{objectPath+}","post",fe.bind(this))({action:"upload",bucketName:e,"objectPath+":t});await fetch(r.signedUrl,{method:"PUT",body:s})}async function ge({bucketName:e,"objectPath+":t}){const s=await this.request("/z3/{bucketName}/{objectPath+}","post",fe.bind(this))({action:"download",bucketName:e,"objectPath+":t}),r=await fetch(s.signedUrl,{method:"GET"});if(!r.ok)throw new Error("Failed to download file");return r.arrayBuffer()}async function ye(e){let t,r;const i=new URL(e.url);if("z3:"===i.protocol){const e=i.pathname.split("/").slice(1);t=i.hostname,r=e.join("/")}else{if(!i.href.startsWith(this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"))throw new s({message:"Invalid Z3 URL",code:400});{const e=i.pathname.split("/").slice(3);t=e[0],r=e.slice(1).join("/")}}const n={action:"upload",bucketName:t,"objectPath+":r};return this.request("/z3/{bucketName}/{objectPath+}","post",fe.bind(this))(n)}class Te extends u{constructor(e){super(e)}#e(){return this.config.services?.projectApiUrl??"https://project-api.zapehr.com/v1"}uploadFile=me;downloadFile=ge;getPresignedUrlForZ3Url=ye;listBuckets(e){return this.request("/z3","get",this.#e.bind(this))(e)}createBucket(e,t){return this.request("/z3/{bucketName}","put",this.#e.bind(this))(e,t)}deleteBucket(e,t){return this.request("/z3/{bucketName}","delete",this.#e.bind(this))(e,t)}listObjects(e,t){return this.request("/z3/{bucketName}/{objectPath+}","get",this.#e.bind(this))(e,t)}getPresignedUrl(e,t){return this.request("/z3/{bucketName}/{objectPath+}","post",this.#e.bind(this))(e,t)}deleteObject(e,t){return this.request("/z3/{bucketName}/{objectPath+}","delete",this.#e.bind(this))(e,t)}}function ke(){return this.config.services?.zambdaApiUrl??"https://zambda-api.zapehr.com/v1"}async function Ue({id:e,file:t,filename:r}){const i=await this.request("/zambda/{id}/presigned-url","post",ke.bind(this))({id:e,action:"upload",filename:r}),n=await fetch(i.signedUrl,{method:"PUT",body:t});if(!n.ok)throw new s({message:"Failed to upload file",code:n.status,cause:n.statusText})}async function qe({id:e}){const t=await this.request("/zambda/{id}/presigned-url","post",ke.bind(this))({id:e,action:"download"}),r=await fetch(t.signedUrl,{method:"GET"});if(!r.ok)throw new s({message:"Failed to download file",code:r.status,cause:r.statusText});return r.arrayBuffer()}class we extends u{constructor(e){super(e)}#e(){return this.config.services?.zambdaApiUrl??"https://zambda-api.zapehr.com/v1"}uploadFile=Ue;downloadFile=qe;list(e){return this.request("/zambda","get",this.#e.bind(this))(e)}create(e,t){return this.request("/zambda","post",this.#e.bind(this))(e,t)}get(e,t){return this.request("/zambda/{id}","get",this.#e.bind(this))(e,t)}update(e,t){return this.request("/zambda/{id}","patch",this.#e.bind(this))(e,t)}delete(e,t){return this.request("/zambda/{id}","delete",this.#e.bind(this))(e,t)}execute(e,t){return this.request("/zambda/{id}/execute","post",this.#e.bind(this))(e,t)}executePublic(e,t){return this.request("/zambda/{id}/execute-public","post",this.#e.bind(this))(e,t)}s3Upload(e,t){return this.request("/zambda/{id}/s3-upload","post",this.#e.bind(this))(e,t)}getPresignedUrl(e,t){return this.request("/zambda/{id}/presigned-url","post",this.#e.bind(this))(e,t)}}class ve extends u{constructor(e){super(e)}#e(){return this.config.services?.zambdaApiUrl??"https://zambda-api.zapehr.com/v1"}list(e,t){return this.request("/zambda/{id}/logStream","post",this.#e.bind(this))(e,t)}search(e,t){return this.request("/zambda/{id}/logStream/search","post",this.#e.bind(this))(e,t)}get(e,t){return this.request("/zambda/{id}/logStream/{logStreamName}","post",this.#e.bind(this))(e,t)}}let je=class{config;application;developer;m2m;messaging;conversation;transactionalSMS;paymentMethod;charge;project;role;secret;telemed;user;version;z3;fax;lab;erx;terminology;zambda;zambdaLogStream;rcm;fhir;constructor(e){if(e.workspaceTag&&e.ignoreTags)throw new s({message:"workspaceTag and ignoreTags are mutually exclusive and cannot both be set in config",code:400});this.config=e,this.config.services??={},this.config.services.projectApiUrl??=e.projectApiUrl,this.config.services.fhirApiUrl??=e.fhirApiUrl,this.application=new l(e),this.developer=new g(e),this.m2m=new ee(e),this.messaging=new te(e),this.conversation=new m(e),this.transactionalSMS=new de(e),this.paymentMethod=new se(e),this.charge=new d(e),this.project=new re(e),this.role=new ue(e),this.secret=new ce(e),this.telemed=new he(e),this.user=new pe(e),this.version=new be(e),this.z3=new Te(e),this.fax=new T(e),this.lab=new Y(e),this.erx=new y(e),this.terminology=new le(e),this.zambda=new we(e),this.zambdaLogStream=new ve(e),this.rcm=new ae(e),this.fhir=new Q(e)}};class Ae extends je{static OystehrFHIRError=i;static OystehrSdkError=s}export{Ae as default};
|
|
2
2
|
//# sourceMappingURL=index.min.js.map
|