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

TIUEDI3.m

Go to the documentation of this file.
  1. TIUEDI3 ; SLC/MAM - Additional Edit Code ;4/19/05
  1. ;;1.0;TEXT INTEGRATION UTILITIES;**100,113,184**;Jun 20, 1997
  1. ;
  1. GETRECNW(DFN,TIU,TIUTYP1,TIUNEW,TIUDPRM,TIUINQ,PERSON,EDIT) ; New GETREC.
  1. ; Code rewritten from the old GETREC^TIUEDI1.
  1. ; GETREC^TIUEDI1 now calls this code.
  1. ; New parameters: Left out TIUCREAT since we always used it as 1.
  1. ; Added PERSON and EDIT.
  1. ; Can be called directly, or via GETREC^TIUEDI1 for
  1. ;backward compatibility. GETREC^TIUEDI1 uses OLD parameters.
  1. ; There are 3 functional differences between GETRECNW and the old
  1. ;GETREC: First, GETRECNW no longer does RETRY since there should no
  1. ;longer be editable entries with no time in the visit field.
  1. ;Second, if user when creating new docmt is asked if user wants
  1. ;to edit existing docmt instead, and user says no, and user
  1. ;cannot create a new docmt, then user is no longer given the
  1. ;existing record to addend. User must use a separate addend action.
  1. ;Third, because code is restructured, code no longer quits before
  1. ;creating a new docmt if GETRECNW is called with DUOUT, etc defined.
  1. ;So quit before calling GETRECNW if DUOUT, etc.
  1. ; Returns document record DA, where DA is:
  1. ; new docmt for user to continue entering, or
  1. ; existing docmt for user to edit or addend.
  1. ; If called by upload, DA is:
  1. ; new docmt to continue entering, or
  1. ; existing docmt for text replacement or addendum.
  1. ;
  1. ; Call with:
  1. ; DFN, TIU array, TIUTYP1 are REQUIRED.
  1. ; [DFN] --> Patient IFN.
  1. ; [TIU] --> Visit info array
  1. ; References TIU("VSTR") = LOC;VDT;VTYP
  1. ; TIU("VISIT") = Visit File IFN
  1. ; TIU("LOC")
  1. ; TIU("VLOC")
  1. ; TIU("STOP") = mark to defer workload
  1. ; [TIUTYP1] --> Title info variable of form:
  1. ; TIUTYP1 = 1^title DA^title Name, where the 1
  1. ; is just style to imitate XQORNOD
  1. ; [TIUNEW] --> flag, passed back with
  1. ; TIUNEW = 1 if returned docmt is new
  1. ; TIUNEW = 0 if returned docmt already existed,
  1. ; timeout, etc
  1. ;
  1. ;[TIUDPRM] --> Docmt param array where
  1. ; $P($G(TIUDPRM(0)),U,10), = 1 if
  1. ; more than ONE record/visit is allowed.
  1. ; If TIUDPRM not received, don't worry about
  1. ; creating multiple documents
  1. ; [TIUINQ] --> Ask user flag, where
  1. ; TIUINQ = 1: ask re edit/addend existing docmt
  1. ; (Interactive List Manager options, TRY docmt def)
  1. ; TIUINQ = 0: don't ask (Upload & GUI options)
  1. ; [PERSON] --> IFN of person asking to edit/create docmt,
  1. ; or for upload, = author of document
  1. ; If not received, assumed to be DUZ.
  1. ; [EDIT] --> flag, passed back with EDIT = 1 if returned
  1. ; PREEXISTING docmt can be edited by PERSON. If
  1. ; preexisting docmt returned and 'EDIT, then
  1. ; docmt cannot be edited by person.
  1. N TIUVSTR,MULTOK,DA,TLFULL,XISONE
  1. N EDABLEDA,YESDOIT ;10/3/00
  1. N TIUTYPDA,TIUTYPNM
  1. I '$G(PERSON) S PERSON=DUZ
  1. S TIUVSTR=TIU("VSTR")
  1. ; -- If just testing a document definition (TRY) rather than
  1. ; doing a real note, skip inquiry into existing notes: --
  1. I +$G(NOSAVE) S DA=$$CREATREC(DFN,.TIU,TIUTYP1),TIUNEW=1 G GETNWX
  1. ; -- MULTOK: More than ONE record/visit is OK (param permits,
  1. ; or didn't care enough to send the parameter)
  1. ; TLFULL: Only 1 docmt allowed, and it
  1. ; already exists on this title/pt/vst --
  1. I '$D(TIUDPRM(0)) S MULTOK=1
  1. E S MULTOK=+$P(TIUDPRM(0),U,10)
  1. S (TIUNEW,EDIT,DA,TLFULL,EDABLEDA)=0
  1. S TIUTYPDA=$P(TIUTYP1,U,2),TIUTYPNM=$P(TIUTYP1,U,3)
  1. S XISONE=$$EXIST(DFN,TIUTYPDA,TIUVSTR)
  1. I 'MULTOK,XISONE S TLFULL=1
  1. ; -- Find existing editable docmts for patient, title, & visit:--
  1. S EDABLEDA=+$$EXIST(DFN,TIUTYPDA,TIUVSTR,1,PERSON)
  1. ; -- If there are NO such docmts,
  1. ; then create new if title not full,
  1. ; or return existing [NONeditable] for addendum [if user wants]: --
  1. I 'EDABLEDA D G GETNWX
  1. . I 'TLFULL S DA=$$CREATREC(DFN,.TIU,TIUTYP1),TIUNEW=1 Q
  1. . I +$G(TIUINQ) D Q
  1. . . W !!,"There is already a ",TIUTYPNM,".",!
  1. . . W "Only ONE record of this type per Visit is allowed...",!
  1. . . S YESDOIT=+$$READ^TIUU("Y"," Would you like to addend the existing record","NO")
  1. . . I YESDOIT S DA=XISONE
  1. . I '+$G(TIUINQ) S DA=XISONE
  1. . Q
  1. ; -- If there ARE such docmts, then
  1. ; If title is full, return existing docmt for edit.
  1. ; If title is NOT full, return existing docmt for edit,
  1. ; or ask user.
  1. I EDABLEDA D G GETNWX
  1. . I TLFULL D:+$G(TIUINQ) S DA=EDABLEDA,EDIT=1 Q
  1. . . W !!,"There is already a ",TIUTYPNM," which you may edit."
  1. . . W !,"Only ONE record of this type per Visit is allowed...",!
  1. . . W "Opening the existing record"
  1. . . S TIUCHNG("EXIST")=1
  1. . I 'TLFULL D Q
  1. . . I '+$G(TIUINQ) S DA=EDABLEDA,EDIT=1 Q
  1. . . W !!,"There is already a ",TIUTYPNM," which you may edit."
  1. . . S YESDOIT=+$$INQUIRE ; "Create new anyway?"
  1. . . I $D(DUOUT)!$D(DTOUT)!$D(DIROUT) Q
  1. . . I YESDOIT S DA=$$CREATREC(DFN,.TIU,TIUTYP1),TIUNEW=1 Q
  1. . . W !!,"Okay, I'll open the existing record then!"
  1. . . S DA=EDABLEDA,EDIT=1,TIUCHNG("EXIST")=1
  1. GETNWX ;
  1. I TIUNEW,'DA S TIUNEW=0
  1. Q +$G(DA)
  1. ;
  1. EXIST(DFN,TIUTYPDA,TIUVSTR,REQEDIT,PERSON) ; If a docmt already
  1. ;EXISTS for the given patient, title, and visit, then return it.
  1. ; Ignore: - docmts of status deleted or retracted
  1. ; - all docmts if run across a docmt w/ requesting pkg
  1. ; - all docmts if Title is PRF Title
  1. ; - I REQEDIT, then also ignore docmts PERSON cannot edit.
  1. ; If there are more than one, get the smallest DA.
  1. ; Receives TIUVSTR = LOC;VDT;VTYP
  1. ; Needs TIUTYPDA = title DA
  1. ; REQEDIT & PERSON are optional
  1. N REQUEST,DA,TIUI,STATUS,RETRY
  1. S REQEDIT=+$G(REQEDIT)
  1. I '$G(PERSON) S PERSON=DUZ
  1. S (REQUEST,TIUI,DA)=0
  1. I $$ISPFTTL^TIUPRFL(TIUTYPDA) G EXISTEX
  1. LOOP ; -- Find existing docmt for given patient, title, & visit:--
  1. F S TIUI=+$O(^TIU(8925,"APTLD",DFN,TIUTYPDA,TIUVSTR,TIUI)) Q:'TIUI D Q:REQUEST Q:DA
  1. . ; -- If TIUI doesn't exist, reject it and keep looking: --
  1. . I '$D(^TIU(8925,TIUI,0)) D Q
  1. . . K ^TIU(8925,"APTLD",DFN,TIUTYPDA,TIUVSTR,TIUI)
  1. . ; -- If TIUI has requesting package (e.g. Consults),
  1. . ; then reject it and quit looking: --
  1. . I +$P($G(^TIU(8925,TIUI,14)),U,5) S REQUEST=1 Q ; **22**
  1. . ; -- If TIUI has status deleted or retracted, reject it
  1. . ; and keep looking: TIU*1*61 --
  1. . S STATUS=+$P($G(^TIU(8925,TIUI,0)),U,5)
  1. . I STATUS=14!(STATUS=15) Q
  1. . ; -- If OK so far, and record not required to be editable,
  1. . ;then grab existing record and stop looking: --
  1. . I 'REQEDIT S DA=TIUI Q
  1. . ; -- If REQEDIT & PERSON can edit existing record,
  1. . ; then grab it and stop looking: --
  1. . N CANEDIT S CANEDIT=+$$CANDO^TIULP(TIUI,"EDIT RECORD",PERSON)
  1. . I +CANEDIT>0 S DA=TIUI
  1. ; -- If record not required to be editable & still haven't
  1. ; found a record, check for records with no visit time: --
  1. ; (Early anomaly with DSs at Boston)
  1. I +DA'>0,($P(TIUVSTR,";",3)="H"),(+$G(RETRY)'>0) D G LOOP
  1. . S RETRY=1,$P(TIUVSTR,";",2)=$P($P(TIUVSTR,";",2),".")
  1. EXISTEX ;
  1. Q +$G(DA)
  1. ;
  1. CREATREC(DFN,TIU,TIUTYP1) ; Create document record - Returns DA
  1. ; Receives array TIU as in GETRECNW
  1. ; Needs var TIUTYP1 as in GETRECNW
  1. N DIC,DLAYGO,X,Y,TIUFPRIV,TIUVTYP,RETRY,TIUVSTR,TIUVISIT,DA
  1. N TIUTYPDA,TIUTYPNM
  1. S TIUTYPDA=$P(TIUTYP1,U,2),TIUTYPNM=$P(TIUTYP1,U,3)
  1. S TIUVSTR=TIU("VSTR")
  1. S DA=0,TIUFPRIV=1
  1. S (DIC,DLAYGO)=8925,DIC(0)="FL"
  1. S X=""""_"`"_TIUTYPDA_"""" D ^DIC
  1. I +Y'>0 W !,TIUTYPNM," record could not be created.",! G CREXIT
  1. ; -- Stuff patient, visit, parent doc type, status,
  1. ; visit type, hosp loc, visit loc, division: --
  1. S DA=+Y
  1. N DIE,DR S DIE=8925
  1. S TIUVTYP=$P($G(TIUVSTR),";",3)
  1. S TIUVISIT=$S(+$G(TIU("VISIT")):+$G(TIU("VISIT")),1:"")
  1. S DR=".02////"_DFN_";.03////"_TIUVISIT_";.04////"_$$DOCCLASS^TIULC1(+$P(Y,U,2))_";.05///"_$$UP^XLFSTR($$STATUS^TIULC(DA))_";.13////"_TIUVTYP_";1205////"_$P($G(TIU("LOC")),U)_";1211////"_$P($G(TIU("VLOC")),U)_";1212////"_$P($G(TIU("INST")),U)
  1. D ^DIE
  1. ; -- [Mark record for deferred crediting of stop code (fld #.11)]: --
  1. I +$G(TIU("STOP")) D DEFER^TIUVSIT(DA,+$G(TIU("STOP")))
  1. CREXIT Q +$G(DA)
  1. ;
  1. INQUIRE() ; Ask user whether to create a new note anyway
  1. N TIUY,TIUPRMT
  1. S TIUY=0,TIUPRMT="Do you want to create a new record anyway"
  1. S TIUY=+$$READ^TIUU("Y",TIUPRMT,"NO")
  1. Q TIUY
  1. ;