Skip to content

Commit

Permalink
feat: add camt.029 Case Assignment ID
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Dec 18, 2023
1 parent 68cc9e0 commit 318c5e4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/rtp/case_assignment.go
Original file line number Diff line number Diff line change
@@ -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)
}
23 changes: 23 additions & 0 deletions pkg/rtp/case_assignment_test.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 318c5e4

Please sign in to comment.