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
use std::fmt;
use serde::{de, Deserialize, ser, Serialize};
/**1336

See docs at <https://www.stedi.com/edi/x12-005010/element/1336>*/
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum InsuranceTypeCode {
    ///12 - Medicare Secondary Working Aged Beneficiary or Spouse with Employer Group Health Plan
    MedicareSecondaryWorkingAgedBeneficiaryOrSpouseWithEmployerGroupHealthPlan,
    ///13 - Medicare Secondary End-Stage Renal Disease Beneficiary in the Mandated Coordination Period with an Employer's Group Health Plan
    MedicareSecondaryEndStageRenalDiseaseBeneficiaryInTheMandatedCoordinationPeriodWithAnEmployersGroupHealthPlan,
    ///14 - Medicare Secondary, No-fault Insurance including Auto is Primary
    Code14,
    ///15 - Medicare Secondary Worker's Compensation
    MedicareSecondaryWorkersCompensation,
    ///16 - Medicare Secondary Public Health Service (PHS)or Other Federal Agency
    Code16,
    ///41 - Medicare Secondary Black Lung
    MedicareSecondaryBlackLung,
    ///42 - Medicare Secondary Veteran's Administration
    MedicareSecondaryVeteransAdministration,
    ///43 - Medicare Secondary Disabled Beneficiary Under Age 65 with Large Group Health Plan (LGHP)
    Code43,
    ///47 - Medicare Secondary, Other Liability Insurance is Primary
    Code47,
    ///AP - Auto Insurance Policy
    AutoInsurancePolicy,
    ///C1 - Commercial
    Commercial,
    ///CO - Consolidated Omnibus Budget Reconciliation Act (COBRA)
    CodeCO,
    ///CP - Medicare Conditionally Primary
    MedicareConditionallyPrimary,
    ///D - Disability
    Disability,
    ///DB - Disability Benefits
    DisabilityBenefits,
    ///E - Medicare - Point of Service (POS)
    CodeE,
    ///EP - Exclusive Provider Organization
    ExclusiveProviderOrganization,
    ///FF - Family or Friends
    FamilyOrFriends,
    ///GP - Group Policy
    GroupPolicy,
    ///HM - Health Maintenance Organization (HMO)
    CodeHM,
    ///HN - Health Maintenance Organization (HMO) - Medicare Risk
    CodeHN,
    ///HS - Special Low Income Medicare Beneficiary
    SpecialLowIncomeMedicareBeneficiary,
    ///IN - Indemnity
    Indemnity,
    ///IP - Individual Policy
    IndividualPolicy,
    ///LC - Long Term Care
    LongTermCare,
    ///LD - Long Term Policy
    LongTermPolicy,
    ///LI - Life Insurance
    LifeInsurance,
    ///LT - Litigation
    Litigation,
    ///MA - Medicare Part A
    MedicarePartA,
    ///MB - Medicare Part B
    MedicarePartB,
    ///MC - Medicaid
    Medicaid,
    ///MH - Medigap Part A
    MedigapPartA,
    ///MI - Medigap Part B
    MedigapPartB,
    ///MP - Medicare Primary
    MedicarePrimary,
    ///OT - Other
    Other,
    ///PE - Property Insurance - Personal
    PropertyInsurancePersonal,
    ///PL - Personal
    Personal,
    ///PP - Personal Payment (Cash - No Insurance)
    CodePP,
    ///PR - Preferred Provider Organization (PPO)
    CodePR,
    ///PS - Point of Service (POS)
    CodePS,
    ///QM - Qualified Medicare Beneficiary
    QualifiedMedicareBeneficiary,
    ///RP - Property Insurance - Real
    PropertyInsuranceReal,
    ///SP - Supplemental Policy
    SupplementalPolicy,
    ///TF - Tax Equity Fiscal Responsibility Act (TEFRA)
    CodeTF,
    ///U - Multiple Options Health Plan
    MultipleOptionsHealthPlan,
    ///WC - Workers Compensation
    WorkersCompensation,
    ///WU - Wrap Up Policy
    WrapUpPolicy,
}
impl InsuranceTypeCode {
    pub fn code(&self) -> &str {
        {
            use InsuranceTypeCode::*;
            match self {
                MedicareSecondaryWorkingAgedBeneficiaryOrSpouseWithEmployerGroupHealthPlan => {
                    "12"
                }
                MedicareSecondaryEndStageRenalDiseaseBeneficiaryInTheMandatedCoordinationPeriodWithAnEmployersGroupHealthPlan => {
                    "13"
                }
                Code14 => "14",
                MedicareSecondaryWorkersCompensation => "15",
                Code16 => "16",
                MedicareSecondaryBlackLung => "41",
                MedicareSecondaryVeteransAdministration => "42",
                Code43 => "43",
                Code47 => "47",
                AutoInsurancePolicy => "AP",
                Commercial => "C1",
                CodeCO => "CO",
                MedicareConditionallyPrimary => "CP",
                Disability => "D",
                DisabilityBenefits => "DB",
                CodeE => "E",
                ExclusiveProviderOrganization => "EP",
                FamilyOrFriends => "FF",
                GroupPolicy => "GP",
                CodeHM => "HM",
                CodeHN => "HN",
                SpecialLowIncomeMedicareBeneficiary => "HS",
                Indemnity => "IN",
                IndividualPolicy => "IP",
                LongTermCare => "LC",
                LongTermPolicy => "LD",
                LifeInsurance => "LI",
                Litigation => "LT",
                MedicarePartA => "MA",
                MedicarePartB => "MB",
                Medicaid => "MC",
                MedigapPartA => "MH",
                MedigapPartB => "MI",
                MedicarePrimary => "MP",
                Other => "OT",
                PropertyInsurancePersonal => "PE",
                Personal => "PL",
                CodePP => "PP",
                CodePR => "PR",
                CodePS => "PS",
                QualifiedMedicareBeneficiary => "QM",
                PropertyInsuranceReal => "RP",
                SupplementalPolicy => "SP",
                CodeTF => "TF",
                MultipleOptionsHealthPlan => "U",
                WorkersCompensation => "WC",
                WrapUpPolicy => "WU",
            }
        }
    }
    pub fn from_code(code: &[u8]) -> Option<InsuranceTypeCode> {
        use InsuranceTypeCode::*;
        match code {
            b"12" => {
                Some(
                    MedicareSecondaryWorkingAgedBeneficiaryOrSpouseWithEmployerGroupHealthPlan,
                )
            }
            b"13" => {
                Some(
                    MedicareSecondaryEndStageRenalDiseaseBeneficiaryInTheMandatedCoordinationPeriodWithAnEmployersGroupHealthPlan,
                )
            }
            b"14" => Some(Code14),
            b"15" => Some(MedicareSecondaryWorkersCompensation),
            b"16" => Some(Code16),
            b"41" => Some(MedicareSecondaryBlackLung),
            b"42" => Some(MedicareSecondaryVeteransAdministration),
            b"43" => Some(Code43),
            b"47" => Some(Code47),
            b"AP" => Some(AutoInsurancePolicy),
            b"C1" => Some(Commercial),
            b"CO" => Some(CodeCO),
            b"CP" => Some(MedicareConditionallyPrimary),
            b"D" => Some(Disability),
            b"DB" => Some(DisabilityBenefits),
            b"E" => Some(CodeE),
            b"EP" => Some(ExclusiveProviderOrganization),
            b"FF" => Some(FamilyOrFriends),
            b"GP" => Some(GroupPolicy),
            b"HM" => Some(CodeHM),
            b"HN" => Some(CodeHN),
            b"HS" => Some(SpecialLowIncomeMedicareBeneficiary),
            b"IN" => Some(Indemnity),
            b"IP" => Some(IndividualPolicy),
            b"LC" => Some(LongTermCare),
            b"LD" => Some(LongTermPolicy),
            b"LI" => Some(LifeInsurance),
            b"LT" => Some(Litigation),
            b"MA" => Some(MedicarePartA),
            b"MB" => Some(MedicarePartB),
            b"MC" => Some(Medicaid),
            b"MH" => Some(MedigapPartA),
            b"MI" => Some(MedigapPartB),
            b"MP" => Some(MedicarePrimary),
            b"OT" => Some(Other),
            b"PE" => Some(PropertyInsurancePersonal),
            b"PL" => Some(Personal),
            b"PP" => Some(CodePP),
            b"PR" => Some(CodePR),
            b"PS" => Some(CodePS),
            b"QM" => Some(QualifiedMedicareBeneficiary),
            b"RP" => Some(PropertyInsuranceReal),
            b"SP" => Some(SupplementalPolicy),
            b"TF" => Some(CodeTF),
            b"U" => Some(MultipleOptionsHealthPlan),
            b"WC" => Some(WorkersCompensation),
            b"WU" => Some(WrapUpPolicy),
            _ => None,
        }
    }
    fn description(&self) -> &str {
        use InsuranceTypeCode::*;
        match self {
            MedicareSecondaryWorkingAgedBeneficiaryOrSpouseWithEmployerGroupHealthPlan => {
                "Medicare Secondary Working Aged Beneficiary or Spouse with Employer Group Health Plan"
            }
            MedicareSecondaryEndStageRenalDiseaseBeneficiaryInTheMandatedCoordinationPeriodWithAnEmployersGroupHealthPlan => {
                "Medicare Secondary End-Stage Renal Disease Beneficiary in the Mandated Coordination Period with an Employer's Group Health Plan"
            }
            Code14 => "Medicare Secondary, No-fault Insurance including Auto is Primary",
            MedicareSecondaryWorkersCompensation => {
                "Medicare Secondary Worker's Compensation"
            }
            Code16 => {
                "Medicare Secondary Public Health Service (PHS)or Other Federal Agency"
            }
            MedicareSecondaryBlackLung => "Medicare Secondary Black Lung",
            MedicareSecondaryVeteransAdministration => {
                "Medicare Secondary Veteran's Administration"
            }
            Code43 => {
                "Medicare Secondary Disabled Beneficiary Under Age 65 with Large Group Health Plan (LGHP)"
            }
            Code47 => "Medicare Secondary, Other Liability Insurance is Primary",
            AutoInsurancePolicy => "Auto Insurance Policy",
            Commercial => "Commercial",
            CodeCO => "Consolidated Omnibus Budget Reconciliation Act (COBRA)",
            MedicareConditionallyPrimary => "Medicare Conditionally Primary",
            Disability => "Disability",
            DisabilityBenefits => "Disability Benefits",
            CodeE => "Medicare - Point of Service (POS)",
            ExclusiveProviderOrganization => "Exclusive Provider Organization",
            FamilyOrFriends => "Family or Friends",
            GroupPolicy => "Group Policy",
            CodeHM => "Health Maintenance Organization (HMO)",
            CodeHN => "Health Maintenance Organization (HMO) - Medicare Risk",
            SpecialLowIncomeMedicareBeneficiary => {
                "Special Low Income Medicare Beneficiary"
            }
            Indemnity => "Indemnity",
            IndividualPolicy => "Individual Policy",
            LongTermCare => "Long Term Care",
            LongTermPolicy => "Long Term Policy",
            LifeInsurance => "Life Insurance",
            Litigation => "Litigation",
            MedicarePartA => "Medicare Part A",
            MedicarePartB => "Medicare Part B",
            Medicaid => "Medicaid",
            MedigapPartA => "Medigap Part A",
            MedigapPartB => "Medigap Part B",
            MedicarePrimary => "Medicare Primary",
            Other => "Other",
            PropertyInsurancePersonal => "Property Insurance - Personal",
            Personal => "Personal",
            CodePP => "Personal Payment (Cash - No Insurance)",
            CodePR => "Preferred Provider Organization (PPO)",
            CodePS => "Point of Service (POS)",
            QualifiedMedicareBeneficiary => "Qualified Medicare Beneficiary",
            PropertyInsuranceReal => "Property Insurance - Real",
            SupplementalPolicy => "Supplemental Policy",
            CodeTF => "Tax Equity Fiscal Responsibility Act (TEFRA)",
            MultipleOptionsHealthPlan => "Multiple Options Health Plan",
            WorkersCompensation => "Workers Compensation",
            WrapUpPolicy => "Wrap Up Policy",
        }
    }
    fn from_description(description: &str) -> Option<InsuranceTypeCode> {
        {
            use InsuranceTypeCode::*;
            match description {
                "Medicare Secondary Working Aged Beneficiary or Spouse with Employer Group Health Plan" => {
                    Some(
                        MedicareSecondaryWorkingAgedBeneficiaryOrSpouseWithEmployerGroupHealthPlan,
                    )
                }
                "Medicare Secondary End-Stage Renal Disease Beneficiary in the Mandated Coordination Period with an Employer's Group Health Plan" => {
                    Some(
                        MedicareSecondaryEndStageRenalDiseaseBeneficiaryInTheMandatedCoordinationPeriodWithAnEmployersGroupHealthPlan,
                    )
                }
                "Medicare Secondary, No-fault Insurance including Auto is Primary" => {
                    Some(Code14)
                }
                "Medicare Secondary Worker's Compensation" => {
                    Some(MedicareSecondaryWorkersCompensation)
                }
                "Medicare Secondary Public Health Service (PHS)or Other Federal Agency" => {
                    Some(Code16)
                }
                "Medicare Secondary Black Lung" => Some(MedicareSecondaryBlackLung),
                "Medicare Secondary Veteran's Administration" => {
                    Some(MedicareSecondaryVeteransAdministration)
                }
                "Medicare Secondary Disabled Beneficiary Under Age 65 with Large Group Health Plan (LGHP)" => {
                    Some(Code43)
                }
                "Medicare Secondary, Other Liability Insurance is Primary" => {
                    Some(Code47)
                }
                "Auto Insurance Policy" => Some(AutoInsurancePolicy),
                "Commercial" => Some(Commercial),
                "Consolidated Omnibus Budget Reconciliation Act (COBRA)" => Some(CodeCO),
                "Medicare Conditionally Primary" => Some(MedicareConditionallyPrimary),
                "Disability" => Some(Disability),
                "Disability Benefits" => Some(DisabilityBenefits),
                "Medicare - Point of Service (POS)" => Some(CodeE),
                "Exclusive Provider Organization" => Some(ExclusiveProviderOrganization),
                "Family or Friends" => Some(FamilyOrFriends),
                "Group Policy" => Some(GroupPolicy),
                "Health Maintenance Organization (HMO)" => Some(CodeHM),
                "Health Maintenance Organization (HMO) - Medicare Risk" => Some(CodeHN),
                "Special Low Income Medicare Beneficiary" => {
                    Some(SpecialLowIncomeMedicareBeneficiary)
                }
                "Indemnity" => Some(Indemnity),
                "Individual Policy" => Some(IndividualPolicy),
                "Long Term Care" => Some(LongTermCare),
                "Long Term Policy" => Some(LongTermPolicy),
                "Life Insurance" => Some(LifeInsurance),
                "Litigation" => Some(Litigation),
                "Medicare Part A" => Some(MedicarePartA),
                "Medicare Part B" => Some(MedicarePartB),
                "Medicaid" => Some(Medicaid),
                "Medigap Part A" => Some(MedigapPartA),
                "Medigap Part B" => Some(MedigapPartB),
                "Medicare Primary" => Some(MedicarePrimary),
                "Other" => Some(Other),
                "Property Insurance - Personal" => Some(PropertyInsurancePersonal),
                "Personal" => Some(Personal),
                "Personal Payment (Cash - No Insurance)" => Some(CodePP),
                "Preferred Provider Organization (PPO)" => Some(CodePR),
                "Point of Service (POS)" => Some(CodePS),
                "Qualified Medicare Beneficiary" => Some(QualifiedMedicareBeneficiary),
                "Property Insurance - Real" => Some(PropertyInsuranceReal),
                "Supplemental Policy" => Some(SupplementalPolicy),
                "Tax Equity Fiscal Responsibility Act (TEFRA)" => Some(CodeTF),
                "Multiple Options Health Plan" => Some(MultipleOptionsHealthPlan),
                "Workers Compensation" => Some(WorkersCompensation),
                "Wrap Up Policy" => Some(WrapUpPolicy),
                _ => None,
            }
        }
    }
}
impl Serialize for InsuranceTypeCode {
    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 = InsuranceTypeCode;
    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        formatter.write_str("Insurance Type Code")
    }
    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
    where
        E: de::Error,
    {
        InsuranceTypeCode::from_description(v)
            .ok_or_else(|| E::custom(format!("Invalid Insurance Type Code: {}", v)))
    }
    fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
    where
        E: de::Error,
    {
        InsuranceTypeCode::from_code(v)
            .ok_or_else(|| E::custom(
                format!(
                    "Invalid Insurance Type Code: {}", std::str::from_utf8(v).unwrap()
                ),
            ))
    }
}
impl<'de> Deserialize<'de> for InsuranceTypeCode {
    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)
        }
    }
}