import * as t from 'io-ts' ; import * as fs from 'fs' ; import * as path from 'path' ; import { RTTI_Account , RTTI_AdverseEvent , RTTI_AllergyIntolerance , RTTI_AppointmentResponse , RTTI_Appointment , RTTI_AuditEvent , RTTI_Basic , RTTI_Binary , RTTI_CapabilityStatement , RTTI_Bundle , RTTI_CarePlan , RTTI_CatalogEntry , RTTI_Claim , RTTI_ActivityDefinition , RTTI_CodeSystem , RTTI_BodyStructure , RTTI_BiologicallyDerivedProduct , RTTI_CareTeam , RTTI_ChargeItem , RTTI_ChargeItemDefinition , RTTI_ClaimResponse , RTTI_ClinicalImpression , RTTI_Communication , RTTI_CommunicationRequest , RTTI_CompartmentDefinition , RTTI_Composition , RTTI_ConceptMap , RTTI_Condition , RTTI_Consent , RTTI_Contract , RTTI_Coverage , RTTI_CoverageEligibilityRequest , RTTI_CoverageEligibilityResponse , RTTI_DetectedIssue , RTTI_Device , RTTI_DeviceDefinition , RTTI_DeviceMetric , RTTI_DeviceRequest , RTTI_DeviceUseStatement , RTTI_DiagnosticReport , RTTI_DocumentManifest , RTTI_DocumentReference , RTTI_EffectEvidenceSynthesis , RTTI_Encounter , RTTI_Endpoint , RTTI_EnrollmentRequest , RTTI_EnrollmentResponse , RTTI_EpisodeOfCare , RTTI_EventDefinition , RTTI_Evidence , RTTI_EvidenceVariable , RTTI_ExampleScenario , RTTI_ExplanationOfBenefit , RTTI_FamilyMemberHistory , RTTI_Flag , RTTI_Goal , RTTI_GraphDefinition , RTTI_Group , RTTI_GuidanceResponse , RTTI_HealthcareService , RTTI_ImagingStudy , RTTI_Immunization , RTTI_ImmunizationEvaluation , RTTI_ImmunizationRecommendation , RTTI_ImplementationGuide , RTTI_InsurancePlan , RTTI_Invoice , RTTI_Library , RTTI_Linkage , RTTI_List , RTTI_Location , RTTI_Measure , RTTI_MeasureReport , RTTI_Media , RTTI_Medication , RTTI_MedicationAdministration , RTTI_MedicationDispense , RTTI_MedicationKnowledge , RTTI_MedicationRequest , RTTI_MedicationStatement , RTTI_MedicinalProduct , RTTI_MedicinalProductAuthorization , RTTI_MedicinalProductContraindication , RTTI_MedicinalProductIndication , RTTI_MedicinalProductIngredient , RTTI_MedicinalProductInteraction , RTTI_MedicinalProductManufactured , RTTI_MedicinalProductPackaged , RTTI_MedicinalProductPharmaceutical , RTTI_MedicinalProductUndesirableEffect , RTTI_MessageDefinition , RTTI_MessageHeader , RTTI_MolecularSequence , RTTI_NamingSystem , RTTI_NutritionOrder , RTTI_Observation , RTTI_ObservationDefinition , RTTI_OperationDefinition , RTTI_OperationOutcome , RTTI_Organization , RTTI_OrganizationAffiliation , RTTI_ParameterDefinition , RTTI_Parameters_Parameter , RTTI_Parameters , RTTI_Patient , RTTI_PaymentNotice , RTTI_PaymentReconciliation , RTTI_Person , RTTI_PlanDefinition , RTTI_Practitioner , RTTI_PractitionerRole , RTTI_Procedure , RTTI_Provenance , RTTI_Questionnaire , RTTI_QuestionnaireResponse , RTTI_RelatedPerson , RTTI_RequestGroup , RTTI_ResearchDefinition , RTTI_ResearchElementDefinition , RTTI_ResearchStudy , RTTI_ResearchSubject , RTTI_RiskAssessment , RTTI_RiskEvidenceSynthesis , RTTI_Schedule , RTTI_SearchParameter , RTTI_ServiceRequest , RTTI_Slot , RTTI_Specimen , RTTI_SpecimenDefinition , RTTI_StructureDefinition , RTTI_StructureMap , RTTI_Subscription , RTTI_Substance , RTTI_SubstanceSpecification , RTTI_SupplyDelivery , RTTI_SupplyRequest , RTTI_Task , RTTI_TerminologyCapabilities , RTTI_TestReport , RTTI_TestScript , RTTI_ValueSet , RTTI_VerificationResult , RTTI_VisionPrescription } from '../R4/Resource' ; const cases = [ [ 'Account' , RTTI_Account ] , [ 'ActivityDefinition' , RTTI_ActivityDefinition ] , [ 'AdverseEvent' , RTTI_AdverseEvent ] , [ 'AllergyIntolerance' , RTTI_AllergyIntolerance ] , [ 'Appointment' , RTTI_Appointment ] , [ 'AppointmentResponse' , RTTI_AppointmentResponse ] , [ 'Basic' , RTTI_Basic ] , [ 'Binary' , RTTI_Binary ] , [ 'BiologicallyDerivedProduct' , RTTI_BiologicallyDerivedProduct ] , [ 'BodyStructure' , RTTI_BodyStructure ] , [ 'Bundle' , RTTI_Bundle ] , [ 'CapabilityStatement' , RTTI_CapabilityStatement ] , [ 'CarePlan' , RTTI_CarePlan ] , [ 'CareTeam' , RTTI_CareTeam ] , [ 'CatalogEntry' , RTTI_CatalogEntry ] , [ 'ChargeItem' , RTTI_ChargeItem ] , [ 'ChargeItemDefinition' , RTTI_ChargeItemDefinition ] , [ 'Claim' , RTTI_Claim ] , [ 'ClaimResponse' , RTTI_ClaimResponse ] , [ 'ClinicalImpression' , RTTI_ClinicalImpression ] , [ 'CodeSystem' , RTTI_CodeSystem ] , [ 'Communication' , RTTI_Communication ] , [ 'CommunicationRequest' , RTTI_CommunicationRequest ] , [ 'CompartmentDefinition' , RTTI_CompartmentDefinition ] , [ 'Composition' , RTTI_Composition ] , [ 'ConceptMap' , RTTI_ConceptMap ] , [ 'Condition' , RTTI_Condition ] , [ 'Consent' , RTTI_Consent ] , [ 'Contract' , RTTI_Contract ] , [ 'Coverage' , RTTI_Coverage ] , [ 'CoverageEligibilityRequest' , RTTI_CoverageEligibilityRequest ] , [ 'CoverageEligibilityResponse' , RTTI_CoverageEligibilityResponse ] , [ 'DetectedIssue' , RTTI_DetectedIssue ] , [ 'Device' , RTTI_Device ] , [ 'DeviceDefinition' , RTTI_DeviceDefinition ] , [ 'DeviceMetric' , RTTI_DeviceMetric ] , [ 'DeviceRequest' , RTTI_DeviceRequest ] , [ 'DeviceUseStatement' , RTTI_DeviceUseStatement ] , [ 'DiagnosticReport' , RTTI_DiagnosticReport ] , [ 'DocumentManifest' , RTTI_DocumentManifest ] , [ 'DocumentReference' , RTTI_DocumentReference ] , [ 'EffectEvidenceSynthesis' , RTTI_EffectEvidenceSynthesis ] , [ 'Encounter' , RTTI_Encounter ] , [ 'Endpoint' , RTTI_Endpoint ] , [ 'EnrollmentRequest' , RTTI_EnrollmentRequest ] , [ 'EnrollmentResponse' , RTTI_EnrollmentResponse ] , [ 'EpisodeOfCare' , RTTI_EpisodeOfCare ] , [ 'EventDefinition' , RTTI_EventDefinition ] , [ 'Evidence' , RTTI_Evidence ] , [ 'EvidenceVariable' , RTTI_EvidenceVariable ] , [ 'ExampleScenario' , RTTI_ExampleScenario ] , [ 'ExplanationOfBenefit' , RTTI_ExplanationOfBenefit ] , [ 'FamilyMemberHistory' , RTTI_FamilyMemberHistory ] , [ 'Flag' , RTTI_Flag ] , [ 'Goal' , RTTI_Goal ] , [ 'GraphDefinition' , RTTI_GraphDefinition ] , [ 'Group' , RTTI_Group ] , [ 'GuidanceResponse' , RTTI_GuidanceResponse ] , [ 'HealthcareService' , RTTI_HealthcareService ] , [ 'ImagingStudy' , RTTI_ImagingStudy ] , [ 'Immunization' , RTTI_Immunization ] , [ 'ImmunizationEvaluation' , RTTI_ImmunizationEvaluation ] , [ 'ImmunizationRecommendation' , RTTI_ImmunizationRecommendation ] , [ 'ImplementationGuide' , RTTI_ImplementationGuide ] , [ 'InsurancePlan' , RTTI_InsurancePlan ] , [ 'Invoice' , RTTI_Invoice ] , [ 'Library' , RTTI_Library ] , [ 'Linkage' , RTTI_Linkage ] , [ 'List' , RTTI_List ] , [ 'Location' , RTTI_Location ] , [ 'Measure' , RTTI_Measure ] , [ 'MeasureReport' , RTTI_MeasureReport ] , [ 'Media' , RTTI_Media ] , [ 'Medication' , RTTI_Medication ] , [ 'MedicationAdministration' , RTTI_MedicationAdministration ] , [ 'MedicationDispense' , RTTI_MedicationDispense ] , [ 'MedicationKnowledge' , RTTI_MedicationKnowledge ] , [ 'MedicationRequest' , RTTI_MedicationRequest ] , [ 'MedicationStatement' , RTTI_MedicationStatement ] , [ 'MedicinalProduct' , RTTI_MedicinalProduct ] , [ 'MedicinalProductAuthorization' , RTTI_MedicinalProductAuthorization ] , [ 'MedicinalProductContraindication' , RTTI_MedicinalProductContraindication ] , [ 'MedicinalProductIndication' , RTTI_MedicinalProductIndication ] , [ 'MedicinalProductIngredient' , RTTI_MedicinalProductIngredient ] , [ 'MedicinalProductInteraction' , RTTI_MedicinalProductInteraction ] , [ 'MedicinalProductManufactured' , RTTI_MedicinalProductManufactured ] , [ 'MedicinalProductPackaged' , RTTI_MedicinalProductPackaged ] , [ 'MedicinalProductPharmaceutical' , RTTI_MedicinalProductPharmaceutical ] , [ 'MedicinalProductUndesirableEffect' , RTTI_MedicinalProductUndesirableEffect ] , [ 'MessageDefinition' , RTTI_MessageDefinition ] , [ 'MessageHeader' , RTTI_MessageHeader ] , [ 'MolecularSequence' , RTTI_MolecularSequence ] , [ 'NamingSystem' , RTTI_NamingSystem ] , [ 'NutritionOrder' , RTTI_NutritionOrder ] , [ 'Observation' , RTTI_Observation ] , [ 'ObservationDefinition' , RTTI_ObservationDefinition ] , [ 'OperationDefinition' , RTTI_OperationDefinition ] , [ 'OperationOutcome' , RTTI_OperationOutcome ] , [ 'Organization' , RTTI_Organization ] , [ 'OrganizationAffiliation' , RTTI_OrganizationAffiliation ] , [ 'Parameters' , RTTI_Parameters ] , [ 'Patient' , RTTI_Patient ] , [ 'PaymentNotice' , RTTI_PaymentNotice ] , [ 'PaymentReconciliation' , RTTI_PaymentReconciliation ] , [ 'Person' , RTTI_Person ] , [ 'PlanDefinition' , RTTI_PlanDefinition ] , [ 'Practitioner' , RTTI_Practitioner ] , [ 'PractitionerRole' , RTTI_PractitionerRole ] , [ 'Procedure' , RTTI_Procedure ] , [ 'Provenance' , RTTI_Provenance ] , [ 'Questionnaire' , RTTI_Questionnaire ] , [ 'QuestionnaireResponse' , RTTI_QuestionnaireResponse ] , [ 'RelatedPerson' , RTTI_RelatedPerson ] , [ 'RequestGroup' , RTTI_RequestGroup ] , [ 'ResearchDefinition' , RTTI_ResearchDefinition ] , [ 'ResearchElementDefinition' , RTTI_ResearchElementDefinition ] , [ 'ResearchStudy' , RTTI_ResearchStudy ] , [ 'ResearchSubject' , RTTI_ResearchSubject ] , [ 'RiskAssessment' , RTTI_RiskAssessment ] , [ 'RiskEvidenceSynthesis' , RTTI_RiskEvidenceSynthesis ] , [ 'Schedule' , RTTI_Schedule ] , [ 'SearchParameter' , RTTI_SearchParameter ] , [ 'ServiceRequest' , RTTI_ServiceRequest ] , [ 'Slot' , RTTI_Slot ] , [ 'Specimen' , RTTI_Specimen ] , [ 'SpecimenDefinition' , RTTI_SpecimenDefinition ] , [ 'StructureDefinition' , RTTI_StructureDefinition ] , [ 'StructureMap' , RTTI_StructureMap ] , [ 'Subscription' , RTTI_Subscription ] , [ 'Substance' , RTTI_Substance ] , [ 'SubstanceSpecification' , RTTI_SubstanceSpecification ] , [ 'SupplyDelivery' , RTTI_SupplyDelivery ] , [ 'SupplyRequest' , RTTI_SupplyRequest ] , [ 'Task' , RTTI_Task ] , [ 'TerminologyCapabilities' , RTTI_TerminologyCapabilities ] , [ 'TestReport' , RTTI_TestReport ] , [ 'TestScript' , RTTI_TestScript ] , [ 'ValueSet' , RTTI_ValueSet ] , [ 'VerificationResult' , RTTI_VerificationResult ] , [ 'VisionPrescription' , RTTI_VisionPrescription ] ] ; describe . each < any > ( cases ) ( 'Validate %s' , ( domain , RTTI ) => { const files = fs . readdirSync ( path . join ( __dirname , `samples/${ domain }` ) ) ; const filesContent = files . map ( ( f ) => { return [ f , fs . readFileSync ( path . join ( __dirname , `samples/${ domain }` , f ) , 'utf8' ) , RTTI ] ; } ) ; test . each ( filesContent ) ( `should decode file %s` , ( filename , fileContent , RTTI ) => { const result = RTTI . decode ( JSON . parse ( fileContent ) ) ; expect ( result . _tag ) . toBe ( 'Right' ) ; } ) ; } ) ;