patbef-ServiceOutside/ServiceOutside/Documents/PBA_LOGS.mpl

578 lines
19 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;LABO:RPCSVC:PBA_LOGS
; I.A read ack log file from service inside (Patienten Befund App)
; input: message in $11
; filename in $12
; key of EXSS in $13
$msg_in=$11
$file_in=$12
$2=0
$cnt=1
$start_msg = $msg_in
while($msg_in!="")
$i95=$msg_in
$line=nextsubstr("\r")
$msg_in=$i95
$i95=$line
$var=nextsubstr(":")
$content=$i95
$nop=message("msg_in=>%%$msg_in%%%<")
switch($var)
case "ORDER_ID": $pba_order = $content
case "ZIP": $pba_zip = $content
case "BIRTHDATE": $pba_birthday = $content
case "UDID": $pba_udid = $content
case "TYPE": $pba_type = $content ; POSIBLE TYPES: SUBSCRIBE, UNSUBSCRIBE, DELETE_DEVICE, PICKEDUP, ERROR
case "PAT_ID": $pba_patid = $content
default:
endswitch
$cnt=$cnt + 1
endwhile
$sampleid_cnt = 0
$ord_lid = ""
$ord_lperiod = ""
$ord_ordnb = ""
$ord_error = ""
; I.A Pathes
$filedir_mdm = "/share/mg-msg/_PBA/mdm2snd_in/"
$ack_error = "/share/mg-msg/_PBA/ack-in/error/"
$ack_done = "/share/mg-msg/_PBA/ack-in/done/"
; I.A Current TimeStamp
$now = fmtldate(ldate_now(),"%0Y%0M%0D%0H%0N%0S")
; I.A Grab the directory and file pathes
$fname=$file_in
$filedir=""
$filename=""
while($fname!="")
$i95=$fname
$ele=nextsubstr("/")
$fname=$i95
if($fname!="")
$filedir="%%$filedir%%%/%%$ele%%%"
else
$filename=$ele
endif
$nop=message("dir=%%$filedir%%%-filename=%%$filename%%%")
endwhile
if($filename == "")
$filename = "%%$pba_order%%%_%%$now%%%"
endif
$nop = message("FOUND: $pba_udid=%%$pba_udid%%%, $pba_type=%%$pba_type%%%")
if($pba_udid != "" && $pba_type != "")
; I.A check type of request
; ***SUBSCRIBE*** - Patient want to get the results over app
if($pba_type == "SUBSCRIBE")
if($pba_order != "" && $pba_zip != "" && $pba_birthday != "" && length($pba_order) #> 5 && length($pba_order) #<= 14)
$sql = "select concat('CNT:', count(*)) CNT from ord inner join patd on patd.patidnb = ord.ordpatidnb where ord.sampleid = '%%$pba_order%%%' and patd.zip is not null and patd.zip = '%%$pba_zip%%%' and patd.birthdt is not null and to_char(patd.birthdt, 'YYYY-MM-DD') = '%%$pba_birthday%%%'"
$sql_res = sqlprint($sql, "LOCAL_DATA/NOCOMMIT")
$nop = message("1. CNT: %%$sql_res%%%")
; I.A get number of available recors for the sampleid from the ord table
if($sql_res != "")
$i95 = $sql_res
nextsubstr('CNT:')
$sampleid_cnt = $i95
; sampleid exists only one time and it is uniq, just use it for internal order id(LID, LPERIOD, ORDNB) PK
if($sampleid_cnt #== 1)
$sql_res = ""
$sql = "select concat('ORD:', concat(ord.lid, concat(ord.lperiod, ord.ordnb))) ordid from ord inner join patd on patd.patidnb = ord.ordpatidnb where ord.sampleid = '%%$pba_order%%%' and patd.zip is not null and patd.zip = '%%$pba_zip%%%' and patd.birthdt is not null and to_char(patd.birthdt, 'YYYY-MM-DD') = '%%$pba_birthday%%%'"
$sql_res = sqlprint($sql, "LOCAL_DATA/NOCOMMIT")
$nop = message("1. ORD: %%$sql_res%%%")
; I.A extract LID, LPERIOD, ORDNB
if($sql_res != "")
$i95 = $sql_res
nextsubstr('ORD:')
$order_id = $i95
if($order_id != "")
$ord_lid = $order_id[1:2]
$ord_lperiod = $order_id[3:6]
$ord_ordnb = $order_id[7:10]
endif
endif
else
; I.A check if sampleid with zip and birthday has uniq order else reject(sampleid not uniq)
if($sampleid_cnt #> 1)
$ord_error = "SAMPLE_ID_NOT_UNIQ"
endif
; I.A sampleid with zip and birthday was not found
if($sampleid_cnt #<= 0)
$ord_error = "SAMPLE_NOT_FOUND"
endif
endif
else
$ord_error = "SAMPLE_NOT_FOUND"
endif
; I.A check if error available
if($ord_error == "")
; I.A check if order found
if($ord_lid != "" && $ord_lperiod != "" && $ord_ordnb != "")
; I.A get pat id and order states
$11 = $ord_lid
$12 = $ord_lperiod
$13 = $ord_ordnb
$14 = "ORDPATIDNB"
$15="RPT_ST" ; C - only last results
$16="ORD_ST1" ; 5 - the results has been already printed
$17 = ""
run("LABO:ORD_L")
$ordpatid=$14
$ord_prt_st=$15
$ord_st1 = $16
$nop = message("ordpatid=%%$ordpatid%%%")
; I.A Patient found
if($14 != "" && $14 != "ORDPATIDNB")
; I.A Set UDID to the patient(KWL) and check if order is ready to send to the backendservice
; Set flag to the order that the patient has been subscribted for the results and it should be sent over app
;PHA 25.07.2022: Read KWL from PATD and ADD UDID
;Read KWL from PATD
$11=$ordpatid
$12="KWL"
$13=""
run("LABO:PATD_L")
$pat_kwl=$12
if($pat_kwl = "EMAIL=" || $pat_kwl = "")
$pat_kwl = "PBA_UDID=\"%%$pba_udid%%%\""
else
$i95 = $pat_kwl
$pat_kwl_i = replsubstr("PBA_UDID", "PBA_UDID")
if($pat_kwl_i #> 0)
$pat_kwl.PBA_UDID = $pba_udid
else
$pat_kwl = "%%$pat_kwl%%%\nPBA_UDID=\"%%$pba_udid%%%\""
endif
endif
;UPDATE PATD field KWL with UDID
$90="LABO"
$91="PATD"
$10="INTUDBU"
$11=$ordpatid
$12="KWL=%%$pat_kwl%%%"
$13=""
run("LABO:PATD_EI")
;COMMIT must be done here (not done in PATD_EI)
$11="COMMIT"
run("LABO:MPLUTIL")
; I.A Set PBA_TYPE to SUBSCRIBE in ORDER.KWL
$11=$ord_lid
$12=$ord_lperiod
$13=$ord_ordnb
$14=";MPL
$kwl=kwl_fill.ORD
$kwl.PBA_TYPE=$pba_type
kwl_fill.ORD=$kwl"
$nop=message("14=%%$14%%%")
run("LABO:ORD_UDY")
; Create a historical record in the journal of order
$rem = "PBA, Patientenbefund wurde für die Befundapp abonniert, type=%%$pba_type%%%"
$nop=message("rem=%%$rem%%%")
$11=$ord_lid
$12=$ord_lperiod
$13=$ord_ordnb
$14="OO"
$15="" ;runnb_dt
$16="" ;runnb_hh
$17=$rem
$18=""
$19=""
run("LABO:ORDTRAIL_UDY")
; I.A move file to done
spawn("mv %%$file_in%%% %%$ack_done%%%/%%$filename%%%")
; I.A check if currently subscripted results is already completed and execute print mode o/1
; I.A Results is ready and can be printed
if($ord_prt_st == "C" && $ord_st1 #== 5)
$cyes=creg("CYES")
$cno=creg("CNO")
$1="BATCH"
$11=$ord_lid
$12=$ord_lperiod
$13=$ord_ordnb
$rmode="o"
$rmodeel="1"
$rpt_cpa="A" ; completion flag
$14="PROV_FL=%%$cyes%%%RMODE=%%$rmode%%%RMODEEL=%%$rmodeel%%%\
RPT_CPA=%%$rpt_cpa%%%REPRINT_FL=%%$cyes%%%ONLY_RPT_TYP=ONLY_RPT_FMT=\
ONLY_RPT_CLASS=ONLY_COPY_TYP=DUBBLE_TXT_FL=DIRECTPRINT_FL=%%$cyes%%%\
DIRP_PRINTER=DIRP_RPT_FMT=DIRP_RPT_TYP="
run("LABO:RPT1_SELS")
endif
else
; ---ERROR--- $14(ORDPATIDNB) == ""
$ord_error = "Patient for sampleid(%%$pba_order%%%) was not found"
$nop = message("Patient for sampleid(%%$pba_order%%%) was not found")
spawn("mv %%$file_in%%% %%$ack_error%%%/%%$filename%%%")
$aa = filewrite("%%$ack_error%%$filename%%%_msg.log", $ord_error)
endif
else
; ---ERROR--- $ord_lid == "" || $ord_lperiod == "" || $ord_ordnb == ""
$ord_error = "SUBSCIBE - Order for sampleid(%%$pba_order%%%), zip(%%$pba_zip%%%), birthday(%%$pba_birthday%%%) was not found"
$nop = message("Error %%$ord_error%%%")
spawn("mv %%$file_in%%% %%$ack_error%%%/%%$filename%%%")
$aa = filewrite("%%$ack_error%%$filename%%%_msg.log", $ord_error)
endif
else
; I.A check if sampleid is not uniq and send reject hl7 to the backendservice
if($ord_error == "SAMPLE_ID_NOT_UNIQ")
;***** REJECT SUBSCRIBE HL7 *****
$hl7_msh = "MSH|1|MOLIS||||%%$now%%%||MDM^T01||P|2.3|||AL|NE|DE\r"
$hl7_evn = "EVN|T01|%%$now%%%|REJECTED\r"
$hl7_pid = "PID|1||%%$pba_birthday%%%|%%$pba_zip%%%|%%$pba_udid%%%\r"
$hl7_txa = "TXA|1|%%$pba_order%%%|\r"
$hl7_obx = "OBX|||||"
$hl7 = "%%$hl7_msh%%$hl7_evn%%$hl7_pid%%$hl7_txa%%$hl7_obx%%%"
$hl7_filename = "MG%%$pba_order%%%_%%$now%%%.hl7"
$aa = filewrite("%%$filedir_mdm%%$hl7_filename%%%", $hl7)
; I.A move ack log to done directory
spawn("mv %%$file_in%%% %%$ack_done%%%/%%$filename%%%")
else
if($ord_error == "SAMPLE_NOT_FOUND")
;***** NOT_FOUND SUBSCRIBE HL7 *****
$hl7_msh = "MSH|1|MOLIS||||%%$now%%%||MDM^T01||P|2.3|||AL|NE|DE\r"
$hl7_evn = "EVN|T01|%%$now%%%|NOT_FOUND\r"
$hl7_pid = "PID|1||%%$pba_birthday%%%|%%$pba_zip%%%|%%$pba_udid%%%\r"
$hl7_txa = "TXA|1|%%$pba_order%%%|\r"
$hl7_obx = "OBX|||||"
$hl7 = "%%$hl7_msh%%$hl7_evn%%$hl7_pid%%$hl7_txa%%$hl7_obx%%%"
$hl7_filename = "MG%%$pba_order%%%_%%$now%%%.hl7"
$aa = filewrite("%%$filedir_mdm%%$hl7_filename%%%", $hl7)
; I.A move ack log to done directory
spawn("mv %%$file_in%%% %%$ack_done%%%/%%$filename%%%")
else
; ---ERROR--- $ord_error != ""
; I.A some of other error was occurred. The current ack file will be moved into ack error
$nop = message("Error: %%$ord_error%%%")
spawn("mv %%$file_in%%% %%$ack_error%%%/%%$filename%%%")
$aa = filewrite("%%$ack_error%%$filename%%%_msg.log", $ord_error)
endif
endif
endif
else
; ---ERROR--- $pba_order, $pba_birthday, $pba_zip
$ord_error = "Missing parameter pba_order or pba_birthday or pba_zip (pba_order = %%$pba_order%%%, pba_birthday = %%$pba_birthday%%%, pba_zip = %%$pba_zip%%%, pba_udid = %%$pba_udid%%%, pba_type = %%$pba_type%%%)"
$nop = message("Error: %%$ord_error%%%")
spawn("mv %%$file_in%%% %%$ack_error%%%/%%$filename%%%")
$aa = filewrite("%%$ack_error%%$filename%%%_msg.log", $ord_error)
endif
endif
; ***UNSUBSCRIBE*** - Patient deleted request on the mobile device ($pba_order should not be notified anymore, but keep storing udid for patient)
if($pba_type == "UNSUBSCRIBE")
if($pba_order != "" && $pba_zip != "" && $pba_birthday != "" && length($pba_order) #> 5 && length($pba_order) #<= 14)
$sql = "select concat('ORD:', concat(ord.lid, concat(ord.lperiod, ord.ordnb))) ordid from ord inner join patd on patd.patidnb = ord.ordpatidnb where ord.sampleid = '%%$pba_order%%%' and patd.zip is not null and patd.zip = '%%$pba_zip%%%' and patd.birthdt is not null and to_char(patd.birthdt, 'YYYY-MM-DD') = '%%$pba_birthday%%%'"
$sql_res = sqlprint($sql, "LOCAL_DATA/NOCOMMIT")
$nop = message("1. ORD: %%$sql_res%%%")
; I.A extract LID, LPERIOD, ORDNB
if($sql_res != "")
$i95 = $sql_res
nextsubstr('ORD:')
$order_id = $i95
if($order_id != "")
$ord_lid = $order_id[1:2]
$ord_lperiod = $order_id[3:6]
$ord_ordnb = $order_id[7:10]
endif
endif
; I.A check if order found
if($ord_lid != "" && $ord_lperiod != "" && $ord_ordnb != "")
; I.A Set PBA_TYPE to UNSUBSCRIBE in ORDER.KWL
;$11=$ord_lid
;$12=$ord_lperiod
;$13=$ord_ordnb
;$14=";MPL
;$kwl=kwl_fill.ORD
;$kwl.PBA_TYPE=$pba_type
;kwl_fill.ORD=$kwl"
;$nop=message("14=%%$14%%%")
;run("LABO:ORD_UDY")
; Create a historical record in the journal of order
$rem = "PBA, Patientenbefund wurde für die Befundapp abbestellt, type=%%$pba_type%%%"
$nop=message("rem=%%$rem%%%")
$11=$ord_lid
$12=$ord_lperiod
$13=$ord_ordnb
$14="OO"
$15="" ;runnb_dt
$16="" ;runnb_hh
$17=$rem
$18=""
$19=""
run("LABO:ORDTRAIL_UDY")
; I.A move file to done
spawn("mv %%$file_in%%% %%$ack_done%%%/%%$filename%%%")
else
; ---ERROR--- $ord_lid == "" || $ord_lperiod == "" || $ord_ordnb == ""
$ord_error = "UNSUBSCRIBE - Order for sampleid(%%$pba_order%%%), zip(%%$pba_zip%%%), birthday(%%$pba_birthday%%%) was not found"
$nop = message("Error %%$ord_error%%%")
spawn("mv %%$file_in%%% %%$ack_error%%%/%%$filename%%%")
$aa = filewrite("%%$ack_error%%$filename%%%_msg.log", $ord_error)
endif
else
; ---ERROR--- $pba_order == ""
$ord_error = "Missing parameter pba_order, (pba_udid = %%$pba_udid%%%, pba_type = %%$pba_type%%%)"
$nop = message("Error: pba_order was not found. pba_udid = %%$pba_udid%%%, pba_type = %%$pba_type%%%")
spawn("mv %%$file_in%%% %%$ack_error%%%/%%$filename%%%")
$aa = filewrite("%%$ack_error%%$filename%%%_msg.log", $ord_error)
endif
endif
; ***DELETE_DEVICE*** - Patient deleted his account on the mobile device(udid must be removed from patient, that it does not want to get results via app anymore)
if($pba_type == "DELETE_DEVICE")
$nop = message("DELETE_DEVICE ordpatid=%%$pba_patid%%%")
; I.A Get Patient over udid and remove it from patient
if($pba_patid != "")
;PHA 25.07.2022: Read KWL from PATD and ADD UDID
;Read KWL from PATD
$11=$pba_patid
$12="KWL"
$13=""
run("LABO:PATD_L")
$pat_kwl=$12
$pat_kwl.PBA_UDID=""
;UPDATE PATD field KWL with UDID
$90="LABO"
$91="PATD"
$10="INTUDBU"
$11=$pba_patid
$12="KWL=%%$pat_kwl%%%"
$13=""
run("LABO:PATD_EI")
;COMMIT must be done here (not done in PATD_EI)
$11="COMMIT"
run("LABO:MPLUTIL")
; I.A move file to done
spawn("mv %%$file_in%%% %%$ack_done%%%/%%$filename%%%")
else
; ---ERROR--- $pba_order == ""
$ord_error = "Missing parameter pba_patid, (pba_patid = %%$pba_patid%%%, pba_type = %%$pba_type%%%)"
$nop = message("Error: %%$ord_error%%%")
spawn("mv %%$file_in%%% %%$ack_error%%%/%%$filename%%%")
$aa = filewrite("%%$ack_error%%$filename%%%_msg.log", $ord_error)
endif
endif
; ***PICKEDUP*** - Patient picked up the results insert log into journal
if($pba_type == "PICKEDUP")
if($pba_order != "" && $pba_zip != "" && $pba_birthday != "" && length($pba_order) #> 5 && length($pba_order) #<= 14)
$sql = "select concat('ORD:', concat(ord.lid, concat(ord.lperiod, ord.ordnb))) ordid from ord inner join patd on patd.patidnb = ord.ordpatidnb where ord.sampleid = '%%$pba_order%%%' and patd.zip is not null and patd.zip = '%%$pba_zip%%%' and patd.birthdt is not null and to_char(patd.birthdt, 'YYYY-MM-DD') = '%%$pba_birthday%%%'"
$sql_res = sqlprint($sql, "LOCAL_DATA/NOCOMMIT")
$nop = message("1. ORD: %%$sql_res%%%")
; I.A extract LID, LPERIOD, ORDNB
if($sql_res != "")
$i95 = $sql_res
nextsubstr('ORD:')
$order_id = $i95
if($order_id != "")
$ord_lid = $order_id[1:2]
$ord_lperiod = $order_id[3:6]
$ord_ordnb = $order_id[7:10]
endif
endif
; I.A check if order found
if($ord_lid != "" && $ord_lperiod != "" && $ord_ordnb != "")
; I.A Set PBA_TYPE to PICKEDUP in ORDER.KWL
$11=$ord_lid
$12=$ord_lperiod
$13=$ord_ordnb
$14=";MPL
$kwl=kwl_fill.ORD
$kwl.PBA_TYPE=$pba_type
kwl_fill.ORD=$kwl"
$nop=message("14=%%$14%%%")
run("LABO:ORD_UDY")
; Create a historical record in the journal of order
$rem = "PBA, Patientenbefund wurde über die Befundapp abgeholt, type=%%$pba_type%%%"
$nop=message("rem=%%$rem%%%")
$11=$ord_lid
$12=$ord_lperiod
$13=$ord_ordnb
$14="OO"
$15="" ;runnb_dt
$16="" ;runnb_hh
$17=$rem
$18=""
$19=""
run("LABO:ORDTRAIL_UDY")
; I.A move file to done
spawn("mv %%$file_in%%% %%$ack_done%%%/%%$filename%%%")
else
; ---ERROR--- $ord_lid == "" || $ord_lperiod == "" || $ord_ordnb == ""
$ord_error = "PICKEDUP - Order for sampleid(%%$pba_order%%%), zip(%%$pba_zip%%%), birthday(%%$pba_birthday%%%) was not found"
$nop = message("Error %%$ord_error%%%")
spawn("mv %%$file_in%%% %%$ack_error%%%/%%$filename%%%")
$aa = filewrite("%%$ack_error%%$filename%%%_msg.log", $ord_error)
endif
else
; ---ERROR--- $pba_order == ""
$ord_error = "Missing parameter pba_order, (pba_udid = %%$pba_udid%%%, pba_type = %%$pba_type%%%)"
$nop = message("Error: pba_order was not found. pba_udid = %%$pba_udid%%%, pba_type = %%$pba_type%%%")
spawn("mv %%$file_in%%% %%$ack_error%%%/%%$filename%%%")
$aa = filewrite("%%$ack_error%%$filename%%%_msg.log", $ord_error)
endif
endif
; ***ERROR*** - Results could not be sent to the app, insert log into journal
if($pba_type == "ERROR")
if($pba_order != "" && $pba_zip != "" && $pba_birthday != "" && length($pba_order) #> 5 && length($pba_order) #<= 14)
$sql = "select concat('ORD:', concat(ord.lid, concat(ord.lperiod, ord.ordnb))) ordid from ord inner join patd on patd.patidnb = ord.ordpatidnb where ord.sampleid = '%%$pba_order%%%' and patd.zip is not null and patd.zip = '%%$pba_zip%%%' and patd.birthdt is not null and to_char(patd.birthdt, 'YYYY-MM-DD') = '%%$pba_birthday%%%'"
$sql_res = sqlprint($sql, "LOCAL_DATA/NOCOMMIT")
$nop = message("1. ORD: %%$sql_res%%%")
; I.A extract LID, LPERIOD, ORDNB
if($sql_res != "")
$i95 = $sql_res
nextsubstr('ORD:')
$order_id = $i95
if($order_id != "")
$ord_lid = $order_id[1:2]
$ord_lperiod = $order_id[3:6]
$ord_ordnb = $order_id[7:10]
endif
endif
; I.A check if order found
if($ord_lid != "" && $ord_lperiod != "" && $ord_ordnb != "")
; I.A Set PBA_TYPE to ERROR in ORDER.KWL
$11=$ord_lid
$12=$ord_lperiod
$13=$ord_ordnb
$14=";MPL
$kwl=kwl_fill.ORD
$kwl.PBA_TYPE=$pba_type
kwl_fill.ORD=$kwl"
$nop=message("14=%%$14%%%")
run("LABO:ORD_UDY")
; Create a historical record in the journal of order
$rem = "PBA, Patientenbefund konnte über die Befundapp nicht verschickt werden, type=%%$pba_type%%%"
$nop=message("rem=%%$rem%%%")
$11=$ord_lid
$12=$ord_lperiod
$13=$ord_ordnb
$14="OO"
$15="" ;runnb_dt
$16="" ;runnb_hh
$17=$rem
$18=""
$19=""
run("LABO:ORDTRAIL_UDY")
; I.A move file to done
spawn("mv %%$file_in%%% %%$ack_done%%%/%%$filename%%%")
else
; ---ERROR--- $ord_lid == "" || $ord_lperiod == "" || $ord_ordnb == ""
$ord_error = "ERROR - Order for sampleid(%%$pba_order%%%), zip(%%$pba_zip%%%), birthday(%%$pba_birthday%%%) was not found"
$nop = message("Error %%$ord_error%%%")
spawn("mv %%$file_in%%% %%$ack_error%%%/%%$filename%%%")
$aa = filewrite("%%$ack_error%%$filename%%%_msg.log", $ord_error)
endif
else
; ---ERROR--- $pba_order == ""
$ord_error = "Missing parameter pba_order, (pba_udid = %%$pba_udid%%%, pba_type = %%$pba_type%%%)"
$nop = message("Error: pba_order was not found. pba_udid = %%$pba_udid%%%, pba_type = %%$pba_type%%%")
spawn("mv %%$file_in%%% %%$ack_error%%%/%%$filename%%%")
$aa = filewrite("%%$ack_error%%$filename%%%_msg.log", $ord_error)
endif
endif
else
; ---ERROR--- $pba_udid == "" or $pba_type == ""
$ord_error = "Missing parameters (pba_udid or pba_type)"
$nop = message("Error: pba_udid or pba_type was not found. pba_udid = %%$pba_udid%%%, pba_type = %%$pba_type%%%")
spawn("mv %%$file_in%%% %%$ack_error%%%/%%$filename%%%")
$aa = filewrite("%%$ack_error%%$filename%%%_msg.log", $ord_error)
endif