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

DGENA1.m

Go to the documentation of this file.
  1. DGENA1 ;ALB/CJM,ISA/KWP,KUM - Enrollment API - File Data ;3/31/08 12:18pm
  1. ;;5.3;Registration;**121,147,232,671,1027**;Aug 13,1993;Build 70
  1. ;PHASE II moved CHECK and TESTVAL to DGENA3
  1. LOCK(DFN) ;
  1. ;Description: This lock is used to prevent another process from editing
  1. ; a patient's enrollment, including the current enrollment and the
  1. ; enrollment history.
  1. ;Input:
  1. ; DFN - Patient IEN
  1. ;Output:
  1. ; Function Value - Returns 1 if the lock was successful, 0 otherwise
  1. ;
  1. I $G(DFN) L +^DPT("ENROLLMENT",DFN):10
  1. Q $T
  1. UNLOCK(DFN) ;
  1. ;Description: Used to release a lock created by $$LOCK.
  1. ;Input:
  1. ; DFN - Patient IEN
  1. ;Output: None
  1. ;
  1. I $G(DFN) L -^DPT("ENROLLMENT",DFN)
  1. Q
  1. STORE(DGENR,NOCHECK,ERRMSG) ;
  1. ;Description: Used to file a PATIENT ENROLLMENT record. Consistency
  1. ; checks are done unless NOCHECK=1.If the
  1. ; enrollment passes the consistency checks specified the
  1. ; PATIENT ENROLLMENT record will be created and the ien returned.
  1. ; If the consistency checks are not passed, or a record can not
  1. ; be created, 0 is returned. This call does NOT lock the record -
  1. ; call LOCK prior to STORE if the record needs to be locked.
  1. ;Input :
  1. ; DGENR - this local array represents a PATIENT ENROLLMENT (pass by reference)
  1. ; NOCHECK - a flag, if NOCHECK=1 it means the consistency checks were done already, so do not do them again. (optional)
  1. ; ERRMSG - error message on failure (optional, pass by reference)
  1. ;Output:
  1. ; Function Value - returns the ien of the PATIENT ENROLLMENT record
  1. ; created if successful , 0 otherwise
  1. N DIC,DA,DIE,Y,DR,DO,DD
  1. ;check that enrollment is valid before storing
  1. I $G(NOCHECK)'=1 Q:'$$CHECK^DGENA3(.DGENR,,.ERRMSG) 0
  1. ;create a new record
  1. S DIC(0)="",X=DGENR("APP"),DIC="^DGEN(27.11,"
  1. D FILE^DICN
  1. I Y=-1 S ERRMSG="FILEMAN UNABLE TO CREATE ENROLLMENT RECORD" Q 0
  1. S DA=+Y
  1. ;if failed to store record, exit
  1. Q:'DA 0
  1. ;edit the record
  1. I '$$EDIT^DGENA1A(DA,.DGENR) Q 0
  1. Q DA
  1. STORECUR(DGENR,NOCHECK,ERRMSG) ;
  1. ;Description: Used to store an enrollment that has already been created
  1. ; as a local array into the PATIENT ENROLLMENT file as the
  1. ; patient's current enrollment. If the enrollment passes the
  1. ; consistency checks specified the enrollment record will be
  1. ; created and the internal entry number returned. If the
  1. ; consistency checks are not passed, or a record can not be
  1. ; created, 0 will be returned
  1. ;Input :
  1. ; DGENR - this local array represents a PATIENT ENROLLMENT and should
  1. ; be passed by reference.
  1. ; NOCHECK - a flag, if NOCHECK=1 it means the consistency checks were done already, so do not do them again. (optional)
  1. ;Output:
  1. ; Function Value - returns the internal entry number of the PATIENT
  1. ; ENROLLMENT record created if successful , 0 otherwise
  1. ; ERRMSG - error message on failure (optional, pass by reference)
  1. N DGENRIEN,OK
  1. S OK=1
  1. I '$$LOCK($G(DGENR("DFN"))) S OK=0
  1. D:OK
  1. .S DGENRIEN=$$STORE(.DGENR,$G(NOCHECK),.ERRMSG)
  1. .I 'DGENRIEN S OK=0
  1. .D:OK
  1. ..N PRIOR
  1. ..;link enrollment record to the prior enrollment
  1. ..D:DGENR("PRIORREC") KILL^DGENA1A(27.11,DGENRIEN,.09,DGENR("PRIORREC"))
  1. ..S PRIOR=$$FINDCUR^DGENA(DGENR("DFN"))
  1. ..S $P(^DGEN(27.11,DGENRIEN,0),"^",9)=PRIOR
  1. ..D:PRIOR SET^DGENA1A(27.11,DGENRIEN,.09,PRIOR)
  1. ..;now link the patient record to the new current enrollment
  1. ..D:PRIOR KILL^DGENA1A(2,DGENR("DFN"),27.01,PRIOR)
  1. ..N DGENFDA
  1. ..S DGENFDA(2,DGENR("DFN")_",",27.01)=DGENRIEN
  1. ..D UPDATE^DIE("","DGENFDA","","ERR")
  1. ..; DG*5.3*1027 - set PT APPLIED field - will sync with PATIENT file via trigger
  1. ..K DGENFDA
  1. ..S DGENFDA(27.11,DGENRIEN_",",.14)=$G(DGENR("PTAPPLIED"))
  1. ..D UPDATE^DIE("","DGENFDA","","ERR")
  1. D UNLOCK(DGENR("DFN"))
  1. Q $S(OK:DGENRIEN,1:0)
  1. EDITCUR(DGENR) ;
  1. ;Description: Used to store an enrollment that has already been created
  1. ; as a local array into the PATIENT ENROLLMENT file as the
  1. ; patient's current enrollment. If the enrollment passes the
  1. ; consistency checks specified the current enrollment record, if
  1. ; it exists, will be overlaid by the enrollment contained in
  1. ; DGENR, otherwise, if there is no current enrollment, a new
  1. ; patient enrollment record will be created as the current
  1. ; enrollment. If the consistency checks are not passed, or a
  1. ; record can not be created, NULL will be returned.
  1. ;Input :
  1. ; DGENR - this local array represents a PATIENT ENROLLMENT and
  1. ; should be passed by reference.
  1. ;Output:
  1. ; Function Value - returns the internal entry number of the PATIENT
  1. ; ENROLLMENT record created if successful , 0 otherwise
  1. N DGENRIEN,OK
  1. S OK=$$LOCK($G(DGENR("DFN")))
  1. D:OK
  1. .S DGENRIEN=$$FINDCUR^DGENA(DGENR("DFN"))
  1. .I 'DGENRIEN D
  1. ..S OK=$$STORECUR(.DGENR)
  1. .E D
  1. ..S OK=$$CHECK^DGENA3(.DGENR)
  1. ..I OK S OK=$$EDIT^DGENA1A(DGENRIEN,.DGENR)
  1. ..; DG*5.3*1027 - set PT APPLIED field - will sync with PATIENT file via trigger if editing the CURRENT ENROLLEMNT
  1. ..I $G(DGENR("PTAPPLIED"))'="" D
  1. ...K DGENFDA
  1. ...S DGENFDA(27.11,DGENRIEN_",",.14)=$G(DGENR("PTAPPLIED"))
  1. ...D UPDATE^DIE("","DGENFDA","","ERR")
  1. D UNLOCK(DGENR("DFN"))
  1. Q $S(OK:DGENRIEN,1:0)