I guess I re-invented the wheel a bit, thanks for the info.
- Log in to post comments
I guess I re-invented the wheel a bit, thanks for the info.
You cannot change the doc type of "msg" as its state is immutable. You'll need to create a clone then change doc type. To create the clone:
s outmsg=msg.%ConstructClone(1)
Also note that not all trigger events (MSH:9.2) share the same doctype either, so you'll need to derive it appropriately. e.g. ADT^A01, ADT^A04, ADT^A05 the doc type is ADT_A01.
This because the RawContent field is a %String where MAXLEN is 10000. You will need to get the contents out as a stream. So it'll be like:
s msg=##class(EnsLib.HL7.Message).%OpenId(EnsMsgBodyID)
d msg.OutputToLibraryStream(.msgstream)
s newmsg=##class(EnsLib.HL7.Message).ImportFromLibraryStream(msgstream)
I had a similar requirement, so created a simple method to achieve this. May be someone else is also looking for something similar
ClassMethod CreateCSVArray(
csvrec = "",
Output csvarray)
{
s csvarray=0
i csvrec'=""{
s csvlen=$l(csvrec)
i csvlen>1{
s token=""
f i=1:1:csvlen{
s char=$we(csvrec,i)
i char=""""{
s closequotepos=$find(csvrec,"""",i+1)
s csvarray($i(csvarray))=$we(csvrec,i+1,closequotepos-2)
s i=closequotepos
s token=""
}else{
i char'=","{
s token=token_char
}else{
s csvarray($i(csvarray))=token
s token=""
}
}
}
s:token'="" csvarray($i(csvarray))=token
}
}
}Which produced the output:
myarr=5
myarr(1)="ABC Company"
myarr(2)="123 Main St, Ste 102"
myarr(3)="Anytown, DC"
myarr(4)=10001
myarr(5)="234-567-8901"