DGADDVAL ;ALB/JAM - UAM Address Validation ;28 May 2020 10:33 AM
;;5.3;Registration;**1014,1040**;Aug 13, 1993;Build 15
;
EN(DGINPUT,DGTYPE) ; Main entry point
; Input: DGINPUT (Required, pass by reference) - Array containing the address to be validated
; DGTYPE (optional) - Address Type: "R"-Residential "C"-Confidential "P"-Permanent (default)
; Output: DGINPUT (Pass by reference) - Array will contain the address accepted by the user
; Return: 0 - error has been encountered
; 1 - validation is completed and DGINPUT contains the accepted address
;
; Format of DGINPUT array
; DGINPUT(field#)=VALUE
;
; Note: For Residential and Perm Addresses:
; State VALUE = "STATENAME^STATECODE"
; Country VALUE = "COUNTRY^COUNTRYCODE"
; County VALUE = "COUNTY^COUNTYCODE
; For Confidential Addresses:
; State VALUE = "STATECODE^STATENAME"
; Country VALUE = "COUNTRYCODE^COUNTRY"
; County VALUE = "COUNTYCODE^COUNTY
;
N DGCNT,DGADDR,DGFLDS,DGFORGN,DGCTRYCD,DGSTR,DGX,DGRECS,DGSELADD,DGSTAT,DGSTATECD,DGTMOT
;
; Set up string of address field numbers - Format:
; "AddressLine1,AddressLine2,AddressLine3,City,State,County,Zip,Province,PostalCode^Country"
S DGFLDS=".111,.112,.113,.114,.115,.117,.1112,.1171,.1172,.1173" ; Permanent Address fields
I $G(DGTYPE)="R" S DGFLDS=".1151,.1152,.1153,.1154,.1155,.1157,.1156,.11571,.11572,.11573" ; Residential address fields
I $G(DGTYPE)="C" S DGFLDS=".1411,.1412,.1413,.1414,.1415,.14111,.1416,.14114,.14115,.14116" ; Confidential address fields
;
; All addresses are placed in the DGADDR array for user selection
; First address displayed is the address DGINPUT
S DGCNT=1
M DGADDR(DGCNT)=DGINPUT
; Normalize the Country and State entries for Conf address in DGADDR so the format is the same for all addresses in DGADDR array
I DGTYPE="C" D
. ; State may not be defined
. I $D(DGADDR(1,$P(DGFLDS,",",5))) S DGX=DGADDR(1,$P(DGFLDS,",",5)),DGADDR(1,$P(DGFLDS,",",5))=$P(DGX,"^",2)_"^"_$P(DGX,"^",1)
. S DGX=DGADDR(1,$P(DGFLDS,",",10)),DGADDR(1,$P(DGFLDS,",",10))=$P(DGX,"^",2)_"^"_$P(DGX,"^",1)
; Capture the State code passed in
S DGCTRYCD=$P(DGADDR(1,$P(DGFLDS,",",10)),"^",2)
; Get flag for domestic/foreign address
S DGFORGN=0
S DGFORGN=$$FORIEN^DGADDUTL(DGCTRYCD)
I 'DGFORGN S DGSTATECD=$P(DGADDR(1,$P(DGFLDS,",",5)),"^",2)
;
; Call the validation service
S DGSTAT=$$EN^DGUAMWS(.DGADDR,DGFLDS,DGFORGN) ; DGADDR is updated with address validation results
I +DGSTAT=0 QUIT DGSTAT
; get total records returned. Subtract one for the original.
S DGRECS=$O(DGADDR(""),-1)-1
F DGX=1:1:DGRECS D
. S DGCNT=DGCNT+1
. ; Store in this array entry the same country that was passed in
. S DGADDR(DGCNT,$P(DGFLDS,",",10))=DGADDR(1,$P(DGFLDS,",",10))
. I 'DGFORGN D
. . ; Store the same county that was passed in
. . S DGADDR(DGCNT,$P(DGFLDS,",",6))=DGADDR(1,$P(DGFLDS,",",6))
;
; Call DGEN ADDR VAL list to show addresses and allow user selection
S DGADDR=DGCNT
; DG*5.3*1040; Add DTMOUT param for Timeout in the subroutine
D EN^DGADDLST(DFN,DGFLDS,.DGADDR,.DGSELADD,.DGTMOT)
; DG*5.3*1040; If DGTMOT set, return -1 to flag that a timeout occurred
I +$G(DGTMOT) Q -1
; Move selected address into DGINPUT array
M DGINPUT=DGSELADD
; Put the State and Country fields back in DGINPUT to the format used for Conf addresses
I DGTYPE="C" D
. I $D(DGADDR(1,$P(DGFLDS,",",5))) D
. . S DGX=DGINPUT($P(DGFLDS,",",5)),DGINPUT($P(DGFLDS,",",5))=$P(DGX,"^",2)_"^"_$P(DGX,"^",1)
. . ; If the State code is empty, put the original State code in the array - Confidential Address needs the State code to file
. . I $P(DGINPUT($P(DGFLDS,",",5)),"^",1)="" S $P(DGINPUT($P(DGFLDS,",",5)),"^",1)=DGSTATECD
. S DGX=DGINPUT($P(DGFLDS,",",10)),DGINPUT($P(DGFLDS,",",10))=$P(DGX,"^",2)_"^"_$P(DGX,"^",1)
Q 1
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HDGADDVAL 3914 printed Dec 13, 2024@02:41:10 Page 2
DGADDVAL ;ALB/JAM - UAM Address Validation ;28 May 2020 10:33 AM
+1 ;;5.3;Registration;**1014,1040**;Aug 13, 1993;Build 15
+2 ;
EN(DGINPUT,DGTYPE) ; Main entry point
+1 ; Input: DGINPUT (Required, pass by reference) - Array containing the address to be validated
+2 ; DGTYPE (optional) - Address Type: "R"-Residential "C"-Confidential "P"-Permanent (default)
+3 ; Output: DGINPUT (Pass by reference) - Array will contain the address accepted by the user
+4 ; Return: 0 - error has been encountered
+5 ; 1 - validation is completed and DGINPUT contains the accepted address
+6 ;
+7 ; Format of DGINPUT array
+8 ; DGINPUT(field#)=VALUE
+9 ;
+10 ; Note: For Residential and Perm Addresses:
+11 ; State VALUE = "STATENAME^STATECODE"
+12 ; Country VALUE = "COUNTRY^COUNTRYCODE"
+13 ; County VALUE = "COUNTY^COUNTYCODE
+14 ; For Confidential Addresses:
+15 ; State VALUE = "STATECODE^STATENAME"
+16 ; Country VALUE = "COUNTRYCODE^COUNTRY"
+17 ; County VALUE = "COUNTYCODE^COUNTY
+18 ;
+19 NEW DGCNT,DGADDR,DGFLDS,DGFORGN,DGCTRYCD,DGSTR,DGX,DGRECS,DGSELADD,DGSTAT,DGSTATECD,DGTMOT
+20 ;
+21 ; Set up string of address field numbers - Format:
+22 ; "AddressLine1,AddressLine2,AddressLine3,City,State,County,Zip,Province,PostalCode^Country"
+23 ; Permanent Address fields
SET DGFLDS=".111,.112,.113,.114,.115,.117,.1112,.1171,.1172,.1173"
+24 ; Residential address fields
IF $GET(DGTYPE)="R"
SET DGFLDS=".1151,.1152,.1153,.1154,.1155,.1157,.1156,.11571,.11572,.11573"
+25 ; Confidential address fields
IF $GET(DGTYPE)="C"
SET DGFLDS=".1411,.1412,.1413,.1414,.1415,.14111,.1416,.14114,.14115,.14116"
+26 ;
+27 ; All addresses are placed in the DGADDR array for user selection
+28 ; First address displayed is the address DGINPUT
+29 SET DGCNT=1
+30 MERGE DGADDR(DGCNT)=DGINPUT
+31 ; Normalize the Country and State entries for Conf address in DGADDR so the format is the same for all addresses in DGADDR array
+32 IF DGTYPE="C"
Begin DoDot:1
+33 ; State may not be defined
+34 IF $DATA(DGADDR(1,$PIECE(DGFLDS,",",5)))
SET DGX=DGADDR(1,$PIECE(DGFLDS,",",5))
SET DGADDR(1,$PIECE(DGFLDS,",",5))=$PIECE(DGX,"^",2)_"^"_$PIECE(DGX,"^",1)
+35 SET DGX=DGADDR(1,$PIECE(DGFLDS,",",10))
SET DGADDR(1,$PIECE(DGFLDS,",",10))=$PIECE(DGX,"^",2)_"^"_$PIECE(DGX,"^",1)
End DoDot:1
+36 ; Capture the State code passed in
+37 SET DGCTRYCD=$PIECE(DGADDR(1,$PIECE(DGFLDS,",",10)),"^",2)
+38 ; Get flag for domestic/foreign address
+39 SET DGFORGN=0
+40 SET DGFORGN=$$FORIEN^DGADDUTL(DGCTRYCD)
+41 IF 'DGFORGN
SET DGSTATECD=$PIECE(DGADDR(1,$PIECE(DGFLDS,",",5)),"^",2)
+42 ;
+43 ; Call the validation service
+44 ; DGADDR is updated with address validation results
SET DGSTAT=$$EN^DGUAMWS(.DGADDR,DGFLDS,DGFORGN)
+45 IF +DGSTAT=0
QUIT DGSTAT
+46 ; get total records returned. Subtract one for the original.
+47 SET DGRECS=$ORDER(DGADDR(""),-1)-1
+48 FOR DGX=1:1:DGRECS
Begin DoDot:1
+49 SET DGCNT=DGCNT+1
+50 ; Store in this array entry the same country that was passed in
+51 SET DGADDR(DGCNT,$PIECE(DGFLDS,",",10))=DGADDR(1,$PIECE(DGFLDS,",",10))
+52 IF 'DGFORGN
Begin DoDot:2
+53 ; Store the same county that was passed in
+54 SET DGADDR(DGCNT,$PIECE(DGFLDS,",",6))=DGADDR(1,$PIECE(DGFLDS,",",6))
End DoDot:2
End DoDot:1
+55 ;
+56 ; Call DGEN ADDR VAL list to show addresses and allow user selection
+57 SET DGADDR=DGCNT
+58 ; DG*5.3*1040; Add DTMOUT param for Timeout in the subroutine
+59 DO EN^DGADDLST(DFN,DGFLDS,.DGADDR,.DGSELADD,.DGTMOT)
+60 ; DG*5.3*1040; If DGTMOT set, return -1 to flag that a timeout occurred
+61 IF +$GET(DGTMOT)
QUIT -1
+62 ; Move selected address into DGINPUT array
+63 MERGE DGINPUT=DGSELADD
+64 ; Put the State and Country fields back in DGINPUT to the format used for Conf addresses
+65 IF DGTYPE="C"
Begin DoDot:1
+66 IF $DATA(DGADDR(1,$PIECE(DGFLDS,",",5)))
Begin DoDot:2
+67 SET DGX=DGINPUT($PIECE(DGFLDS,",",5))
SET DGINPUT($PIECE(DGFLDS,",",5))=$PIECE(DGX,"^",2)_"^"_$PIECE(DGX,"^",1)
+68 ; If the State code is empty, put the original State code in the array - Confidential Address needs the State code to file
+69 IF $PIECE(DGINPUT($PIECE(DGFLDS,",",5)),"^",1)=""
SET $PIECE(DGINPUT($PIECE(DGFLDS,",",5)),"^",1)=DGSTATECD
End DoDot:2
+70 SET DGX=DGINPUT($PIECE(DGFLDS,",",10))
SET DGINPUT($PIECE(DGFLDS,",",10))=$PIECE(DGX,"^",2)_"^"_$PIECE(DGX,"^",1)
End DoDot:1
+71 QUIT 1