@medplum/cli 4.3.0 → 4.3.1
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/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +2 -2
- package/package.json +5 -5
package/dist/esm/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ Configuration values come from a file named **medplum.<tag>.config.server.json**
|
|
|
11
11
|
`+Z.yellow("**Services must be restarted to apply changes.**"))).argument("<tag>","The Medplum stack tag").option("--file [file]",kt("File to provide overrides for **apiPort**, **baseUrl**, **appDomainName** and **storageDomainName** values that appear in the config file.")).option("--dryrun","Displays the operations that would be performed using the specified command without actually running them.").option("--yes","Automatically confirm the update").action(us),y(e,new g("update-server").alias("deploy-server").description("Update the server image").argument("<tag>","The Medplum stack tag").option("--file [file]","Specifies the config file to use. If not specified, the file is based on the tag.").option("--to-version [version]","Specifies the version of the configuration to update. If not specified, the latest version is updated.").action(ds)),e.command("update-app").alias("deploy-app").description("Update the app site").argument("<tag>","The Medplum stack tag").option("--file [file]","Specifies the config file to use. If not specified, the file is based on the tag.").option("--to-version [version]","Specifies the version of the configuration to update. If not specified, the latest version is updated.").option("--dryrun","Displays the operations that would be performed using the specified command without actually running them.").option("--tar-path [tarPath]","Specifies the path to the extracted tarball of the @medplum/app package.").action(is),e.command("update-bucket-policies").description("Update S3 bucket policies").argument("<tag>","The Medplum stack tag").option("--file [file]","Specifies the config file to use. If not specified, the file is based on the tag.").option("--dryrun","Displays the operations that would be performed using the specified command without actually running them.").action(ls),e}var fs=new g("save"),hs=new g("deploy"),gs=new g("create"),be=new g("bot");y(be,fs);y(be,hs);y(be,gs);var rr=new g("save-bot"),or=new g("deploy-bot"),nr=new g("create-bot");fs.description("Saving the bot").argument("<botName>").action(async(e,t)=>{let r=await R(t);await it(r,e)});hs.description("Deploy the app to AWS").argument("<botName>").action(async(e,t)=>{let r=await R(t);await it(r,e,!0)});gs.arguments("<botName> <projectId> <sourceFile> <distFile>").description("Creating a bot").option("--runtime-version <runtimeVersion>","Runtime version (awslambda, vmcontext)").option("--no-write-config","Do not write bot to config").action(async(e,t,r,o,n)=>{let s=await R(n);await Ct(s,e,t,r,o,n.runtimeVersion,!!n.writeConfig)});async function it(e,t,r=!1){let o=Kr(t),n=[],s=[],i=0,c=0;for(let l of o)try{let u=await e.readResource("Bot",l.id);await bt(e,l,u),i++,r&&(await Pt(e,l,u),c++)}catch(u){n.push(u),s.push(`${l.name} [${l.id}]`)}if(console.log(`Number of bots saved: ${i}`),console.log(`Number of bots deployed: ${c}`),console.log(`Number of errors: ${n.length}`),n.length)throw new Error(`${n.length} bot(s) had failures. Bots with failures:
|
|
12
12
|
|
|
13
13
|
${s.join(`
|
|
14
|
-
`)}`,{cause:n})}rr.description("Saves the bot").argument("<botName>").action(async(e,t)=>{let r=await R(t);await it(r,e)});or.description("Deploy the bot to AWS").argument("<botName>").action(async(e,t)=>{let r=await R(t);await it(r,e,!0)});nr.arguments("<botName> <projectId> <sourceFile> <distFile>").description("Creates and saves the bot").action(async(e,t,r,o,n)=>{let s=await R(n);await Ct(s,e,t,r,o)});import{createReadStream as ip,writeFile as ap}from"node:fs";import{resolve as ws}from"node:path";import{createInterface as cp}from"node:readline";var Es=new g("export"),Ss=new g("import"),at=new g("bulk");y(at,Es);y(at,Ss);Es.option("-e, --export-level <exportLevel>",'Optional export level. Defaults to system level export. "Group/:id" - Group of Patients, "Patient" - All Patients.').option("-t, --types <types>","optional resource types to export").option("-s, --since <since>","optional Resources will be included in the response if their state has changed after the supplied time (e.g. if Resource.meta.lastUpdated is later than the supplied _since time).").option("-d, --target-directory <targetDirectory>","optional target directory to save files from the bulk export operations.").action(async e=>{let{exportLevel:t,types:r,since:o,targetDirectory:n}=e,s=await R(e);(await s.bulkExport(t,r,o,{pollStatusOnAccepted:!0})).output?.forEach(async({type:c,url:l})=>{let u=new URL(l),h=await s.download(l),f=`${c}_${u.pathname}`.replace(/[^a-zA-Z0-9]+/g,"_")+".ndjson",S=ws(n??"",f);ap(`${S}`,await h.text(),()=>{console.log(`${S} is created`)})})});Ss.argument("<filename>","File Name").option("--num-resources-per-request <numResourcesPerRequest>","optional number of resources to import per batch request. Defaults to 25.","25").option("--add-extensions-for-missing-values","optional flag to add extensions for missing values in a resource",!1).option("-d, --target-directory <targetDirectory>","optional target directory of file to be imported").action(async(e,t)=>{let{numResourcesPerRequest:r,addExtensionsForMissingValues:o,targetDirectory:n}=t,s=ws(n??process.cwd(),e),i=await R(t);await lp(s,Number.parseInt(r,10),i,o)});async function lp(e,t,r,o){let n=[],s=ip(e),i=cp({input:s});for await(let c of i){let l=up(c,o);n.push({resource:l,request:{method:"POST",url:l.resourceType}}),n.length%t===0&&(await ys(n,r),n=[])}n.length>0&&await ys(n,r)}async function ys(e,t){(await t.executeBatch({resourceType:"Bundle",type:"transaction",entry:e})).entry?.forEach(o=>{K(o.response)})}function up(e,t){let r=JSON.parse(e);return t?pp(r):r}function pp(e){return e.resourceType==="ExplanationOfBenefit"?dp(e):e}function dp(e){return e.provider||(e.provider=Tt()),e.item?.forEach(t=>{t?.productOrService||(t.productOrService=Tt())}),e}import{formatHl7DateTime as wp,Hl7Message as Ep}from"@medplum/core";import{connect as mp}from"node:net";import{Hl7Message as fp}from"@medplum/core";import Rs from"iconv-lite";import{sleep as gp}from"@medplum/core";import yp from"node:net";var As=class extends EventTarget{addEventListener(e,t,r){super.addEventListener(e,t,r)}removeEventListener(e,t,r){super.removeEventListener(e,t,r)}};var hp=class extends Event{constructor(e,t){super("message"),this.connection=e,this.message=t}},ct=class extends Event{constructor(e){super("error"),this.error=e}},Is=class extends Event{constructor(){super("close")}},vs=class extends As{constructor(e,t="utf-8",r=!1){super(),this.chunks=[],this.messageQueue=[],this.socket=e,this.encoding=t,this.enhancedMode=r,e.on("data",o=>{try{if(this.appendData(o),o.at(-2)===28&&o.at(-1)===13){let n=Buffer.concat(this.chunks),s=n.subarray(1,n.length-2),i=Rs.decode(s,this.encoding),c=fp.parse(i);this.dispatchEvent(new hp(this,c)),this.resetBuffer()}}catch(n){this.dispatchEvent(new ct(n))}}),e.on("error",o=>{this.resetBuffer(),this.dispatchEvent(new ct(o))}),e.on("end",()=>{this.close()}),this.addEventListener("message",o=>{r&&this.send(o.message.buildAck({ackCode:"CA"}));let n=this.messageQueue.shift();if(!n){this.dispatchEvent(new ct(new Error(`Received a message when no pending messages were in the queue. Message: ${o.message}`)));return}n.resolve?.(o.message)})}sendImpl(e,t){this.messageQueue.push(t);let r=e.toString(),o=Rs.encode(r,this.encoding),n=Buffer.alloc(o.length+3);n.writeInt8(11,0),o.copy(n,1),n.writeInt8(28,o.length+1),n.writeInt8(13,o.length+2),this.socket.write(n)}send(e){this.sendImpl(e,{message:e})}async sendAndWait(e){return new Promise((t,r)=>{let o={message:e,resolve:t,reject:r};this.sendImpl(e,o)})}close(){this.socket.end(),this.socket.destroy(),this.dispatchEvent(new Is)}appendData(e){this.chunks.push(e)}resetBuffer(){this.chunks=[]}},bs=class extends As{constructor(e){super(),this.options=e,this.host=this.options.host,this.port=this.options.port,this.encoding=this.options.encoding,this.keepAlive=this.options.keepAlive??!1,this.connectTimeout=this.options.connectTimeout??3e4}connect(){return this.connection?Promise.resolve(this.connection):(this.socket&&(this.socket.removeAllListeners(),this.socket.destroy(),this.socket=void 0),new Promise((e,t)=>{this.socket=mp({host:this.host,port:this.port,keepAlive:this.keepAlive}),this.connectTimeout>0&&(this.socket.setTimeout(this.connectTimeout),this.socket.on("timeout",()=>{let r=new Error(`Connection timeout after ${this.connectTimeout}ms`);this.socket&&(this.socket.destroy(),this.socket=void 0),t(r)})),this.socket.on("connect",()=>{if(!this.socket)return;let r;this.connection=r=new vs(this.socket,this.encoding),this.socket.setTimeout(0),r.addEventListener("close",()=>{this.socket=void 0,this.dispatchEvent(new Is)}),r.addEventListener("error",o=>{this.dispatchEvent(new ct(o.error))}),e(this.connection)}),this.socket.on("error",r=>{this.socket&&(this.socket.destroy(),this.socket=void 0),t(r)})}))}async send(e){return(await this.connect()).send(e)}async sendAndWait(e){return(await this.connect()).sendAndWait(e)}close(){this.socket&&(this.socket.removeAllListeners(),this.socket.destroy(),this.socket=void 0),this.connection&&(this.connection.close(),delete this.connection)}},Ps=class{constructor(e){this.handler=e}start(e,t,r=!1){let o=yp.createServer(s=>{let i=new vs(s,t,r);this.handler(i)}),n=async s=>{s?.code==="EADDRINUSE"&&(await gp(50),o.close(),o.listen(e))};o.on("error",n),o.once("listening",()=>{o.off("error",n)}),o.listen(e),this.server=o}async stop(){return new Promise((e,t)=>{if(!this.server){t(new Error("Stop was called but there is no server running"));return}this.server.close(r=>{if(r){t(r);return}e()}),this.server=void 0})}};import{readFileSync as Sp}from"node:fs";var Rp=new g("send").description("Send an HL7 v2 message via MLLP").argument("<host>","The destination host name or IP address").argument("<port>","The destination port number").argument("[body]","Optional HL7 message body").option("--generate-example","Generate a sample HL7 message").option("--file <file>","Read the HL7 message from a file").option("--encoding <encoding>","The encoding to use").action(async(e,t,r,o)=>{if(o.generateExample?r=Ip():o.file&&(r=Sp(o.file,"utf8")),!r)throw new Error("Missing HL7 message body");let n=new bs({host:e,port:Number.parseInt(t,10),encoding:o.encoding});try{let s=await n.sendAndWait(Ep.parse(r));console.log(s.toString().replaceAll("\r",`
|
|
14
|
+
`)}`,{cause:n})}rr.description("Saves the bot").argument("<botName>").action(async(e,t)=>{let r=await R(t);await it(r,e)});or.description("Deploy the bot to AWS").argument("<botName>").action(async(e,t)=>{let r=await R(t);await it(r,e,!0)});nr.arguments("<botName> <projectId> <sourceFile> <distFile>").description("Creates and saves the bot").action(async(e,t,r,o,n)=>{let s=await R(n);await Ct(s,e,t,r,o)});import{createReadStream as ip,writeFile as ap}from"node:fs";import{resolve as ws}from"node:path";import{createInterface as cp}from"node:readline";var Es=new g("export"),Ss=new g("import"),at=new g("bulk");y(at,Es);y(at,Ss);Es.option("-e, --export-level <exportLevel>",'Optional export level. Defaults to system level export. "Group/:id" - Group of Patients, "Patient" - All Patients.').option("-t, --types <types>","optional resource types to export").option("-s, --since <since>","optional Resources will be included in the response if their state has changed after the supplied time (e.g. if Resource.meta.lastUpdated is later than the supplied _since time).").option("-d, --target-directory <targetDirectory>","optional target directory to save files from the bulk export operations.").action(async e=>{let{exportLevel:t,types:r,since:o,targetDirectory:n}=e,s=await R(e);(await s.bulkExport(t,r,o,{pollStatusOnAccepted:!0})).output?.forEach(async({type:c,url:l})=>{let u=new URL(l),h=await s.download(l),f=`${c}_${u.pathname}`.replace(/[^a-zA-Z0-9]+/g,"_")+".ndjson",S=ws(n??"",f);ap(`${S}`,await h.text(),()=>{console.log(`${S} is created`)})})});Ss.argument("<filename>","File Name").option("--num-resources-per-request <numResourcesPerRequest>","optional number of resources to import per batch request. Defaults to 25.","25").option("--add-extensions-for-missing-values","optional flag to add extensions for missing values in a resource",!1).option("-d, --target-directory <targetDirectory>","optional target directory of file to be imported").action(async(e,t)=>{let{numResourcesPerRequest:r,addExtensionsForMissingValues:o,targetDirectory:n}=t,s=ws(n??process.cwd(),e),i=await R(t);await lp(s,Number.parseInt(r,10),i,o)});async function lp(e,t,r,o){let n=[],s=ip(e),i=cp({input:s});for await(let c of i){let l=up(c,o);n.push({resource:l,request:{method:"POST",url:l.resourceType}}),n.length%t===0&&(await ys(n,r),n=[])}n.length>0&&await ys(n,r)}async function ys(e,t){(await t.executeBatch({resourceType:"Bundle",type:"transaction",entry:e})).entry?.forEach(o=>{K(o.response)})}function up(e,t){let r=JSON.parse(e);return t?pp(r):r}function pp(e){return e.resourceType==="ExplanationOfBenefit"?dp(e):e}function dp(e){return e.provider||(e.provider=Tt()),e.item?.forEach(t=>{t?.productOrService||(t.productOrService=Tt())}),e}import{formatHl7DateTime as wp,Hl7Message as Ep}from"@medplum/core";import{connect as mp}from"node:net";import{Hl7Message as fp}from"@medplum/core";import Rs from"iconv-lite";import{sleep as gp}from"@medplum/core";import yp from"node:net";var As=class extends EventTarget{addEventListener(e,t,r){super.addEventListener(e,t,r)}removeEventListener(e,t,r){super.removeEventListener(e,t,r)}};var hp=class extends Event{constructor(e,t){super("message"),this.connection=e,this.message=t}},ct=class extends Event{constructor(e){super("error"),this.error=e}},Is=class extends Event{constructor(){super("close")}},vs=class extends As{constructor(e,t="utf-8",r=!1){super(),this.chunks=[],this.messageQueue=[],this.socket=e,this.encoding=t,this.enhancedMode=r,e.on("data",o=>{try{if(this.appendData(o),o.at(-2)===28&&o.at(-1)===13){let n=Buffer.concat(this.chunks),s=n.subarray(1,n.length-2),i=Rs.decode(s,this.encoding),c=fp.parse(i);this.dispatchEvent(new hp(this,c)),this.resetBuffer()}}catch(n){this.dispatchEvent(new ct(n))}}),e.on("error",o=>{this.resetBuffer(),this.dispatchEvent(new ct(o))}),e.on("end",()=>{this.close()}),this.addEventListener("message",o=>{r&&this.send(o.message.buildAck({ackCode:"CA"}));let n=this.messageQueue.shift();if(!n){this.dispatchEvent(new ct(new Error(`Received a message when no pending messages were in the queue. Message: ${o.message}`)));return}n.resolve?.(o.message)})}sendImpl(e,t){this.messageQueue.push(t);let r=e.toString(),o=Rs.encode(r,this.encoding),n=Buffer.alloc(o.length+3);n.writeInt8(11,0),o.copy(n,1),n.writeInt8(28,o.length+1),n.writeInt8(13,o.length+2),this.socket.write(n)}send(e){this.sendImpl(e,{message:e})}async sendAndWait(e){return new Promise((t,r)=>{let o={message:e,resolve:t,reject:r};this.sendImpl(e,o)})}close(){this.socket.end(),this.socket.destroy(),this.dispatchEvent(new Is)}appendData(e){this.chunks.push(e)}resetBuffer(){this.chunks=[]}},bs=class extends As{constructor(e){super(),this.options=e,this.host=this.options.host,this.port=this.options.port,this.encoding=this.options.encoding,this.keepAlive=this.options.keepAlive??!1,this.connectTimeout=this.options.connectTimeout??3e4}connect(){return this.connection?Promise.resolve(this.connection):(this.socket&&(this.socket.removeAllListeners(),this.socket.destroy(),this.socket=void 0),new Promise((e,t)=>{this.socket=mp({host:this.host,port:this.port,keepAlive:this.keepAlive}),this.connectTimeout>0&&(this.socket.setTimeout(this.connectTimeout),this.socket.on("timeout",()=>{let r=new Error(`Connection timeout after ${this.connectTimeout}ms`);this.socket&&(this.socket.destroy(),this.socket=void 0),t(r)})),this.socket.on("connect",()=>{if(!this.socket)return;let r;this.connection=r=new vs(this.socket,this.encoding),this.socket.setTimeout(0),r.addEventListener("close",()=>{this.socket=void 0,this.connection=void 0,this.dispatchEvent(new Is)}),r.addEventListener("error",o=>{this.dispatchEvent(new ct(o.error))}),e(this.connection)}),this.socket.on("error",r=>{this.socket&&(this.socket.destroy(),this.socket=void 0),t(r)})}))}async send(e){return(await this.connect()).send(e)}async sendAndWait(e){return(await this.connect()).sendAndWait(e)}close(){this.socket&&(this.socket.removeAllListeners(),this.socket.destroy(),this.socket=void 0),this.connection&&(this.connection.close(),delete this.connection)}},Ps=class{constructor(e){this.handler=e}start(e,t,r=!1){let o=yp.createServer(s=>{let i=new vs(s,t,r);this.handler(i)}),n=async s=>{s?.code==="EADDRINUSE"&&(await gp(50),o.close(),o.listen(e))};o.on("error",n),o.once("listening",()=>{o.off("error",n)}),o.listen(e),this.server=o}async stop(){return new Promise((e,t)=>{if(!this.server){t(new Error("Stop was called but there is no server running"));return}this.server.close(r=>{if(r){t(r);return}e()}),this.server=void 0})}};import{readFileSync as Sp}from"node:fs";var Rp=new g("send").description("Send an HL7 v2 message via MLLP").argument("<host>","The destination host name or IP address").argument("<port>","The destination port number").argument("[body]","Optional HL7 message body").option("--generate-example","Generate a sample HL7 message").option("--file <file>","Read the HL7 message from a file").option("--encoding <encoding>","The encoding to use").action(async(e,t,r,o)=>{if(o.generateExample?r=Ip():o.file&&(r=Sp(o.file,"utf8")),!r)throw new Error("Missing HL7 message body");let n=new bs({host:e,port:Number.parseInt(t,10),encoding:o.encoding});try{let s=await n.sendAndWait(Ep.parse(r));console.log(s.toString().replaceAll("\r",`
|
|
15
15
|
`))}finally{n.close()}}),Ap=new g("listen").description("Starts an HL7 v2 MLLP server").argument("<port>").option("--encoding <encoding>","The encoding to use").action(async(e,t)=>{new Ps(o=>{o.addEventListener("message",({message:n})=>{console.log(n.toString().replaceAll("\r",`
|
|
16
16
|
`)),o.send(n.buildAck())})}).start(Number.parseInt(e,10),t.encoding),console.log("Listening on port "+e)}),lt=new g("hl7");y(lt,Rp);y(lt,Ap);function Ip(){let e=wp(new Date),t=Date.now().toString();return`MSH|^~\\&|ADTSYS|HOSPITAL|RECEIVER|DEST|${e}||ADT^A01|${t}|P|2.5|
|
|
17
17
|
EVN|A01|${e}||
|