`4F„2‡„MSH0\Ec:\tempHL7#7ƒg ÿÿÿÿÿÿÿÿ#7ƒg|~FR#7ƒg^Sÿÿÿÿ#7ƒg&Tÿÿÿÿ ÿHL7NQ…>™å¦{R/5²º`NQ…>™å¦{R/5²º`Y4F„V6&‡ PatientSwapÿÿÿÿE53TE53T9'MSH52’Field Separatorc”STCb3Value String Data52’Encoding Characters52’Sending Applicationc”HDCb3 Namespace IDc”ISCb3Value String DataCb3 Universal IDCb3Universal ID Typec”IDCb3Value String DataHierarchic Designator52’Sending Facility 52’Receiving Application 52’Receiving Facility 52’Date/time Of Messagec”TSCb3Timec”DTMCb3Value‰TrDateTime !0 DTM DateTime Date/TimeCb3Degree Of Precision Time Stamp52’Security52’ Message Typec”MSGCb3 Message CodeCb3 Trigger EventCb3Message Structure Message Type52’Message Control ID52’ Processing IDc”PTCb3 Processing IDCb3Processing ModeProcessing Type52’ Version IDc”VIDCb3 Version IDCb3Internationalization Codec”CECb3 IdentifierCb3TextCb3Name Of Coding SystemCb3Alternate IdentifierCb3Alternate TextCb3Name Of Alternate Coding System Coded ElementCb3International Version ID*Version Identifier52’Sequence Numberc”NMCb3ValueNumeric52’Continuation Pointer52’Accept Acknowledgment Type52’Application Acknowledgment Type52’ Country Code52’ Character Setÿÿÿÿ52’Principal Language Of Message*52’'Alternate Character Set Handling Scheme52’Message Profile Identifierÿÿÿÿc”EICb3Entity IdentifierCb3 Namespace ID Cb3 Universal IDCb3Universal ID TypeEntity IdentifierMessage HeaderMessageADT™x#A17™x# PatientSwap Swap Patients  c”XCNCb3 ID NumberCb3 Family Namec”FNCb3SurnameCb3Own Surname PrefixCb3 Own SurnameCb3"Surname Prefix From Partner/spouseCb3Surname From Partner/spouse Family NameCb3 Given NameCb32Second And Further Given Names Or Initials ThereofCb3Suffix (e.g., Jr Or III)Cb3Prefix (e.g., Dr)Cb3Degree (e.g., Md) Cb3 Source Table Cb3Assigning Authority Cb3Name Type CodeCb3Identifier Check DigitCb3Check Digit SchemeCb3Identifier Type CodeCb3Assigning Facility Cb3Name Representation CodeCb3 Name Context*Cb3Name Validity Rangec”DRCb3Range Start Date/timeCb3Range End Date/timeDate/Time RangeCb3Name Assembly OrderCb3Effective DateCb3Expiration DateCb3Professional SuffixCb3Assigning Jurisdictionc”CWE Cb3 IdentifierCb3TextCb3Name Of Coding SystemCb3Alternate IdentifierCb3Alternate TextCb3Name Of Alternate Coding SystemCb3Coding System Version IDCb3"Alternate Coding System Version IDCb3 Original TextCoded With ExceptionsCb3Assigning Agency Or Departmentb1Extended Composite ID Number And Name For PersonsbE*Z=#'3c”XADCb3Street Addressc”SADCb3Street Or Mailing AddressCb3 Street NameCb3Dwelling NumberStreet AddressCb3Other DesignationCb3CityCb3State Or ProvinceCb3Zip Or Postal CodeCb3CountryCb3 Address TypeCb3Other Geographic DesignationCb3County/parish Code Cb3 Census Tract Cb3Address Representation CodeCb3Address Validity RangeZCb3Effective DateCb3Expiration DateExtended Addressoc”SICb3Value Sequence IDc”DLNCb3License NumberCb3 Issuing State, Province, Country Cb3Expiration Datec”DTCb3Value‰TrDateDT DateDateDriver's License Number†c”XPNCb3 Family NameECb3 Given NameCb32Second And Further Given Names Or Initials ThereofCb3Suffix (e.g., Jr Or III)Cb3Prefix (e.g., Dr)Cb3Degree (e.g., Md) Cb3Name Type CodeCb3Name Representation CodeCb3 Name Context*Cb3Name Validity RangeZCb3Name Assembly OrderCb3Effective DateCb3Expiration DateCb3Professional SuffixExtended Person Namec”XTN Cb3Telephone NumberCb3Telecommunication Use CodeCb3 Telecommunication Equipment TypeCb3 Email AddressCb3 Country Code3Cb3Area/city Code3Cb3 Local Number3Cb3 Extension3Cb3Any TextCb3Extension PrefixCb3Speed Dial CodeCb3Unformatted Telephone Number!Extended Telecommunication Numberc”CX Cb3 ID NumberCb3 Check DigitCb3Check Digit SchemeCb3Assigning Authority Cb3Identifier Type CodeCb3Assigning Facility Cb3Effective Date†Cb3Expiration Date†Cb3Assigning JurisdictionbCb3Assigning Agency Or Departmentb&Extended Composite ID With Check Digitc”DLDCb3Discharge Location Cb3Effective DateDischarge Location And Datec”PL Cb3 Point Of Care Cb3Room Cb3Bed Cb3Facility Cb3Location Status Cb3Person Location Type Cb3Building Cb3Floor Cb3Location DescriptionCb3!Comprehensive Location Identifier=Cb3 Assigning Authority For Location Person Locationc”FCCb3Financial Class Code Cb3Effective DateFinancial Classc”XON Cb3Organization NameCb3Organization Name Type Code Cb3 ID Number3Cb3 Check Digit3Cb3Check Digit SchemeCb3Assigning Authority Cb3Identifier Type CodeCb3Assigning Facility Cb3Name Representation CodeCb3Organization IdentifierCExtended Composite Name And Identification Number For Organizationsc”TXCb3Value Text Data9'EVN52’Event Type Code52’Recorded Date/time52’Date/time Planned Event52’Event Reason Code 52’ Operator IDÿÿÿÿB52’Event Occurred52’Event Facility Event Type9'PID'52’ Set ID - Pid€52’ Patient ID¥52’Patient Identifier Listÿÿÿÿ¥52’Alternate Patient ID - Pidÿÿÿÿ¥52’ Patient Nameÿÿÿÿ‰52’Mother's Maiden Nameÿÿÿÿ‰52’Date/time Of Birth52’Administrative Sex 52’ Patient Aliasÿÿÿÿ‰52’Raceÿÿÿÿ*52’Patient Addressÿÿÿÿm52’ County Code 52’Phone Number - Homeÿÿÿÿ˜52’Phone Number - Businessÿÿÿÿ˜52’Primary Language*52’Marital Status*52’Religion*52’Patient Account Number¥52’Ssn Number - Patient52’!Driver's License Number - Patient‚52’Mother's Identifierÿÿÿÿ¥52’ Ethnic Groupÿÿÿÿ*52’ Birth Place52’Multiple Birth Indicator52’ Birth Order352’ Citizenshipÿÿÿÿ*52’Veterans Military Status*52’ Nationality*52’Patient Death Date And Time52’Patient Death Indicator52’Identity Unknown Indicator52’Identity Reliability Codeÿÿÿÿ 52’Last Update Date/time52’Last Update Facility 52’ Species Code*52’ Breed Code*52’Strain52’Production Class Code*52’Tribal CitizenshipÿÿÿÿbPatient Identification9'PV1452’ Set ID - Pv1€52’ Patient Class 52’Assigned Patient Location³52’Admission Type 52’Preadmit Number¥52’Prior Patient Location³52’Attending DoctorÿÿÿÿB52’Referring DoctorÿÿÿÿB52’Consulting DoctorÿÿÿÿB52’Hospital Service 52’Temporary Location³52’Preadmit Test Indicator 52’Re-admission Indicator 52’ Admit Source 52’Ambulatory Statusÿÿÿÿ 52’ Vip Indicator 52’Admitting DoctorÿÿÿÿB52’ Patient Type 52’ Visit Number¥52’Financial Classÿÿÿÿ¿52’Charge Price Indicator 52’ Courtesy Code 52’ Credit Rating 52’ Contract Codeÿÿÿÿ 52’Contract Effective Dateÿÿÿÿ†52’Contract Amountÿÿÿÿ352’Contract Periodÿÿÿÿ352’ Interest Code 52’Transfer To Bad Debt Code 52’Transfer To Bad Debt Date†52’Bad Debt Agency Code 52’Bad Debt Transfer Amount352’Bad Debt Recovery Amount352’Delete Account Indicator 52’Delete Account Date†52’Discharge Disposition 52’Discharged To Location°52’ Diet Type*52’Servicing Facility 52’ Bed Status 52’Account Status 52’Pending Location³52’Prior Temporary Location³52’Admit Date/time52’Discharge Date/timeÿÿÿÿ52’Current Patient Balance352’ Total Charges352’Total Adjustments352’Total Payments352’Alternate Visit ID¥52’Visit Indicator 52’Other Healthcare ProviderÿÿÿÿB Patient Visit9'PV2152’Prior Pending Location³52’Accommodation Code*52’ Admit Reason*52’Transfer Reason*52’Patient Valuablesÿÿÿÿ52’Patient Valuables Location52’Visit User Codeÿÿÿÿ 52’Expected Admit Date/time52’Expected Discharge Date/time52’"Estimated Length Of Inpatient Stay352’Actual Length Of Inpatient Stay352’Visit Description52’Referral Source CodeÿÿÿÿB52’Previous Service Date†52’$Employment Illness Related Indicator52’Purge Status Code 52’Purge Status Date†52’Special Program Code 52’Retention Indicator52’"Expected Number Of Insurance Plans352’Visit Publicity Code 52’Visit Protection Indicator52’Clinic Organization NameÿÿÿÿÂ52’Patient Status Code 52’Visit Priority Code 52’Previous Treatment Date†52’Expected Discharge Disposition 52’Signature On File Date†52’First Similar Illness Date†52’Patient Charge Adjustment Code*52’Recurring Service Code 52’Billing Media Code52’Expected Surgery Date And Time52’Military Partnership Code52’Military Non-availability Code52’Newborn Baby Indicator52’Baby Detained Indicator52’Mode Of Arrival Code*52’Recreational Drug Use Codeÿÿÿÿ*52’Admission Level Of Care Code*52’Precaution Codeÿÿÿÿ*52’Patient Condition Code*52’Living Will Code 52’Organ Donor Code 52’Advance Directive Codeÿÿÿÿ*52’Patient Status Effective Date†52’Expected Loa Return Date/time52’(Expected Pre-admission Testing Date/time52’Notify Clergy Codeÿÿÿÿ Additional Information9'SFT52’Software Vendor OrganizationÂ52’,Software Certified Version Or Release Number52’Software Product Name52’Software Binary ID52’Software Product InformationÍ52’Software Install DateSoftware Segmentˆ MACHINEIDCODEMSHMSHÿÿÿÿdefaultÿÿÿÿÿÿÿÿADT™x#MSHA17™x#MSH.q from ifware import guid # Function to write a message to a file def flush_new_message(message, outputDirectory, extension): fileName = guid.generate_guid(128) outfilename = outputDirectory + fileName + extension f=open(outfilename, 'wb') f.write(message) f.close() # Initialize the newMessage variable prior to processing the next Inbound # message. Otherwise, Chameleon would remember the value of newMessage from # the previously processed message, if any such message exists. newMessage = None # Specify the default location for output files outputDirectory = "c:/output/" # Specify the file name extension for output files extension = ".txt" # Initialize iterator current_segment = environment.input_segment_iterator() # Current segment becomes MSH. # Apply segment scripts if they exist current_segment.apply_transform() # Modify Message Type to be ADT^A02 current_segment.field(9).value = 'ADT^A02' output = current_segment.output() while current_segment.move_one(): # Append each segment which repeats with each of future A02 messages if current_segment.segment_id()[0:3] in ('SFT', 'EVN'): # apply segment scripts if they exist current_segment.apply_transform() output = output + current_segment.output() # Reset the iterator to parse the message again # current segment becomes MSH current_segment.reset() while current_segment.move_one(): if current_segment.segment_id()[0:3] == 'PID': # Apply segment scripts if they exist current_segment.apply_transform() if newMessage == None: # On first pass, the new message doesn't exist, so # we assign newMessage a value and initialize it, but # don't flush the message to a file. newMessage = output + current_segment.output() else: # On any other pass, the newMessage variable already has a # value, so we flush the new message content to a file. flush_new_message(newMessage, outputDirectory, extension) # Re-initialize the newMessage variable. newMessage = output + current_segment.output() if current_segment.segment_id()[0:2] == 'PV': # Apply segment scripts if they exist current_segment.apply_transform() newMessage = newMessage + current_segment.output() # Flush last remaining new message to file flush_new_message(newMessage, outputDirectory, extension) # If we don't want any messages to be output by this Scripted Transformation, # the special variable "value" can be assigned the empty string. value = '' ASCIISTANDARD VER 2'41