- MAGDHOWP ;WOIFO/PMK - Generate VistA Imaging HL7 message for Clinical Procedures Check-in ;04 Sep 2018 10:41 AM
- ;;3.0;IMAGING;**208**;Mar 19, 2002;Build 6;Sep 03, 2013
- ;; Per VHA Directive 2004-038, this routine should not be modified.
- ;; +---------------------------------------------------------------+
- ;; | Property of the US Government. |
- ;; | No permission to copy or redistribute this software is given. |
- ;; | Use of unreleased versions of this software requires the user |
- ;; | to execute a written test agreement with the VistA Imaging |
- ;; | Development Office of the Department of Veterans Affairs, |
- ;; | telephone (301) 734-0100. |
- ;; | The Food and Drug Administration classifies this software as |
- ;; | a medical device. As such, it may not be changed in any way. |
- ;; | Modifications to this software may result in an adulterated |
- ;; | medical device under 21CFR820, the use of which is considered |
- ;; | to be a violation of US Federal Statutes. |
- ;; +---------------------------------------------------------------+
- ;;
- ;;
- ;
- ; Supported IA #10000 reference NOW^%DTC subroutine call
- ; Supported IA #2056 reference $$GET1^DIQ function call
- ; Supported IA #2056 reference GETS^DIQ subroutine call
- ; Controlled IA #4110 to read REQUEST/CONSULTATION file (#123)
- ; Private IA #6928 to read CP INSTRUMENT file (#702.09)
- ; Private IA #6929 to read CP TRANSACTION file (#702)
- ; Private IA #6929 to $Order thru "ACON" xfef in ^MDD(702)
- ; Private IA #6930 to read CP DEFINITION file (#702.01)
- ;
- ; CLINPROC is called by MDHL7BH to generate VistA Imaging HL7
- ; for a check-in or cancellation of a Clinical Procedure.
- ;
- CLINPROC(FILE702P,ORDERFLAG) ; entry point from MDHL7BH
- ; FILE702P ---- pointer to the clinical procedure in ^MDD(702,FILE702P,...)
- ; ORDERFLAG --- 0=cancel, 1=new order
- N APTSCHED,CPINVOCATION,DFN,FILE70201P,FILLER2,GMRCIEN,ORC1,ORC5,SDATE,SERVICE
- S DFN=$$GET1^DIQ(702,FILE702P,.01,"I")
- S GMRCIEN=$$GET1^DIQ(702,FILE702P,.05,"I")
- S SERVICE=$$GET1^DIQ(123,GMRCIEN,1,"I")
- S SDATE=$$GET1^DIQ(702,FILE702P,.07,"I")
- I SDATE[";" S SDATE=$P(SDATE,";",2)
- I SDATE="" D NOW^%DTC S SDATE=%
- I SDATE<DT D NOW^%DTC S SDATE=%
- S APTSCHED("FM DATETIME")=SDATE
- S FILE70201P=$$GET1^DIQ(702,FILE702P,.04,"I")
- S APTSCHED("CLINIC IEN")=$$GET1^DIQ(702.01,FILE70201P,.05,"I")
- S APTSCHED("CLINIC NAME")=$$GET1^DIQ(702.01,FILE70201P,.05,"E")
- S FILLER2="GMRC-SCHEDULED" ; over-ride GMRC's status
- I ORDERFLAG D ; new CP order check-in
- . S (ORC1,ORC5)="OK"
- . Q
- E D ; cancel CP order
- . S (ORC1,ORC5)="CA"
- . Q
- ;
- D TELEREAD(ORC1) ; put CP study on TeleReader Read/Unread list
- ;
- S CPINVOCATION=1 ; Clinical Procedures HL7 flag
- D MSGSETUP^MAGDHOW1(GMRCIEN,SERVICE,ORC1,ORC5,.APTSCHED)
- Q
- ;
- TELEREAD(ORC1) ; add the CP order to the TeleReader Read/Unread list
- N DEL,DEL2,HL7ORC
- S DEL="|",DEL2="^"
- S $P(HL7ORC,DEL)=ORC1
- D ^MAGDTR01
- Q
- ;
- OUTPUT(N) ; called by OUTPUT^MAGDHOW2 if CPINVOCATION=1
- N FILE70209P,CPDICOM
- S FILE70209P=$$GET1^DIQ(702,FILE702P,.11,"I") ; get instrument
- S CPDICOM=$$GET1^DIQ(702.09,FILE70209P,.19,"I") ; get CP - DICOM Interoperability
- I CPDICOM=2 D ; replace CP's HL7 message with VistA's
- . ; Replace the CP HL7 message body in HLA with the VI HL7 message body
- . K HLA
- . F I=2:1:N S HLA("HLS",I-1)=HL7(I)
- . Q
- Q
- ;
- ;
- ; CPORDER is called by MAGDHOW4, MAGDHOWC and MAGDHOWS to determine
- ; if this a Clinical Procedures order.
- ;
- ; In addition, MAGDHOW4 is concerned if this is a Clinical Procedures
- ; order and get the HL7 Universal Service ID.
- ;
- ; MAGDHOWC and MAGDHOWS need to know if this is a new/active CP order
- ; for one or more bidirectional instruments. If so, MAGDHOWC(which
- ; handles GMRC CPRS Consult Request Tracking) and MAGDHOWS(which handles
- ; SDAM Appointment Management) will not prematurely generate an HL7
- ; message at order release time or when the appointment is scheduled.
- ;
- ; Instead, the HL7 message will be generated by the CLINPROC subroutine
- ; (above) when it is invoked by MDHL7BH for CP check-in.
- ;
- CPORDER(GMRCIEN,HL7USID) ; entry point from OBR^MAGDHOW4, ENTRY^MAGDHOWC, MAGDHOWS
- ; Return Code
- ; -1,ERROR -------- error return
- ; 0,NOT A CP ----- not a clinical procedure
- ; 1,UNIDIRECT ---- clinical procedure with no bidirectional instruments
- ; 2,UNFINISHED --- unfinished clinical procedure with bidirectional instruments
- ; 3,FINISHED ----- finished clinical procedure with bidirectional instruments
- ;
- ; MAGHOWC and MAGDHOWS ignore consult & appointment transactions for
- ; unfinished CP's ("2,UNFINISHED") and process them for cancelled, completed,
- ; and discontinued CP's, CP's with no bidirectional instruments, and non-CP
- ; CPRS Consult Request Tracking consults & procedures.
- ;
- ; MAGDHOW4 needs to get CP's HL7 Universal Service Identifier (HL7USID) and
- ; store it in OBR-4 for clinical procedures.
- ;
- N BIDIRECT,E,I,FILE702P,FILE70201P,FILE70209P,MCODE,STATUS,TAG
- ;
- S HL7USID="" ; initialize CP's HL7 Universal Service Identifier
- ;
- ; is this a consult/procedure in Clinical Procedures?
- S FILE70201P=$$GET1^DIQ(123,GMRCIEN,1.01,"I") ; get Clinical Procedures definition
- ;
- I 'FILE70201P Q "0,NOT A CP" ; not a CP
- ;
- ; look for a bidirectional instrument associated with this CP definition
- S BIDIRECT=0 ; initialize bidirectional switch
- S I=0 F S I=$O(^MDS(702.01,FILE70201P,.1,I)) Q:'I D Q:BIDIRECT
- . S FILE70209P=$$GET1^DIQ(702.011,I_","_FILE70201P,.01,"I") Q:'FILE70209P
- . S HL7USID=$$GET1^DIQ(702.09,FILE70209P,.17,"E")
- . S BIDIRECT=$$GET1^DIQ(702.09,FILE70209P,.13,"I")
- . Q
- ;
- I 'BIDIRECT Q "1,UNIDIRECT" ; no bidirectional instrument
- ;
- ; get CP's HL7 Universal Service Identifier from the transaction
- ; the transaction is created at check-in; there is none for order release
- S FILE702P=$O(^MDD(702,"ACON",GMRCIEN,""),-1) ; get last transaction
- I FILE702P D ; CP transaction exists
- . S FILE70209P=$$GET1^DIQ(702,FILE702P,.11,"I") Q:'FILE70209P
- . S HL7USID=$$GET1^DIQ(702.09,FILE70209P,.17,"E")
- . Q
- ;
- S STATUS=$$GET1^DIQ(123,GMRCIEN,8,"I")
- S TAG="IEN"_$TR($J(STATUS,2)," ",0)
- S MCODE=$T(@TAG)
- Q $S($P(MCODE,";",3)="U":"2,UNFINISHED",1:"3,FINISHED")
- ;
- ; Table of Order Status (from file #100.01)
- ; IEN ;;F=finished, U=unfinished;name
- IEN01 ;;F;DISCONTINUED
- IEN02 ;;F;COMPLETE
- IEN03 ;;U;HOLD
- IEN04 ;;U;FLAGGED
- IEN05 ;;U;PENDING
- IEN06 ;;U;ACTIVE
- IEN07 ;;F;EXPIRED
- IEN08 ;;U;SCHEDULED
- IEN09 ;;U;PARTIAL RESULTS
- IEN10 ;;U;DELAYED
- IEN11 ;;U;UNRELEASED
- IEN12 ;;F;DISCONTINUED/EDIT
- IEN13 ;;F;CANCELLED
- IEN14 ;;U;LAPSED
- IEN15 ;;U;RENEWED
- IEN99 ;;F;NO STATUS
- --- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGDHOWP 6810 printed Feb 18, 2025@23:26:41 Page 2
- MAGDHOWP ;WOIFO/PMK - Generate VistA Imaging HL7 message for Clinical Procedures Check-in ;04 Sep 2018 10:41 AM
- +1 ;;3.0;IMAGING;**208**;Mar 19, 2002;Build 6;Sep 03, 2013
- +2 ;; Per VHA Directive 2004-038, this routine should not be modified.
- +3 ;; +---------------------------------------------------------------+
- +4 ;; | Property of the US Government. |
- +5 ;; | No permission to copy or redistribute this software is given. |
- +6 ;; | Use of unreleased versions of this software requires the user |
- +7 ;; | to execute a written test agreement with the VistA Imaging |
- +8 ;; | Development Office of the Department of Veterans Affairs, |
- +9 ;; | telephone (301) 734-0100. |
- +10 ;; | The Food and Drug Administration classifies this software as |
- +11 ;; | a medical device. As such, it may not be changed in any way. |
- +12 ;; | Modifications to this software may result in an adulterated |
- +13 ;; | medical device under 21CFR820, the use of which is considered |
- +14 ;; | to be a violation of US Federal Statutes. |
- +15 ;; +---------------------------------------------------------------+
- +16 ;;
- +17 ;;
- +18 ;
- +19 ; Supported IA #10000 reference NOW^%DTC subroutine call
- +20 ; Supported IA #2056 reference $$GET1^DIQ function call
- +21 ; Supported IA #2056 reference GETS^DIQ subroutine call
- +22 ; Controlled IA #4110 to read REQUEST/CONSULTATION file (#123)
- +23 ; Private IA #6928 to read CP INSTRUMENT file (#702.09)
- +24 ; Private IA #6929 to read CP TRANSACTION file (#702)
- +25 ; Private IA #6929 to $Order thru "ACON" xfef in ^MDD(702)
- +26 ; Private IA #6930 to read CP DEFINITION file (#702.01)
- +27 ;
- +28 ; CLINPROC is called by MDHL7BH to generate VistA Imaging HL7
- +29 ; for a check-in or cancellation of a Clinical Procedure.
- +30 ;
- CLINPROC(FILE702P,ORDERFLAG) ; entry point from MDHL7BH
- +1 ; FILE702P ---- pointer to the clinical procedure in ^MDD(702,FILE702P,...)
- +2 ; ORDERFLAG --- 0=cancel, 1=new order
- +3 NEW APTSCHED,CPINVOCATION,DFN,FILE70201P,FILLER2,GMRCIEN,ORC1,ORC5,SDATE,SERVICE
- +4 SET DFN=$$GET1^DIQ(702,FILE702P,.01,"I")
- +5 SET GMRCIEN=$$GET1^DIQ(702,FILE702P,.05,"I")
- +6 SET SERVICE=$$GET1^DIQ(123,GMRCIEN,1,"I")
- +7 SET SDATE=$$GET1^DIQ(702,FILE702P,.07,"I")
- +8 IF SDATE[";"
- SET SDATE=$PIECE(SDATE,";",2)
- +9 IF SDATE=""
- DO NOW^%DTC
- SET SDATE=%
- +10 IF SDATE<DT
- DO NOW^%DTC
- SET SDATE=%
- +11 SET APTSCHED("FM DATETIME")=SDATE
- +12 SET FILE70201P=$$GET1^DIQ(702,FILE702P,.04,"I")
- +13 SET APTSCHED("CLINIC IEN")=$$GET1^DIQ(702.01,FILE70201P,.05,"I")
- +14 SET APTSCHED("CLINIC NAME")=$$GET1^DIQ(702.01,FILE70201P,.05,"E")
- +15 ; over-ride GMRC's status
- SET FILLER2="GMRC-SCHEDULED"
- +16 ; new CP order check-in
- IF ORDERFLAG
- Begin DoDot:1
- +17 SET (ORC1,ORC5)="OK"
- +18 QUIT
- End DoDot:1
- +19 ; cancel CP order
- IF '$TEST
- Begin DoDot:1
- +20 SET (ORC1,ORC5)="CA"
- +21 QUIT
- End DoDot:1
- +22 ;
- +23 ; put CP study on TeleReader Read/Unread list
- DO TELEREAD(ORC1)
- +24 ;
- +25 ; Clinical Procedures HL7 flag
- SET CPINVOCATION=1
- +26 DO MSGSETUP^MAGDHOW1(GMRCIEN,SERVICE,ORC1,ORC5,.APTSCHED)
- +27 QUIT
- +28 ;
- TELEREAD(ORC1) ; add the CP order to the TeleReader Read/Unread list
- +1 NEW DEL,DEL2,HL7ORC
- +2 SET DEL="|"
- SET DEL2="^"
- +3 SET $PIECE(HL7ORC,DEL)=ORC1
- +4 DO ^MAGDTR01
- +5 QUIT
- +6 ;
- OUTPUT(N) ; called by OUTPUT^MAGDHOW2 if CPINVOCATION=1
- +1 NEW FILE70209P,CPDICOM
- +2 ; get instrument
- SET FILE70209P=$$GET1^DIQ(702,FILE702P,.11,"I")
- +3 ; get CP - DICOM Interoperability
- SET CPDICOM=$$GET1^DIQ(702.09,FILE70209P,.19,"I")
- +4 ; replace CP's HL7 message with VistA's
- IF CPDICOM=2
- Begin DoDot:1
- +5 ; Replace the CP HL7 message body in HLA with the VI HL7 message body
- +6 KILL HLA
- +7 FOR I=2:1:N
- SET HLA("HLS",I-1)=HL7(I)
- +8 QUIT
- End DoDot:1
- +9 QUIT
- +10 ;
- +11 ;
- +12 ; CPORDER is called by MAGDHOW4, MAGDHOWC and MAGDHOWS to determine
- +13 ; if this a Clinical Procedures order.
- +14 ;
- +15 ; In addition, MAGDHOW4 is concerned if this is a Clinical Procedures
- +16 ; order and get the HL7 Universal Service ID.
- +17 ;
- +18 ; MAGDHOWC and MAGDHOWS need to know if this is a new/active CP order
- +19 ; for one or more bidirectional instruments. If so, MAGDHOWC(which
- +20 ; handles GMRC CPRS Consult Request Tracking) and MAGDHOWS(which handles
- +21 ; SDAM Appointment Management) will not prematurely generate an HL7
- +22 ; message at order release time or when the appointment is scheduled.
- +23 ;
- +24 ; Instead, the HL7 message will be generated by the CLINPROC subroutine
- +25 ; (above) when it is invoked by MDHL7BH for CP check-in.
- +26 ;
- CPORDER(GMRCIEN,HL7USID) ; entry point from OBR^MAGDHOW4, ENTRY^MAGDHOWC, MAGDHOWS
- +1 ; Return Code
- +2 ; -1,ERROR -------- error return
- +3 ; 0,NOT A CP ----- not a clinical procedure
- +4 ; 1,UNIDIRECT ---- clinical procedure with no bidirectional instruments
- +5 ; 2,UNFINISHED --- unfinished clinical procedure with bidirectional instruments
- +6 ; 3,FINISHED ----- finished clinical procedure with bidirectional instruments
- +7 ;
- +8 ; MAGHOWC and MAGDHOWS ignore consult & appointment transactions for
- +9 ; unfinished CP's ("2,UNFINISHED") and process them for cancelled, completed,
- +10 ; and discontinued CP's, CP's with no bidirectional instruments, and non-CP
- +11 ; CPRS Consult Request Tracking consults & procedures.
- +12 ;
- +13 ; MAGDHOW4 needs to get CP's HL7 Universal Service Identifier (HL7USID) and
- +14 ; store it in OBR-4 for clinical procedures.
- +15 ;
- +16 NEW BIDIRECT,E,I,FILE702P,FILE70201P,FILE70209P,MCODE,STATUS,TAG
- +17 ;
- +18 ; initialize CP's HL7 Universal Service Identifier
- SET HL7USID=""
- +19 ;
- +20 ; is this a consult/procedure in Clinical Procedures?
- +21 ; get Clinical Procedures definition
- SET FILE70201P=$$GET1^DIQ(123,GMRCIEN,1.01,"I")
- +22 ;
- +23 ; not a CP
- IF 'FILE70201P
- QUIT "0,NOT A CP"
- +24 ;
- +25 ; look for a bidirectional instrument associated with this CP definition
- +26 ; initialize bidirectional switch
- SET BIDIRECT=0
- +27 SET I=0
- FOR
- SET I=$ORDER(^MDS(702.01,FILE70201P,.1,I))
- if 'I
- QUIT
- Begin DoDot:1
- +28 SET FILE70209P=$$GET1^DIQ(702.011,I_","_FILE70201P,.01,"I")
- if 'FILE70209P
- QUIT
- +29 SET HL7USID=$$GET1^DIQ(702.09,FILE70209P,.17,"E")
- +30 SET BIDIRECT=$$GET1^DIQ(702.09,FILE70209P,.13,"I")
- +31 QUIT
- End DoDot:1
- if BIDIRECT
- QUIT
- +32 ;
- +33 ; no bidirectional instrument
- IF 'BIDIRECT
- QUIT "1,UNIDIRECT"
- +34 ;
- +35 ; get CP's HL7 Universal Service Identifier from the transaction
- +36 ; the transaction is created at check-in; there is none for order release
- +37 ; get last transaction
- SET FILE702P=$ORDER(^MDD(702,"ACON",GMRCIEN,""),-1)
- +38 ; CP transaction exists
- IF FILE702P
- Begin DoDot:1
- +39 SET FILE70209P=$$GET1^DIQ(702,FILE702P,.11,"I")
- if 'FILE70209P
- QUIT
- +40 SET HL7USID=$$GET1^DIQ(702.09,FILE70209P,.17,"E")
- +41 QUIT
- End DoDot:1
- +42 ;
- +43 SET STATUS=$$GET1^DIQ(123,GMRCIEN,8,"I")
- +44 SET TAG="IEN"_$TRANSLATE($JUSTIFY(STATUS,2)," ",0)
- +45 SET MCODE=$TEXT(@TAG)
- +46 QUIT $SELECT($PIECE(MCODE,";",3)="U":"2,UNFINISHED",1:"3,FINISHED")
- +47 ;
- +48 ; Table of Order Status (from file #100.01)
- +49 ; IEN ;;F=finished, U=unfinished;name
- IEN01 ;;F;DISCONTINUED
- IEN02 ;;F;COMPLETE
- IEN03 ;;U;HOLD
- IEN04 ;;U;FLAGGED
- IEN05 ;;U;PENDING
- IEN06 ;;U;ACTIVE
- IEN07 ;;F;EXPIRED
- IEN08 ;;U;SCHEDULED
- IEN09 ;;U;PARTIAL RESULTS
- IEN10 ;;U;DELAYED
- IEN11 ;;U;UNRELEASED
- IEN12 ;;F;DISCONTINUED/EDIT
- IEN13 ;;F;CANCELLED
- IEN14 ;;U;LAPSED
- IEN15 ;;U;RENEWED
- IEN99 ;;F;NO STATUS