import xml.dom.minidom import time from v3Helpers import * __all__ = [ 'hl7version3' ] def v3Header(): value = '\n' value += '\n' return value def v3LabRequestHeader(EffectiveTime): value = '\n' value += ' \n' value += ' \n' value += ' \n' value += ' \n' value += ' \n' value += ' \n' return value def v3Name(GivenName, FamilyName, i): value = v3Indent(i) + '\n' value += v3Indent(i + 1) + '' + esc(GivenName) + '\n' value += v3Indent(i + 1) + '' + esc(FamilyName) + '\n' value += v3Indent(i) + '\n' return value def v3Address(Type, Line1, Line2, Line3, PostalCode, i): value = v3Indent(i) + '\n' value += v3Indent(i+1) + '' + esc(Line1) + '\n' value += v3Indent(i+1) + '' + esc(Line2) + '\n' value += v3Indent(i+1) + '' + esc(Line3) + '\n' value += v3Indent(i+1) + '' + esc(PostalCode) + '\n' value += v3Indent(i) + '\n' return value def v3Sex(Sex): if Sex=='M': return '0'; else: return '1'; def v3Doctor(Doctor, i): value = v3Indent(i) + '\n' value += v3Indent(i+1) + '\n' value += v3Indent(i+1) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+3) + '' + esc(Doctor) + '\n' value += v3Indent(i+3) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+1) + '\n' value += v3Indent(i) + '\n' return value def v3PatientRecordTarget(InMsg, PatientIndex, i): value = v3Indent(i) + '\n' value += v3Indent(i+1) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+2) + '\n' value += v3Name(getItem(InMsg, "Patient", PatientIndex, "PatientFirstName"), getItem(InMsg, "Patient", PatientIndex, "PatientLastName"), i+3) value += v3Indent(i+3) + '\n' value += v3Indent(i+3) + '\n' value += v3Address("H", getItem(InMsg, "Patient", PatientIndex, "PatientStreetAddress"), getItem(InMsg, "Patient", PatientIndex, "PatientAddressOtherDesignation"), getItem(InMsg, "Patient", PatientIndex, "PatientAddressCity"), getItem(InMsg, "Patient", PatientIndex, "PatientAddressZip"), i+3) value += v3Indent(i+3) + '\n' value += v3Indent(i+4) + '\n' value += v3Indent(i+5) + '\n' value += v3Indent(i+6) + '\n' value += v3Doctor("Dr Responsible", i+6) # TODO - need to map in a real doctor. value += v3Indent(i+5) + '\n' value += v3Indent(i+4) + '\n' value += v3Indent(i+3) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+1) + '\n' value += v3Indent(i) + '\n' return value def v3HospitalTestProvider(HospitalName,i): value = v3Indent(i) + '\n' value += v3Indent(i+1) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+3) + '' + esc(HospitalName) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+1) + '\n' value += v3Indent(i) + '\n' return value def v3DoctorAuthor(DoctorName, i): value = v3Indent(i) + '\n' value += v3Indent(i+1) + '\n' return value def v3HospitalReceiver(Hospital, i): value = v3Indent(i) + '\n' value += v3Indent(i+1) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+3) + '' + esc(Hospital) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+1) + '\n' value += v3Indent(i) + '\n' return value def v3MedicationReason(InMsg, i): value = v3Indent(i) + '\n' value += v3Indent(i+1) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+2) + '\n' # TODO - need to figure out what the effective time should be mapped from value += v3Indent(i+3) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+3) + '\n' value += v3Indent(i+4) + '\n' # TODO - need to map in a code for the drug here value += v3Indent(i+5) + '\n' value += v3Indent(i+4) + '\n' value += v3Indent(i+3) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+3) + '\n' value += v3Indent(i+3) + '\n' # TODO - codes can go in here to describe how the drug should be taken. value += v3Indent(i+4) + '\n' value += v3Indent(i+4) + '\n' value += v3Indent(i+3) + '\n' value += v3Indent(i+2) + '\n' value += v3Indent(i+1) + '\n' value += v3Indent(i) + '\n' return value def v3LabRequestFooter(): return '\n'; def hl7version3(PlainLabDataXml): InMsg = xml.dom.minidom.parseString(PlainLabDataXml) v3 = v3Header() v3 += v3LabRequestHeader(time.strftime("%Y%m%d")) v3 += v3PatientRecordTarget(InMsg, 0, 1) # TODO - we assume exactly 1 patient v3 += v3HospitalTestProvider("The Performing Organisation",1) v3 += v3DoctorAuthor("Dr Responsible", 1) v3 += v3HospitalReceiver("The Requesting Organization", 1) v3 += v3MedicationReason(InMsg, 1) v3 += v3LabRequestFooter() return v3