- EDPLOGA ;SLC/KCM - Add Entry to ED Log ;2/28/12 08:33am
- ;;2.0;EMERGENCY DEPARTMENT;**6**;Feb 24, 2012;Build 200
- ;
- ;TODO: add transaction processing
- ;
- ADD(NEWPT,AREA,TIME,CHOICES) ; Create a new ED Log record for a patient
- ; add the new record to the returned XML
- ; NEWPT = dfn \T name \T dob \T ssn
- N DFN,NAME,SSN,STATUS,BED,ARR,REC,AMB,CLINIC,EDPLOG,EDPFAIL
- S EDPFAIL=0
- S AMB="(ambulance en route)"
- ;
- ; Set up the patient fields that were passed in
- D NVPARSE^EDPX(.REC,NEWPT)
- S DFN=REC("dfn"),NAME=REC("name"),SSN="",CLINIC=$G(REC("clinic"))
- I DFN S REC("name")=$P(^DPT(DFN,0),U),REC("ssn")=$P(^DPT(DFN,0),U,9)
- ;S SSN=REC("ssn") S:SSN="*SENSITIVE*" SSN="" --NtoL
- I 'DFN,(NAME="") S EDPFAIL=$$FAIL^EDPLOG("add",2300014) Q EDPFAIL
- ;
- ; Add default values to stub entry (should be based on config for area)
- S BED=$P(^EDPB(231.9,AREA,1),U,12) I 'BED S BED=$O(^EDPB(231.8,"B","EDIS_DEFAULT",0)) I 'BED S EDPFAIL=$$FAIL^EDPLOG("add",2300019) Q EDPFAIL
- I $G(REC("name"))=AMB D
- . S ARR=$O(^EDPB(233.1,"B","edp.arrival.ambulance",0))
- . S BED=$P(^EDPB(231.9,AREA,1),U,11)
- S STATUS="" I BED S STATUS=$P(^EDPB(231.8,BED,0),U,8)
- ;
- I +DFN,$D(^EDP(230,"AP",EDPSITE,AREA,DFN)) S EDPFAIL=$$FAIL^EDPLOG("add",2300002) Q EDPFAIL
- I 'DFN,(NAME'=AMB),$D(^EDP(230,"AN",EDPSITE,AREA,NAME)) S EDPFAIL=$$FAIL^EDPLOG("add",2300002) Q EDPFAIL
- N ERR S ERR=$$VALID^EDPLOG1(.REC) I $L(ERR) S EDPFAIL=$$FAIL^EDPLOG("add",ERR) Q EDPFAIL
- S ^EDPB(231.9,AREA,230)=$H ; last update timestamp
- ;
- ; Create a current log record
- N FDA,FDAIEN,DIERR,HIST,HISTIEN,LOGIEN
- S FDA(230,"+1,",.01)=TIME
- S FDA(230,"+1,",.02)=EDPSITE
- S FDA(230,"+1,",.03)=AREA
- S FDA(230,"+1,",.04)=NAME
- ;S FDA(230,"+1,",.05)=SSN --NtoL
- S FDA(230,"+1,",.06)=DFN
- S FDA(230,"+1,",3.2)=STATUS
- S FDA(230,"+1,",3.4)=BED
- I $L(SSN) S FDA(230,"+1,",.11)=$E(NAME)_$E(SSN,6,9)
- I NAME=AMB S FDA(230,"+1,",.11)="(amb)"
- I NAME'=AMB S FDA(230,"+1,",.08)=TIME
- I $G(ARR) S FDA(230,"+1,",.1)=ARR
- I CLINIC S FDA(230,"+1,",.14)=CLINIC
- I $G(REC("create")) S FDA(230,"+1,",.13)=REC("create")
- M HIST(230.1)=FDA(230)
- D UPDATE^DIE("","FDA","FDAIEN","ERR")
- I $D(DIERR) S EDPFAIL=$$FAIL^EDPLOG("add",2300004) Q EDPFAIL
- S LOGIEN=FDAIEN(1)
- ;
- ; Post new patient event
- I DFN,TIME D EVT(LOGIEN)
- ;
- ; Create the first history entry
- S HIST(230.1,"+1,",.01)=LOGIEN
- S HIST(230.1,"+1,",.02)=TIME
- S HIST(230.1,"+1,",.03)=EDPUSER
- K HIST(230.1,"+1,",.11) ; don't need last4
- K HIST(230.1,"+1,",.13) ; don't need creation source
- D UPDATE^DIE("","HIST","HISTIEN","ERR")
- I $D(DIERR) S EDPFAIL=$$FAIL^EDPLOG("add",2300004) Q EDPFAIL
- ;
- D XML^EDPX("<add status='ok' id='"_FDAIEN(1)_"' />")
- D GET^EDPQLE(FDAIEN(1),CHOICES)
- Q EDPFAIL
- ;
- DEL(AREA,LOGID) ; Delete Stub Log Entry
- N I,CNT,DIK,DA
- S I=0,CNT=0 F S I=$O(^EDP(230.1,"B",LOGID,I)) Q:'I S CNT=CNT+1
- I $L($P($G(^EDP(230,LOGID,1)),U))!(CNT>1) D Q
- . D FAIL^EDPLOG("upd","Does not appear to be a stub entry")
- ;
- ; Delete initial history entry
- S DIK="^EDP(230.1,",DA=$O(^EDP(230.1,"B",LOGID,0))
- I DA D ^DIK
- ; Delete stub log entry
- S DIK="^EDP(230,",DA=LOGID
- D ^DIK
- ;
- D XML^EDPX("<upd status='ok' />")
- Q
- ;
- EVT(LOG) ; -- post new patient event [expects EDPSITE]
- N X0,DFN,SDT,SDCL,SDATA,SDAMEVT,X
- S X0=$G(^EDP(230,+$G(LOG),0)),DFN=+$P(X0,U,6),SDT=+$P(X0,U,8)
- I 'DFN!'SDT Q ;missing data
- S SDCL=$$DFLTLOC^EDPLPCE(DFN) Q:'SDCL
- ; have patient, time, hosp loc -> post event
- S SDATA=U_DFN_U_SDT_U_SDCL,SDAMEVT=1
- S EDPDATA=LOG_SDATA
- S X=+$O(^ORD(101,"B","EDP NEW PATIENT",0))_";ORD(101,"
- D EN^XQOR
- K EDPDATA
- Q
- --- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HEDPLOGA 3624 printed Dec 13, 2024@01:52:01 Page 2
- EDPLOGA ;SLC/KCM - Add Entry to ED Log ;2/28/12 08:33am
- +1 ;;2.0;EMERGENCY DEPARTMENT;**6**;Feb 24, 2012;Build 200
- +2 ;
- +3 ;TODO: add transaction processing
- +4 ;
- ADD(NEWPT,AREA,TIME,CHOICES) ; Create a new ED Log record for a patient
- +1 ; add the new record to the returned XML
- +2 ; NEWPT = dfn \T name \T dob \T ssn
- +3 NEW DFN,NAME,SSN,STATUS,BED,ARR,REC,AMB,CLINIC,EDPLOG,EDPFAIL
- +4 SET EDPFAIL=0
- +5 SET AMB="(ambulance en route)"
- +6 ;
- +7 ; Set up the patient fields that were passed in
- +8 DO NVPARSE^EDPX(.REC,NEWPT)
- +9 SET DFN=REC("dfn")
- SET NAME=REC("name")
- SET SSN=""
- SET CLINIC=$GET(REC("clinic"))
- +10 IF DFN
- SET REC("name")=$PIECE(^DPT(DFN,0),U)
- SET REC("ssn")=$PIECE(^DPT(DFN,0),U,9)
- +11 ;S SSN=REC("ssn") S:SSN="*SENSITIVE*" SSN="" --NtoL
- +12 IF 'DFN
- IF (NAME="")
- SET EDPFAIL=$$FAIL^EDPLOG("add",2300014)
- QUIT EDPFAIL
- +13 ;
- +14 ; Add default values to stub entry (should be based on config for area)
- +15 SET BED=$PIECE(^EDPB(231.9,AREA,1),U,12)
- IF 'BED
- SET BED=$ORDER(^EDPB(231.8,"B","EDIS_DEFAULT",0))
- IF 'BED
- SET EDPFAIL=$$FAIL^EDPLOG("add",2300019)
- QUIT EDPFAIL
- +16 IF $GET(REC("name"))=AMB
- Begin DoDot:1
- +17 SET ARR=$ORDER(^EDPB(233.1,"B","edp.arrival.ambulance",0))
- +18 SET BED=$PIECE(^EDPB(231.9,AREA,1),U,11)
- End DoDot:1
- +19 SET STATUS=""
- IF BED
- SET STATUS=$PIECE(^EDPB(231.8,BED,0),U,8)
- +20 ;
- +21 IF +DFN
- IF $DATA(^EDP(230,"AP",EDPSITE,AREA,DFN))
- SET EDPFAIL=$$FAIL^EDPLOG("add",2300002)
- QUIT EDPFAIL
- +22 IF 'DFN
- IF (NAME'=AMB)
- IF $DATA(^EDP(230,"AN",EDPSITE,AREA,NAME))
- SET EDPFAIL=$$FAIL^EDPLOG("add",2300002)
- QUIT EDPFAIL
- +23 NEW ERR
- SET ERR=$$VALID^EDPLOG1(.REC)
- IF $LENGTH(ERR)
- SET EDPFAIL=$$FAIL^EDPLOG("add",ERR)
- QUIT EDPFAIL
- +24 ; last update timestamp
- SET ^EDPB(231.9,AREA,230)=$HOROLOG
- +25 ;
- +26 ; Create a current log record
- +27 NEW FDA,FDAIEN,DIERR,HIST,HISTIEN,LOGIEN
- +28 SET FDA(230,"+1,",.01)=TIME
- +29 SET FDA(230,"+1,",.02)=EDPSITE
- +30 SET FDA(230,"+1,",.03)=AREA
- +31 SET FDA(230,"+1,",.04)=NAME
- +32 ;S FDA(230,"+1,",.05)=SSN --NtoL
- +33 SET FDA(230,"+1,",.06)=DFN
- +34 SET FDA(230,"+1,",3.2)=STATUS
- +35 SET FDA(230,"+1,",3.4)=BED
- +36 IF $LENGTH(SSN)
- SET FDA(230,"+1,",.11)=$EXTRACT(NAME)_$EXTRACT(SSN,6,9)
- +37 IF NAME=AMB
- SET FDA(230,"+1,",.11)="(amb)"
- +38 IF NAME'=AMB
- SET FDA(230,"+1,",.08)=TIME
- +39 IF $GET(ARR)
- SET FDA(230,"+1,",.1)=ARR
- +40 IF CLINIC
- SET FDA(230,"+1,",.14)=CLINIC
- +41 IF $GET(REC("create"))
- SET FDA(230,"+1,",.13)=REC("create")
- +42 MERGE HIST(230.1)=FDA(230)
- +43 DO UPDATE^DIE("","FDA","FDAIEN","ERR")
- +44 IF $DATA(DIERR)
- SET EDPFAIL=$$FAIL^EDPLOG("add",2300004)
- QUIT EDPFAIL
- +45 SET LOGIEN=FDAIEN(1)
- +46 ;
- +47 ; Post new patient event
- +48 IF DFN
- IF TIME
- DO EVT(LOGIEN)
- +49 ;
- +50 ; Create the first history entry
- +51 SET HIST(230.1,"+1,",.01)=LOGIEN
- +52 SET HIST(230.1,"+1,",.02)=TIME
- +53 SET HIST(230.1,"+1,",.03)=EDPUSER
- +54 ; don't need last4
- KILL HIST(230.1,"+1,",.11)
- +55 ; don't need creation source
- KILL HIST(230.1,"+1,",.13)
- +56 DO UPDATE^DIE("","HIST","HISTIEN","ERR")
- +57 IF $DATA(DIERR)
- SET EDPFAIL=$$FAIL^EDPLOG("add",2300004)
- QUIT EDPFAIL
- +58 ;
- +59 DO XML^EDPX("<add status='ok' id='"_FDAIEN(1)_"' />")
- +60 DO GET^EDPQLE(FDAIEN(1),CHOICES)
- +61 QUIT EDPFAIL
- +62 ;
- DEL(AREA,LOGID) ; Delete Stub Log Entry
- +1 NEW I,CNT,DIK,DA
- +2 SET I=0
- SET CNT=0
- FOR
- SET I=$ORDER(^EDP(230.1,"B",LOGID,I))
- if 'I
- QUIT
- SET CNT=CNT+1
- +3 IF $LENGTH($PIECE($GET(^EDP(230,LOGID,1)),U))!(CNT>1)
- Begin DoDot:1
- +4 DO FAIL^EDPLOG("upd","Does not appear to be a stub entry")
- End DoDot:1
- QUIT
- +5 ;
- +6 ; Delete initial history entry
- +7 SET DIK="^EDP(230.1,"
- SET DA=$ORDER(^EDP(230.1,"B",LOGID,0))
- +8 IF DA
- DO ^DIK
- +9 ; Delete stub log entry
- +10 SET DIK="^EDP(230,"
- SET DA=LOGID
- +11 DO ^DIK
- +12 ;
- +13 DO XML^EDPX("<upd status='ok' />")
- +14 QUIT
- +15 ;
- EVT(LOG) ; -- post new patient event [expects EDPSITE]
- +1 NEW X0,DFN,SDT,SDCL,SDATA,SDAMEVT,X
- +2 SET X0=$GET(^EDP(230,+$GET(LOG),0))
- SET DFN=+$PIECE(X0,U,6)
- SET SDT=+$PIECE(X0,U,8)
- +3 ;missing data
- IF 'DFN!'SDT
- QUIT
- +4 SET SDCL=$$DFLTLOC^EDPLPCE(DFN)
- if 'SDCL
- QUIT
- +5 ; have patient, time, hosp loc -> post event
- +6 SET SDATA=U_DFN_U_SDT_U_SDCL
- SET SDAMEVT=1
- +7 SET EDPDATA=LOG_SDATA
- +8 SET X=+$ORDER(^ORD(101,"B","EDP NEW PATIENT",0))_";ORD(101,"
- +9 DO EN^XQOR
- +10 KILL EDPDATA
- +11 QUIT