@oystehr/sdk 4.3.8 → 4.3.10

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.
Files changed (39) hide show
  1. package/README.md +105 -41
  2. package/dist/cjs/client/client.cjs +137 -5
  3. package/dist/cjs/client/client.cjs.map +1 -1
  4. package/dist/cjs/client/client.d.ts +28 -3
  5. package/dist/cjs/index.min.cjs +1 -1
  6. package/dist/cjs/index.min.cjs.map +1 -1
  7. package/dist/cjs/resources/classes/fhir-ext.cjs +277 -17
  8. package/dist/cjs/resources/classes/fhir-ext.cjs.map +1 -1
  9. package/dist/cjs/resources/classes/fhir-ext.d.ts +114 -12
  10. package/dist/cjs/resources/classes/fhir.cjs +14 -0
  11. package/dist/cjs/resources/classes/fhir.cjs.map +1 -1
  12. package/dist/cjs/resources/classes/fhir.d.ts +14 -0
  13. package/dist/cjs/resources/types/FaxSendParams.d.ts +1 -1
  14. package/dist/cjs/resources/types/ZambdaCreateParams.d.ts +1 -1
  15. package/dist/cjs/resources/types/ZambdaUpdateParams.d.ts +1 -1
  16. package/dist/cjs/resources/types/fhir.d.ts +74 -0
  17. package/dist/esm/client/client.d.ts +28 -3
  18. package/dist/esm/client/client.js +137 -5
  19. package/dist/esm/client/client.js.map +1 -1
  20. package/dist/esm/index.min.js +1 -1
  21. package/dist/esm/index.min.js.map +1 -1
  22. package/dist/esm/resources/classes/fhir-ext.d.ts +114 -12
  23. package/dist/esm/resources/classes/fhir-ext.js +273 -19
  24. package/dist/esm/resources/classes/fhir-ext.js.map +1 -1
  25. package/dist/esm/resources/classes/fhir.d.ts +14 -0
  26. package/dist/esm/resources/classes/fhir.js +15 -1
  27. package/dist/esm/resources/classes/fhir.js.map +1 -1
  28. package/dist/esm/resources/types/FaxSendParams.d.ts +1 -1
  29. package/dist/esm/resources/types/ZambdaCreateParams.d.ts +1 -1
  30. package/dist/esm/resources/types/ZambdaUpdateParams.d.ts +1 -1
  31. package/dist/esm/resources/types/fhir.d.ts +74 -0
  32. package/package.json +1 -1
  33. package/src/client/client.ts +214 -7
  34. package/src/resources/classes/fhir-ext.ts +483 -38
  35. package/src/resources/classes/fhir.ts +14 -0
  36. package/src/resources/types/FaxSendParams.ts +1 -1
  37. package/src/resources/types/ZambdaCreateParams.ts +1 -1
  38. package/src/resources/types/ZambdaUpdateParams.ts +1 -1
  39. package/src/resources/types/fhir.ts +97 -0
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});class e extends Error{constructor({message:t,code:i,cause:s}){super(t,{cause:s}),Object.setPrototypeOf(this,e.prototype),this.code=i,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 t(e){var t;const i=[];for(const s of null!==(t=e.issue)&&void 0!==t?t:[])s.details&&s.details.text&&i.push(s.details.text);return i.length||i.push("Unknown FHIR error"),i.join(",")}class i extends e{constructor({error:e,code:s}){super({message:t(e),code:s}),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}}}function s(e,t,i,s){return new(i||(i=Promise))((function(r,n){function o(e){try{a(s.next(e))}catch(t){n(t)}}function u(e){try{a(s.throw(e))}catch(t){n(t)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,u)}a((s=s.apply(e,t||[])).next())}))}function r(e,t,i,s){if("a"===i&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(e):s?s.value:t.get(e)}"function"==typeof SuppressedError&&SuppressedError;var n=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;const o=[];for(let vt=0;vt<256;++vt)o.push((vt+256).toString(16).slice(1));let u;const a=new Uint8Array(16);var d={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};class c{constructor({level:e}){this._level=e}error(e,t={}){this._level&&["error","info","debug"].includes(this._level)&&console.error(JSON.stringify(Object.assign({message:e},t)))}info(e,t={}){this._level&&["info","debug"].includes(this._level)&&console.info(JSON.stringify(Object.assign({message:e},t)))}debug(e,t={}){this._level&&["debug"].includes(this._level)&&console.debug(JSON.stringify(Object.assign({message:e},t)))}time(e,t={}){this._level&&["debug"].includes(this._level)&&console.time(JSON.stringify(Object.assign({message:e},t)))}timeEnd(e,t={}){this._level&&["debug"].includes(this._level)&&console.timeEnd(JSON.stringify(Object.assign({message:e},t)))}}const h=[408,429,500,502,503,504],l=["ECONNRESET","ECONNREFUSED","EPIPE","ETIMEDOUT","UND_ERR_CONNECT_TIMEOUT","UND_ERR_HEADERS_TIMEOUT","UND_ERR_HEADERS_TIMEOUT","UND_ERR_SOCKET"];class p{constructor(e){this.config=e,this.logger=new c({level:this.config.logLevel})}request(t,i,r){return(n,o)=>s(this,void 0,void 0,(function*(){const s=()=>this.config,u=()=>this.logger;try{return yield m(r,s,u,t,i)(n,o)}catch(a){const t=a;throw this.logger.error(t.message,{code:t.code,cause:t.cause}),new e({message:t.message,code:t.code,cause:t.cause})}}))}fhirRequest(t,r){return(n,o)=>s(this,void 0,void 0,(function*(){try{const e=()=>{var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.fhirApiUrl)&&void 0!==t?t:"https://fhir-api.zapehr.com"},i=()=>this.config,s=()=>this.logger;return yield m(e,i,s,t,r)(n,o)}catch(s){const t=s;if("string"==typeof t.message)throw new e({message:t.message,code:t.code,cause:t.cause});throw new i({error:t.message,code:t.code})}}))}}function v(e){var t,i;return"accessToken"in e||"projectId"in e&&"string"==typeof(i=e.projectId)&&n.test(i)||"contentType"in e&&2===(null===(t=e.contentType)||void 0===t?void 0:t.split("/").length)||"requestId"in e||"ifMatch"in e&&e.ifMatch.startsWith('W/"')}function m(t,i,r,n,c){return(p,m)=>s(this,void 0,void 0,(function*(){var g,b,y,q,w,j,T,O,k,U,S,I,E,x;let[z,A]=function(e,t){var i;return[e&&!t&&!Array.isArray(e)&&v(e)?{}:null!==(i=e)&&void 0!==i?i:{},e&&!t&&!Array.isArray(e)&&v(e)?e:t]}(p,m);null!=A||(A={}),null!==(g=A.requestId)&&void 0!==g||(A.requestId=function(e){if(d.randomUUID&&!e)return d.randomUUID();const t=(e=e||{}).random??e.rng?.()??function(){if(!u){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");u=crypto.getRandomValues.bind(crypto)}return u(a)}();if(t.length<16)throw new Error("Random bytes length must be >= 16");return t[6]=15&t[6]|64,t[8]=63&t[8]|128,function(e,t=0){return(o[e[t+0]]+o[e[t+1]]+o[e[t+2]]+o[e[t+3]]+"-"+o[e[t+4]]+o[e[t+5]]+"-"+o[e[t+6]]+o[e[t+7]]+"-"+o[e[t+8]]+o[e[t+9]]+"-"+o[e[t+10]]+o[e[t+11]]+o[e[t+12]]+o[e[t+13]]+o[e[t+14]]+o[e[t+15]]).toLowerCase()}(t)}());const P=i(),R=r(),N=c.toLowerCase();R.debug("Beginning fetch",{method:N,path:n,requestId:null==A?void 0:A.requestId});const _=null!==(b=P.fetch)&&void 0!==b?b:fetch,$=null!==(y=null==A?void 0:A.accessToken)&&void 0!==y?y:P.accessToken,W=null!==(q=null==A?void 0:A.projectId)&&void 0!==q?q:P.projectId;let M=n,C=z;if(!Array.isArray(z)){const[t,i]=function(t,i){const s=Object.assign({},i),r=t.replace(/\{([^}]+)\}/g,((t,r)=>{if(delete s[r],r.match(/^.*\+$/))return i[r]+"";if(!i[r]||""===i[r])throw new e({message:`Required path parameter is an empty string: ${r}`,code:400});return i[r]?encodeURIComponent(i[r]+""):""})),n=Object.keys(s);return[r,n.length?n.reduce(((e,t)=>Object.assign(Object.assign({},e),{[t]:s[t]})),{}):{}]}(n,z);M=t,C=i}R.debug("Substituted parameters in path",{method:N,path:n,requestId:null==A?void 0:A.requestId}),M=M.replace(/^\//,"");const D=t(),L=D.endsWith("/")?D:D+"/",G=new URL(M,L);let J;if(Array.isArray(C))J=JSON.stringify(C);else if(Object.keys(C).length)if("get"===N)f(C,G.searchParams);else if("application/x-www-form-urlencoded"===(null==A?void 0:A.contentType)){const e=new URLSearchParams;f(C,e),J=e.toString()}else J=JSON.stringify(C);else"application/x-www-form-urlencoded"!==(null==A?void 0:A.contentType)&&"post"===N&&(J="{}");R.debug("Prepared request body",{method:N,path:n,requestId:null==A?void 0:A.requestId});const F=Object.assign(W?{"x-zapehr-project-id":W,"x-oystehr-project-id":W}:{},{"content-type":null!==(w=null==A?void 0:A.contentType)&&void 0!==w?w:"application/json"},$?{Authorization:`Bearer ${$}`}:{},(null==A?void 0:A.ifMatch)?{"If-Match":A.ifMatch}:{},{"x-oystehr-request-id":null==A?void 0:A.requestId}),H={retries:null!==(T=null===(j=P.retry)||void 0===j?void 0:j.retries)&&void 0!==T?T:3,jitter:null!==(k=null===(O=P.retry)||void 0===O?void 0:O.jitter)&&void 0!==k?k:20,delay:null!==(S=null===(U=P.retry)||void 0===U?void 0:U.delay)&&void 0!==S?S:100,onRetry:null===(I=P.retry)||void 0===I?void 0:I.onRetry,retryOn:[...null!==(x=null===(E=P.retry)||void 0===E?void 0:E.retryOn)&&void 0!==x?x:[],...h]};return H.retryOn.push(...h),function(e,t){return s(this,void 0,void 0,(function*(){var i,s;let r;for(const o of Array.from({length:(null!==(i=t.retries)&&void 0!==i?i:0)+1},((e,t)=>t)))try{return yield e()}catch(n){let e=!1;if("response"in n){const i=n;e=t.retryOn.includes(i.code),r={message:n.message,code:n.code}}else if(r=n,"code"in n&&"string"==typeof n.code){const t=n;e=l.includes(t.code)}if(!e)break;const i=Math.floor(Math.random()*(t.jitter+1));yield new Promise((e=>setTimeout(e,t.delay+i))),t.onRetry&&o!==(null!==(s=t.retries)&&void 0!==s?s:0)&&t.onRetry(o+1)}throw r}))}((()=>s(this,void 0,void 0,(function*(){var e,t,i,s,r,n,o,u;R.info("Request start",{method:N,url:G,requestId:null==A?void 0:A.requestId});const a=Date.now(),d=yield _(new Request(G,{method:N.toUpperCase(),body:J,headers:F}));R.info("Request end",{method:N,url:G,duration:Date.now()-a,requestId:null==A?void 0:A.requestId});const c=d.body?yield d.text():null;let h;const l=d.headers.get("content-type");try{c&&((null==l?void 0:l.includes("application/json"))||(null==l?void 0:l.includes("application/fhir+json")))?(R.time("Deserialized JSON response",{method:N,url:G,requestId:null==A?void 0:A.requestId}),h=JSON.parse(c),R.timeEnd("Deserialized JSON response",{method:N,url:G,requestId:null==A?void 0:A.requestId})):c&&((null==l?void 0:l.includes("application/xml"))||(null==l?void 0:l.includes("text/xml")))?(R.time("Deserialized XML response",{method:N,url:G,requestId:null==A?void 0:A.requestId}),h=function(e){try{const t=e.match(/<status>(\d+)<\/status>/),i=t?parseInt(t[1],10):null,s=e.match(/<output>([\s\S]*?)<\/output>/),r=s?s[1]:null;return null===i||null===r?null:{status:i,output:r}}catch(t){return null}}(c),R.timeEnd("Deserialized XML response",{method:N,url:G,requestId:null==A?void 0:A.requestId})):h=null}catch(p){h=null}if(R.debug("Deserialized response",{method:N,url:G,requestId:null==A?void 0:A.requestId}),!d.ok||d.status>=400)throw{message:null!==(r=null!==(s=null!==(i=null!==(t="string"==typeof(null==h?void 0:h.output)?h.output:null===(e=null==h?void 0:h.output)||void 0===e?void 0:e.message)&&void 0!==t?t:null==h?void 0:h.message)&&void 0!==i?i:h)&&void 0!==s?s:c)&&void 0!==r?r:d.statusText,code:null!==(u=null!==(o=null===(n=null==h?void 0:h.output)||void 0===n?void 0:n.code)&&void 0!==o?o:null==h?void 0:h.code)&&void 0!==u?u:d.status,response:d};return h}))),H)}))}function f(e,t){for(const[i,s]of Object.entries(e))Array.isArray(s)?s.forEach((e=>null!=e&&t.append(i,e))):null!=s&&t.append(i,s)}var g,b,y,q;class w extends p{constructor(e){super(e),g.add(this)}list(e){return this.request("/application","get",r(this,g,"m",b).bind(this))(e)}create(e,t){return this.request("/application","post",r(this,g,"m",b).bind(this))(e,t)}get(e,t){return this.request("/application/{id}","get",r(this,g,"m",b).bind(this))(e,t)}update(e,t){return this.request("/application/{id}","patch",r(this,g,"m",b).bind(this))(e,t)}delete(e,t){return this.request("/application/{id}","delete",r(this,g,"m",b).bind(this))(e,t)}rotateSecret(e,t){return this.request("/application/{id}/rotate-secret","post",r(this,g,"m",b).bind(this))(e,t)}revokeRefreshToken(e,t){return this.request("/application/{id}/revoke-refresh-token","post",r(this,g,"m",b).bind(this))(e,t)}revokeAccessToken(e,t){return this.request("/application/{id}/revoke-access-token","post",r(this,g,"m",b).bind(this))(e,t)}}g=new WeakSet,b=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class j extends p{constructor(e){super(e),y.add(this)}issue(e,t){return this.request("/payment/charge/issue","post",r(this,y,"m",q).bind(this))(e,t)}status(e,t){return this.request("/payment/charge/status","post",r(this,y,"m",q).bind(this))(e,t)}}y=new WeakSet,q=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};const T="https://extensions.fhir.zapehr.com/encounter-virtual-service-pre-release",O="addressString";function k(e){var t,i,s;if(function(e){return Object.hasOwn(e,"virtualService")}(e)){const i=null===(t=e.virtualService)||void 0===t?void 0:t.find((e=>{var t;return"https://fhir.zapehr.com/virtual-service-type"===(null===(t=e.channelType)||void 0===t?void 0:t.system)}));return null==i?void 0:i.addressString}if(!e.extension)return;const r=e.extension.find((e=>e.url===T));return(null==r?void 0:r.extension)?null===(s=null===(i=r.extension)||void 0===i?void 0:i.find((e=>e.url===O)))||void 0===s?void 0:s.valueString:void 0}var U,S,I,E,x,z,A,P;class R extends p{constructor(e){super(e),U.add(this),this.ENCOUNTER_VS_EXTENSION_URL=T,this.ENCOUNTER_VS_EXTENSION_RELATIVE_URL=O,this.getConversationIdFromEncounter=k}create(e,t){return this.request("/messaging/conversation","post",r(this,U,"m",S).bind(this))(e,t)}getToken(e){return this.request("/messaging/conversation/token","get",r(this,U,"m",S).bind(this))(e)}addParticipant(e,t){return this.request("/messaging/conversation/{conversationId}/participant","post",r(this,U,"m",S).bind(this))(e,t)}removeParticipant(e,t){return this.request("/messaging/conversation/{conversationId}/participant","delete",r(this,U,"m",S).bind(this))(e,t)}message(e,t){return this.request("/messaging/conversation/{conversationId}/message","post",r(this,U,"m",S).bind(this))(e,t)}}U=new WeakSet,S=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class N extends p{constructor(e){super(e),I.add(this)}get(e,t){return this.request("/developer/{id}","get",r(this,I,"m",E).bind(this))(e,t)}update(e,t){return this.request("/developer/{id}","patch",r(this,I,"m",E).bind(this))(e,t)}delete(e,t){return this.request("/developer/{id}","delete",r(this,I,"m",E).bind(this))(e,t)}invite(e,t){return this.request("/developer/invite","post",r(this,I,"m",E).bind(this))(e,t)}list(e){return this.request("/developer","get",r(this,I,"m",E).bind(this))(e)}listV2(e,t){return this.request("/developer/v2/list","get",r(this,I,"m",E).bind(this))(e,t)}}I=new WeakSet,E=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class _ extends p{constructor(e){super(e),x.add(this)}searchAllergens(e,t){return this.request("/allergen","get",r(this,x,"m",z).bind(this))(e,t)}searchMedications(e,t){return this.request("/medication","get",r(this,x,"m",z).bind(this))(e,t)}getMedication(e,t){return this.request("/medication/details","get",r(this,x,"m",z).bind(this))(e,t)}getConfiguration(e){return this.request("/config","get",r(this,x,"m",z).bind(this))(e)}checkAllergyInteractions(e,t){return this.request("/patient/{patientId}/interactions/allergy","get",r(this,x,"m",z).bind(this))(e,t)}checkMedicationInteractions(e,t){return this.request("/patient/{patientId}/interactions/medication","get",r(this,x,"m",z).bind(this))(e,t)}checkPrecheckInteractions(e,t){return this.request("/patient/{patientId}/interactions/precheck/{drugId}","get",r(this,x,"m",z).bind(this))(e,t)}getMedicationHistory(e,t){return this.request("/patient/{patientId}/medication-history","get",r(this,x,"m",z).bind(this))(e,t)}addPatientPharmacy(e,t){return this.request("/patient/{patientId}/pharmacies","post",r(this,x,"m",z).bind(this))(e,t)}cancelPrescription(e,t){return this.request("/patient/{patientId}/prescriptions/{medicationRequestId}","delete",r(this,x,"m",z).bind(this))(e,t)}syncPatient(e,t){return this.request("/patient/{patientId}/sync","post",r(this,x,"m",z).bind(this))(e,t)}searchPharmacies(e,t){return this.request("/pharmacy","get",r(this,x,"m",z).bind(this))(e,t)}connectPractitioner(e,t){return this.request("/practitioner/connect","get",r(this,x,"m",z).bind(this))(e,t)}checkPractitionerEnrollment(e,t){return this.request("/practitioner/{practitionerId}","get",r(this,x,"m",z).bind(this))(e,t)}enrollPractitioner(e,t){return this.request("/practitioner/{practitionerId}","post",r(this,x,"m",z).bind(this))(e,t)}unenrollPractitioner(e,t){return this.request("/practitioner/{practitionerId}","delete",r(this,x,"m",z).bind(this))(e,t)}}x=new WeakSet,z=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.erxApiUrl)&&void 0!==t?t:"https://erx-api.zapehr.com/v3"};class $ extends p{constructor(e){super(e),A.add(this)}offboard(e){return this.request("/offboard","post",r(this,A,"m",P).bind(this))(e)}onboard(e){return this.request("/onboard","post",r(this,A,"m",P).bind(this))(e)}getConfiguration(e){return this.request("/config","get",r(this,A,"m",P).bind(this))(e)}send(e,t){return this.request("/send","post",r(this,A,"m",P).bind(this))(e,t)}}A=new WeakSet,P=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.faxApiUrl)&&void 0!==t?t:"https://fax-api.zapehr.com/v1"};const W=65535;function M(e){const t=(new globalThis.TextEncoder).encode(e);let i="";for(let s=0;s<t.length;s+=W){const e=t.subarray(s,s+W);i+=globalThis.btoa(String.fromCodePoint.apply(void 0,e))}return i}function C(e){var t,i;return e.system?`${e.system}|${null!==(t=e.code)&&void 0!==t?t:""}`:null!==(i=e.code)&&void 0!==i?i:""}function D(e,t){var i,s,r,n;return(null!==(i=e.system)&&void 0!==i?i:"")===(null!==(s=t.system)&&void 0!==s?s:"")&&(null!==(r=e.code)&&void 0!==r?r:"")===(null!==(n=t.code)&&void 0!==n?n:"")}function L(t,i){var s,r,n,o,u,a,d;const c=i;if(null===(s=t.ignoreTags)||void 0===s?void 0:s.length){const s=null!==(n=null===(r=c.meta)||void 0===r?void 0:r.tag)&&void 0!==n?n:[];for(const i of t.ignoreTags)if(s.some((e=>D(e,i))))throw new e({message:`Resource has an ignored tag (system: "${null!==(o=i.system)&&void 0!==o?o:""}", code: "${null!==(u=i.code)&&void 0!==u?u:""}") and cannot be mutated in ignoreTags mode`,code:400});return i}if(t.workspaceTag){const e=t.workspaceTag,s=null!==(d=null===(a=c.meta)||void 0===a?void 0:a.tag)&&void 0!==d?d:[];if(!s.some((t=>D(t,e))))return Object.assign(Object.assign({},i),{meta:Object.assign(Object.assign({},c.meta),{tag:[...s,e]})})}return i}function G(t,i){var s,r,n;if(null===(s=t.ignoreTags)||void 0===s?void 0:s.length){for(const s of i)if("add"===s.op||"replace"===s.op||"test"===s.op){const i=s.value;if(null!=i&&"object"==typeof i){const s=i;if(void 0!==s.code)for(const i of t.ignoreTags)if(D(s,i))throw new e({message:`Patch operation contains an ignored tag (system: "${null!==(r=i.system)&&void 0!==r?r:""}", code: "${null!==(n=i.code)&&void 0!==n?n:""}") and cannot be applied in ignoreTags mode`,code:400})}}return i}if(t.workspaceTag){const e=t.workspaceTag;return i.reduce(((t,i)=>{var s;if("remove"===i.op&&"/meta/tag"===i.path)return t.push(i),t.push({op:"add",path:"/meta/tag",value:[e]}),t;if("remove"===i.op&&"/meta"===i.path)return t.push(i),t.push({op:"add",path:"/meta",value:{tag:[e]}}),t;if(("add"===i.op||"replace"===i.op)&&"/meta/tag"===i.path){const s=Array.isArray(i.value)?i.value:[];return s.some((t=>D(t,e)))?t.push(i):t.push(Object.assign(Object.assign({},i),{value:[...s,e]})),t}if(("add"===i.op||"replace"===i.op)&&"/meta"===i.path){const r=null!=i.value&&"object"==typeof i.value?i.value:{},n=null!==(s=r.tag)&&void 0!==s?s:[];return n.some((t=>D(t,e)))?t.push(i):t.push(Object.assign(Object.assign({},i),{value:Object.assign(Object.assign({},r),{tag:[...n,e]})})),t}return t.push(i),t}),[])}return i}function J(e,t){var s,r,n;const o=null!==(r=null===(s=t.meta)||void 0===s?void 0:s.tag)&&void 0!==r?r:[];if(e.workspaceTag){const t=e.workspaceTag;if(!o.some((e=>D(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(null===(n=e.ignoreTags)||void 0===n?void 0:n.length)for(const u of e.ignoreTags)if(o.some((e=>D(e,u))))throw new i({error:{resourceType:"OperationOutcome",id:"not-found",issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},code:404})}function F(e,t){return s(this,void 0,void 0,(function*(){const{resourceType:i}=e,s=function(e,t){var i;const s=t?[...t]:[];if(e.workspaceTag)s.push({name:"_tag",value:C(e.workspaceTag)});else if(null===(i=e.ignoreTags)||void 0===i?void 0:i.length)for(const r of e.ignoreTags)s.push({name:"_tag:not",value:C(r)});return s}(this.config,e.params);let r;s.length&&(r=s.reduce(((e,t)=>(e[t.name]||(e[t.name]=[]),e[t.name].push(t.value),e)),{}));const n=yield this.fhirRequest(`/${i}/_search`,"POST")(r,Object.assign(Object.assign({},t),{contentType:"application/x-www-form-urlencoded"}));return Object.assign(Object.assign({},n),{entry:n.entry,unbundle:function(){var e,t;return null!==(t=null===(e=this.entry)||void 0===e?void 0:e.map((e=>e.resource)).filter((e=>void 0!==e)))&&void 0!==t?t:[]}})}))}function H(e,t){return s(this,void 0,void 0,(function*(){const i=L(this.config,e),{resourceType:s}=i;return this.fhirRequest(`/${s}`,"POST")(i,t)}))}function V(e,t){return s(this,arguments,void 0,(function*({resourceType:e,id:t},i){const s=yield this.fhirRequest(`/${e}/${t}`,"GET")({},i);return J(this.config,s),s}))}function B(e,t){return s(this,void 0,void 0,(function*(){const i=L(this.config,e),{id:s,resourceType:r}=i;return this.fhirRequest(`/${r}/${s}`,"PUT")(i,Object.assign(Object.assign({},t),{ifMatch:(null==t?void 0:t.optimisticLockingVersionId)?`W/"${t.optimisticLockingVersionId}"`:void 0}))}))}function X(e,t){return s(this,arguments,void 0,(function*({resourceType:e,id:t,operations:i},s){const r=G(this.config,i);return this.fhirRequest(`/${e}/${t}`,"PATCH")(r,Object.assign(Object.assign({},s),{contentType:"application/json-patch+json",ifMatch:(null==s?void 0:s.optimisticLockingVersionId)?`W/"${s.optimisticLockingVersionId}"`:void 0}))}))}function Z(e,t){return s(this,arguments,void 0,(function*({resourceType:e,id:t},i){return this.fhirRequest(`/${e}/${t}`,"DELETE")({},i)}))}function K(e,t){return s(this,arguments,void 0,(function*({resourceType:e,id:t,versionId:i,count:s,offset:r},n){return i?this.fhirRequest(`/${e}/${t}/_history/${i}`,"GET")({},n):s?this.fhirRequest(`/${e}/${t}/_history?_total=accurate&_count=${s}\n ${r?`&_offset=${r}`:""}`,"GET")({},n):this.fhirRequest(`/${e}/${t}/_history?_total=accurate`,"GET")({},n)}))}function Q(e){const t=e.split("?")[0].split("/").filter(Boolean);return t.length<=1||t[1].startsWith("_")}function Y(e){return e.split("?")[0].endsWith("/_search")}function ee(e,t){var i;const{method:s}=e;let r=e.url;if((("GET"===s||"HEAD"===s)&&Q(r)||"POST"===s&&Y(r))&&(t.workspaceTag&&(r+=(r.includes("?")?"&":"?")+`_tag=${C(t.workspaceTag)}`),null===(i=t.ignoreTags)||void 0===i?void 0:i.length))for(const o of t.ignoreTags)r+=(r.includes("?")?"&":"?")+`_tag:not=${C(o)}`;const n={request:{method:s,url:r}};if(r.split("?").length>1){const[e,t]=r.split("?"),i=t.split("&").map((e=>{const[t,i]=e.split("=");return{name:t,value:i}})).reduce(((e,{name:t,value:i})=>t?(e[t]||(e[t]=[]),e[t].push(i),e):e),{}),s=new URLSearchParams;f(i,s),n.request.url=`${e}?${s.toString()}`}if(["GET","DELETE","HEAD"].includes(s))return n;if("PUT"===s){const i=L(t,e.resource);return{request:Object.assign(Object.assign({},n.request),{ifMatch:e.ifMatch}),resource:i}}if("PATCH"===s){if("resource"in e){let i=e.resource;const s=i.data;if(s){const e=G(t,JSON.parse(function(e){const t=globalThis.atob(e),i=new Uint8Array(t.length);for(let s=0;s<t.length;s++)i[s]=t.charCodeAt(s);return(new globalThis.TextDecoder).decode(i)}(s)));i=Object.assign(Object.assign({},i),{data:M(JSON.stringify(e))})}return{request:Object.assign(Object.assign({},n.request),{ifMatch:e.ifMatch}),resource:i}}const i=G(t,e.operations),s=M(JSON.stringify(i));return Object.assign(Object.assign({},n),{resource:{resourceType:"Binary",contentType:"application/json-patch+json",data:s}})}if("POST"===s&&Y(r))return n;if("POST"===s&&"resource"in e){const i=L(t,e.resource),{fullUrl:s}=e;return Object.assign(Object.assign({},n),{resource:i,fullUrl:s})}throw new Error("Unrecognized method")}function te(e,t){return s(this,void 0,void 0,(function*(){var s;const r=yield this.fhirRequest("/","POST")({resourceType:"Bundle",type:"batch",entry:e.requests.map((e=>ee(e,this.config)))},t),n=r.entry,o=this.config.workspaceTag||(null===(s=this.config.ignoreTags)||void 0===s?void 0:s.length)?null==n?void 0:n.map(((t,s)=>{const r=e.requests[s];if(!r||!(null==t?void 0:t.resource))return t;if(("GET"===r.method||"HEAD"===r.method)&&!Q(r.url))try{J(this.config,t.resource)}catch(n){if(!(n instanceof i))throw n;return{request:t.request,response:{status:"404",outcome:n.cause}}}return t})):n,u=Object.assign(Object.assign({},r),{entry:o,unbundle:function(){var e,t;return null!==(t=null===(e=this.entry)||void 0===e?void 0:e.map((e=>e.resource)).filter((e=>void 0!==e)))&&void 0!==t?t:[]},errors:function(){var e;return null===(e=this.entry)||void 0===e?void 0:e.filter((e=>{var t,i,s,r;return(null===(i=null===(t=e.response)||void 0===t?void 0:t.status)||void 0===i?void 0:i.startsWith("4"))||(null===(r=null===(s=e.response)||void 0===s?void 0:s.status)||void 0===r?void 0:r.startsWith("5"))})).map((e=>{var t;return null===(t=e.response)||void 0===t?void 0:t.outcome})).filter((e=>void 0!==e))}});return u}))}function ie(e,t){return s(this,void 0,void 0,(function*(){var i,s;const r=yield this.fhirRequest("/","POST")({resourceType:"Bundle",type:"transaction",entry:e.requests.map((e=>ee(e,this.config)))},t);(this.config.workspaceTag||(null===(i=this.config.ignoreTags)||void 0===i?void 0:i.length))&&(null===(s=r.entry)||void 0===s||s.forEach(((t,i)=>{const s=e.requests[i];s&&(null==t?void 0:t.resource)&&("GET"!==s.method&&"HEAD"!==s.method||Q(s.url)||J(this.config,t.resource))})));const n=Object.assign(Object.assign({},r),{entry:r.entry,unbundle:function(){var e,t;return null!==(t=null===(e=this.entry)||void 0===e?void 0:e.map((e=>e.resource)).filter((e=>void 0!==e)))&&void 0!==t?t:[]}});return n}))}function se(e,t){return s(this,arguments,void 0,(function*({id:e},t){return this.fhirRequest(`/Patient/${e}/$generate-friendly-patient-id`,"POST")({},t)}))}function re(e,t){const i=[];if(e.line&&i.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),i.push(t.join(", "))}return e.use&&((null==t?void 0:t.all)||(null==t?void 0:t.use))&&i.push("["+e.use+"]"),i.join((null==t?void 0:t.lineSeparator)||", ").trim()}function ne(e,t){const i=[];return e.prefix&&!1!==(null==t?void 0:t.prefix)&&i.push(...e.prefix),e.given&&i.push(...e.given),e.family&&i.push(e.family),e.suffix&&!1!==(null==t?void 0:t.suffix)&&i.push(...e.suffix),e.use&&((null==t?void 0:t.all)||(null==t?void 0:t.use))&&i.push("["+e.use+"]"),i.join(" ").trim()}var oe,ue,ae,de,ce,he,le,pe,ve,me,fe,ge,be,ye,qe,we,je,Te,Oe,ke,Ue,Se,Ie,Ee,xe,ze,Ae,Pe,Re,Ne,_e,$e,We;class Me extends p{constructor(e){super(e),oe.add(this),this.search=F,this.create=H,this.get=V,this.update=B,this.patch=X,this.delete=Z,this.history=K,this.batch=te,this.transaction=ie,this.generateFriendlyPatientId=se,this.formatAddress=re,this.formatHumanName=ne}}oe=new WeakSet;class Ce extends p{constructor(e){super(e),ue.add(this)}routeList(e){return this.request("/route","get",r(this,ue,"m",ae).bind(this))(e)}routeCreate(e,t){return this.request("/route","post",r(this,ue,"m",ae).bind(this))(e,t)}routeGet(e,t){return this.request("/route/{routeGuid}","get",r(this,ue,"m",ae).bind(this))(e,t)}routeDelete(e,t){return this.request("/route/{routeGuid}","delete",r(this,ue,"m",ae).bind(this))(e,t)}orderableItemList(e,t){return this.request("/orderableItem","get",r(this,ue,"m",ae).bind(this))(e,t)}orderableItemQuestionnaireGet(e,t){return this.request("/canonical-questionnaire/lab/{labGuid}/compendium/{compendiumVersion}/item/{itemCode}/questionnaire","get",r(this,ue,"m",ae).bind(this))(e,t)}orderSubmit(e,t){return this.request("/submit","post",r(this,ue,"m",ae).bind(this))(e,t)}}ue=new WeakSet,ae=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.labApiUrl)&&void 0!==t?t:"https://labs-api.zapehr.com/v1"};class De extends p{constructor(e){super(e),de.add(this)}list(e){return this.request("/m2m","get",r(this,de,"m",ce).bind(this))(e)}create(e,t){return this.request("/m2m","post",r(this,de,"m",ce).bind(this))(e,t)}me(e){return this.request("/m2m/me","get",r(this,de,"m",ce).bind(this))(e)}get(e,t){return this.request("/m2m/{id}","get",r(this,de,"m",ce).bind(this))(e,t)}update(e,t){return this.request("/m2m/{id}","patch",r(this,de,"m",ce).bind(this))(e,t)}delete(e,t){return this.request("/m2m/{id}","delete",r(this,de,"m",ce).bind(this))(e,t)}rotateSecret(e,t){return this.request("/m2m/{id}/rotate-secret","post",r(this,de,"m",ce).bind(this))(e,t)}listV2(e,t){return this.request("/m2m/v2/list","get",r(this,de,"m",ce).bind(this))(e,t)}}de=new WeakSet,ce=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class Le extends p{constructor(e){super(e),he.add(this)}getMessagingConfig(e){return this.request("/messaging/config","get",r(this,he,"m",le).bind(this))(e)}}he=new WeakSet,le=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class Ge extends p{constructor(e){super(e),pe.add(this)}setUp(e,t){return this.request("/payment/payment-method/setup","post",r(this,pe,"m",ve).bind(this))(e,t)}setDefault(e,t){return this.request("/payment/payment-method/set-default","post",r(this,pe,"m",ve).bind(this))(e,t)}delete(e,t){return this.request("/payment/payment-method","delete",r(this,pe,"m",ve).bind(this))(e,t)}list(e,t){return this.request("/payment/payment-method/list","post",r(this,pe,"m",ve).bind(this))(e,t)}}pe=new WeakSet,ve=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class Je extends p{constructor(e){super(e),me.add(this)}get(e){return this.request("/project","get",r(this,me,"m",fe).bind(this))(e)}update(e,t){return this.request("/project","patch",r(this,me,"m",fe).bind(this))(e,t)}}function Fe(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.rcmApiUrl)&&void 0!==t?t:"https://rcm-api.zapehr.com/v1"}function He({id:e}){return`${Fe.call(this)}/payer/${e}`}function Ve(t,i){return s(this,arguments,void 0,(function*({url:t},i){if(!t.startsWith(He.call(this,{id:""})))throw new e({code:400,message:"Invalid payer URL."});const s=new URL(t).pathname.split("/").filter(Boolean),r=s[s.length-1];return this.request("/payer/{id}","get",Fe.bind(this))({id:r},i)}))}me=new WeakSet,fe=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class Be extends p{constructor(e){super(e),ge.add(this),this.constructPayerUrl=He,this.getPayerByUrl=Ve}eligibilityCheck(e,t){return this.request("/eligibility-check","post",r(this,ge,"m",be).bind(this))(e,t)}submitClaim(e,t){return this.request("/claim/{claimId}/submit","post",r(this,ge,"m",be).bind(this))(e,t)}setClaimStatus(e,t){return this.request("/claim/{claimId}/status","post",r(this,ge,"m",be).bind(this))(e,t)}listPayers(e,t){return this.request("/payer","get",r(this,ge,"m",be).bind(this))(e,t)}getPayer(e,t){return this.request("/payer/{id}","get",r(this,ge,"m",be).bind(this))(e,t)}}ge=new WeakSet,be=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.rcmApiUrl)&&void 0!==t?t:"https://rcm-api.zapehr.com/v1"};class Xe extends p{constructor(e){super(e),ye.add(this)}list(e){return this.request("/iam/role","get",r(this,ye,"m",qe).bind(this))(e)}create(e,t){return this.request("/iam/role","post",r(this,ye,"m",qe).bind(this))(e,t)}get(e,t){return this.request("/iam/role/{roleId}","get",r(this,ye,"m",qe).bind(this))(e,t)}update(e,t){return this.request("/iam/role/{roleId}","patch",r(this,ye,"m",qe).bind(this))(e,t)}delete(e,t){return this.request("/iam/role/{roleId}","delete",r(this,ye,"m",qe).bind(this))(e,t)}}ye=new WeakSet,qe=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class Ze extends p{constructor(e){super(e),we.add(this)}list(e){return this.request("/secret","get",r(this,we,"m",je).bind(this))(e)}set(e,t){return this.request("/secret","post",r(this,we,"m",je).bind(this))(e,t)}get(e,t){return this.request("/secret/{name}","get",r(this,we,"m",je).bind(this))(e,t)}delete(e,t){return this.request("/secret/{name}","delete",r(this,we,"m",je).bind(this))(e,t)}}we=new WeakSet,je=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class Ke extends p{constructor(e){super(e),Te.add(this)}createMeeting(e,t){return this.request("/telemed/v2/meeting","post",r(this,Te,"m",Oe).bind(this))(e,t)}joinMeeting(e,t){return this.request("/telemed/v2/meeting/{encounterId}/join","get",r(this,Te,"m",Oe).bind(this))(e,t)}}Te=new WeakSet,Oe=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class Qe extends p{constructor(e){super(e),ke.add(this)}searchCpt(e,t){return this.request("/cpt/search","get",r(this,ke,"m",Ue).bind(this))(e,t)}searchHcpcs(e,t){return this.request("/hcpcs/search","get",r(this,ke,"m",Ue).bind(this))(e,t)}}ke=new WeakSet,Ue=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.terminologyApiUrl)&&void 0!==t?t:"https://terminology-api.zapehr.com/v1"};class Ye extends p{constructor(e){super(e),Se.add(this)}send(e,t){return this.request("/messaging/transactional-sms/send","post",r(this,Se,"m",Ie).bind(this))(e,t)}}Se=new WeakSet,Ie=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class et extends p{constructor(e){super(e),Ee.add(this)}me(e){return this.request("/user/me","get",r(this,Ee,"m",xe).bind(this))(e)}get(e,t){return this.request("/user/{id}","get",r(this,Ee,"m",xe).bind(this))(e,t)}update(e,t){return this.request("/user/{id}","patch",r(this,Ee,"m",xe).bind(this))(e,t)}delete(e,t){return this.request("/user/{id}","delete",r(this,Ee,"m",xe).bind(this))(e,t)}resetMfa(e,t){return this.request("/user/{id}/reset-mfa","post",r(this,Ee,"m",xe).bind(this))(e,t)}resetPasswordLink(e,t){return this.request("/user/{id}/reset-password-link","post",r(this,Ee,"m",xe).bind(this))(e,t)}changePassword(e,t){return this.request("/user/{id}/change-password","post",r(this,Ee,"m",xe).bind(this))(e,t)}invite(e,t){return this.request("/user/invite","post",r(this,Ee,"m",xe).bind(this))(e,t)}list(e){return this.request("/user","get",r(this,Ee,"m",xe).bind(this))(e)}listV2(e,t){return this.request("/user/v2/list","get",r(this,Ee,"m",xe).bind(this))(e,t)}}Ee=new WeakSet,xe=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class tt extends p{constructor(e){super(e),ze.add(this)}get(e){return this.request("/version","get",r(this,ze,"m",Ae).bind(this))(e)}}function it(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"}function st(e){return s(this,arguments,void 0,(function*({bucketName:e,"objectPath+":t,file:i}){const s=yield this.request("/z3/{bucketName}/{objectPath+}","post",it.bind(this))({action:"upload",bucketName:e,"objectPath+":t});yield fetch(s.signedUrl,{method:"PUT",body:i})}))}function rt(e){return s(this,arguments,void 0,(function*({bucketName:e,"objectPath+":t}){const i=yield this.request("/z3/{bucketName}/{objectPath+}","post",it.bind(this))({action:"download",bucketName:e,"objectPath+":t}),s=yield fetch(i.signedUrl,{method:"GET"});if(!s.ok)throw new Error("Failed to download file");return s.arrayBuffer()}))}function nt(t){return s(this,void 0,void 0,(function*(){var i,s;let r,n;const o=new URL(t.url);if("z3:"===o.protocol){const e=o.pathname.split("/").slice(1);r=o.hostname,n=e.join("/")}else{if(!o.href.startsWith(null!==(s=null===(i=this.config.services)||void 0===i?void 0:i.projectApiUrl)&&void 0!==s?s:"https://project-api.zapehr.com/v1"))throw new e({message:"Invalid Z3 URL",code:400});{const e=o.pathname.split("/").slice(3);r=e[0],n=e.slice(1).join("/")}}const u={action:"upload",bucketName:r,"objectPath+":n};return this.request("/z3/{bucketName}/{objectPath+}","post",it.bind(this))(u)}))}ze=new WeakSet,Ae=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class ot extends p{constructor(e){super(e),Pe.add(this),this.uploadFile=st,this.downloadFile=rt,this.getPresignedUrlForZ3Url=nt}listBuckets(e){return this.request("/z3","get",r(this,Pe,"m",Re).bind(this))(e)}createBucket(e,t){return this.request("/z3/{bucketName}","put",r(this,Pe,"m",Re).bind(this))(e,t)}deleteBucket(e,t){return this.request("/z3/{bucketName}","delete",r(this,Pe,"m",Re).bind(this))(e,t)}listObjects(e,t){return this.request("/z3/{bucketName}/{objectPath+}","get",r(this,Pe,"m",Re).bind(this))(e,t)}getPresignedUrl(e,t){return this.request("/z3/{bucketName}/{objectPath+}","post",r(this,Pe,"m",Re).bind(this))(e,t)}deleteObject(e,t){return this.request("/z3/{bucketName}/{objectPath+}","delete",r(this,Pe,"m",Re).bind(this))(e,t)}}function ut(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.zambdaApiUrl)&&void 0!==t?t:"https://zambda-api.zapehr.com/v1"}function at(t){return s(this,arguments,void 0,(function*({id:t,file:i,filename:s}){const r=yield this.request("/zambda/{id}/presigned-url","post",ut.bind(this))({id:t,action:"upload",filename:s}),n=yield fetch(r.signedUrl,{method:"PUT",body:i});if(!n.ok)throw new e({message:"Failed to upload file",code:n.status,cause:n.statusText})}))}function dt(t){return s(this,arguments,void 0,(function*({id:t}){const i=yield this.request("/zambda/{id}/presigned-url","post",ut.bind(this))({id:t,action:"download"}),s=yield fetch(i.signedUrl,{method:"GET"});if(!s.ok)throw new e({message:"Failed to download file",code:s.status,cause:s.statusText});return s.arrayBuffer()}))}Pe=new WeakSet,Re=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.projectApiUrl)&&void 0!==t?t:"https://project-api.zapehr.com/v1"};class ct extends p{constructor(e){super(e),Ne.add(this),this.uploadFile=at,this.downloadFile=dt}list(e){return this.request("/zambda","get",r(this,Ne,"m",_e).bind(this))(e)}create(e,t){return this.request("/zambda","post",r(this,Ne,"m",_e).bind(this))(e,t)}get(e,t){return this.request("/zambda/{id}","get",r(this,Ne,"m",_e).bind(this))(e,t)}update(e,t){return this.request("/zambda/{id}","patch",r(this,Ne,"m",_e).bind(this))(e,t)}delete(e,t){return this.request("/zambda/{id}","delete",r(this,Ne,"m",_e).bind(this))(e,t)}execute(e,t){return this.request("/zambda/{id}/execute","post",r(this,Ne,"m",_e).bind(this))(e,t)}executePublic(e,t){return this.request("/zambda/{id}/execute-public","post",r(this,Ne,"m",_e).bind(this))(e,t)}s3Upload(e,t){return this.request("/zambda/{id}/s3-upload","post",r(this,Ne,"m",_e).bind(this))(e,t)}getPresignedUrl(e,t){return this.request("/zambda/{id}/presigned-url","post",r(this,Ne,"m",_e).bind(this))(e,t)}}Ne=new WeakSet,_e=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.zambdaApiUrl)&&void 0!==t?t:"https://zambda-api.zapehr.com/v1"};class ht extends p{constructor(e){super(e),$e.add(this)}list(e,t){return this.request("/zambda/{id}/logStream","post",r(this,$e,"m",We).bind(this))(e,t)}search(e,t){return this.request("/zambda/{id}/logStream/search","post",r(this,$e,"m",We).bind(this))(e,t)}get(e,t){return this.request("/zambda/{id}/logStream/{logStreamName}","post",r(this,$e,"m",We).bind(this))(e,t)}}$e=new WeakSet,We=function(){var e,t;return null!==(t=null===(e=this.config.services)||void 0===e?void 0:e.zambdaApiUrl)&&void 0!==t?t:"https://zambda-api.zapehr.com/v1"};let lt=class{constructor(t){var i,s,r,n,o,u;if(t.workspaceTag&&t.ignoreTags)throw new e({message:"workspaceTag and ignoreTags are mutually exclusive and cannot both be set in config",code:400});this.config=t,null!==(i=(n=this.config).services)&&void 0!==i||(n.services={}),null!==(s=(o=this.config.services).projectApiUrl)&&void 0!==s||(o.projectApiUrl=t.projectApiUrl),null!==(r=(u=this.config.services).fhirApiUrl)&&void 0!==r||(u.fhirApiUrl=t.fhirApiUrl),this.application=new w(t),this.developer=new N(t),this.m2m=new De(t),this.messaging=new Le(t),this.conversation=new R(t),this.transactionalSMS=new Ye(t),this.paymentMethod=new Ge(t),this.charge=new j(t),this.project=new Je(t),this.role=new Xe(t),this.secret=new Ze(t),this.telemed=new Ke(t),this.user=new et(t),this.version=new tt(t),this.z3=new ot(t),this.fax=new $(t),this.lab=new Ce(t),this.erx=new _(t),this.terminology=new Qe(t),this.zambda=new ct(t),this.zambdaLogStream=new ht(t),this.rcm=new Be(t),this.fhir=new Me(t)}};class pt extends lt{}pt.OystehrFHIRError=i,pt.OystehrSdkError=e,exports.default=pt;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});class t extends Error{constructor({message:e,code:i,cause:s}){super(e,{cause:s}),Object.setPrototypeOf(this,t.prototype),this.code=i,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 e(t){var e;const i=[];for(const s of null!==(e=t.issue)&&void 0!==e?e:[])s.details&&s.details.text&&i.push(s.details.text);return i.length||i.push("Unknown FHIR error"),i.join(",")}class i extends t{constructor({error:t,code:s}){super({message:e(t),code:s}),Object.setPrototypeOf(this,i.prototype),this.cause=t,this.name="OystehrFHIRError"}toJSON(){return{name:this.name,message:this.message,code:this.code,cause:this.cause}}}function s(t,e,i,s){return new(i||(i=Promise))((function(n,r){function o(t){try{a(s.next(t))}catch(e){r(e)}}function u(t){try{a(s.throw(t))}catch(e){r(e)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,u)}a((s=s.apply(t,e||[])).next())}))}function n(t,e,i,s){if("a"===i&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(t):s?s.value:e.get(t)}"function"==typeof SuppressedError&&SuppressedError;var r=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;const o=[];for(let Oe=0;Oe<256;++Oe)o.push((Oe+256).toString(16).slice(1));let u;const a=new Uint8Array(16);var c={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};class d{constructor({level:t}){this._level=t}error(t,e={}){this._level&&["error","info","debug"].includes(this._level)&&console.error(JSON.stringify(Object.assign({message:t},e)))}info(t,e={}){this._level&&["info","debug"].includes(this._level)&&console.info(JSON.stringify(Object.assign({message:t},e)))}debug(t,e={}){this._level&&["debug"].includes(this._level)&&console.debug(JSON.stringify(Object.assign({message:t},e)))}time(t,e={}){this._level&&["debug"].includes(this._level)&&console.time(JSON.stringify(Object.assign({message:t},e)))}timeEnd(t,e={}){this._level&&["debug"].includes(this._level)&&console.timeEnd(JSON.stringify(Object.assign({message:t},e)))}}const l=[408,429,500,502,503,504],h=["ECONNRESET","ECONNREFUSED","EPIPE","ETIMEDOUT","UND_ERR_CONNECT_TIMEOUT","UND_ERR_HEADERS_TIMEOUT","UND_ERR_HEADERS_TIMEOUT","UND_ERR_SOCKET"];class p{constructor(t){this.config=t,this.logger=new d({level:this.config.logLevel})}request(e,i,n){return(r,o)=>s(this,void 0,void 0,(function*(){const s=()=>this.config,u=()=>this.logger;try{return yield f(n,s,u,e,i)(r,o)}catch(a){const e=a;throw this.logger.error(e.message,{code:e.code,cause:e.cause}),new t({message:e.message,code:e.code,cause:e.cause})}}))}fhirRequest(e,n){return(r,o,u)=>s(this,void 0,void 0,(function*(){try{const t=()=>{var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.fhirApiUrl)&&void 0!==e?e:"https://fhir-api.zapehr.com"},i=()=>this.config,s=()=>this.logger;return yield f(t,i,s,e,n)(r,o,u)}catch(s){const e=s;if("string"==typeof e.message)throw new t({message:e.message,code:e.code,cause:e.cause});throw new i({error:e.message,code:e.code})}}))}startAsyncJob(e,i,n,r,o){return s(this,void 0,void 0,(function*(){const s="async-bulk"===r?"bulk":"bundle",u="async-bulk"===r?this.appendBulkOutputFormat(e):e,a=yield this.fhirRequest(u,i)(n,Object.assign(Object.assign({},o),{rawResponse:!0}),r);if(202!==a.status)throw new t({message:`Expected start async job to return 202 Accepted, received ${a.status}`,code:a.status});const c=this.readHeader(a.headers,"content-location");if(!c)throw new t({message:"Start Async job response missing Content-Location header",code:500});const d=this.parseAsyncJobId(c);if(!d)throw new t({message:`Could not parse async job id from Content-Location: ${c}`,code:500});return{jobId:d,contentLocation:c,mode:s}}))}fetchAsyncJobStatus(t,e){return s(this,void 0,void 0,(function*(){var i,s,n;const r=yield this.fhirRequest(`/async-job/${t}`,"GET")({},Object.assign(Object.assign({},e),{rawResponse:!0}));if(202===r.status)return{status:202,xProgress:this.readHeader(r.headers,"x-progress"),retryAfter:this.readHeader(r.headers,"retry-after")};if(410===r.status)return{status:410};if(404===r.status)return{status:404};if(200===r.status){if(this.isBulkManifest(r.body))return{status:200,mode:"bulk",manifest:r.body};const t=r.body;if("Bundle"===(null==t?void 0:t.resourceType)&&"batch-response"===(null==t?void 0:t.type)){const e=null===(i=t.entry)||void 0===i?void 0:i[0];return{status:200,mode:"bundle",bundle:t,interactionStatus:null===(s=null==e?void 0:e.response)||void 0===s?void 0:s.status,resource:null==e?void 0:e.resource,outcome:null===(n=null==e?void 0:e.response)||void 0===n?void 0:n.outcome}}return{status:200,body:r.body}}return{status:r.status,body:r.body}}))}readHeader(t,e){const i=t[e];if(null!=i)return i;const s=e.toLowerCase(),n=Object.keys(t).find((t=>t.toLowerCase()===s));return n?t[n]:void 0}parseAsyncJobId(t){const e=t.split("/").filter(Boolean),i=e.lastIndexOf("async-job");if(!(i<0||i+1>=e.length))return e[i+1]}appendBulkOutputFormat(t){const e=t.includes("?")?"&":"?";return`${t}${e}_outputFormat=${encodeURIComponent("application/fhir+ndjson")}`}isBulkManifest(t){if(null==t||"object"!=typeof t)return!1;const e=t;return"string"==typeof e.transactionTime&&"string"==typeof e.request&&"boolean"==typeof e.requiresAccessToken&&Array.isArray(e.output)&&Array.isArray(e.error)}}function v(t){var e,i;return"accessToken"in t||"projectId"in t&&"string"==typeof(i=t.projectId)&&r.test(i)||"contentType"in t&&2===(null===(e=t.contentType)||void 0===e?void 0:e.split("/").length)||"requestId"in t||"ifMatch"in t&&t.ifMatch.startsWith('W/"')||"mode"in t||"rawResponse"in t}function f(e,i,n,r,d){return(p,f,g)=>s(this,void 0,void 0,(function*(){var b,y,q,w,j,O,T,k,A,S,I,E,U,x;let[P,$]=function(t,e){var i;return[t&&!e&&!Array.isArray(t)&&v(t)?{}:null!==(i=t)&&void 0!==i?i:{},t&&!e&&!Array.isArray(t)&&v(t)?t:e]}(p,f);null!=$||($={}),null!==(b=$.requestId)&&void 0!==b||($.requestId=function(t){if(c.randomUUID&&!t)return c.randomUUID();const e=(t=t||{}).random??t.rng?.()??function(){if(!u){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");u=crypto.getRandomValues.bind(crypto)}return u(a)}();if(e.length<16)throw new Error("Random bytes length must be >= 16");return e[6]=15&e[6]|64,e[8]=63&e[8]|128,function(t,e=0){return(o[t[e+0]]+o[t[e+1]]+o[t[e+2]]+o[t[e+3]]+"-"+o[t[e+4]]+o[t[e+5]]+"-"+o[t[e+6]]+o[t[e+7]]+"-"+o[t[e+8]]+o[t[e+9]]+"-"+o[t[e+10]]+o[t[e+11]]+o[t[e+12]]+o[t[e+13]]+o[t[e+14]]+o[t[e+15]]).toLowerCase()}(e)}());const z=i(),R=n(),N=d.toLowerCase();R.debug("Beginning fetch",{method:N,path:r,requestId:null==$?void 0:$.requestId});const _=null!==(y=z.fetch)&&void 0!==y?y:fetch,M=null!==(q=null==$?void 0:$.accessToken)&&void 0!==q?q:z.accessToken,C=null!==(w=null==$?void 0:$.projectId)&&void 0!==w?w:z.projectId;let J=r,D=P;if(!Array.isArray(P)){const[e,i]=function(e,i){const s=Object.assign({},i),n=e.replace(/\{([^}]+)\}/g,((e,n)=>{if(delete s[n],n.match(/^.*\+$/))return i[n]+"";if(!i[n]||""===i[n])throw new t({message:`Required path parameter is an empty string: ${n}`,code:400});return i[n]?encodeURIComponent(i[n]+""):""})),r=Object.keys(s);return[n,r.length?r.reduce(((t,e)=>Object.assign(Object.assign({},t),{[e]:s[e]})),{}):{}]}(r,P);J=e,D=i}R.debug("Substituted parameters in path",{method:N,path:r,requestId:null==$?void 0:$.requestId}),J=J.replace(/^\//,"");const W=e(),L=W.endsWith("/")?W:W+"/",B=new URL(J,L);let F;if(Array.isArray(D))F=JSON.stringify(D);else if(Object.keys(D).length)if("get"===N)m(D,B.searchParams);else if("application/x-www-form-urlencoded"===(null==$?void 0:$.contentType)){const t=new URLSearchParams;m(D,t),F=t.toString()}else F=JSON.stringify(D);else"application/x-www-form-urlencoded"!==(null==$?void 0:$.contentType)&&"post"===N&&(F="{}");R.debug("Prepared request body",{method:N,path:r,requestId:null==$?void 0:$.requestId});const G=function(t){if("async-bundle"===t||"async-bulk"===t)return"respond-async"}(g),H=Object.assign(C?{"x-zapehr-project-id":C,"x-oystehr-project-id":C}:{},{"content-type":null!==(j=null==$?void 0:$.contentType)&&void 0!==j?j:"application/json"},G?{Prefer:G}:{},M?{Authorization:`Bearer ${M}`}:{},(null==$?void 0:$.ifMatch)?{"If-Match":$.ifMatch}:{},{"x-oystehr-request-id":null==$?void 0:$.requestId}),V={retries:null!==(T=null===(O=z.retry)||void 0===O?void 0:O.retries)&&void 0!==T?T:3,jitter:null!==(A=null===(k=z.retry)||void 0===k?void 0:k.jitter)&&void 0!==A?A:20,delay:null!==(I=null===(S=z.retry)||void 0===S?void 0:S.delay)&&void 0!==I?I:100,onRetry:null===(E=z.retry)||void 0===E?void 0:E.onRetry,retryOn:[...null!==(x=null===(U=z.retry)||void 0===U?void 0:U.retryOn)&&void 0!==x?x:[],...l]};return V.retryOn.push(...l),function(t,e){return s(this,void 0,void 0,(function*(){var i,s;let n;for(const o of Array.from({length:(null!==(i=e.retries)&&void 0!==i?i:0)+1},((t,e)=>e)))try{return yield t()}catch(r){let t=!1;if("response"in r){const i=r;t=e.retryOn.includes(i.code),n={message:r.message,code:r.code}}else if(n=r,"code"in r&&"string"==typeof r.code){const e=r;t=h.includes(e.code)}if(!t)break;const i=Math.floor(Math.random()*(e.jitter+1));yield new Promise((t=>setTimeout(t,e.delay+i))),e.onRetry&&o!==(null!==(s=e.retries)&&void 0!==s?s:0)&&e.onRetry(o+1)}throw n}))}((()=>s(this,void 0,void 0,(function*(){var t,e,i,s,n,r,o,u;R.info("Request start",{method:N,url:B,requestId:null==$?void 0:$.requestId});const a=Date.now(),c=yield _(new Request(B,{method:N.toUpperCase(),body:F,headers:H}));R.info("Request end",{method:N,url:B,duration:Date.now()-a,requestId:null==$?void 0:$.requestId});const d=c.body?yield c.text():null;let l;const h=c.headers.get("content-type");try{d&&((null==h?void 0:h.includes("application/json"))||(null==h?void 0:h.includes("application/fhir+json")))?(R.time("Deserialized JSON response",{method:N,url:B,requestId:null==$?void 0:$.requestId}),l=JSON.parse(d),R.timeEnd("Deserialized JSON response",{method:N,url:B,requestId:null==$?void 0:$.requestId})):d&&((null==h?void 0:h.includes("application/xml"))||(null==h?void 0:h.includes("text/xml")))?(R.time("Deserialized XML response",{method:N,url:B,requestId:null==$?void 0:$.requestId}),l=function(t){try{const e=t.match(/<status>(\d+)<\/status>/),i=e?parseInt(e[1],10):null,s=t.match(/<output>([\s\S]*?)<\/output>/),n=s?s[1]:null;return null===i||null===n?null:{status:i,output:n}}catch(e){return null}}(d),R.timeEnd("Deserialized XML response",{method:N,url:B,requestId:null==$?void 0:$.requestId})):l=null}catch(p){l=null}if(R.debug("Deserialized response",{method:N,url:B,requestId:null==$?void 0:$.requestId}),null==$?void 0:$.rawResponse){const t={};return c.headers.forEach(((e,i)=>{t[i]=e})),{status:c.status,headers:t,body:null!=l?l:d}}if(!c.ok||c.status>=400)throw{message:null!==(n=null!==(s=null!==(i=null!==(e="string"==typeof(null==l?void 0:l.output)?l.output:null===(t=null==l?void 0:l.output)||void 0===t?void 0:t.message)&&void 0!==e?e:null==l?void 0:l.message)&&void 0!==i?i:l)&&void 0!==s?s:d)&&void 0!==n?n:c.statusText,code:null!==(u=null!==(o=null===(r=null==l?void 0:l.output)||void 0===r?void 0:r.code)&&void 0!==o?o:null==l?void 0:l.code)&&void 0!==u?u:c.status,response:c};return l}))),V)}))}function m(t,e){for(const[i,s]of Object.entries(t))Array.isArray(s)?s.forEach((t=>null!=t&&e.append(i,t))):null!=s&&e.append(i,s)}var g,b,y,q;class w extends p{constructor(t){super(t),g.add(this)}list(t){return this.request("/application","get",n(this,g,"m",b).bind(this))(t)}create(t,e){return this.request("/application","post",n(this,g,"m",b).bind(this))(t,e)}get(t,e){return this.request("/application/{id}","get",n(this,g,"m",b).bind(this))(t,e)}update(t,e){return this.request("/application/{id}","patch",n(this,g,"m",b).bind(this))(t,e)}delete(t,e){return this.request("/application/{id}","delete",n(this,g,"m",b).bind(this))(t,e)}rotateSecret(t,e){return this.request("/application/{id}/rotate-secret","post",n(this,g,"m",b).bind(this))(t,e)}revokeRefreshToken(t,e){return this.request("/application/{id}/revoke-refresh-token","post",n(this,g,"m",b).bind(this))(t,e)}revokeAccessToken(t,e){return this.request("/application/{id}/revoke-access-token","post",n(this,g,"m",b).bind(this))(t,e)}}g=new WeakSet,b=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class j extends p{constructor(t){super(t),y.add(this)}issue(t,e){return this.request("/payment/charge/issue","post",n(this,y,"m",q).bind(this))(t,e)}status(t,e){return this.request("/payment/charge/status","post",n(this,y,"m",q).bind(this))(t,e)}}y=new WeakSet,q=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};const O="https://extensions.fhir.zapehr.com/encounter-virtual-service-pre-release",T="addressString";function k(t){var e,i,s;if(function(t){return Object.hasOwn(t,"virtualService")}(t)){const i=null===(e=t.virtualService)||void 0===e?void 0:e.find((t=>{var e;return"https://fhir.zapehr.com/virtual-service-type"===(null===(e=t.channelType)||void 0===e?void 0:e.system)}));return null==i?void 0:i.addressString}if(!t.extension)return;const n=t.extension.find((t=>t.url===O));return(null==n?void 0:n.extension)?null===(s=null===(i=n.extension)||void 0===i?void 0:i.find((t=>t.url===T)))||void 0===s?void 0:s.valueString:void 0}var A,S,I,E,U,x,P,$;class z extends p{constructor(t){super(t),A.add(this),this.ENCOUNTER_VS_EXTENSION_URL=O,this.ENCOUNTER_VS_EXTENSION_RELATIVE_URL=T,this.getConversationIdFromEncounter=k}create(t,e){return this.request("/messaging/conversation","post",n(this,A,"m",S).bind(this))(t,e)}getToken(t){return this.request("/messaging/conversation/token","get",n(this,A,"m",S).bind(this))(t)}addParticipant(t,e){return this.request("/messaging/conversation/{conversationId}/participant","post",n(this,A,"m",S).bind(this))(t,e)}removeParticipant(t,e){return this.request("/messaging/conversation/{conversationId}/participant","delete",n(this,A,"m",S).bind(this))(t,e)}message(t,e){return this.request("/messaging/conversation/{conversationId}/message","post",n(this,A,"m",S).bind(this))(t,e)}}A=new WeakSet,S=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class R extends p{constructor(t){super(t),I.add(this)}get(t,e){return this.request("/developer/{id}","get",n(this,I,"m",E).bind(this))(t,e)}update(t,e){return this.request("/developer/{id}","patch",n(this,I,"m",E).bind(this))(t,e)}delete(t,e){return this.request("/developer/{id}","delete",n(this,I,"m",E).bind(this))(t,e)}invite(t,e){return this.request("/developer/invite","post",n(this,I,"m",E).bind(this))(t,e)}list(t){return this.request("/developer","get",n(this,I,"m",E).bind(this))(t)}listV2(t,e){return this.request("/developer/v2/list","get",n(this,I,"m",E).bind(this))(t,e)}}I=new WeakSet,E=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class N extends p{constructor(t){super(t),U.add(this)}searchAllergens(t,e){return this.request("/allergen","get",n(this,U,"m",x).bind(this))(t,e)}searchMedications(t,e){return this.request("/medication","get",n(this,U,"m",x).bind(this))(t,e)}getMedication(t,e){return this.request("/medication/details","get",n(this,U,"m",x).bind(this))(t,e)}getConfiguration(t){return this.request("/config","get",n(this,U,"m",x).bind(this))(t)}checkAllergyInteractions(t,e){return this.request("/patient/{patientId}/interactions/allergy","get",n(this,U,"m",x).bind(this))(t,e)}checkMedicationInteractions(t,e){return this.request("/patient/{patientId}/interactions/medication","get",n(this,U,"m",x).bind(this))(t,e)}checkPrecheckInteractions(t,e){return this.request("/patient/{patientId}/interactions/precheck/{drugId}","get",n(this,U,"m",x).bind(this))(t,e)}getMedicationHistory(t,e){return this.request("/patient/{patientId}/medication-history","get",n(this,U,"m",x).bind(this))(t,e)}addPatientPharmacy(t,e){return this.request("/patient/{patientId}/pharmacies","post",n(this,U,"m",x).bind(this))(t,e)}cancelPrescription(t,e){return this.request("/patient/{patientId}/prescriptions/{medicationRequestId}","delete",n(this,U,"m",x).bind(this))(t,e)}syncPatient(t,e){return this.request("/patient/{patientId}/sync","post",n(this,U,"m",x).bind(this))(t,e)}searchPharmacies(t,e){return this.request("/pharmacy","get",n(this,U,"m",x).bind(this))(t,e)}connectPractitioner(t,e){return this.request("/practitioner/connect","get",n(this,U,"m",x).bind(this))(t,e)}checkPractitionerEnrollment(t,e){return this.request("/practitioner/{practitionerId}","get",n(this,U,"m",x).bind(this))(t,e)}enrollPractitioner(t,e){return this.request("/practitioner/{practitionerId}","post",n(this,U,"m",x).bind(this))(t,e)}unenrollPractitioner(t,e){return this.request("/practitioner/{practitionerId}","delete",n(this,U,"m",x).bind(this))(t,e)}}U=new WeakSet,x=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.erxApiUrl)&&void 0!==e?e:"https://erx-api.zapehr.com/v3"};class _ extends p{constructor(t){super(t),P.add(this)}offboard(t){return this.request("/offboard","post",n(this,P,"m",$).bind(this))(t)}onboard(t){return this.request("/onboard","post",n(this,P,"m",$).bind(this))(t)}getConfiguration(t){return this.request("/config","get",n(this,P,"m",$).bind(this))(t)}send(t,e){return this.request("/send","post",n(this,P,"m",$).bind(this))(t,e)}}P=new WeakSet,$=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.faxApiUrl)&&void 0!==e?e:"https://fax-api.zapehr.com/v1"};const M=65535;function C(t){const e=(new globalThis.TextEncoder).encode(t);let i="";for(let s=0;s<e.length;s+=M){const t=e.subarray(s,s+M);i+=globalThis.btoa(String.fromCodePoint.apply(void 0,t))}return i}function J(t){var e,i;return t.system?`${t.system}|${null!==(e=t.code)&&void 0!==e?e:""}`:null!==(i=t.code)&&void 0!==i?i:""}function D(t,e){var i,s,n,r;return(null!==(i=t.system)&&void 0!==i?i:"")===(null!==(s=e.system)&&void 0!==s?s:"")&&(null!==(n=t.code)&&void 0!==n?n:"")===(null!==(r=e.code)&&void 0!==r?r:"")}function W(e,i){var s,n,r,o,u,a,c;const d=i;if(null===(s=e.ignoreTags)||void 0===s?void 0:s.length){const s=null!==(r=null===(n=d.meta)||void 0===n?void 0:n.tag)&&void 0!==r?r:[];for(const i of e.ignoreTags)if(s.some((t=>D(t,i))))throw new t({message:`Resource has an ignored tag (system: "${null!==(o=i.system)&&void 0!==o?o:""}", code: "${null!==(u=i.code)&&void 0!==u?u:""}") and cannot be mutated in ignoreTags mode`,code:400});return i}if(e.workspaceTag){const t=e.workspaceTag,s=null!==(c=null===(a=d.meta)||void 0===a?void 0:a.tag)&&void 0!==c?c:[];if(!s.some((e=>D(e,t))))return Object.assign(Object.assign({},i),{meta:Object.assign(Object.assign({},d.meta),{tag:[...s,t]})})}return i}function L(e,i){var s,n,r;if(null===(s=e.ignoreTags)||void 0===s?void 0:s.length){for(const s of i)if("add"===s.op||"replace"===s.op||"test"===s.op){const i=s.value;if(null!=i&&"object"==typeof i){const s=i;if(void 0!==s.code)for(const i of e.ignoreTags)if(D(s,i))throw new t({message:`Patch operation contains an ignored tag (system: "${null!==(n=i.system)&&void 0!==n?n:""}", code: "${null!==(r=i.code)&&void 0!==r?r:""}") and cannot be applied in ignoreTags mode`,code:400})}}return i}if(e.workspaceTag){const t=e.workspaceTag;return i.reduce(((e,i)=>{var s;if("remove"===i.op&&"/meta/tag"===i.path)return e.push(i),e.push({op:"add",path:"/meta/tag",value:[t]}),e;if("remove"===i.op&&"/meta"===i.path)return e.push(i),e.push({op:"add",path:"/meta",value:{tag:[t]}}),e;if(("add"===i.op||"replace"===i.op)&&"/meta/tag"===i.path){const s=Array.isArray(i.value)?i.value:[];return s.some((e=>D(e,t)))?e.push(i):e.push(Object.assign(Object.assign({},i),{value:[...s,t]})),e}if(("add"===i.op||"replace"===i.op)&&"/meta"===i.path){const n=null!=i.value&&"object"==typeof i.value?i.value:{},r=null!==(s=n.tag)&&void 0!==s?s:[];return r.some((e=>D(e,t)))?e.push(i):e.push(Object.assign(Object.assign({},i),{value:Object.assign(Object.assign({},n),{tag:[...r,t]})})),e}return e.push(i),e}),[])}return i}function B(t,e){var s,n,r;const o=null!==(n=null===(s=e.meta)||void 0===s?void 0:s.tag)&&void 0!==n?n:[];if(t.workspaceTag){const e=t.workspaceTag;if(!o.some((t=>D(t,e))))throw new i({error:{resourceType:"OperationOutcome",id:"not-found",issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},code:404})}else if(null===(r=t.ignoreTags)||void 0===r?void 0:r.length)for(const u of t.ignoreTags)if(o.some((t=>D(t,u))))throw new i({error:{resourceType:"OperationOutcome",id:"not-found",issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},code:404})}function F(t){return"async-bundle"===t||"async-bulk"===t}function G(t,e){return s(this,void 0,void 0,(function*(){const{resourceType:i}=t,s=function(t,e){var i;const s=e?[...e]:[];if(t.workspaceTag)s.push({name:"_tag",value:J(t.workspaceTag)});else if(null===(i=t.ignoreTags)||void 0===i?void 0:i.length)for(const n of t.ignoreTags)s.push({name:"_tag:not",value:J(n)});return s}(this.config,t.params);let n;s.length&&(n=s.reduce(((t,e)=>(t[e.name]||(t[e.name]=[]),t[e.name].push(e.value),t)),{}));const r=null==e?void 0:e.mode;if(F(r))return yield this.startAsyncJob(`/${i}/_search`,"POST",null!=n?n:{},r,Object.assign(Object.assign({},e),{contentType:"application/x-www-form-urlencoded"}));const o=yield this.fhirRequest(`/${i}/_search`,"POST")(n,Object.assign(Object.assign({},e),{contentType:"application/x-www-form-urlencoded"}));return Object.assign(Object.assign({},o),{entry:o.entry,unbundle:function(){var t,e;return null!==(e=null===(t=this.entry)||void 0===t?void 0:t.map((t=>t.resource)).filter((t=>void 0!==t)))&&void 0!==e?e:[]}})}))}function H(t,e){return s(this,void 0,void 0,(function*(){var i,s,n,r,o;const{pageSize:u}=t,a=function(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}(t,["pageSize"]);let c=a;if(u){const t=null!==(s=(null!==(i=a.params)&&void 0!==i?i:[]).filter((t=>"_count"!==t.name)))&&void 0!==s?s:[];c=Object.assign(Object.assign({},a),{params:[...t,{name:"_count",value:u}]})}const d=[],l=G;let h=yield l.call(this,c,e);const p=Object.assign(Object.assign({},h),{link:null===(n=h.link)||void 0===n?void 0:n.filter((t=>"next"!==t.relation))});for(;;){const t=h.entry;t&&d.push(...t);const i=null===(o=null===(r=h.link)||void 0===r?void 0:r.find((t=>"next"===t.relation)))||void 0===o?void 0:o.url;if(!i)break;h=yield this.fhirRequest(i,"GET")({},e)}return Object.assign(Object.assign({},p),{entry:d.length?d:void 0,unbundle:function(){var t,e;return null!==(e=null===(t=this.entry)||void 0===t?void 0:t.map((t=>t.resource)).filter((t=>void 0!==t)))&&void 0!==e?e:[]}})}))}function V(t,e){return s(this,void 0,void 0,(function*(){const i=W(this.config,t),{resourceType:s}=i,n=null==e?void 0:e.mode;return F(n)?yield this.startAsyncJob(`/${s}`,"POST",i,n,e):yield this.fhirRequest(`/${s}`,"POST")(i,e)}))}function X(t,e){return s(this,arguments,void 0,(function*({resourceType:t,id:e},i){const s=null==i?void 0:i.mode;if(F(s))return yield this.startAsyncJob(`/${t}/${e}`,"GET",{},s,i);const n=yield this.fhirRequest(`/${t}/${e}`,"GET")({},i);return B(this.config,n),n}))}function Z(t,e){return s(this,void 0,void 0,(function*(){const i=W(this.config,t),{id:s,resourceType:n}=i,r=null==e?void 0:e.mode,o=Object.assign(Object.assign({},e),{ifMatch:(null==e?void 0:e.optimisticLockingVersionId)?`W/"${e.optimisticLockingVersionId}"`:void 0});return F(r)?yield this.startAsyncJob(`/${n}/${s}`,"PUT",i,r,o):yield this.fhirRequest(`/${n}/${s}`,"PUT")(i,o)}))}function K(t,e){return s(this,arguments,void 0,(function*({resourceType:t,id:e,operations:i},s){const n=L(this.config,i),r=null==s?void 0:s.mode,o=Object.assign(Object.assign({},s),{ifMatch:(null==s?void 0:s.optimisticLockingVersionId)?`W/"${s.optimisticLockingVersionId}"`:void 0});return F(r)?yield this.startAsyncJob(`/${t}/${e}`,"PATCH",n,r,Object.assign(Object.assign({},o),{contentType:"application/json-patch+json"})):this.fhirRequest(`/${t}/${e}`,"PATCH")(n,Object.assign(Object.assign({},o),{contentType:"application/json-patch+json"}))}))}function Q(t,e){return s(this,arguments,void 0,(function*({resourceType:t,id:e},i){const s=null==i?void 0:i.mode;return F(s)?yield this.startAsyncJob(`/${t}/${e}`,"DELETE",{},s,i):yield this.fhirRequest(`/${t}/${e}`,"DELETE")({},i)}))}function Y(t,e){if(!t)return e;const i=Number(t);if(Number.isFinite(i)&&i>=0)return Math.max(0,Math.floor(1e3*i));const s=Date.parse(t);return Number.isFinite(s)?Math.max(0,s-Date.now()):e}function tt(t,e){return s(this,void 0,void 0,(function*(){return yield this.fetchAsyncJobStatus(t,e)}))}function et(e,i,n){return s(this,void 0,void 0,(function*(){var s,r;const o=null!==(s=null==i?void 0:i.pollIntervalMs)&&void 0!==s?s:5e3,u=null!==(r=null==i?void 0:i.timeoutMs)&&void 0!==r?r:9e5,a=Math.max(1,Math.ceil(u/o));for(let t=0;t<a;t++){const i=yield this.fetchAsyncJobStatus(e,n);if(202!==i.status)return i;if(t<a-1){const t="retryAfter"in i?i.retryAfter:void 0;yield new Promise((e=>setTimeout(e,Y(t,o))))}}throw new t({message:`Async job ${e} did not complete within ${u} ms`,code:408})}))}function it(e,i){const s=[],n=e.split("\n");for(let o=0;o<n.length;o++){const e=n[o].trim();if(0!==e.length)try{s.push(JSON.parse(e))}catch(r){throw new t({message:`Failed to parse NDJSON line ${o+1} from ${i}`,code:500,cause:r})}}return s}function st(e,i,n){return s(this,void 0,void 0,(function*(){var r,o,u;const a=yield et.call(this,e,i,n);if(404===a.status)throw new t({message:`Async job ${e} not found`,code:404});if(410===a.status)throw new t({message:`Async job ${e} expired`,code:410});if(200!==a.status||!("mode"in a)||"bulk"!==a.mode)throw new t({message:`Async job ${e} did not complete in bulk mode`,code:a.status});const c=null!==(r=null==n?void 0:n.accessToken)&&void 0!==r?r:this.config.accessToken,d=null!==(o=null==n?void 0:n.projectId)&&void 0!==o?o:this.config.projectId;if(a.manifest.requiresAccessToken&&!c)throw new t({message:`Bulk output for async job ${e} requires an access token`,code:401});const l=null!==(u=this.config.fetch)&&void 0!==u?u:fetch,h={};d&&(h["x-zapehr-project-id"]=d,h["x-oystehr-project-id"]=d),a.manifest.requiresAccessToken&&c&&(h.Authorization=`Bearer ${c}`);const p=Object.keys(h).length>0?h:void 0,v=yield Promise.all(a.manifest.output.map((e=>s(this,void 0,void 0,(function*(){const i=yield l(new Request(e.url,{method:"GET",headers:p}));if(!i.ok)throw new t({message:`Failed to download bulk output (${e.type}): HTTP ${i.status}`,code:i.status});const s=yield i.text();return Object.assign(Object.assign({},e),{resources:it(s,e.url)})})))));return{manifest:a.manifest,output:v}}))}function nt(t,e,i){return s(this,void 0,void 0,(function*(){return{resourceType:"Bundle",type:"collection",entry:(yield st.call(this,t,e,i)).output.flatMap((t=>t.resources)).map((t=>({resource:t}))),unbundle:function(){var t,e;return null!==(e=null===(t=this.entry)||void 0===t?void 0:t.map((t=>t.resource)).filter((t=>void 0!==t)))&&void 0!==e?e:[]}}}))}function rt(t,e){return s(this,void 0,void 0,(function*(){yield this.fhirRequest(`/async-job/${t}`,"DELETE")({},e)}))}function ot(t,e){return s(this,arguments,void 0,(function*({resourceType:t,id:e,versionId:i,count:s,offset:n},r){const o=null==r?void 0:r.mode;return F(o)?i?yield this.startAsyncJob(`/${t}/${e}/_history/${i}`,"GET",{},o,r):yield this.startAsyncJob(`/${t}/${e}/_history`,"GET",{},o,r):i?this.fhirRequest(`/${t}/${e}/_history/${i}`,"GET")({},r):s?this.fhirRequest(`/${t}/${e}/_history?_total=accurate&_count=${s}\n ${n?`&_offset=${n}`:""}`,"GET")({},r):this.fhirRequest(`/${t}/${e}/_history?_total=accurate`,"GET")({},r)}))}function ut(t){const e=t.split("?")[0].split("/").filter(Boolean);return e.length<=1||e[1].startsWith("_")}function at(t){return t.split("?")[0].endsWith("/_search")}function ct(t,e){var i;const{method:s}=t;let n=t.url;if((("GET"===s||"HEAD"===s)&&ut(n)||"POST"===s&&at(n))&&(e.workspaceTag&&(n+=(n.includes("?")?"&":"?")+`_tag=${J(e.workspaceTag)}`),null===(i=e.ignoreTags)||void 0===i?void 0:i.length))for(const o of e.ignoreTags)n+=(n.includes("?")?"&":"?")+`_tag:not=${J(o)}`;const r={request:{method:s,url:n}};if(n.split("?").length>1){const[t,e]=n.split("?"),i=e.split("&").map((t=>{const[e,i]=t.split("=");return{name:e,value:i}})).reduce(((t,{name:e,value:i})=>e?(t[e]||(t[e]=[]),t[e].push(i),t):t),{}),s=new URLSearchParams;m(i,s),r.request.url=`${t}?${s.toString()}`}if(["GET","DELETE","HEAD"].includes(s))return r;if("PUT"===s){const i=W(e,t.resource);return{request:Object.assign(Object.assign({},r.request),{ifMatch:t.ifMatch}),resource:i}}if("PATCH"===s){if("resource"in t){let i=t.resource;const s=i.data;if(s){const t=L(e,JSON.parse(function(t){const e=globalThis.atob(t),i=new Uint8Array(e.length);for(let s=0;s<e.length;s++)i[s]=e.charCodeAt(s);return(new globalThis.TextDecoder).decode(i)}(s)));i=Object.assign(Object.assign({},i),{data:C(JSON.stringify(t))})}return{request:Object.assign(Object.assign({},r.request),{ifMatch:t.ifMatch}),resource:i}}const i=L(e,t.operations),s=C(JSON.stringify(i));return Object.assign(Object.assign({},r),{resource:{resourceType:"Binary",contentType:"application/json-patch+json",data:s}})}if("POST"===s&&at(n))return r;if("POST"===s&&"resource"in t){const i=W(e,t.resource),{fullUrl:s}=t;return Object.assign(Object.assign({},r),{resource:i,fullUrl:s})}throw new Error("Unrecognized method")}function dt(t,e){return s(this,void 0,void 0,(function*(){var s;const n={resourceType:"Bundle",type:"batch",entry:t.requests.map((t=>ct(t,this.config)))},r=null==e?void 0:e.mode;if(F(r))return yield this.startAsyncJob("/","POST",n,r,e);const o=yield this.fhirRequest("/","POST")(n,e),u=o.entry,a=this.config.workspaceTag||(null===(s=this.config.ignoreTags)||void 0===s?void 0:s.length)?null==u?void 0:u.map(((e,s)=>{const n=t.requests[s];if(!n||!(null==e?void 0:e.resource))return e;if(("GET"===n.method||"HEAD"===n.method)&&!ut(n.url))try{B(this.config,e.resource)}catch(r){if(!(r instanceof i))throw r;return{request:e.request,response:{status:"404",outcome:r.cause}}}return e})):u,c=Object.assign(Object.assign({},o),{entry:a,unbundle:function(){var t,e;return null!==(e=null===(t=this.entry)||void 0===t?void 0:t.map((t=>t.resource)).filter((t=>void 0!==t)))&&void 0!==e?e:[]},errors:function(){var t;return null===(t=this.entry)||void 0===t?void 0:t.filter((t=>{var e,i,s,n;return(null===(i=null===(e=t.response)||void 0===e?void 0:e.status)||void 0===i?void 0:i.startsWith("4"))||(null===(n=null===(s=t.response)||void 0===s?void 0:s.status)||void 0===n?void 0:n.startsWith("5"))})).map((t=>{var e;return null===(e=t.response)||void 0===e?void 0:e.outcome})).filter((t=>void 0!==t))}});return c}))}function lt(t,e){return s(this,void 0,void 0,(function*(){var i,s;const n={resourceType:"Bundle",type:"transaction",entry:t.requests.map((t=>ct(t,this.config)))},r=null==e?void 0:e.mode;if(F(r))return yield this.startAsyncJob("/","POST",n,r,e);const o=yield this.fhirRequest("/","POST")(n,e);(this.config.workspaceTag||(null===(i=this.config.ignoreTags)||void 0===i?void 0:i.length))&&(null===(s=o.entry)||void 0===s||s.forEach(((e,i)=>{const s=t.requests[i];s&&(null==e?void 0:e.resource)&&("GET"!==s.method&&"HEAD"!==s.method||ut(s.url)||B(this.config,e.resource))})));const u=Object.assign(Object.assign({},o),{entry:o.entry,unbundle:function(){var t,e;return null!==(e=null===(t=this.entry)||void 0===t?void 0:t.map((t=>t.resource)).filter((t=>void 0!==t)))&&void 0!==e?e:[]}});return u}))}function ht(t,e){return s(this,arguments,void 0,(function*({id:t},e){return this.fhirRequest(`/Patient/${t}/$generate-friendly-patient-id`,"POST")({},e)}))}function pt(t,e){const i=[];if(t.line&&i.push(...t.line),t.city||t.state||t.postalCode){const e=[];t.city&&e.push(t.city),t.state&&e.push(t.state),t.postalCode&&e.push(t.postalCode),i.push(e.join(", "))}return t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&i.push("["+t.use+"]"),i.join((null==e?void 0:e.lineSeparator)||", ").trim()}function vt(t,e){const i=[];return t.prefix&&!1!==(null==e?void 0:e.prefix)&&i.push(...t.prefix),t.given&&i.push(...t.given),t.family&&i.push(t.family),t.suffix&&!1!==(null==e?void 0:e.suffix)&&i.push(...t.suffix),t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&i.push("["+t.use+"]"),i.join(" ").trim()}var ft,mt,gt,bt,yt,qt,wt,jt,Ot,Tt,kt,At,St,It,Et,Ut,xt,Pt,$t,zt,Rt,Nt,_t,Mt,Ct,Jt,Dt,Wt,Lt,Bt,Ft,Gt,Ht;class Vt extends p{constructor(t){super(t),ft.add(this),this.search=G,this.searchAndGetAllPages=H,this.create=V,this.get=X,this.update=Z,this.patch=K,this.delete=Q,this.getAsyncJob=tt,this.waitForAsyncJob=et,this.waitForAsyncBulkOutput=st,this.waitForAsyncBulkBundle=nt,this.cancelAsyncJob=rt,this.history=ot,this.batch=dt,this.transaction=lt,this.generateFriendlyPatientId=ht,this.formatAddress=pt,this.formatHumanName=vt}}ft=new WeakSet;class Xt extends p{constructor(t){super(t),mt.add(this)}routeList(t){return this.request("/route","get",n(this,mt,"m",gt).bind(this))(t)}routeCreate(t,e){return this.request("/route","post",n(this,mt,"m",gt).bind(this))(t,e)}routeGet(t,e){return this.request("/route/{routeGuid}","get",n(this,mt,"m",gt).bind(this))(t,e)}routeDelete(t,e){return this.request("/route/{routeGuid}","delete",n(this,mt,"m",gt).bind(this))(t,e)}orderableItemList(t,e){return this.request("/orderableItem","get",n(this,mt,"m",gt).bind(this))(t,e)}orderableItemQuestionnaireGet(t,e){return this.request("/canonical-questionnaire/lab/{labGuid}/compendium/{compendiumVersion}/item/{itemCode}/questionnaire","get",n(this,mt,"m",gt).bind(this))(t,e)}orderSubmit(t,e){return this.request("/submit","post",n(this,mt,"m",gt).bind(this))(t,e)}}mt=new WeakSet,gt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.labApiUrl)&&void 0!==e?e:"https://labs-api.zapehr.com/v1"};class Zt extends p{constructor(t){super(t),bt.add(this)}list(t){return this.request("/m2m","get",n(this,bt,"m",yt).bind(this))(t)}create(t,e){return this.request("/m2m","post",n(this,bt,"m",yt).bind(this))(t,e)}me(t){return this.request("/m2m/me","get",n(this,bt,"m",yt).bind(this))(t)}get(t,e){return this.request("/m2m/{id}","get",n(this,bt,"m",yt).bind(this))(t,e)}update(t,e){return this.request("/m2m/{id}","patch",n(this,bt,"m",yt).bind(this))(t,e)}delete(t,e){return this.request("/m2m/{id}","delete",n(this,bt,"m",yt).bind(this))(t,e)}rotateSecret(t,e){return this.request("/m2m/{id}/rotate-secret","post",n(this,bt,"m",yt).bind(this))(t,e)}listV2(t,e){return this.request("/m2m/v2/list","get",n(this,bt,"m",yt).bind(this))(t,e)}}bt=new WeakSet,yt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Kt extends p{constructor(t){super(t),qt.add(this)}getMessagingConfig(t){return this.request("/messaging/config","get",n(this,qt,"m",wt).bind(this))(t)}}qt=new WeakSet,wt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Qt extends p{constructor(t){super(t),jt.add(this)}setUp(t,e){return this.request("/payment/payment-method/setup","post",n(this,jt,"m",Ot).bind(this))(t,e)}setDefault(t,e){return this.request("/payment/payment-method/set-default","post",n(this,jt,"m",Ot).bind(this))(t,e)}delete(t,e){return this.request("/payment/payment-method","delete",n(this,jt,"m",Ot).bind(this))(t,e)}list(t,e){return this.request("/payment/payment-method/list","post",n(this,jt,"m",Ot).bind(this))(t,e)}}jt=new WeakSet,Ot=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Yt extends p{constructor(t){super(t),Tt.add(this)}get(t){return this.request("/project","get",n(this,Tt,"m",kt).bind(this))(t)}update(t,e){return this.request("/project","patch",n(this,Tt,"m",kt).bind(this))(t,e)}}function te(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.rcmApiUrl)&&void 0!==e?e:"https://rcm-api.zapehr.com/v1"}function ee({id:t}){return`${te.call(this)}/payer/${t}`}function ie(e,i){return s(this,arguments,void 0,(function*({url:e},i){if(!e.startsWith(ee.call(this,{id:""})))throw new t({code:400,message:"Invalid payer URL."});const s=new URL(e).pathname.split("/").filter(Boolean),n=s[s.length-1];return this.request("/payer/{id}","get",te.bind(this))({id:n},i)}))}Tt=new WeakSet,kt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class se extends p{constructor(t){super(t),At.add(this),this.constructPayerUrl=ee,this.getPayerByUrl=ie}eligibilityCheck(t,e){return this.request("/eligibility-check","post",n(this,At,"m",St).bind(this))(t,e)}submitClaim(t,e){return this.request("/claim/{claimId}/submit","post",n(this,At,"m",St).bind(this))(t,e)}setClaimStatus(t,e){return this.request("/claim/{claimId}/status","post",n(this,At,"m",St).bind(this))(t,e)}listPayers(t,e){return this.request("/payer","get",n(this,At,"m",St).bind(this))(t,e)}getPayer(t,e){return this.request("/payer/{id}","get",n(this,At,"m",St).bind(this))(t,e)}}At=new WeakSet,St=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.rcmApiUrl)&&void 0!==e?e:"https://rcm-api.zapehr.com/v1"};class ne extends p{constructor(t){super(t),It.add(this)}list(t){return this.request("/iam/role","get",n(this,It,"m",Et).bind(this))(t)}create(t,e){return this.request("/iam/role","post",n(this,It,"m",Et).bind(this))(t,e)}get(t,e){return this.request("/iam/role/{roleId}","get",n(this,It,"m",Et).bind(this))(t,e)}update(t,e){return this.request("/iam/role/{roleId}","patch",n(this,It,"m",Et).bind(this))(t,e)}delete(t,e){return this.request("/iam/role/{roleId}","delete",n(this,It,"m",Et).bind(this))(t,e)}}It=new WeakSet,Et=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class re extends p{constructor(t){super(t),Ut.add(this)}list(t){return this.request("/secret","get",n(this,Ut,"m",xt).bind(this))(t)}set(t,e){return this.request("/secret","post",n(this,Ut,"m",xt).bind(this))(t,e)}get(t,e){return this.request("/secret/{name}","get",n(this,Ut,"m",xt).bind(this))(t,e)}delete(t,e){return this.request("/secret/{name}","delete",n(this,Ut,"m",xt).bind(this))(t,e)}}Ut=new WeakSet,xt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class oe extends p{constructor(t){super(t),Pt.add(this)}createMeeting(t,e){return this.request("/telemed/v2/meeting","post",n(this,Pt,"m",$t).bind(this))(t,e)}joinMeeting(t,e){return this.request("/telemed/v2/meeting/{encounterId}/join","get",n(this,Pt,"m",$t).bind(this))(t,e)}}Pt=new WeakSet,$t=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class ue extends p{constructor(t){super(t),zt.add(this)}searchCpt(t,e){return this.request("/cpt/search","get",n(this,zt,"m",Rt).bind(this))(t,e)}searchHcpcs(t,e){return this.request("/hcpcs/search","get",n(this,zt,"m",Rt).bind(this))(t,e)}}zt=new WeakSet,Rt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.terminologyApiUrl)&&void 0!==e?e:"https://terminology-api.zapehr.com/v1"};class ae extends p{constructor(t){super(t),Nt.add(this)}send(t,e){return this.request("/messaging/transactional-sms/send","post",n(this,Nt,"m",_t).bind(this))(t,e)}}Nt=new WeakSet,_t=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class ce extends p{constructor(t){super(t),Mt.add(this)}me(t){return this.request("/user/me","get",n(this,Mt,"m",Ct).bind(this))(t)}get(t,e){return this.request("/user/{id}","get",n(this,Mt,"m",Ct).bind(this))(t,e)}update(t,e){return this.request("/user/{id}","patch",n(this,Mt,"m",Ct).bind(this))(t,e)}delete(t,e){return this.request("/user/{id}","delete",n(this,Mt,"m",Ct).bind(this))(t,e)}resetMfa(t,e){return this.request("/user/{id}/reset-mfa","post",n(this,Mt,"m",Ct).bind(this))(t,e)}resetPasswordLink(t,e){return this.request("/user/{id}/reset-password-link","post",n(this,Mt,"m",Ct).bind(this))(t,e)}changePassword(t,e){return this.request("/user/{id}/change-password","post",n(this,Mt,"m",Ct).bind(this))(t,e)}invite(t,e){return this.request("/user/invite","post",n(this,Mt,"m",Ct).bind(this))(t,e)}list(t){return this.request("/user","get",n(this,Mt,"m",Ct).bind(this))(t)}listV2(t,e){return this.request("/user/v2/list","get",n(this,Mt,"m",Ct).bind(this))(t,e)}}Mt=new WeakSet,Ct=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class de extends p{constructor(t){super(t),Jt.add(this)}get(t){return this.request("/version","get",n(this,Jt,"m",Dt).bind(this))(t)}}function le(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"}function he(t){return s(this,arguments,void 0,(function*({bucketName:t,"objectPath+":e,file:i}){const s=yield this.request("/z3/{bucketName}/{objectPath+}","post",le.bind(this))({action:"upload",bucketName:t,"objectPath+":e});yield fetch(s.signedUrl,{method:"PUT",body:i})}))}function pe(t){return s(this,arguments,void 0,(function*({bucketName:t,"objectPath+":e}){const i=yield this.request("/z3/{bucketName}/{objectPath+}","post",le.bind(this))({action:"download",bucketName:t,"objectPath+":e}),s=yield fetch(i.signedUrl,{method:"GET"});if(!s.ok)throw new Error("Failed to download file");return s.arrayBuffer()}))}function ve(e){return s(this,void 0,void 0,(function*(){var i,s;let n,r;const o=new URL(e.url);if("z3:"===o.protocol){const t=o.pathname.split("/").slice(1);n=o.hostname,r=t.join("/")}else{if(!o.href.startsWith(null!==(s=null===(i=this.config.services)||void 0===i?void 0:i.projectApiUrl)&&void 0!==s?s:"https://project-api.zapehr.com/v1"))throw new t({message:"Invalid Z3 URL",code:400});{const t=o.pathname.split("/").slice(3);n=t[0],r=t.slice(1).join("/")}}const u={action:"upload",bucketName:n,"objectPath+":r};return this.request("/z3/{bucketName}/{objectPath+}","post",le.bind(this))(u)}))}Jt=new WeakSet,Dt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class fe extends p{constructor(t){super(t),Wt.add(this),this.uploadFile=he,this.downloadFile=pe,this.getPresignedUrlForZ3Url=ve}listBuckets(t){return this.request("/z3","get",n(this,Wt,"m",Lt).bind(this))(t)}createBucket(t,e){return this.request("/z3/{bucketName}","put",n(this,Wt,"m",Lt).bind(this))(t,e)}deleteBucket(t,e){return this.request("/z3/{bucketName}","delete",n(this,Wt,"m",Lt).bind(this))(t,e)}listObjects(t,e){return this.request("/z3/{bucketName}/{objectPath+}","get",n(this,Wt,"m",Lt).bind(this))(t,e)}getPresignedUrl(t,e){return this.request("/z3/{bucketName}/{objectPath+}","post",n(this,Wt,"m",Lt).bind(this))(t,e)}deleteObject(t,e){return this.request("/z3/{bucketName}/{objectPath+}","delete",n(this,Wt,"m",Lt).bind(this))(t,e)}}function me(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.zambdaApiUrl)&&void 0!==e?e:"https://zambda-api.zapehr.com/v1"}function ge(e){return s(this,arguments,void 0,(function*({id:e,file:i,filename:s}){const n=yield this.request("/zambda/{id}/presigned-url","post",me.bind(this))({id:e,action:"upload",filename:s}),r=yield fetch(n.signedUrl,{method:"PUT",body:i});if(!r.ok)throw new t({message:"Failed to upload file",code:r.status,cause:r.statusText})}))}function be(e){return s(this,arguments,void 0,(function*({id:e}){const i=yield this.request("/zambda/{id}/presigned-url","post",me.bind(this))({id:e,action:"download"}),s=yield fetch(i.signedUrl,{method:"GET"});if(!s.ok)throw new t({message:"Failed to download file",code:s.status,cause:s.statusText});return s.arrayBuffer()}))}Wt=new WeakSet,Lt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class ye extends p{constructor(t){super(t),Bt.add(this),this.uploadFile=ge,this.downloadFile=be}list(t){return this.request("/zambda","get",n(this,Bt,"m",Ft).bind(this))(t)}create(t,e){return this.request("/zambda","post",n(this,Bt,"m",Ft).bind(this))(t,e)}get(t,e){return this.request("/zambda/{id}","get",n(this,Bt,"m",Ft).bind(this))(t,e)}update(t,e){return this.request("/zambda/{id}","patch",n(this,Bt,"m",Ft).bind(this))(t,e)}delete(t,e){return this.request("/zambda/{id}","delete",n(this,Bt,"m",Ft).bind(this))(t,e)}execute(t,e){return this.request("/zambda/{id}/execute","post",n(this,Bt,"m",Ft).bind(this))(t,e)}executePublic(t,e){return this.request("/zambda/{id}/execute-public","post",n(this,Bt,"m",Ft).bind(this))(t,e)}s3Upload(t,e){return this.request("/zambda/{id}/s3-upload","post",n(this,Bt,"m",Ft).bind(this))(t,e)}getPresignedUrl(t,e){return this.request("/zambda/{id}/presigned-url","post",n(this,Bt,"m",Ft).bind(this))(t,e)}}Bt=new WeakSet,Ft=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.zambdaApiUrl)&&void 0!==e?e:"https://zambda-api.zapehr.com/v1"};class qe extends p{constructor(t){super(t),Gt.add(this)}list(t,e){return this.request("/zambda/{id}/logStream","post",n(this,Gt,"m",Ht).bind(this))(t,e)}search(t,e){return this.request("/zambda/{id}/logStream/search","post",n(this,Gt,"m",Ht).bind(this))(t,e)}get(t,e){return this.request("/zambda/{id}/logStream/{logStreamName}","post",n(this,Gt,"m",Ht).bind(this))(t,e)}}Gt=new WeakSet,Ht=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.zambdaApiUrl)&&void 0!==e?e:"https://zambda-api.zapehr.com/v1"};let we=class{constructor(e){var i,s,n,r,o,u;if(e.workspaceTag&&e.ignoreTags)throw new t({message:"workspaceTag and ignoreTags are mutually exclusive and cannot both be set in config",code:400});this.config=e,null!==(i=(r=this.config).services)&&void 0!==i||(r.services={}),null!==(s=(o=this.config.services).projectApiUrl)&&void 0!==s||(o.projectApiUrl=e.projectApiUrl),null!==(n=(u=this.config.services).fhirApiUrl)&&void 0!==n||(u.fhirApiUrl=e.fhirApiUrl),this.application=new w(e),this.developer=new R(e),this.m2m=new Zt(e),this.messaging=new Kt(e),this.conversation=new z(e),this.transactionalSMS=new ae(e),this.paymentMethod=new Qt(e),this.charge=new j(e),this.project=new Yt(e),this.role=new ne(e),this.secret=new re(e),this.telemed=new oe(e),this.user=new ce(e),this.version=new de(e),this.z3=new fe(e),this.fax=new _(e),this.lab=new Xt(e),this.erx=new N(e),this.terminology=new ue(e),this.zambda=new ye(e),this.zambdaLogStream=new qe(e),this.rcm=new se(e),this.fhir=new Vt(e)}};class je extends we{}je.OystehrFHIRError=i,je.OystehrSdkError=t,exports.default=je;
2
2
  //# sourceMappingURL=index.min.cjs.map