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

BJPNAPI.m

Go to the documentation of this file.
  1. BJPNAPI ;GDIT/HS/BEE-Prenatal Care Module API Calls ; 08 May 2012 12:00 PM
  1. ;;2.0;PRENATAL CARE MODULE;**8**;Feb 24, 2015;Build 25
  1. ;
  1. Q
  1. ;
  1. PIPA(TARGET,DFN,PARM) ;PEP - Returns PIPA - Active All Notes
  1. ;
  1. ;This API returns all Active problems on the prenatal PIP for a patient. For
  1. ;each problem entry, ALL ACTIVE goals and Care Plans and ALL Visit Instructions associated
  1. ;with that problem will be returned (even if outside of the current pregnancy window).
  1. ;
  1. ;Input:
  1. ; DFN - Patient IEN
  1. ; PARM - (Optional) - Formatting parameter which can contain one or more of the following codes
  1. ; - 'V' - Do NOT display the date beside visit instructions/OB Notes
  1. ; - 'P' - Do NOT display the date entered for the problem
  1. ; - 'H' - Do Not display a hyphen next to each care plan, goal, and visit instruction
  1. ; - 'O' - Include OB Notes
  1. ; - So as an example, passing "VP" would not display either date listed, but the hyphen
  1. ; would still display
  1. ;
  1. ;Reset output
  1. K @TARGET
  1. ;
  1. Q $$PIP^BJPNAPI2(TARGET,$G(DFN),"A","","","","",$G(PARM),1)
  1. ;
  1. PIPN(TARGET,DFN,PARM) ;PEP - Returns PIPN - Active/Inactive All Notes
  1. ;
  1. ;This API returns all Active and Inactive problems on the prenatal PIP for a patient. For
  1. ;each problem entry, ALL ACTIVE and INACTIVE goals and Care Plans, and ALL Visit Instructions associated
  1. ;with that problem will be returned.
  1. ;
  1. ;Input:
  1. ; DFN - Patient IEN
  1. ; PARM - (Optional) - Formatting parameter which can contain one or more of the following codes
  1. ; - 'V' - Do NOT display the date beside visit instructions/OB Notes
  1. ; - 'P' - Do NOT display the date entered for the problem
  1. ; - 'H' - Do Not display a hyphen next to each care plan, goal, and visit instruction
  1. ; - 'O' - Include OB Notes
  1. ; - So as an example, passing "VP" would not display either date listed, but the hyphen
  1. ; would still display
  1. ;
  1. ;Reset output
  1. K @TARGET
  1. ;
  1. Q $$PIP^BJPNAPI2(TARGET,$G(DFN),"A",1,"","","",$G(PARM))
  1. ;
  1. PIPC(TARGET,DFN,PARM) ;PEP - Returns PIPC - Active All Current Notes
  1. ;
  1. ;This API returns all Active problems on the prenatal PIP for a patient. For
  1. ;each problem entry, ALL ACTIVE goals, Care Plans, and Visit Instructions associated
  1. ;with that problem FOR THE CURRENT PREGNANCY WINDOW will be returned.
  1. ;
  1. ;Input:
  1. ; DFN - Patient IEN
  1. ; PARM - (Optional) - Formatting parameter which can contain one or more of the following codes
  1. ; - 'V' - Do NOT display the date beside visit instructions/OB Notes
  1. ; - 'P' - Do NOT display the date entered for the problem
  1. ; - 'H' - Do Not display a hyphen next to each care plan, goal, and visit instruction
  1. ; - 'O' - Include OB Notes
  1. ; - So as an example, passing "VP" would not display either date listed, but the hyphen
  1. ; would still display
  1. ;
  1. ;Reset output
  1. K @TARGET
  1. ;
  1. Q $$PIP^BJPNAPI2(TARGET,$G(DFN),"C","","","","",$G(PARM))
  1. ;
  1. VPOV(TARGET,DFN,VIEN,PARM) ;PEP - Returns VPOV - Returns POV Active Problems for visit (just VI notes)
  1. ;
  1. ;This API returns all active and inactive problems on a patients PIP that were selected as a POV
  1. ;for the specified visit. Only associated visit instructions are returned.
  1. ;
  1. ;Input:
  1. ; DFN - Patient IEN
  1. ; VIEN - Visit IEN - If not passed in, attempt to pull from CONTEXT
  1. ; PARM - (Optional) - Formatting parameter which can contain one or more of the following codes
  1. ; - 'V' - Do NOT display the date beside visit instructions/OB Notes
  1. ; - 'P' - Do NOT display the date entered for the problem
  1. ; - 'O' - Include OB Notes
  1. ; - So as an example, passing "VP" would not display either date listed
  1. ;
  1. ;Reset output
  1. K @TARGET
  1. ;
  1. S VIEN=$G(VIEN)
  1. I $G(DFN)="" S @TARGET@(1,0)="Invalid DFN" Q "~@"_$NA(@TARGET)
  1. ;
  1. ;Pull visit from context
  1. I VIEN="" D I VIEN="" Q "~@"_$NA(@TARGET)
  1. . NEW VST,X
  1. . I $T(GETVAR^CIAVMEVT)="" S @TARGET@(1,0)="Invalid context variables" Q
  1. . S VST=$$GETVAR^CIAVMEVT("ENCOUNTER.ID.ALTERNATEVISITID",,"CONTEXT.ENCOUNTER")
  1. . I VST="" S @TARGET@(1,0)="Invalid visit" Q
  1. . S X="BEHOENCX" X ^%ZOSF("TEST")
  1. . I $T S VST=+$$VSTR2VIS^BEHOENCX(DFN,VST) I VST<1 S @TARGET@(1,0)="Invalid visit" Q
  1. . S VIEN=VST
  1. ;
  1. Q $$PIP^BJPNAPI2(TARGET,$G(DFN),"A",1,$G(VIEN),1,"",$G(PARM))
  1. ;
  1. APOV(TARGET,DFN,VIEN,PARM) ;PEP - Returns VPOV - Returns POV Active Problems for visit (all notes)
  1. ;
  1. ;This API returns all problems on a patients PIP that were selected as a POV
  1. ;for the specified visit. Only associated visit instructions as well as all active
  1. ;care plans and goals are returned.
  1. ;
  1. ;Input:
  1. ; DFN - Patient IEN
  1. ; VIEN - Visit IEN - If not passed in, attempt to pull from CONTEXT
  1. ; PARM - (Optional) - Formatting parameter which can contain one or more of the following codes
  1. ; - 'V' - Do NOT display the date beside visit instructions/OB Notes
  1. ; - 'P' - Do NOT display the date entered for the problem
  1. ; - 'H' - Do Not display a hyphen next to each care plan, goal, and visit instruction
  1. ; - 'O' - Include OB Notes
  1. ; - So as an example, passing "VP" would not display either date listed, but the hyphen
  1. ; would still display
  1. ;
  1. ;Reset output
  1. K @TARGET
  1. ;
  1. I $G(DFN)="" S @TARGET@(1,0)="Invalid DFN" Q "~@"_$NA(@TARGET)
  1. S VIEN=$G(VIEN)
  1. ;
  1. ;Pull visit from context
  1. I VIEN="" D I VIEN="" Q "~@"_$NA(@TARGET)
  1. . NEW VST,X
  1. . I $T(GETVAR^CIAVMEVT)="" S @TARGET@(1,0)="Invalid context variables" Q
  1. . S VST=$$GETVAR^CIAVMEVT("ENCOUNTER.ID.ALTERNATEVISITID",,"CONTEXT.ENCOUNTER")
  1. . I VST="" S @TARGET@(1,0)="Invalid visit" Q
  1. . S X="BEHOENCX" X ^%ZOSF("TEST")
  1. . I $T S VST=+$$VSTR2VIS^BEHOENCX(DFN,VST) I VST<1 S @TARGET@(1,0)="Invalid visit" Q
  1. . S VIEN=VST
  1. ;
  1. Q $$PIP^BJPNAPI2(TARGET,$G(DFN),"A",1,$G(VIEN),"","",$G(PARM))
  1. ;
  1. APIP(TARGET,DFN,TYPE,ASTS,PARM) ;PEP - Returns Prenatal PIP Entry Information
  1. ;
  1. ;Input:
  1. ; DFN - Patient IEN
  1. ; TYPE - "C" - Returns list of ALL ACTIVE problem entries on the PIP.
  1. ; For each problem entry, returns any notes for each entry
  1. ; entered within the date range for the current pregnancy.
  1. ; "A" - Returns list of ALL ACTIVE problem entries on the PIP.
  1. ; For each problem entry, returns ALL notes for each entry,
  1. ; regardless of whether they apply to the current pregnancy
  1. ; or to prior pregnancies.
  1. ; ASTS - All Statuses (Optional) - If 1, return both Active and Inactive
  1. ; Problems. Otherwise, just return
  1. ; Active problems.
  1. ; PARM - (Optional) - Formatting parameter which can contain one or more of the following codes
  1. ; - 'V' - Do NOT display the date beside visit instructions/OB Notes
  1. ; - 'P' - Do NOT display the date entered for the problem
  1. ; - 'H' - Do Not display a hyphen next to each care plan, goal, and visit instruction
  1. ; - 'O' - Include OB Notes
  1. ; - So as an example, passing "VP" would not display either date listed, but the hyphen
  1. ; would still display
  1. ;
  1. ;Reset output
  1. K @TARGET
  1. ;
  1. ;Input validation
  1. S ASTS=$G(ASTS)
  1. S PARM=$G(PARM)
  1. I $G(DFN)="" S @TARGET@(1,0)="Invalid DFN" Q "~@"_$NA(@TARGET)
  1. I $G(TYPE)="" S @TARGET@(1,0)="Invalid TYPE" Q "~@"_$NA(@TARGET)
  1. I (",C,A,")'[TYPE D Q "~@"_$NA(@TARGET)
  1. . S @TARGET@(1,0)="Invalid TYPE - Must be C or A"
  1. S VIEN=$G(VIEN) I VIEN]"",$$GET1^DIQ(9000010,VIEN_",",.01,"I")="" D Q "~@"_$NA(@TARGET)
  1. . S @TARGET@(1,0)="Invalid VIEN"
  1. ;
  1. NEW II,CNT,RESULT,PRBIEN,PCNT,SPACE,TMP,UID,NEDT
  1. ;
  1. ;Define task id
  1. S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
  1. ;
  1. ;Definitive EDD date range check
  1. D GETPAR^CIAVMRPC(.NEDT,"BJPN POST DEDD DAYS","SYS",1,"I","")
  1. ;
  1. ;If blank default to 70
  1. I +$G(NEDT)<1 S NEDT=70
  1. ;
  1. ;Call EHR API and format results into usable data
  1. D COMP^BJPNUTIL(DFN,UID,VIEN)
  1. S TMP=$NA(^TMP("BJPNIPL",UID)) ;Define compiled data reference
  1. ;
  1. ;Loop through PIP - Process each entry
  1. S PRBIEN="",II=0,PCNT=0 F S PRBIEN=$O(^BJPNPL("F",DFN,PRBIEN)) Q:PRBIEN="" D
  1. . NEW BPIEN,LINE
  1. . S BPIEN="" F S BPIEN=$O(^BJPNPL("F",DFN,PRBIEN,BPIEN)) Q:BPIEN="" D PROC^BJPNAPI1(PRBIEN,BPIEN,ASTS,PARM,PCNT,.II,TYPE,TMP,.RESULT)
  1. ;
  1. ;Clear out scratch global
  1. K ^TMP("BJPNPRL",$J)
  1. ;
  1. ;Define Output
  1. S (II,CNT)=0 F S II=$O(RESULT(II)) Q:'II D
  1. .S CNT=CNT+1
  1. .S @TARGET@(CNT,0)=RESULT(II)
  1. I 'CNT S @TARGET@(1,0)="No Active Problems for Current Pregnanacy"
  1. Q "~@"_$NA(@TARGET)
  1. ;
  1. LPIP(TARGET,DFN,LNOTE,PARM) ;PEP - Returns Prenatal Problems for LATEST prenatal visit
  1. ;
  1. ;Returns a list of all prenatal problem entries on the PIP that were used
  1. ;as the POV for the LATEST (most recent) prenatal visit for the patient. For
  1. ;each entry, displays the visit instructions entered for that visit (or the
  1. ;latest visit instruction entered - see LNOTE)
  1. ;
  1. ;Input:
  1. ; DFN - Patient IEN
  1. ; LNOTE (optional) - If 1, for each POV problem for the visit, pull the latest
  1. ; visit instruction entered. If none were entered for the
  1. ; visit, look back to previous visit(s) to get the last one
  1. ; and return it.
  1. ; If not 1, do not look to get the latest visit instruction
  1. ; from the previous visit(s) if the current visit didn't have
  1. ; any.
  1. ; PARM - (Optional) - Formatting parameter which can contain one or more of the following codes
  1. ; - 'V' - Do NOT display the date beside visit instructions/OB Notes
  1. ; - 'P' - Do NOT display the date entered for the problem
  1. ; - 'H' - Do Not display a hyphen next to each care plan, goal, and visit instruction
  1. ; - 'O' - Include OB Notes
  1. ; - So as an example, passing "VP" would not display either date listed, but the hyphen
  1. ; would still display
  1. ;
  1. NEW VIEN,X,PRBIEN,RLIST,PBLIST
  1. ;
  1. ;Reset output
  1. K @TARGET
  1. ;
  1. S LNOTE=$G(LNOTE)
  1. I $G(DFN)="" S @TARGET@(1,0)="Invalid DFN" Q "~@"_$NA(@TARGET)
  1. ;
  1. ;Get ordered list of prenatal visits
  1. D PVST(DFN,.ORLIST,.PBLIST)
  1. ;
  1. ;Get current visit
  1. S VIEN=$G(ORLIST(1))
  1. I VIEN="" S @TARGET@(1,0)="Could not find Prenatal Visit" Q "~@"_$NA(@TARGET)
  1. ;
  1. Q $$PIP^BJPNAPI2(TARGET,$G(DFN),"A",1,$G(VIEN),1,$G(LNOTE),$G(PARM))
  1. ;
  1. ;Get list of prenatal visits
  1. PVST(DFN,ORLIST,PBLIST) ;Return list of prenatal POV visits and problems for patient
  1. ;
  1. ;This function returns a list of patient visits that have a POV that points to a
  1. ;problem on the patient's PIP
  1. ;
  1. ;Input
  1. ; DFN - Patient IEN
  1. ;
  1. ;Output
  1. ; ORLIST(#) - Array of visits, ranked newest to oldest
  1. ;
  1. NEW PRBIEN,INVTM,ORD,DPLIST
  1. ;
  1. ;Loop through prenatal PIP problems and assemble list of associated IPL entries
  1. S PRBIEN="" F S PRBIEN=$O(^BJPNPL("F",DFN,PRBIEN)) Q:PRBIEN="" D
  1. . NEW BPIEN
  1. . S BPIEN="" F S BPIEN=$O(^BJPNPL("F",DFN,PRBIEN,BPIEN)) Q:BPIEN="" D
  1. .. NEW DEL
  1. .. ;
  1. .. ;Skip deletes
  1. .. S DEL=$$GET1^DIQ(90680.01,PRBIEN_",",2.01,"I") Q:DEL]"" ;PIP Delete
  1. .. S DEL=$$GET1^DIQ(9000011,PRBIEN_",",2.02,"I") Q:DEL]"" ;IPL Delete
  1. .. ;
  1. .. ;Add entry to list
  1. .. S PBLIST(PRBIEN)=BPIEN
  1. ;
  1. ;Now loop through the V POV and find the last V POV entry for a PIP problem
  1. S INVTM="",ORD=0 F S INVTM=$O(^AUPNVPOV("AA",DFN,INVTM)) Q:INVTM="" D
  1. . NEW VPVIEN
  1. . S VPVIEN="" F S VPVIEN=$O(^AUPNVPOV("AA",DFN,INVTM,VPVIEN),-1) Q:VPVIEN="" D
  1. .. NEW PRBIEN,VIEN
  1. .. ;
  1. .. ;Get the IPL entry
  1. .. S PRBIEN=$$GET1^DIQ(9000010.07,VPVIEN_",",.16,"I") Q:PRBIEN=""
  1. .. ;
  1. .. ;Quit if not a prenatal problem
  1. .. I '$D(PBLIST(PRBIEN)) Q
  1. .. ;
  1. .. ;Get the VIEN
  1. .. S VIEN=$$GET1^DIQ(9000010.07,VPVIEN_",",.03,"I") Q:VIEN=""
  1. .. Q:$D(DPLIST(VIEN)) ;Quit if visit already filed
  1. .. ;
  1. .. ;Set up the ordered list
  1. .. S ORD=ORD+1,ORLIST(ORD)=VIEN
  1. .. S DPLIST(VIEN)=""
  1. Q
  1. ;
  1. VPIP(TARGET,DFN,VIEN,LNOTE,PARM) ;PEP - Returns Prenatal POV Problems for a Visit
  1. ;
  1. ;Returns a list of all prenatal problem entries on the PIP that were used
  1. ;as the POV for the specified visit. For each entry, displays the visit instructions
  1. ;entered for that visit (or the latest visit instruction entered - see LNOTE).
  1. ;
  1. ;Input:
  1. ; DFN - Patient IEN
  1. ; VIEN (optional) - Visit IEN - If blank VIEN is pulled from Context
  1. ; LNOTE (optional) - If 1, for each POV problem for the visit, pull the latest
  1. ; visit instruction entered. If none were entered for the
  1. ; visit, look back to previous visit(s) to get the last one
  1. ; and return it.
  1. ; If not 1, do not look to get the latest visit instruction
  1. ; from the previous visit(s) if the current visit didn't have
  1. ; any.
  1. ; PARM - (Optional) - Formatting parameter which can contain one or more of the following codes
  1. ; - 'V' - Do NOT display the date beside visit instructions/OB Notes
  1. ; - 'P' - Do NOT display the date entered for the problem
  1. ; - 'H' - Do Not display a hyphen next to each care plan, goal, and visit instruction
  1. ; - 'O' - Include OB Notes
  1. ; - So as an example, passing "VP" would not display either date listed, but the hyphen
  1. ; would still display
  1. ;
  1. ;Reset output
  1. K @TARGET
  1. ;
  1. ;Input validation
  1. S LNOTE=$G(LNOTE)
  1. I $G(DFN)="" S @TARGET@(1,0)="Invalid DFN" Q "~@"_$NA(@TARGET)
  1. S VIEN=$G(VIEN) I VIEN]"",$$GET1^DIQ(9000010,VIEN_",",.01,"I")="" D Q "~@"_$NA(@TARGET)
  1. . S @TARGET@(1,0)="Invalid VIEN"
  1. ;
  1. NEW II,CNT,RESULT,VFIEN,PCNT,SPACE,PARY,X,TMP,UID,TMP,PBLIST,ORLIST,PRBIEN
  1. ;
  1. ;Pull visit from context
  1. I VIEN="" D I VIEN="" Q "~@"_$NA(@TARGET)
  1. . NEW VST,X
  1. . I $T(GETVAR^CIAVMEVT)="" S @TARGET@(1,0)="Invalid context variables" Q
  1. . S VST=$$GETVAR^CIAVMEVT("ENCOUNTER.ID.ALTERNATEVISITID",,"CONTEXT.ENCOUNTER")
  1. . I VST="" S @TARGET@(1,0)="Invalid visit" Q
  1. . S X="BEHOENCX" X ^%ZOSF("TEST")
  1. . I $T S VST=+$$VSTR2VIS^BEHOENCX(DFN,VST) I VST<1 S @TARGET@(1,0)="Invalid visit" Q
  1. . S VIEN=VST
  1. ;
  1. ;Get the prenatal problems and visit
  1. ;
  1. I VIEN="" S @TARGET@(1,0)="No Visit Identified" Q "~@"_$NA(@TARGET)
  1. ;
  1. Q $$PIP^BJPNAPI2(TARGET,DFN,"A",1,VIEN,1,LNOTE,$G(PARM))