x12_alt 0.1.0

Data types for X12 EDI
Documentation
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
use std::fmt;
use serde::{de, Deserialize, ser, Serialize};
/**1166

See docs at <https://www.stedi.com/edi/x12-005010/element/1166>*/
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ContractTypeCode {
    ///01 - Diagnosis Related Group (DRG)
    Code01,
    ///02 - Per Diem
    PerDiem,
    ///03 - Variable Per Diem
    VariablePerDiem,
    ///04 - Flat
    Flat,
    ///05 - Capitated
    Capitated,
    ///06 - Percent
    Percent,
    ///09 - Other
    Other,
    ///AB - Negotiated Growing Equity Mortgage (GEM)
    CodeAB,
    ///AC - Anticipated Contract
    AnticipatedContract,
    ///AD - Federal Housing Authority Adjustable Rate Mortgage
    FederalHousingAuthorityAdjustableRateMortgage,
    ///AE - Federal Housing Authority Veterans Affairs Fixed Rate Mortgage (including standard Growing Equity Mortgages)
    CodeAE,
    ///AF - Conventional Second Mortgages
    ConventionalSecondMortgages,
    ///AG - Conventional Fixed Rate Mortgages
    ConventionalFixedRateMortgages,
    ///AH - Federal Housing Authority Veterans Affairs Graduated Payment Mortgage
    FederalHousingAuthorityVeteransAffairsGraduatedPaymentMortgage,
    ///AI - Negotiated Conventional, Graduated Payment, or Step Rate Mortgage
    CodeAI,
    ///AJ - Conventional Adjustable Rate Mortgage
    ConventionalAdjustableRateMortgage,
    ///CA - Cost Plus Incentive Fee (With Performance Incentives)
    CodeCA,
    ///CB - Cost Plus Incentive Fee (Without Performance Incentives)
    CodeCB,
    ///CH - Cost Sharing
    CostSharing,
    ///CP - Cost Plus
    CostPlus,
    ///CS - Cost
    Cost,
    ///CW - Cost Plus Award Fee
    CostPlusAwardFee,
    ///CX - Cost Plus Fixed Fee
    CostPlusFixedFee,
    ///CY - Cost Plus Incentive Fee
    CostPlusIncentiveFee,
    ///DI - Distributor
    Distributor,
    ///EA - Exclusive Agency
    ExclusiveAgency,
    ///ER - Exclusive Right
    ExclusiveRight,
    ///FA - Firm or Actual Contract
    FirmOrActualContract,
    ///FB - Fixed Price Incentive Firm Target (With Performance Incentive)
    CodeFB,
    ///FC - Fixed Price Incentive Firm Target (Without Performance Incentive)
    CodeFC,
    ///FD - Fixed Price Redetermination
    FixedPriceRedetermination,
    ///FE - Fixed Price with Escalation
    FixedPriceWithEscalation,
    ///FF - Fixed Price Incentive Successive Target (With Performance Incentive)
    CodeFF,
    ///FG - Fixed Price Incentive Successive Target (Without Performance Incentive)
    CodeFG,
    ///FH - Fixed Price Award Fee
    FixedPriceAwardFee,
    ///FI - Fixed Price Incentive
    FixedPriceIncentive,
    ///FJ - Fixed Price Level of Effort
    FixedPriceLevelOfEffort,
    ///FK - No Cost
    NoCost,
    ///FL - Flat Amount
    FlatAmount,
    ///FM - Retroactive Fixed Price Redetermination
    RetroactiveFixedPriceRedetermination,
    ///FR - Firm Fixed Price
    FirmFixedPrice,
    ///FX - Fixed Price with Economic Price Adjustment
    FixedPriceWithEconomicPriceAdjustment,
    ///LA - Labor
    Labor,
    ///LE - Level of Effort
    LevelOfEffort,
    ///LH - Labor Hours
    LaborHours,
    ///OC - Other Contract Type
    OtherContractType,
    ///PR - Prospect Reservation
    ProspectReservation,
    ///SP - Same Percentage as Film Rental Earned (SPFRE)
    CodeSP,
    ///TM - Time and Materials
    TimeAndMaterials,
    ///ZZ - Mutually Defined
    MutuallyDefined,
}
impl ContractTypeCode {
    pub fn code(&self) -> &str {
        {
            use ContractTypeCode::*;
            match self {
                Code01 => "01",
                PerDiem => "02",
                VariablePerDiem => "03",
                Flat => "04",
                Capitated => "05",
                Percent => "06",
                Other => "09",
                CodeAB => "AB",
                AnticipatedContract => "AC",
                FederalHousingAuthorityAdjustableRateMortgage => "AD",
                CodeAE => "AE",
                ConventionalSecondMortgages => "AF",
                ConventionalFixedRateMortgages => "AG",
                FederalHousingAuthorityVeteransAffairsGraduatedPaymentMortgage => "AH",
                CodeAI => "AI",
                ConventionalAdjustableRateMortgage => "AJ",
                CodeCA => "CA",
                CodeCB => "CB",
                CostSharing => "CH",
                CostPlus => "CP",
                Cost => "CS",
                CostPlusAwardFee => "CW",
                CostPlusFixedFee => "CX",
                CostPlusIncentiveFee => "CY",
                Distributor => "DI",
                ExclusiveAgency => "EA",
                ExclusiveRight => "ER",
                FirmOrActualContract => "FA",
                CodeFB => "FB",
                CodeFC => "FC",
                FixedPriceRedetermination => "FD",
                FixedPriceWithEscalation => "FE",
                CodeFF => "FF",
                CodeFG => "FG",
                FixedPriceAwardFee => "FH",
                FixedPriceIncentive => "FI",
                FixedPriceLevelOfEffort => "FJ",
                NoCost => "FK",
                FlatAmount => "FL",
                RetroactiveFixedPriceRedetermination => "FM",
                FirmFixedPrice => "FR",
                FixedPriceWithEconomicPriceAdjustment => "FX",
                Labor => "LA",
                LevelOfEffort => "LE",
                LaborHours => "LH",
                OtherContractType => "OC",
                ProspectReservation => "PR",
                CodeSP => "SP",
                TimeAndMaterials => "TM",
                MutuallyDefined => "ZZ",
            }
        }
    }
    pub fn from_code(code: &[u8]) -> Option<ContractTypeCode> {
        use ContractTypeCode::*;
        match code {
            b"01" => Some(Code01),
            b"02" => Some(PerDiem),
            b"03" => Some(VariablePerDiem),
            b"04" => Some(Flat),
            b"05" => Some(Capitated),
            b"06" => Some(Percent),
            b"09" => Some(Other),
            b"AB" => Some(CodeAB),
            b"AC" => Some(AnticipatedContract),
            b"AD" => Some(FederalHousingAuthorityAdjustableRateMortgage),
            b"AE" => Some(CodeAE),
            b"AF" => Some(ConventionalSecondMortgages),
            b"AG" => Some(ConventionalFixedRateMortgages),
            b"AH" => Some(FederalHousingAuthorityVeteransAffairsGraduatedPaymentMortgage),
            b"AI" => Some(CodeAI),
            b"AJ" => Some(ConventionalAdjustableRateMortgage),
            b"CA" => Some(CodeCA),
            b"CB" => Some(CodeCB),
            b"CH" => Some(CostSharing),
            b"CP" => Some(CostPlus),
            b"CS" => Some(Cost),
            b"CW" => Some(CostPlusAwardFee),
            b"CX" => Some(CostPlusFixedFee),
            b"CY" => Some(CostPlusIncentiveFee),
            b"DI" => Some(Distributor),
            b"EA" => Some(ExclusiveAgency),
            b"ER" => Some(ExclusiveRight),
            b"FA" => Some(FirmOrActualContract),
            b"FB" => Some(CodeFB),
            b"FC" => Some(CodeFC),
            b"FD" => Some(FixedPriceRedetermination),
            b"FE" => Some(FixedPriceWithEscalation),
            b"FF" => Some(CodeFF),
            b"FG" => Some(CodeFG),
            b"FH" => Some(FixedPriceAwardFee),
            b"FI" => Some(FixedPriceIncentive),
            b"FJ" => Some(FixedPriceLevelOfEffort),
            b"FK" => Some(NoCost),
            b"FL" => Some(FlatAmount),
            b"FM" => Some(RetroactiveFixedPriceRedetermination),
            b"FR" => Some(FirmFixedPrice),
            b"FX" => Some(FixedPriceWithEconomicPriceAdjustment),
            b"LA" => Some(Labor),
            b"LE" => Some(LevelOfEffort),
            b"LH" => Some(LaborHours),
            b"OC" => Some(OtherContractType),
            b"PR" => Some(ProspectReservation),
            b"SP" => Some(CodeSP),
            b"TM" => Some(TimeAndMaterials),
            b"ZZ" => Some(MutuallyDefined),
            _ => None,
        }
    }
    fn description(&self) -> &str {
        use ContractTypeCode::*;
        match self {
            Code01 => "Diagnosis Related Group (DRG)",
            PerDiem => "Per Diem",
            VariablePerDiem => "Variable Per Diem",
            Flat => "Flat",
            Capitated => "Capitated",
            Percent => "Percent",
            Other => "Other",
            CodeAB => "Negotiated Growing Equity Mortgage (GEM)",
            AnticipatedContract => "Anticipated Contract",
            FederalHousingAuthorityAdjustableRateMortgage => {
                "Federal Housing Authority Adjustable Rate Mortgage"
            }
            CodeAE => {
                "Federal Housing Authority Veterans Affairs Fixed Rate Mortgage (including standard Growing Equity Mortgages)"
            }
            ConventionalSecondMortgages => "Conventional Second Mortgages",
            ConventionalFixedRateMortgages => "Conventional Fixed Rate Mortgages",
            FederalHousingAuthorityVeteransAffairsGraduatedPaymentMortgage => {
                "Federal Housing Authority Veterans Affairs Graduated Payment Mortgage"
            }
            CodeAI => "Negotiated Conventional, Graduated Payment, or Step Rate Mortgage",
            ConventionalAdjustableRateMortgage => "Conventional Adjustable Rate Mortgage",
            CodeCA => "Cost Plus Incentive Fee (With Performance Incentives)",
            CodeCB => "Cost Plus Incentive Fee (Without Performance Incentives)",
            CostSharing => "Cost Sharing",
            CostPlus => "Cost Plus",
            Cost => "Cost",
            CostPlusAwardFee => "Cost Plus Award Fee",
            CostPlusFixedFee => "Cost Plus Fixed Fee",
            CostPlusIncentiveFee => "Cost Plus Incentive Fee",
            Distributor => "Distributor",
            ExclusiveAgency => "Exclusive Agency",
            ExclusiveRight => "Exclusive Right",
            FirmOrActualContract => "Firm or Actual Contract",
            CodeFB => "Fixed Price Incentive Firm Target (With Performance Incentive)",
            CodeFC => "Fixed Price Incentive Firm Target (Without Performance Incentive)",
            FixedPriceRedetermination => "Fixed Price Redetermination",
            FixedPriceWithEscalation => "Fixed Price with Escalation",
            CodeFF => {
                "Fixed Price Incentive Successive Target (With Performance Incentive)"
            }
            CodeFG => {
                "Fixed Price Incentive Successive Target (Without Performance Incentive)"
            }
            FixedPriceAwardFee => "Fixed Price Award Fee",
            FixedPriceIncentive => "Fixed Price Incentive",
            FixedPriceLevelOfEffort => "Fixed Price Level of Effort",
            NoCost => "No Cost",
            FlatAmount => "Flat Amount",
            RetroactiveFixedPriceRedetermination => {
                "Retroactive Fixed Price Redetermination"
            }
            FirmFixedPrice => "Firm Fixed Price",
            FixedPriceWithEconomicPriceAdjustment => {
                "Fixed Price with Economic Price Adjustment"
            }
            Labor => "Labor",
            LevelOfEffort => "Level of Effort",
            LaborHours => "Labor Hours",
            OtherContractType => "Other Contract Type",
            ProspectReservation => "Prospect Reservation",
            CodeSP => "Same Percentage as Film Rental Earned (SPFRE)",
            TimeAndMaterials => "Time and Materials",
            MutuallyDefined => "Mutually Defined",
        }
    }
    fn from_description(description: &str) -> Option<ContractTypeCode> {
        {
            use ContractTypeCode::*;
            match description {
                "Diagnosis Related Group (DRG)" => Some(Code01),
                "Per Diem" => Some(PerDiem),
                "Variable Per Diem" => Some(VariablePerDiem),
                "Flat" => Some(Flat),
                "Capitated" => Some(Capitated),
                "Percent" => Some(Percent),
                "Other" => Some(Other),
                "Negotiated Growing Equity Mortgage (GEM)" => Some(CodeAB),
                "Anticipated Contract" => Some(AnticipatedContract),
                "Federal Housing Authority Adjustable Rate Mortgage" => {
                    Some(FederalHousingAuthorityAdjustableRateMortgage)
                }
                "Federal Housing Authority Veterans Affairs Fixed Rate Mortgage (including standard Growing Equity Mortgages)" => {
                    Some(CodeAE)
                }
                "Conventional Second Mortgages" => Some(ConventionalSecondMortgages),
                "Conventional Fixed Rate Mortgages" => {
                    Some(ConventionalFixedRateMortgages)
                }
                "Federal Housing Authority Veterans Affairs Graduated Payment Mortgage" => {
                    Some(FederalHousingAuthorityVeteransAffairsGraduatedPaymentMortgage)
                }
                "Negotiated Conventional, Graduated Payment, or Step Rate Mortgage" => {
                    Some(CodeAI)
                }
                "Conventional Adjustable Rate Mortgage" => {
                    Some(ConventionalAdjustableRateMortgage)
                }
                "Cost Plus Incentive Fee (With Performance Incentives)" => Some(CodeCA),
                "Cost Plus Incentive Fee (Without Performance Incentives)" => {
                    Some(CodeCB)
                }
                "Cost Sharing" => Some(CostSharing),
                "Cost Plus" => Some(CostPlus),
                "Cost" => Some(Cost),
                "Cost Plus Award Fee" => Some(CostPlusAwardFee),
                "Cost Plus Fixed Fee" => Some(CostPlusFixedFee),
                "Cost Plus Incentive Fee" => Some(CostPlusIncentiveFee),
                "Distributor" => Some(Distributor),
                "Exclusive Agency" => Some(ExclusiveAgency),
                "Exclusive Right" => Some(ExclusiveRight),
                "Firm or Actual Contract" => Some(FirmOrActualContract),
                "Fixed Price Incentive Firm Target (With Performance Incentive)" => {
                    Some(CodeFB)
                }
                "Fixed Price Incentive Firm Target (Without Performance Incentive)" => {
                    Some(CodeFC)
                }
                "Fixed Price Redetermination" => Some(FixedPriceRedetermination),
                "Fixed Price with Escalation" => Some(FixedPriceWithEscalation),
                "Fixed Price Incentive Successive Target (With Performance Incentive)" => {
                    Some(CodeFF)
                }
                "Fixed Price Incentive Successive Target (Without Performance Incentive)" => {
                    Some(CodeFG)
                }
                "Fixed Price Award Fee" => Some(FixedPriceAwardFee),
                "Fixed Price Incentive" => Some(FixedPriceIncentive),
                "Fixed Price Level of Effort" => Some(FixedPriceLevelOfEffort),
                "No Cost" => Some(NoCost),
                "Flat Amount" => Some(FlatAmount),
                "Retroactive Fixed Price Redetermination" => {
                    Some(RetroactiveFixedPriceRedetermination)
                }
                "Firm Fixed Price" => Some(FirmFixedPrice),
                "Fixed Price with Economic Price Adjustment" => {
                    Some(FixedPriceWithEconomicPriceAdjustment)
                }
                "Labor" => Some(Labor),
                "Level of Effort" => Some(LevelOfEffort),
                "Labor Hours" => Some(LaborHours),
                "Other Contract Type" => Some(OtherContractType),
                "Prospect Reservation" => Some(ProspectReservation),
                "Same Percentage as Film Rental Earned (SPFRE)" => Some(CodeSP),
                "Time and Materials" => Some(TimeAndMaterials),
                "Mutually Defined" => Some(MutuallyDefined),
                _ => None,
            }
        }
    }
}
impl Serialize for ContractTypeCode {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: ser::Serializer,
    {
        let value = if serializer.is_human_readable() {
            self.description()
        } else {
            self.code()
        };
        serializer.serialize_str(value)
    }
}
struct Visitor;
impl<'de> de::Visitor<'de> for Visitor {
    type Value = ContractTypeCode;
    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        formatter.write_str("Contract Type Code")
    }
    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
    where
        E: de::Error,
    {
        ContractTypeCode::from_description(v)
            .ok_or_else(|| E::custom(format!("Invalid Contract Type Code: {}", v)))
    }
    fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
    where
        E: de::Error,
    {
        ContractTypeCode::from_code(v)
            .ok_or_else(|| E::custom(
                format!(
                    "Invalid Contract Type Code: {}", std::str::from_utf8(v).unwrap()
                ),
            ))
    }
}
impl<'de> Deserialize<'de> for ContractTypeCode {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: de::Deserializer<'de>,
    {
        if deserializer.is_human_readable() {
            deserializer.deserialize_str(Visitor)
        } else {
            deserializer.deserialize_bytes(Visitor)
        }
    }
}