From 318c5e49a6d9439147175fe7fcadf400ce8a0d2f Mon Sep 17 00:00:00 2001 From: Adam Shannon Date: Mon, 18 Dec 2023 15:17:56 -0600 Subject: [PATCH] feat: add camt.029 Case Assignment ID --- pkg/rtp/case_assignment.go | 25 +++++++++++++++++++++++++ pkg/rtp/case_assignment_test.go | 23 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 pkg/rtp/case_assignment.go create mode 100644 pkg/rtp/case_assignment_test.go diff --git a/pkg/rtp/case_assignment.go b/pkg/rtp/case_assignment.go new file mode 100644 index 0000000..5bfef42 --- /dev/null +++ b/pkg/rtp/case_assignment.go @@ -0,0 +1,25 @@ +package rtp + +import ( + "fmt" + "time" +) + +// CaseAssignmentID generates an Assignment Identifier for a Case. +// This is used in camt.029 responses. +// +// Format: MYYYYMMDDbbbbbbbbbbbBAAAnnnnnnnnnnn +// Pos. 01-01 – Prefix ‘M’ +// Pos. 02-09 - File creation date in format YYYYMMDD +// Pos. 10-20 - Participant ID (11 characters) +// Pos. 21-21 - Message generation source ("B" if generated by a Participant) +// Pos. 22-24 - Discretionary bank field (3 digit alpha numeric that can be used to serialize, identify specific systems, etc.) +// Pos. 25-35 - Message serial number (11 numeric characters) +func CaseAssignmentID(ts time.Time, participantID, bankField string) string { + timestamp := ts.Format("20060102") + partID := fmt.Sprintf("%011.11s", participantID) + bank := fmt.Sprintf("%03.3s", bankField) + serial := NumericSerialNumber(11) + + return fmt.Sprintf("M%s%sB%s%011.11s", timestamp, partID, bank, serial) +} diff --git a/pkg/rtp/case_assignment_test.go b/pkg/rtp/case_assignment_test.go new file mode 100644 index 0000000..e744d32 --- /dev/null +++ b/pkg/rtp/case_assignment_test.go @@ -0,0 +1,23 @@ +package rtp_test + +import ( + "regexp" + "testing" + "time" + + "github.com/moov-io/rtp20022/pkg/rtp" + + "github.com/stretchr/testify/require" +) + +func TestCaseAssignment(t *testing.T) { + eastern, _ := time.LoadLocation("America/New_York") + when := time.Date(2015, time.November, 15, 0, 30, 0, 0, eastern) + participantID := "11021200201" + + caseAssignmentID := rtp.CaseAssignmentID(when, participantID, "FFF") + require.Contains(t, caseAssignmentID, "M2015111511021200201BFFF") + + rr := regexp.MustCompile(`^M[0-9]{4}(((01|03|05|07|08|10|12)((0[1-9])|([1-2][0-9])|(3[0-1])))|((04|06|09|11)((0[1-9])|([1-2][0-9])|30))|((02)((0[1-9])|([1-2][0-9]))))[A-Z0-9]{11}.*$`) + require.True(t, rr.MatchString(caseAssignmentID)) +}