-
Notifications
You must be signed in to change notification settings - Fork 1
/
ISA.fs
154 lines (117 loc) · 4.68 KB
/
ISA.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//
// Author:
// evan <>
//
// Copyright (c) 2016 evan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
module BrandX.ISA
open FParsec
open BrandX.Structures
open System
// Parse a record like:
//
// ISA*00* *00* *ZZ*MGCTLYST *02*BLNJ *160930*1453*U*00401*000000001*0*P*:
//
// ISA-01: The Authorization Qualifier
type AuthQual = AQNone
// We only have one of these anyway
let pAuthQual : Parser<AuthQual> = stringReturn "00" AQNone .>> pFSep
//ISA-02: this is 10 chars, may be whitespace
type AuthInfo =
| AuthInfo of string
let pAuthInfo : Parser<AuthInfo> = anyString 10 |>> AuthInfo .>> pFSep
// The Authorization Qualifier and Info
type Auth =
{ authQual : AuthQual
authInfo : AuthInfo }
let pAuth =
pipe2 pAuthQual pAuthInfo (fun q i ->
{ authQual = q
authInfo = i })
// The Security Info Qualifier
type SecQual = SQNone
//ISA-03
let pSecQual : Parser<SecQual> = stringReturn "00" SQNone .>> pFSep
type SecInfo =
| SecInfo of string
//ISA-04
let pSecInfo : Parser<SecInfo> = anyString 10 |>> SecInfo .>> pFSep
// The Security Info Qualifier and stuff
type Sec =
{ secQual : SecQual
secInfo : SecInfo }
let pSec =
pipe2 pSecQual pSecInfo (fun q i ->
{ secQual = q
secInfo = i })
// ISA-05: The Interchange ID Qualifier
type InterchangeID = InterchangeID of string
let pInterchgeID = anyString 2 |>> InterchangeID .>> pFSep
// ISA-06: The Interchange Sender ID
type InterchgSndrID = InterchgSndrID of string
let pInterchgSndrId = anyString 15 |>> InterchgSndrID .>> pFSep
// ISA-07 is exactly the same as ISA-05 in the MG-EDI pdf manual
type InterchgIdQual = InterchgIdQual of string
let pInterchgIdQual = anyString 2 |>> InterchgIdQual .>> pFSep
//ISA-08: The Interchange Receiver ID
type InterchgRecvrID = InterchgRecvrID of string
let pInterchgRcvId = anyString 15 |>> InterchgRecvrID .>> pFSep
//ISA-09/ISA-10: Interchange Date/Time
type InterchgDateTime = InterchgDateTime of DateTime
let pInterchgDateTime = pDateTime |>> InterchgDateTime
//ISA-11: Interchange Control Standards Identifier
type InterchgCtrlStds = InterchgCtrlStds of string
let pInterchgCtrlStds<'T, 'u> = anyString 1 |>> InterchgCtrlStds .>> pFSep
//ISA-12: Interchange Control Version Number
type InterchgCtrlVerNo = InterchgCtrlVerNo of string
let pInterchgCtrlVerNo = anyString 5 |>> InterchgCtrlVerNo .>> pFSep
//ISA-13: Interchange Control Number
type InterchgCtrlNo = InterchgCtrlNo of string
let pInterchgCtrlNo = anyString 9 |>> InterchgCtrlNo .>> pFSep
//ISA-14: Acknowledgement Requested
type AckReq = AckReq of string
let pAckReq = anyString 1 |>> AckReq .>> pFSep
//ISA-15: Usage Indicator
type UsageInd = UsageInd of string
let pUsageInd = anyString 1 |>> UsageInd .>> pFSep
type ISA =
| ISA of Auth * Sec * InterchangeID * InterchgSndrID * InterchgIdQual * InterchgRecvrID * InterchgDateTime * InterchgCtrlStds * InterchgCtrlVerNo * InterchgCtrlNo * AckReq * UsageInd
let pISA =
pAuth
>>= fun a ->
pSec
>>= fun b ->
pInterchgeID
>>= fun c ->
pInterchgSndrId
>>= fun d ->
pInterchgIdQual
>>= fun e ->
pInterchgRcvId
>>= fun f ->
pInterchgDateTime
>>= fun g ->
pInterchgCtrlStds
>>= fun i ->
pInterchgCtrlVerNo
>>= fun j ->
pInterchgCtrlNo
>>= fun k ->
pAckReq
>>= fun l ->
pUsageInd
>>= fun m ->
preturn (ISA(a, b, c, d, e, f, g, i, j, k, l, m))
let pISARec = skipString "ISA" >>. pFSep >>. pISA .>> pElSep .>> pRSep