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

PSULRHL3.m

Go to the documentation of this file.
  1. PSULRHL3 ;HCIOFO/BH - Daily file procesing ; 4/28/04 3:10pm
  1. ;;4.0;PHARMACY BENEFITS MANAGEMENT;**3**;MARCH, 2005
  1. ;
  1. ; ** THIS ROUTINE SHOULD NEVER BE INSTALLED AT A SITE ***
  1. ; ** THIS ROUTINE IS ONLY TO BE RUN ON THE CMOP-NAT SERVER ***
  1. ;
  1. Q
  1. ;
  1. PROCESS ; This process loops through the file containing parsed HL7 data.
  1. ; This process runs each day and collects up to the previous days data.
  1. ; The data is ordered by facility. All the data for the facility for
  1. ; for up to the previous day gets filed into one flat file for PBM to
  1. ; process. A pre-init sub routine CULL loops through all x-refs that
  1. ; indicate processed data for facility and date and culls the data and
  1. ; removes the FD x-ref.
  1. ;
  1. ;
  1. D CULL
  1. ;
  1. ;
  1. N DFN,EDATE,FACILITY,FILE,IEN,OPEN,OUTDIR,PSUDTE,QUIT,RDATE,RC,SDATE,TEMP,X,X1,X2
  1. ;
  1. ; End date for search
  1. D NOW^%DTC S TEMP=%,EDATE=$P(TEMP,".",1)
  1. ; Run date i.e. going to process data up to yesterday
  1. S X1=$P(TEMP,".",1),X2="-1" D C^%DTC S RDATE=$P(X,".",1)
  1. ;
  1. ;
  1. S FACILITY="",(QUIT,OPEN)=0
  1. ;
  1. F S FACILITY=$O(^DIZ(99999,"FDP",FACILITY)) Q:'FACILITY!(QUIT) D
  1. . ;
  1. . I $D(^DIZ(99999,"FD",FACILITY,RDATE)) D Q
  1. . . D ERROR(3,FACILITY,RDATE) Q
  1. . ; New facility so close any open files.
  1. . I OPEN D CLOSE S OPEN=0
  1. . S DATE="0"
  1. . F S DATE=$O(^DIZ(99999,"FDP",FACILITY,DATE)) Q:'DATE!(DATE'<EDATE)!(QUIT) D
  1. . . ;
  1. . . S DFN=""
  1. . . F S DFN=$O(^DIZ(99999,"FDP",FACILITY,DATE,DFN)) Q:'DFN!(QUIT) D
  1. . . . S IEN=""
  1. . . . F S IEN=$O(^DIZ(99999,"FDP",FACILITY,DATE,DFN,IEN)) Q:'IEN!(QUIT) D
  1. . . . . I 'OPEN D Q:'RC
  1. . . . . . S RC=$$OPEN()
  1. . . . . . I 'RC S QUIT=1 Q
  1. . . . . . S OPEN=1
  1. . . . . D FILE
  1. I OPEN D CLOSE
  1. Q
  1. ;
  1. ;
  1. OPEN() ; Open the output directory
  1. N DST,POP,SRC
  1. S FILE=FACILITY_DT_".DAT"
  1. ;S OUTDIR="W:\PBM\National-PBM"
  1. S OUTDIR="USER$:[PBM.LAB]"
  1. ;
  1. K DST,SRC
  1. S SRC(FILE)=""
  1. I $$LIST^%ZISH(OUTDIR,"SRC","DST") D ERROR(2,FACILITY,FILE) Q 0
  1. ;
  1. D OPEN^%ZISH("HL7FILE",OUTDIR,FILE,"W")
  1. I $G(POP) D ERROR(1,FACILITY,OUTDIR_FILE) Q 0
  1. ;
  1. Q 1
  1. ;
  1. CLOSE ; Set Cross ref indicating that facilities data for the day got
  1. ; processed, and close the output file.
  1. N FDA
  1. K FDA
  1. S FDA(99999,"+1,",.01)=$E(FILE,1,3)
  1. S FDA(99999,"+1,",.03)=RDATE
  1. D UPDATE^DIE("","FDA",)
  1. D CLOSE^%ZISH("HL7FILE")
  1. Q
  1. ;
  1. FILE ; File the lab data to the output file in the following single string format.
  1. ;
  1. ; PAT|Facility|ICN|SSN|DFN|Date/Time Specimen Collected|Site/Specimen|Local Lab Number^Local Lab Name|
  1. ; NLT Code^NLT Name|LOINC Code^LOINC Name|Result|Units|Low Range|High Range|
  1. ;
  1. ;
  1. N CNT,CR,DFN,FAC,HRANGE,ICN,LABA,LABB,LABC,LNCODE,LNNAME,LOCALLAB,LRANGE,NLTCODE,NLTNAME,RANGE,REC,RESIEN,RESREC,RESREC1,RESULT,SPEC,SPECDATE,SPECREC,SPECIEN,SSN,STR,STR1,TEST,UNITS
  1. ;
  1. U IO
  1. S REC=^DIZ(99999,IEN,0)
  1. S SSN=$P(REC,U,5),ICN=$P(REC,U,4),FAC=$P(REC,U,1),DFN=$P(REC,U,2)
  1. ;
  1. S SPECIEN=0
  1. F S SPECIEN=$O(^DIZ(99999,IEN,1,SPECIEN)) Q:'SPECIEN D
  1. . ; Do not file if Specimen has no results
  1. . S TEST=0
  1. . S TEST=$O(^DIZ(99999,IEN,1,SPECIEN,1,TEST)) Q:'TEST
  1. . S SPECREC=^DIZ(99999,IEN,1,SPECIEN,0)
  1. . S SPEC=$P(SPECREC,U,1),SPECDATE=$P(SPECREC,U,2)
  1. . S STR="PAT|"_FAC_"|"_ICN_"|"_SSN_"|"_DFN_"|"_SPECDATE_"|"_SPEC
  1. . ;W STR
  1. . S RESIEN=0
  1. . ;S CNT=0
  1. . F S RESIEN=$O(^DIZ(99999,IEN,1,SPECIEN,1,RESIEN)) Q:'RESIEN D
  1. . . S RESREC=^DIZ(99999,IEN,1,SPECIEN,1,RESIEN,0)
  1. . . S RESREC1=^DIZ(99999,IEN,1,SPECIEN,1,RESIEN,2)
  1. . . ;S CNT=CNT+1
  1. . . S LOCALLAB=$P(RESREC,U,6),NLTCODE=$P(RESREC,U,2)
  1. . . S NLTNAME=$P(RESREC,U,3),LNNAME=$P(RESREC,U,5)
  1. . . S LNCODE=$P(RESREC,U,4),RESULT=$P(RESREC,U,1)
  1. . . S UNITS=$P(RESREC1,U,1),RANGE=$P(RESREC1,U,2)
  1. . . ; Most of the time High and Low range are separated by a "-"
  1. . . I RANGE["-" D
  1. . . . S LRANGE=$P(RANGE,"-",1),HRANGE=$P(RANGE,"-",2)
  1. . . I RANGE'["-" D
  1. . . . S LRANGE=RANGE,HRANGE=""
  1. . . S LABA="|^"_LOCALLAB_"|"_NLTCODE_"^"_NLTNAME_"|"_LNCODE_"^"_LNNAME_"|"
  1. . . ;
  1. . . S LABB=RESULT_"|"_UNITS_"|"
  1. . . ;
  1. . . S LABC=LRANGE_"|"_HRANGE_"|"
  1. . . W STR_LABA_LABB_LABC,!
  1. Q
  1. ;
  1. ERROR(CODE,FAC,MESSAGE) ; Error processing
  1. N ARR,STR
  1. I CODE=1 S STR=DT_": Cannot open output file "_MESSAGE
  1. I CODE=2 S STR=DT_": File name already exists in the output directory "_MESSAGE
  1. I CODE=3 D
  1. . S MESSAGE=$E(MESSAGE,4,5)_"/"_$E(MESSAGE,6,7)_"/"_$E(MESSAGE,2,3)
  1. . S STR=DT_": Trying to process records for Facility #"_FAC_" for the date of "_MESSAGE_" that have already been processed."
  1. S FDA(99999,"+1,",.01)=FAC
  1. S FDA(99999,"+1,",2)=STR
  1. D UPDATE^DIE("","FDA",)
  1. Q
  1. ;
  1. ;
  1. CULL ; Cull all entries for a facility that have been processed on or before the date in FD x-ref
  1. N A,B,DFN,DELLIEN,FAC,IDATE,IEN,PDATE
  1. S FAC="0"
  1. F S FAC=$O(^DIZ(99999,"FD",FAC)) Q:'FAC D
  1. . S PDATE=0
  1. . F S PDATE=$O(^DIZ(99999,"FD",FAC,PDATE)) Q:'PDATE D
  1. . . S IDATE=0
  1. . . ; Remove entry with FD x-ref
  1. . . S DELLIEN=0
  1. . . S DELLIEN=$O(^DIZ(99999,"FD",FAC,PDATE,DELLIEN))
  1. . . K B
  1. . . S B(99999,DELLIEN_",",.01)="@" D FILE^DIE(,"B")
  1. . . ;
  1. . . F S IDATE=$O(^DIZ(99999,"FDP",FAC,IDATE)) Q:'IDATE!($P(IDATE,".",1)>PDATE) D
  1. . . . S DFN=0
  1. . . . F S DFN=$O(^DIZ(99999,"FDP",FAC,IDATE,DFN)) Q:'DFN D
  1. . . . . S IEN=0
  1. . . . . F S IEN=$O(^DIZ(99999,"FDP",FAC,IDATE,DFN,IEN)) Q:'IEN D
  1. . . . . . K A
  1. . . . . . S A(99999,IEN_",",.01)="@" D FILE^DIE(,"A")
  1. Q
  1. ;
  1. ;
  1. ERORDSP ; Display errors
  1. ;
  1. N DATE,DONE,EDATE,FAC,IEN,PG
  1. S PG=0,DATE=$E(DT,4,5)_"/"_$E(DT,6,7)_"/"_$E(DT,2,3)
  1. D HEAD
  1. I '$D(^DIZ(99999,"FDE")) W "No Error's to report." H 4 Q
  1. ;
  1. ;
  1. S FAC="0"
  1. F S FAC=$O(^DIZ(99999,"FDE",FAC)) Q:'FAC D
  1. . ;
  1. . S EDATE=0
  1. . F S EDATE=$O(^DIZ(99999,"FDE",FAC,EDATE)) Q:'EDATE D
  1. . . S IEN=0
  1. . . F S IEN=$O(^DIZ(99999,"FDE",FAC,EDATE,IEN)) Q:'IEN D
  1. . . . S MSG=^DIZ(99999,IEN,2)
  1. . . . I ($Y+4>IOSL) D PRTC Q:$D(DONE) D HEAD
  1. . . . W !," "_MSG,!
  1. Q
  1. ;
  1. W:$Y>0 @IOF S PG=PG+1
  1. W " "_DATE,?71,"Page ",PG,!!
  1. W " Error log for PBM III national database processing.",!
  1. W " ---------------------------------------------------",!
  1. Q
  1. ;
  1. PRTC ;press return to continue prompt
  1. Q:$E(IOST,1,2)'="C-"!($D(IO("S")))
  1. K DIR W ! S DIR(0)="E" D ^DIR K DIR I 'Y S DONE=1
  1. Q
  1. ;
  1. ;