Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: RAMAG06

RAMAG06.m

Go to the documentation of this file.
  1. RAMAG06 ;HCIOFO/SG,GJC - ORDERS/EXAMS API (EXAM COMPLETION) ; 4/12/13 6:21pm
  1. ;;5.0;Radiology/Nuclear Medicine;**90,116**;Mar 16, 1998;Build 1
  1. ;
  1. Q
  1. ;
  1. ;##### COMPLETES THE EXAM
  1. ;
  1. ; .RAPARAMS Reference to the API descriptor
  1. ; (see the ^RA01 routine for details)
  1. ;
  1. ; RACASE Exam/case identifiers
  1. ; ^01: IEN of the patient in the file #70 (RADFN)
  1. ; ^02: IEN in the REGISTERED EXAMS multiple (RADTI)
  1. ; ^03: IEN in the EXAMINATIONS multiple (RACNI)
  1. ;
  1. ; [.RAMISC] Reference to a local array containing miscellaneous
  1. ; exam parameters.
  1. ;
  1. ; See the ^RAMAG routine for additional important
  1. ; details regarding this parameter.
  1. ;
  1. ; RAMISC(
  1. ;
  1. ; "ACLHIST", Text for the ADDITIONAL CLINICAL HISTORY field
  1. ; Seq#) (400) of the RAD/NUC MED REPORTS file (#74).
  1. ; Required: No
  1. ; Default: undefined
  1. ;
  1. ; "FLAGS") Flags that control the execution (see the ^RAMAG
  1. ; routine for details). Supported flags: "F", "S".
  1. ; Required: No
  1. ; Default: undefined
  1. ;
  1. ; "IMPRESSION", Text for the IMPRESSION TEXT field (300) of the
  1. ; Seq#) file #74.
  1. ; Required: Site and/or imaging type specific
  1. ; Default: undefined
  1. ;
  1. ; "PROBSTAT") Free text value for the PROBLEM STATEMENT field
  1. ; (25) of the file #74. If this parameter is defined
  1. ; and not empty (space characters are not counted),
  1. ; then the PROBLEM DRAFT status is assigned to the
  1. ; report.
  1. ; Required: No
  1. ; Default: undefined
  1. ;
  1. ; "REPORT", Text for the REPORT TEXT field (200)
  1. ; Seq#) of the file #74.
  1. ; Required: Yes
  1. ; Default: undefined
  1. ;
  1. ; "RPTDTE") Internal date value (FileMan) for the REPORTED
  1. ; DATE field (8) of the file #74. The date must be
  1. ; exact. If time is provided, it is ignored.
  1. ; Required: Yes
  1. ; Default: undefined
  1. ;
  1. ; "RPTSTATUS") Internal value for the REPORT STATUS field (5) of
  1. ; the file #74. Currently, only "V" (Verified) and
  1. ; "EF" (Electronically Filed) codes are supported.
  1. ; Required: Yes
  1. ; Default: "V"
  1. ;
  1. ; "TRANSCRST") Internal value for the TRANSCRIPTIONIST field (11)
  1. ; of the file #74: IEN in the NEW PERSON file (#200).
  1. ; Required: No
  1. ; Default: undefined
  1. ;
  1. ; "VERDTE") Internal date value (FileMan) for the VERIFIED DATE
  1. ; field (7) of the file #74. The date must be exact.
  1. ; Required: No
  1. ; Default: undefined
  1. ;
  1. ; "VERPHYS") Internal value for the VERIFYING PHYSICIAN field
  1. ; (9) of the file #74: IEN in the NEW PERSON file
  1. ; (#200).
  1. ; Required: No
  1. ; Default: undefined
  1. ;
  1. ; "BEDSECT") If any of these optional parameters are defined,
  1. ; "CMUSED") their values replace the existing ones assigned
  1. ; "COMPLICAT") by the $$REGISTER^RAMAG03 and $$EXAMINED^RAMAG07.
  1. ; "CONTMEDIA",#)
  1. ; "CPTMODS",#)
  1. ; "EXAMCAT")
  1. ; "FILMSIZE",#)
  1. ; "PRIMCAM")
  1. ; "PRIMDXCODE")
  1. ; "PRIMINTRES")
  1. ; "PRIMINTSTF")
  1. ; "PRINCLIN")
  1. ; "RDPHARMS",#,"RDPH-...")
  1. ; "SECDXCODE",#)
  1. ; "SERVICE")
  1. ; "TECH",#)
  1. ; "TECHCOMM")
  1. ; "WARD")
  1. ;
  1. ; Return values:
  1. ; <0 Error descriptor (see $$ERROR^RAERR)
  1. ; 0 Exam has been completed
  1. ;
  1. COMPLETE(RAPARAMS,RACASE,RAMISC) ;
  1. N RACN ; Case number
  1. N RACNI ; IEN of the exam in the EXAMINATIONS multiple
  1. N RADFN ; IEN of the patient in the file #70
  1. N RADTE ; Date/time of the exam
  1. N RADTI ; Inverted date/time of the exam
  1. N RAIENS ; IENS of the exam record
  1. N RAIMGTYI ; Imaging type IEN (file #79.2)
  1. N RAMSPSDEFS ; Data for miscellaneous parameters validation
  1. N RANMDIEN ; IEN of the nuclear medicine data (file #70.2)
  1. N RAOIFN ; IEN of the order (file #75.1)
  1. N RAPROCIEN ; Radiology procedure IEN
  1. N RPTIEN ; IEN of the report (file #74)
  1. ;
  1. N RACTION,RALOCK,RAMSG,RAPOST,RAPRIEN,RARC,RARCP,RATRKCMB,TMP
  1. D:$G(RAPARAMS("DEBUG"))>1
  1. . D W^RAMAGU11("$$COMPLETE^RAMAG06","!!")
  1. . D VARS^RAMAGU11("RACASE")
  1. . D ZW^RAUTL22("RAMISC")
  1. S (RARC,RARCP)=0
  1. ;
  1. ;--- Validate case identifiers
  1. S RARC=$$CHKREQ^RAUTL22("RACASE") Q:RARC<0 RARC
  1. S RARC=$$CHKEXMID^RAMAGU04(RACASE) Q:RARC<0 RARC
  1. S RADFN=$P(RACASE,U),RADTI=$P(RACASE,U,2),RACNI=$P(RACASE,U,3)
  1. S RAIENS=$$EXAMIENS^RAMAGU04(RACASE)
  1. ;
  1. ;--- Get the order IEN
  1. S RAOIFN=$$GET1^DIQ(70.03,RAIENS,11,"I",,"RAMSG")
  1. Q:$G(DIERR) $$DBS^RAERR("RAMSG",-9,70.03,RAIENS)
  1. Q:RAOIFN'>0 $$ERROR^RAERR(-19,,70.03,RAIENS,11)
  1. ;
  1. ;--- Create the report stub if necessary
  1. S RPTIEN=$$RPTSTUB^RAMAGU12(RACASE,.RADTE,.RACN)
  1. Q:RPTIEN<0 RPTIEN
  1. ;
  1. ;--- Lock affected objects
  1. K TMP
  1. S TMP(70.03,RAIENS)=""
  1. S TMP(74,RPTIEN_",")=""
  1. S TMP(75.1,RAOIFN_",")=""
  1. S RARC=$$LOCKFM^RALOCK(.TMP)
  1. Q:RARC $$LOCKERR^RAERR(RARC,"exam/order/report")
  1. M RALOCK=TMP
  1. ;
  1. D
  1. . ;--- Setup the error handler
  1. . N $ESTACK,$ETRAP D SETDEFEH^RAERR("RARC")
  1. . ;
  1. . ;--- Initialize variables
  1. . N EXMST,RAFDA,RAFDAM
  1. . D LDMSPRMS^RAMAGU01(.RAMSPSDEFS)
  1. . S RACTION="EC"
  1. . ;
  1. . ;--- Load exam properties
  1. . S RARC=$$EXAMVARS^RAMAGU04(RAIENS) Q:RARC<0
  1. . ;
  1. . ;--- Get descriptor of the desired exam status
  1. . S EXMST=$$EXMSTINF^RAMAGU06("^^9",RAIMGTYI)
  1. . I EXMST<0 S RARC=EXMST Q
  1. . ;
  1. . ;--- Validate general parameters
  1. . S RARC=$$VAL70^RAMAGU08(RAIENS,+EXMST,.RACTION,.RAMISC,.RAFDAM)
  1. . I RARC<0 S RARC=$$ERROR^RAERR(-11) Q
  1. . Q:RACTION="" ;--- Exam already has requested status
  1. . S RARC=$$VAL74^RAMAGU10(RPTIEN_",",RACTION,.RAMISC,.RAFDAM)
  1. . I RARC<0 S RARC=$$ERROR^RAERR(-11) Q
  1. . ;
  1. . ;--- Nuclear medicine (including parameter validation)
  1. . S RARC=$$NUCMED^RAMAG06A(RACASE,RACTION,.RAMISC,.RAFDAM) Q:RARC<0
  1. . S RANMDIEN=RARC
  1. . ;
  1. . ;--- Pre-processing
  1. . S RARC=$$EDTPRE^RAMAG06A(RACTION,.RATRKCMB,.RAPRIEN) Q:RARC<0
  1. . K RAFDAM("RACNT"),RAFDAM("RAIENS")
  1. . ;
  1. . ;--- Update the exam record
  1. . K RAFDA,RAMSG M RAFDA(70.03)=RAFDAM(70.03) K RAFDAM(70.03)
  1. . I $D(RAFDA)>1 D Q:RARC<0 S RAPOST=1
  1. . . D FILE^DIE(,"RAFDA","RAMSG")
  1. . . S:$G(DIERR) RARC=$$DBS^RAERR("RAMSG",-9,70.03,RAIENS)
  1. . ;
  1. . ;--- Update the nuclear medicine data
  1. . K RAFDA,RAMSG M RAFDA(70.21)=RAFDAM(70.21) K RAFDAM(70.21)
  1. . I $D(RAFDA)>1 D Q:RARC<0 S RAPOST=1
  1. . . S RARC=$$UPDMULT^RAMAGU13(.RAFDA,RANMDIEN_",")
  1. . ;
  1. . ;--- Update the report record
  1. . K RAFDA,RAMSG M RAFDA(74)=RAFDAM(74) K RAFDAM(74)
  1. . I $D(RAFDA)>1 D Q:RARC<0 S RAPOST=1
  1. . . D FILE^DIE(,"RAFDA","RAMSG")
  1. . . S:$G(DIERR) RARC=$$DBS^RAERR("RAMSG",-9,74,RPTIEN_",")
  1. . ;
  1. . ;--- Update multiples of the exam record
  1. . I $D(RAFDAM)>1 D Q:RARC<0 S RAPOST=1
  1. . . S RARC=$$UPDMULT^RAMAGU13(.RAFDAM,RAIENS)
  1. . ;
  1. . ;--- Report status
  1. . S TMP=$G(RAMISC("PROBSTAT"))
  1. . S RARC=$$UPDRPTST^RAMAGU12(RPTIEN,$G(RAMISC("RPTSTATUS")),TMP)
  1. . Q:RARC<0
  1. . ;--- Exam status
  1. . S TMP=$$TRFLAGS^RAUTL22($G(RAMISC("FLAGS")),"F","F")
  1. . S RARC=$$UPDEXMST^RAMAGU05(RACASE,EXMST,TMP) Q:RARC<0
  1. . ;--- Activity log
  1. . S TMP=$G(RAMISC("TECHCOMM"))
  1. . S RARC=$$UPDEXMAL^RAMAGU05(RACASE,"C",TMP)
  1. ;
  1. ;--- Post-processing is performed and notifications are sent if any
  1. ; changes to the case have been made (even if its status has not
  1. ;--- been changed to 'COMPLETE').
  1. D:$G(RAPOST)
  1. . N $ESTACK,$ETRAP
  1. . D SETDEFEH^RAERR("RARCP")
  1. . S RARCP=$$EDTPST^RAMAG06A(RACTION,RATRKCMB,.RAPRIEN)
  1. ;
  1. ;--- Error handling and cleanup
  1. D UNLOCKFM^RALOCK(.RALOCK)
  1. Q $S(RARC<0:RARC,RARCP<0:RARCP,1:0)