{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "https://dscsagovernance.org/dscsa-exception-notification-message-schemas/pdg-dscsa-exception-notification-draft-v1.0.1.json",
    "title": "PDG DSCSA TI Exception Notification Schema",
    "description": "Defines notifications of TI exceptions.",
    "type": "object",
    "properties": {
        "exceptionNotification": {
            "properties": {
                "exceptionNotificationSchemaOrTemplateVersion": {
                    "$ref": "#/definitions/schemaVersionType",
                    "$comment": "This is the JSON schema version.  Please check https://dscsagovernance.org/ to ensure you are using the latest version of this schema."
                },
                "dscsaCredentialPresentation": {
                    "$ref": "#/definitions/dscsaCredentialPresentationType",
                    "$comment": "A Presentation of the Notifier's ATP or ATP Equivalent Credential."
                },
                "notifyingOrganizationInformation": {
                    "type": "object",
                    "required": [
                        "contactInformation",
                        "notifyingOrganizationName"
                    ],
                    "properties": {
                        "notifyingOrganizationName": {
                            "type": "string",
                            "$comment": "The name of the organization making the exception notification."
                        },
                        "contactInformation": {
                            "$ref": "#/definitions/contactInformationType",
                            "$comment": "Information to aid the notified party in contacting the notifying party regarding the notification"
                        },
                        "notifyingPartyGLN": {
                            "$ref": "#/definitions/glnType",
                            "$comment": "The Global Location Number (GLN) of the Organization making the Notification."
                        }
                    },
                    "$comment": "Provide contact information to allow the Seller to follow up with a resolution or questions."
                },
                "notifiedOrganizationInformation": {
                    "type": "object",
                    "properties": {
                        "notifiedOrganizationName": {
                            "type": "string",
                            "$comment": "The name of the organization being notified of an exception."
                        },
                        "notifiedPartyGLN": {
                            "$ref": "#/definitions/glnType",
                            "$comment": "The Global Location Number (GLN) of the Organization being Notified of the exception."
                        }
                    },
                    "required": ["notifiedOrganizationName"]
                },
                "references": {
                    "type": "object",
                    "properties": {
                        "notificationID": {
                            "$ref": "#/definitions/uuidType",
                            "$comment": "This is a unique ID you have assigned to this notification.  The receiver of the notification can reference this ID in communications."
                        },
                        "timestamp": {
                            "$ref": "#/definitions/timestampType",
                            "$comment": "The date and time the notification was created.  "
                        },
                        "incidentID": {
                            "type": "string",
                            "$comment": "This is a unique ID the Notifier has assigned to the Incident.  The receiver of the notification can reference this ID in communications.  "
                        },
                        "shipmentID": {
                            "type": "string",
                            "$comment": "The Shipment ID from the shipment papers."
                        },
                        "purchaseOrderList": {
                            "type": "array",
                            "$comment": "The Purchase Order Number(s) associated with the shipment.",
                            "items": {"$ref": "#/definitions/purchaseOrderType"}
                        },
                        "shipmentReceiptDate": {
                            "$ref": "#/definitions/dateType",
                            "$comment": "The date the shipment was received by the Buyer. "
                        },
                        "carrierTrackingNumber": {
                            "type": "string",
                            "$comment": "The tracking number assigned by the carrier."
                        },
                        "exceptionLocation": {
                            "$comment": "The location in the Notifier's operation where the exception was first identified (receiving, picking, etc).",
                            "$ref": "#/definitions/exceptionLocationType"
                        },
                        "receivingLocationGLN": {
                            "$ref": "#/definitions/glnType",
                            "$comment": "The Global Location Number (GLN) of the receiving location."
                        },
                        "receivingLocationName": {"type": "string"},
                        "receivingLocationAddress": {
                            "$comment": "The street address of the receiving location.",
                            "$ref": "#/definitions/addressType"
                        }
                    },
                    "if": {
                        "properties": {
                            "exceptionLocation": {"const": "Other"}
                        }
                    },
                    "then": {
                        "properties": {
                            "exceptionLocationOther": {"type": "string"}
                        },
                        "required": ["exceptionLocationOther"]
                    },
                    "required": [
                        "notificationID",
                        "timestamp"
                    ],
                    "$comment": "Key information associated with the shipment and Exception Notification."
                },
                "exceptions": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "$comment": "repeats for each exception.",
                        "properties": {
                            "exceptionLineNumber": {
                                "type": "integer",
                                "$comment": "Used for reference between the Notifier and the organization receiving the notification."
                            },
                            "exceptionDescription": {
                                "$ref": "#/definitions/exceptionDescriptionType",
                                "$comment": "A short description of the exception(s) you have observed."
                            },
                            "buyerResolutionRequests": {
                                "type": "array",
                                "items": {
                                    "properties": {
                                        "buyerResolutionRequest": {
                                            "$ref": "#/definitions/buyerResolutionRequestType",
                                            "$comment": "Used if the notifying party is the Buyer.  This is a prefered resolution outcome of the Buyer.  Standard choices are provided in the enum list."
                                        }
                                    },
                                    "if": {
                                        "properties": {
                                            "buyerResolutionRequest": {"const": "Other"}
                                        }
                                    },
                                    "then": {
                                        "properties": {
                                            "buyerResolutionRequestOther": {"type": "string"}
                                        },
                                        "required": ["buyerResolutionRequestOther"]
                                    }
                                },
                                "$comment": "Used if the notifying party is the Buyer.  These are the prefered resolution outcome(s) of the Buyer.  Standard choices are provided in the enum list."
                            },
                            "buyerActionTaken": {
                                "$ref": "#/definitions/buyerActionTakenType",
                                "$comment": "Used if the notifying party is the Buyer.  This is the action that the Buyer has already taken due to the exception.  Standard choices are provided in the enum list."
                            },
                            "sellerResolutionRequests": {
                                "type": "array",
                                "items": {
                                    "properties": {
                                        "sellerResolutionRequest": {
                                            "$ref": "#/definitions/sellerResolutionRequestType",
                                            "$comment": "Used if the notifying party is the Seller.  This is a prefered resolution outcome of the Seller.  Standard choices are provided in the enum list."
                                        }
                                    },
                                    "if": {
                                        "properties": {
                                            "sellerResolutionRequest": {"const": "Other"}
                                        }
                                    },
                                    "then": {
                                        "properties": {
                                            "sellerResolutionRequestOther": {"type": "string"}
                                        },
                                        "required": ["sellerResolutionRequestOther"]
                                    }
                                },
                                "$comment": "Used if the notifying party is the Seller.  These are the prefered resolution outcome(s) of the Seller.  Standard choices are provided in the enum list."
                            },
                            "sellerActionTaken": {
                                "$ref": "#/definitions/sellerActionTakenType",
                                "$comment": "Used if the notifying party is the Seller.  This is the action that the Seller has already taken due to the exception.  Standard choices are provided in the enum list."
                            },
                            "exceptionAppliesTo": {
                                "$ref": "#/definitions/exceptionAppliesToType",
                                "$comment": "This exception applies to either the entire shipment or certain products in the shipment.   Standard choices are provided in the enum list."
                            },
                            "exceptionPriority": {
                                "$ref": "#/definitions/exceptionPriorityType",
                                "$comment": "The priority the notifier has assigned to this notification.  Standard choices are provided in the enum list."
                            },
                            "exceptionStatus": {
                                "$ref": "#/definitions/exceptionStatusType",
                                "$comment": "The status the notifier has assigned to this notification.   Standard choices are provided in the enum list."
                            },
                            "exceptionCategoryList": {
                                "type": "array",
                                "items": {
                                    "properties": {
                                        "exceptionCategory": {
                                            "$ref": "#/definitions/exceptionCategoryType",
                                            "$comment": "The category the notifier has assigned to this notification.   Standard choices are provided in the enum list."
                                        }
                                    },
                                    "if": {
                                        "properties": {
                                            "exceptionCategory": {"const": "Other"}
                                        }
                                    },
                                    "then": {
                                        "properties": {
                                            "exceptionCategoryOther": {"type": "string"}
                                        },
                                        "required": ["exceptionCategoryOther"]
                                    }
                                },
                                "$comment": "The categories the notifier has assigned to this notification.   Standard choices are provided in the enum list."
                            },
                            "exceptionTypeList": {
                                "type": "array",
                                "items": {
                                    "properties": {
                                        "exceptionType": {
                                            "$ref": "#/definitions/exceptionTypeType",
                                            "$comment": "An exception type the notifier has assigned to this notification (usually a further refinement of the category).   Standard choices are provided in the enum list."
                                        }
                                    },
                                    "if": {
                                        "properties": {
                                            "exceptionType": {"const": "Other"}
                                        }
                                    },
                                    "then": {
                                        "properties": {
                                            "exceptionTypeOther": {"type": "string"}
                                        },
                                        "required": ["exceptionTypeOther"]
                                    }
                                },
                                "$comment": "The exception type(s) the notifier has assigned to this notification (usually a further refinement of the category).   Standard choices are provided in the enum list."
                            },
                            "InformationOnPhysicalProduct": {
                                "type": "object",
                                "properties": {
                                    "sscc": {
                                        "type": "string",
                                        "$comment": "The Serial Shipping Container Code (SSCC) found in the Transaction Information (TI) sent by the Seller."
                                    },
                                    "drugProductInformation": {
                                        "$ref": "#/definitions/drugProductType",
                                        "$comment": "Information about the drug product (master data)."
                                    },
                                    "physicalProductNotes": {
                                        "type": "string",
                                        "$comment": "Any additional notes about the physical product or packaging."
                                    }
                                },
                                "$comment": "These fields apply to the physical product in the shipment.  This data is found on the product itself. "
                            },
                            "InformationReceivedOrSent": {
                                "type": "object",
                                "properties": {
                                    "sscc": {
                                        "type": "string",
                                        "$comment": "The Serial Shipping Container Code (SSCC) found in the Transaction Information (TI) sent by the Seller."
                                    },
                                    "drugProductInformation": {
                                        "$ref": "#/definitions/drugProductType",
                                        "$comment": "Information provided by the Seller in the Transaction Information."
                                    },
                                    "dataNotes": {
                                        "type": "string",
                                        "$comment": "Any additional notes about the Transaction Information or Transaction Statement."
                                    }
                                },
                                "$comment": "These fields apply to the date in the Transaction Information (TI) or Transaction Statement (TS) associated with the shipment."
                            }
                        },
                        "allOf": [
                            {
                                "if": {
                                    "properties": {
                                        "buyerActionTaken": {"const": "Other"}
                                    }
                                },
                                "then": {
                                    "properties": {
                                        "buyerActionTakenOther": {"type": "string"}
                                    },
                                    "required": ["buyerActionTakenOther"]
                                }
                            },
                            {
                                "if": {
                                    "properties": {
                                        "sellerActionTaken": {"const": "Other"}
                                    },
                                    "required": ["sellerActionTaken"]
                                },
                                "then": {
                                    "required": ["sellerActionTakenOther"]
                                }
                            },
                            {
                                "if": {
                                    "properties": {
                                        "exceptionAppliesTo": {"const": "Other"}
                                    }
                                },
                                "then": {
                                    "properties": {
                                        "exceptionAppliesToOther": {"type": "string"}
                                    },
                                    "required": ["exceptionAppliesToOther"]
                                }
                            },
                            {
                                "if": {
                                    "properties": {
                                        "exceptionPriority": {"const": "Other"}
                                    }
                                },
                                "then": {
                                    "properties": {
                                        "exceptionPriorityOther": {"type": "string"}
                                    },
                                    "required": ["exceptionPriorityOther"]
                                }
                            },
                            {
                                "if": {
                                    "properties": {
                                        "exceptionStatus": {"const": "Other"}
                                    }
                                },
                                "then": {
                                    "properties": {
                                        "exceptionStatusOther": {"type": "string"}
                                    },
                                    "required": ["exceptionStatusOther"]
                                }
                            }
                        ],
                        "required": []
                    },
                    "minItems": 1,
                    "$comment": "Documentation of the issues observed by the Notifier about the shipment, product, or information provided by the Seller."
                },
                "exceptionAdditionalInformation": {
                    "type": "object",
                    "properties": {
                        "additionalInformationLinkList": {
                            "type": "array",
                            "items": {
                                "properties": {
                                    "additionalInformationLink": {"$ref": "#/definitions/additionalInformationLinkType"}
                                }
                            },
                            "$comment": "List the addresses to documents or files that are related to this notification."
                        },
                        "additionalInformationBase64List": {
                            "type": "array",
                            "items": {
                                "properties": {
                                    "additionalInformationBase64": {"$ref": "#/definitions/additionalInformationBase64Type"}
                                }
                            },
                            "$comment": "Documents or files encoded in Base 64 associated with this notification."
                        }
                    },
                    "$comment": "Additional documents or images sent or available concerning this Exception Notification."
                }
            },
            "type": "object",
            "required": [
                "exceptionNotificationSchemaOrTemplateVersion",
                "references",
                "exceptions",
                "notifyingOrganizationInformation",
                "notifiedOrganizationInformation"
            ],
            "$comment": "The primary container for all exception-related data, including actions taken by the buyer and seller, product details, and status of the exception."
        }
    },
    "definitions": {
        "additionalInformationBase64Type": {
            "type": "string",
            "contentEncoding": "base64",
            "description": "This property can hold base64 encoded data of various image and document formats (e.g., PNG, JPG, PDF).",
            "$comment": "Documents or files encoded in Base 64 associated with this notification.",
            "pattern": "^[A-Za-z0-9+/]+={0,2}$"
        },
        "additionalInformationLinkType": {
            "type": "string",
            "format": "uri",
            "$comment": "List the addresses to documents or files that are related to this notification."
        },
        "addressType": {
            "type": "object",
            "properties": {
                "streetAddressLine1": {
                    "type": "string",
                    "pattern": "^[0-9a-zA-Z ]*$",
                    "$comment": "Represents the name of the street or road."
                },
                "streetAddressLine2": {
                    "type": "string",
                    "pattern": "^[0-9a-zA-Z ]*$",
                    "$comment": "Optional additional address information"
                },
                "city": {
                    "type": "string",
                    "$comment": "The name of the town or city. If overseas military location, use \"APO\", \"FPO\", \"DPO\"",
                    "pattern": "^[A-Za-z .'\\\\-]+$"
                },
                "stateProvinceOrRegion": {
                    "anyOf": [
                        {
                            "enum": [
                                "AL",
                                "AK",
                                "AZ",
                                "AR",
                                "CA",
                                "CO",
                                "CT",
                                "DE",
                                "FL",
                                "GA",
                                "HI",
                                "ID",
                                "IL",
                                "IN",
                                "IA",
                                "KS",
                                "KY",
                                "LA",
                                "ME",
                                "MD",
                                "MA",
                                "MI",
                                "MN",
                                "MS",
                                "MO",
                                "MT",
                                "NE",
                                "NV",
                                "NH",
                                "NJ",
                                "NM",
                                "NY",
                                "NC",
                                "ND",
                                "OH",
                                "OK",
                                "OR",
                                "PA",
                                "RI",
                                "SC",
                                "SD",
                                "TN",
                                "TX",
                                "UT",
                                "VT",
                                "VA",
                                "WA",
                                "WV",
                                "WI",
                                "WY",
                                "DC",
                                "AS",
                                "GU",
                                "MP",
                                "PR",
                                "VI",
                                "UM",
                                "AA",
                                "AE",
                                "AP"
                            ]
                        },
                        {"type": "string"}
                    ],
                    "$comment": "The state, province, or region using the standard two-letter abbreviation specified in ISO 3166-2:1998 country subdivision code."
                },
                "postalCode": {
                    "type": "string",
                    "$comment": "Alphanumeric code assigned by postal authorities for sorting and delivering mail."
                },
                "countryCode": {
                    "type": "string",
                    "$comment": "The country using the standard two-letter abbreviation specified in ISO 3166-1 alpha-2 list of 2-letter country codes.",
                    "maxLength": 2,
                    "minLength": 2
                }
            },
            "required": [
                "streetAddressLine1",
                "city",
                "stateProvinceOrRegion",
                "postalCode",
                "countryCode"
            ]
        },
        "buyerActionTakenType": {
            "type": "string",
            "enum": [
                "Product has been returned",
                "Shipment has been refused"
            ]
        },
        "buyerResolutionRequestType": {
            "type": "string",
            "enum": [
                "Send Corrected Data",
                "Send Product",
                "Return Product",
                "Credit Account",
                "Debit Account"
            ],
            "$comment": "Used if the notifying party is the Buyer.  This is a prefered resolution outcome of the Buyer.  Standard choices are provided in the enum list."
        },
        "contactInformationType": {
            "properties": {
                "personOrDepartmentName": {
                    "$ref": "#/definitions/nameValueType",
                    "$comment": "The person or Department that can be contacted regarding the Exception Notification."
                },
                "organizationName": {
                    "$ref": "#/definitions/nameValueType",
                    "$comment": "Name of organization sending the Notification."
                },
                "phone": {
                    "$ref": "#/definitions/phoneType",
                    "$comment": "The phone number of the Notifying party."
                },
                "email": {
                    "$ref": "#/definitions/emailType",
                    "$comment": "The email address of the Notifying party."
                }
            },
            "type": "object",
            "required": [
                "personOrDepartmentName",
                "organizationName",
                "phone",
                "email"
            ],
            "$comment": "Information to aid the Requester or Responder in contacting the other party in regard to the Request or Response."
        },
        "dateType": {
            "type": "string",
            "maxLength": 10,
            "minLength": 10,
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
            "format": "date"
        },
        "drugProductType": {
            "type": "object",
            "properties": {
                "gtin": {
                    "type": "string",
                    "$comment": "The Global Trade Item Number (GTIN) found on the product label, in the product Data Matrix barcode or in the Transaction Information."
                },
                "ndc": {
                    "type": "string",
                    "$comment": "The National Drug Code (NDC) found on the product label or in the Transaction Information."
                },
                "drugName": {
                    "type": "string",
                    "$comment": "The Drug Name found on the product label or in the Transaction Information."
                },
                "lotNumber": {
                    "type": "string",
                    "$comment": "The Lot Number found on the product label or in the Transaction Information."
                },
                "expirationDate": {
                    "type": "string",
                    "$comment": "The Expiration Date found on the product label or in the Transaction Information."
                },
                "serialNumberList": {
                    "type": "array",
                    "items": {
                        "properties": {
                            "serialNumber": {
                                "type": "string",
                                "$comment": "A Serial Number found on the product label, product Data Matrix barcode or Transaction Information."
                            },
                            "barcodeScan": {
                                "type": "string",
                                "$comment": "The barcode scan of the Data Matrix barcode on the product label associated with the gtin, lotNumber expirationDate and serialNumber combination (Product Identifier)."
                            }
                        }
                    },
                    "$comment": "The Serial Number(s) found on the product label(s), the product Data Matrix barcode(s) or Transaction Information record(s)."
                }
            }
        },
        "dscsaCredentialPresentationType": {
            "type": "object",
            "properties": {
                "dscsaATPCredentialPresentation": {
                    "type": "string",
                    "format": "jwt",
                    "$comment": "A W3C standard verifiable credential conformant to the OCI DSCSA ATP Credential specification."
                },
                "dscsaATP-EquivalentCredentialPresentation": {
                    "type": "string",
                    "format": "jwt",
                    "$comment": "A W3C standard verifiable credential conformant with the OCI DSCSA ATP Equivalent Credential specification."
                },
                "dscsaAuthorityCredentialPresentation": {
                    "type": "string",
                    "format": "jwt",
                    "$comment": "A W3C standard verifiable credential conformant with the OCI DSCSA Authority Credential specification."
                }
            },
            "oneOf": [
                {
                    "required": ["dscsaATPCredentialPresentation"]
                },
                {
                    "required": ["dscsaATP-EquivalentCredentialPresentation"]
                },
                {
                    "required": ["dscsaAuthorityCredentialPresentation"]
                }
            ],
            "$comment": "Requester or Responder signed presentation of an ATP, ATP-Equivalent or DSCSA Authority credential. See latest OCI Schema Version."
        },
        "emailType": {
            "type": "string",
            "format": "email"
        },
        "exceptionAppliesToType": {
            "type": "string",
            "enum": [
                "Entire Shipment",
                "Items in Shipment"
            ],
            "$comment": "This exception applies to either the entire shipment or certain products in the shipment.   Standard choices are provided in the enum list."
        },
        "exceptionCategoryType": {
            "type": "string",
            "enum": [
                "Data Issue",
                "Damaged Product",
                "Product No Data",
                "Data No Product",
                "Packaging and Labeling",
                "Other"
            ],
            "$comment": "The category the notifier has assigned to this notification.   Standard choices are provided in the enum list."
        },
        "exceptionDescriptionType": {"type": "string"},
        "exceptionLocationType": {
            "type": "string",
            "enum": [
                "Receiving",
                "Outbound Picking",
                "Returns Processing",
                "Reconciliation",
                "Other"
            ]
        },
        "exceptionPriorityType": {
            "type": "string",
            "enum": [
                "High",
                "Medium",
                "Low"
            ],
            "$comment": "The priority the notifier has assigned to this notification.  Standard choices are provided in the enum list."
        },
        "exceptionStatusType": {
            "type": "string",
            "enum": [
                "Open",
                "In Progress",
                "In Review",
                "Pending Response",
                "Cancelled",
                "Resolved",
                "Closed"
            ],
            "$comment": "The status the notifier has assigned to this notification.   Standard choices are provided in the enum list."
        },
        "exceptionTypeType": {
            "type": "string",
            "$comment": "An exception type the notifier has assigned to this notification (usually a further refinement of the category).   Standard choices are provided in the enum list.",
            "enum": [
                "Barcode Reading Issue",
                "Barcode Encoding Issue",
                "Certificate Issue",
                "Duplicate EPCIS Events",
                "EPCIS Event Formatting Issue",
                "EPCIS Event Timestamp Sequence",
                "Missing Attributes",
                "Missing EPCIS Events",
                "Unrecognized Buyer GCP and/or GLN",
                "Unrecognized Seller GCP and/or GLN",
                "Unrecognized Product Information",
                "Unrecognized Seller",
                "Unrecognized Buyer",
                "Unrecognized P.O. #",
                "Other"
            ]
        },
        "glnType": {
            "type": "string",
            "minLength": 13,
            "pattern": "^\\d{13}$",
            "maxLength": 13,
            "$comment": "The GS1 Global Location Number (GLN) as recorded in the TI record. See Implementation Guideline: Applying GS1 Standards for DSCSA and Traceability."
        },
        "nameValueType": {
            "type": "string",
            "pattern": "^[\\p{L}\\s.'-]+$"
        },
        "phoneType": {
            "type": "string",
            "$comment": "The phone number of the Requester or Responder."
        },
        "purchaseOrderType": {"type": "string"},
        "sellerActionTakenType": {
            "type": "string",
            "enum": [
                "Credit Applied",
                "RMA Sent",
                "Other"
            ],
            "$comment": "Used if the notifying party is the Seller.  This is the action that the Seller has already taken due to the exception.  Standard choices are provided in the enum list."
        },
        "sellerResolutionRequestType": {
            "type": "string",
            "enum": ["Send Back Product"]
        },
        "schemaVersionType": {
            "type": "string",
            "description": "Exception Notification Schema Version. ",
            "default": "1.0.1",
            "pattern": "^[0-9]{1}.[0-9]{1}.[0-9]{1}$"
        },
        "timestampType": {
            "$comment": "A timestamp to millisecond precision, with an explicit timezone indicator (+/‐hh:mm) relative to UTC  Use 00 for miliseconds if you are unable to be percise at that level.",
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$",
            "format": "date-time"
        },
        "uuidType": {
            "type": "string",
            "pattern": "^[a-fA-F\\d]{8}-[a-fA-F\\d]{4}-4[a-fA-F\\d]{3}-[89abAB][a-fA-F\\d]{3}-[a-fA-F\\d]{12}$",
            "$comment": "Universally Unique Identifier (UUID)"
        }
    },
    "required": ["exceptionNotification"],
    "$comment": "This JSON Schema defines the structure for managing DSCSA exception notifications within the pharmaceutical supply chain. It helps ensure data consistency and validation across all parties involved in an exception."
}