Maintain provider tax ID and sync TIN contact¶
clsProviderTaxID maintains a provider's tax identification records, keyed by the raw 9-digit TaxID. Once saved, the TIN value itself is immutable — only its display formatting may change — and only the record flagged primary is synchronized to Contact Manager through clsTaxApi.UpdateTinContact.
| Field | Value |
|---|---|
| Operation ID | OP-PRV-07 |
| Trigger | Caller calls NewProviderTaxID/GetProviderTaxID, edits properties, and calls Save() or Delete() |
| Inputs | ProviderSeqNum, TaxID/TaxIDDisplayDescr, RegisteredName, EffDate/ExpDate, W9SentDate/W9ReceivedDate, Report1099Flag, address fields, ForeignAddressFlag, PrimaryTaxIDFlag |
| Outputs | Persisted PROVIDER_TAX_ID row; ContactManager TaxDto sync for the primary TIN |
| Primary components | clsProviderTaxID.Create, BeforeInsert/BeforeUpdate/BeforeDelete, FillTinContact, clsTaxApi.UpdateTinContact |
| Entry point | Business\SAIF.Business.Provider\clsProviderTaxID.vb |
Steps¶
- Create.
Create()setsProviderSeqNumfrom the criteria and defaultsStateCode = "OR",CountryCode = "US". - Retrieve.
BeforeRetrievejoins PROVIDER_TAX_ID to PROVIDER onPROVIDER_SEQ_NUM, keyed by:TaxID(SQL-060).PrimaryTaxIDFlagis derived in SQL withDECODE(PROVIDER.PRIMARY_TAX_ID, PROVIDER_TAX_ID.TAX_ID, 'Y', 'N')rather than stored directly on the row.Fill()also storesm_RetrievedTaxIDfor the immutability check. - Validate before save.
MissingTIN/BR-011:ValidTINrequires a numeric value at least 9 digits long;ValidTINFormatrequires the formatted display to match00-0000000(EIN) or000-00-0000(SSN) exactly.- BR-025:
AlteredTINblocks changing the digits of an existing TIN (m_RetrievedTaxIDdiffers from the current value); only the display format may change. IsDuplicateTIN: hard error querying PROVIDER_TAX_ID for an existing row with the sameTAX_ID(BR-011).MissingRegisteredName: hard error requiringRegisteredName.ValidSentReceiptDate: hard error ifW9ReceivedDateprecedesW9SentDate;UnreasonableW9SentDate: hard error if the sent date is before 01/01/1850.- BR-012:
HasDuplicatePrimaryTaxIDblocks a save whenPrimaryTaxIDFlag = "Y"and another primary TIN already exists for the provider. ValidStatecode: hard error validatingStateCodeagainst theSTATEreference table;ValidZipCodeExt: hard error requiring a numeric ZIP+4 when present.ValidateCleanAddress(warning only): runs the same USPS cleansing service directly, ignoring USPS error code"10"; any remaining error surfaces"Warning: Address may not be valid."without blocking the save.- Foreign/domestic address side effects. Setting
ForeignAddressFlag = "Y"clears city/state/country/ZIP/ZIP+4; switching back to domestic clearsAddressLine4and resetsStateCode = "OR",CountryCode = "US". TheStateCodesetter itself derivesCountryCode: blank state clears the country, a nonblank state sets"US". - Insert.
BeforeInsertwritesTAX_ID,TAX_ID_DISPLAY_DESCR,PROVIDER_SEQ_NUM,REGISTERED_NAME/REGISTERED_NAME_UPPER_CASE,EFF_DATE/EXP_DATE,W9_SENT_DATE/W9_RECEIVED_DATE,REPORT_1099_FLAG, address fields,FOREIGN_ADDRESS_FLAG, and audit fields to PROVIDER_TAX_ID (SQL-036). FillTinContact()buildsTaxDto { providerNumber, tinId = TaxID, tinNumber = TaxIDDisplayDescr }.- On a rows-affected value other than
1: add"Insert Failed". - On success, only if
PrimaryTaxIDFlag = "Y": callclsTaxApi.UpdateTinContact(...)against routeprovider/{taxDto.ProviderNumber}/tin; on exception, serialize the DTO, log it, and addApiInsertError. - Update.
BeforeUpdatewrites the same fields to PROVIDER_TAX_ID (SQL-084) with concurrency check onUPDATE_NUM. - On success, if primary: call
clsTaxApi.UpdateTinContact(...); on API exception, log and addApiUpdateError. - Delete. Deletes the PROVIDER_TAX_ID row by
TAX_ID(SQL-106) — no ContactManager sync call is made on delete, unlike insert/update for the primary TIN.* - Payment-history helper (not gated by a rule).
HasPaymentcallsclsPaymentApi.GetPaymentstwice — once with an EIN-formatted TIN (00-0000000) and once with an SSN-formatted TIN (000-00-0000) — but no business rule in this file consumes the result, so it functions as an on-demand check available to callers rather than an enforced save-time gate.*
Process flow¶
flowchart TD
Start([Caller edits tax ID]) --> Altered{Existing TIN digits changed?}
Altered -->|Yes| Fail([Immutable TIN change<br>blocks save])
Altered -->|No| FormatCheck{Numeric, 9+ digits,<br>matches EIN/SSN mask?}
FormatCheck -->|No| Fail2([Invalid format or<br>duplicate blocks save])
FormatCheck -->|Yes| DupCheck{Duplicate TIN on file?}
DupCheck -->|Yes| Fail2
DupCheck -->|No| PrimaryCheck{Marked primary and<br>another primary exists?}
PrimaryCheck -->|Yes| Fail3([Second primary<br>TIN blocks save])
PrimaryCheck -->|No| Clean[Normalize address;<br>warning only]
Clean --> Persist[Insert/update/delete PROVIDER_TAX_ID]
Persist --> Rows{RowsAffected = 1?}
Rows -->|No| Contention([Insert Failed / DB contention error])
Rows -->|Yes| PrimaryFlag{PrimaryTaxIDFlag = Y?}
PrimaryFlag -->|Yes, insert/update| Api[Call clsTaxApi.UpdateTinContact]
PrimaryFlag -->|No, or delete| NoApi([No ContactManager call])
Api --> Done([Save complete])
NoApi --> Done
Failure and edge-case behavior¶
- Deleting a tax ID never calls ContactManager, so a removed TIN can remain visible there until a subsequent primary-TIN save elsewhere triggers a sync.*
- Only the primary TIN synchronizes to ContactManager; non-primary TIN inserts/updates persist to the database with no external side effect.
HasPaymentexists as a read-only helper but is not wired into any enforced business rule in this file, so its use is caller-driven.*- USPS address cleansing on a tax ID's mailing address is warning-only and never blocks the save, mirroring the pattern used for provider addresses.
Related documentation¶
Note: Statements marked with
*were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
Business\SAIF.Business.Provider\clsProviderTaxID.vbBusiness\SAIF.Business.Provider\Api\clsTaxApi.vbBusiness\SAIF.Business.Provider\Api\clsPaymentApi.vb