#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  Generated from FHIR 0.5.0.5149 on 2015-07-06.
#  2015, SMART Health IT.


import os
import io
import unittest
import json
from . import questionnaire
from .fhirdate import FHIRDate


class QuestionnaireTests(unittest.TestCase):
    def instantiate_from(self, filename):
        datadir = os.environ.get('FHIR_UNITTEST_DATADIR') or ''
        with io.open(os.path.join(datadir, filename), 'r', encoding='utf-8') as handle:
            js = json.load(handle)
            self.assertEqual("Questionnaire", js["resourceType"])
        return questionnaire.Questionnaire(js)
    
    def testQuestionnaire1(self):
        inst = self.instantiate_from("questionnaire-example-bluebook.json")
        self.assertIsNotNone(inst, "Must have instantiated a Questionnaire instance")
        self.implQuestionnaire1(inst)
        
        js = inst.as_json()
        self.assertEqual("Questionnaire", js["resourceType"])
        inst2 = questionnaire.Questionnaire(js)
        self.implQuestionnaire1(inst2)
    
    def implQuestionnaire1(self, inst):
        self.assertEqual(inst.date.date, FHIRDate("2013-02-19").date)
        self.assertEqual(inst.date.as_json(), "2013-02-19")
        self.assertEqual(inst.group.group[0].group[0].question[0].text, "Name of child")
        self.assertEqual(inst.group.group[0].group[0].question[1].text, "Sex")
        self.assertEqual(inst.group.group[0].group[1].question[0].text, "Birth weight (kg)")
        self.assertEqual(inst.group.group[0].group[1].question[1].text, "Birth length (cm)")
        self.assertEqual(inst.group.group[0].group[1].question[2].group[0].extension[0].url, "http://example.org/Profile/questionnaire#visibilityCondition")
        self.assertEqual(inst.group.group[0].group[1].question[2].group[0].extension[0].valueString, "HAS_VALUE(../choice/code) AND NEQ(../choice/code,'NO')")
        self.assertEqual(inst.group.group[0].group[1].question[2].group[0].question[0].text, "1st dose")
        self.assertEqual(inst.group.group[0].group[1].question[2].group[0].question[1].text, "2nd dose")
        self.assertEqual(inst.group.group[0].group[1].question[2].text, "Vitamin K given")
        self.assertEqual(inst.group.group[0].group[1].question[3].group[0].question[0].text, "Date given")
        self.assertEqual(inst.group.group[0].group[1].question[3].text, "Hep B given y / n")
        self.assertEqual(inst.group.group[0].group[1].question[4].text, "Abnormalities noted at birth")
        self.assertEqual(inst.group.group[0].group[1].title, "Neonatal Information")
        self.assertEqual(inst.group.group[0].title, "Birth details - To be completed by health professional")
        self.assertEqual(inst.group.title, "NSW Government My Personal Health Record")
        self.assertEqual(inst.id, "bb")
        self.assertEqual(inst.publisher, "New South Wales Department of Health")
        self.assertEqual(inst.status, "draft")
        self.assertEqual(inst.text.status, "generated")
    
    def testQuestionnaire2(self):
        inst = self.instantiate_from("questionnaire-example-f201-lifelines.json")
        self.assertIsNotNone(inst, "Must have instantiated a Questionnaire instance")
        self.implQuestionnaire2(inst)
        
        js = inst.as_json()
        self.assertEqual("Questionnaire", js["resourceType"])
        inst2 = questionnaire.Questionnaire(js)
        self.implQuestionnaire2(inst2)
    
    def implQuestionnaire2(self, inst):
        self.assertEqual(inst.date.date, FHIRDate("2010").date)
        self.assertEqual(inst.date.as_json(), "2010")
        self.assertEqual(inst.group.concept[0].code, "VL 1-1, 18-65_1.2.2")
        self.assertEqual(inst.group.concept[0].display, "Lifelines Questionnaire 1 part 1")
        self.assertEqual(inst.group.concept[0].system, "http://example.org/system/code/lifelines/nl")
        self.assertEqual(inst.group.group[0].question[0].text, "Do you have allergies?")
        self.assertEqual(inst.group.group[1].question[0].text, "What is your gender?")
        self.assertEqual(inst.group.group[1].question[1].text, "What is your date of birth?")
        self.assertEqual(inst.group.group[1].question[2].text, "What is your country of birth?")
        self.assertEqual(inst.group.group[1].question[3].text, "What is your marital status?")
        self.assertEqual(inst.group.group[1].text, "General questions")
        self.assertEqual(inst.group.group[2].question[0].text, "Do you smoke?")
        self.assertEqual(inst.group.group[2].question[1].text, "Do you drink alchohol?")
        self.assertEqual(inst.group.group[2].title, "Intoxications")
        self.assertEqual(inst.id, "f201")
        self.assertEqual(inst.status, "published")
        self.assertEqual(inst.text.status, "generated")
    
    def testQuestionnaire3(self):
        inst = self.instantiate_from("questionnaire-example.json")
        self.assertIsNotNone(inst, "Must have instantiated a Questionnaire instance")
        self.implQuestionnaire3(inst)
        
        js = inst.as_json()
        self.assertEqual("Questionnaire", js["resourceType"])
        inst2 = questionnaire.Questionnaire(js)
        self.implQuestionnaire3(inst2)
    
    def implQuestionnaire3(self, inst):
        self.assertEqual(inst.date.date, FHIRDate("2012-01").date)
        self.assertEqual(inst.date.as_json(), "2012-01")
        self.assertEqual(inst.group.group[0].concept[0].code, "COMORBIDITY")
        self.assertEqual(inst.group.group[0].concept[0].system, "http://example.org/system/code/sections")
        self.assertEqual(inst.group.group[0].question[0].concept[0].code, "COMORB")
        self.assertEqual(inst.group.group[0].question[0].concept[0].system, "http://example.org/system/code/questions")
        self.assertEqual(inst.group.group[0].question[0].group[0].concept[0].code, "CARDIAL")
        self.assertEqual(inst.group.group[0].question[0].group[0].concept[0].system, "http://example.org/system/code/sections")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[0].concept[0].code, "COMORBCAR")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[0].concept[0].system, "http://example.org/system/code/questions")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[0].type, "choice")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[1].concept[0].code, "COMCAR00")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[1].concept[0].display, "Angina Pectoris")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[1].concept[0].system, "http://example.org/system/code/questions")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[1].concept[1].code, "194828000")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[1].concept[1].display, "Angina (disorder)")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[1].concept[1].system, "http://snomed.info/sct")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[1].type, "choice")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[2].concept[0].code, "22298006")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[2].concept[0].display, "Myocardial infarction (disorder)")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[2].concept[0].system, "http://snomed.info/sct")
        self.assertEqual(inst.group.group[0].question[0].group[0].question[2].type, "choice")
        self.assertEqual(inst.group.group[0].question[0].group[1].concept[0].code, "VASCULAR")
        self.assertEqual(inst.group.group[0].question[0].group[1].concept[0].system, "http://example.org/system/code/sections")
        self.assertEqual(inst.group.group[0].question[0].type, "choice")
        self.assertEqual(inst.group.group[1].concept[0].code, "HISTOPATHOLOGY")
        self.assertEqual(inst.group.group[1].concept[0].system, "http://example.org/system/code/sections")
        self.assertEqual(inst.group.group[1].group[0].concept[0].code, "ABDOMINAL")
        self.assertEqual(inst.group.group[1].group[0].concept[0].system, "http://example.org/system/code/sections")
        self.assertEqual(inst.group.group[1].group[0].question[0].concept[0].code, "STADPT")
        self.assertEqual(inst.group.group[1].group[0].question[0].concept[0].display, "pT category")
        self.assertEqual(inst.group.group[1].group[0].question[0].concept[0].system, "http://example.org/system/code/questions")
        self.assertEqual(inst.group.title, "Cancer Quality Forum Questionnaire 2012")
        self.assertEqual(inst.id, "3141")
        self.assertEqual(inst.status, "draft")
        self.assertEqual(inst.text.status, "generated")
    
    def testQuestionnaire4(self):
        inst = self.instantiate_from("questionnaire-sdc-profile-example-LOINC.json")
        self.assertIsNotNone(inst, "Must have instantiated a Questionnaire instance")
        self.implQuestionnaire4(inst)
        
        js = inst.as_json()
        self.assertEqual("Questionnaire", js["resourceType"])
        inst2 = questionnaire.Questionnaire(js)
        self.implQuestionnaire4(inst2)
    
    def implQuestionnaire4(self, inst):
        self.assertEqual(inst.date.date, FHIRDate("2012-04-01").date)
        self.assertEqual(inst.date.as_json(), "2012-04-01")
        self.assertEqual(inst.extension[0].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-category")
        self.assertEqual(inst.extension[0].valueCodeableConcept.coding[0].code, "Acute Care Hospitals")
        self.assertEqual(inst.group.group[0].extension[0].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-sdc-specialGroup")
        self.assertEqual(inst.group.group[0].extension[0].valueCode, "header")
        self.assertEqual(inst.group.group[0].linkId, "Medication/header")
        self.assertEqual(inst.group.group[0].question[0].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[0].question[0].extension[0].valueInteger, 3)
        self.assertEqual(inst.group.group[0].question[0].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[0].question[0].extension[1].valueInteger, 9)
        self.assertEqual(inst.group.group[0].question[0].linkId, "74080-3/74081-1")
        self.assertTrue(inst.group.group[0].question[0].required)
        self.assertEqual(inst.group.group[0].question[0].text, "Event ID:")
        self.assertEqual(inst.group.group[0].question[0].type, "string")
        self.assertEqual(inst.group.group[0].question[1].linkId, "74080-3/30947-6")
        self.assertTrue(inst.group.group[0].question[1].required)
        self.assertEqual(inst.group.group[0].question[1].text, "Initial Report Date (HERF Q1)")
        self.assertEqual(inst.group.group[0].question[1].type, "string")
        self.assertEqual(inst.group.group[1].group[0].linkId, "Medication/SEC01/74080-3")
        self.assertEqual(inst.group.group[1].group[0].question[0].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[1].group[0].question[0].extension[0].valueInteger, 1)
        self.assertEqual(inst.group.group[1].group[0].question[0].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[1].group[0].question[0].extension[1].valueInteger, 30)
        self.assertEqual(inst.group.group[1].group[0].question[0].extension[2].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-deReference")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].linkId, "74080-3/74076-1/LA20271-5")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].extension[0].valueInteger, 7)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].extension[1].valueInteger, 65)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].extension[2].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-deReference")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].group[0].linkId, "74080-3/74077-9")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].group[0].question[0].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].group[0].question[0].extension[0].valueInteger, 0)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].group[0].question[0].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].group[0].question[0].extension[1].valueInteger, 500)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].group[0].question[0].extension[2].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-deReference")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].group[0].question[0].linkId, "74080-3/74077-9-q")
        self.assertTrue(inst.group.group[1].group[0].question[0].group[0].question[0].group[0].question[0].repeats)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].group[0].question[0].text, "Please list all ingredients:")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].group[0].question[0].type, "string")
        self.assertFalse(inst.group.group[1].group[0].question[0].group[0].question[0].group[0].repeats)
        self.assertFalse(inst.group.group[1].group[0].question[0].group[0].question[0].group[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].linkId, "74080-3/74075-3")
        self.assertTrue(inst.group.group[1].group[0].question[0].group[0].question[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].text, "What type of medication?")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[0].question[0].type, "open-choice")
        self.assertFalse(inst.group.group[1].group[0].question[0].group[0].repeats)
        self.assertFalse(inst.group.group[1].group[0].question[0].group[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[1].linkId, "74080-3/74076-1/LA20335-8")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[1].question[0].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[1].question[0].extension[0].valueInteger, 8)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[1].question[0].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[1].question[0].extension[1].valueInteger, 65)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[1].question[0].group[0].linkId, "74080-3/74074-6/LA20283-0")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[1].question[0].group[0].question[0].linkId, "74080-3/30959-1")
        self.assertTrue(inst.group.group[1].group[0].question[0].group[1].question[0].group[0].question[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[1].question[0].group[0].question[0].text, "What was the lot number of the vaccine?")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[1].question[0].group[0].question[0].type, "string")
        self.assertFalse(inst.group.group[1].group[0].question[0].group[1].question[0].group[0].repeats)
        self.assertFalse(inst.group.group[1].group[0].question[0].group[1].question[0].group[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[1].question[0].linkId, "74080-3/74074-6")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[1].question[0].text, "What type of biological product?")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[1].question[0].type, "open-choice")
        self.assertFalse(inst.group.group[1].group[0].question[0].group[1].repeats)
        self.assertFalse(inst.group.group[1].group[0].question[0].group[1].required)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[2].linkId, "74080-3/74076-1/LA20336-6")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[2].question[0].linkId, "74080-3/74073-8")
        self.assertTrue(inst.group.group[1].group[0].question[0].group[2].question[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[0].group[2].question[0].text, "What type of nutritional product?")
        self.assertEqual(inst.group.group[1].group[0].question[0].group[2].question[0].type, "open-choice")
        self.assertFalse(inst.group.group[1].group[0].question[0].group[2].repeats)
        self.assertFalse(inst.group.group[1].group[0].question[0].group[2].required)
        self.assertEqual(inst.group.group[1].group[0].question[0].linkId, "74080-3/74076-1")
        self.assertTrue(inst.group.group[1].group[0].question[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[0].text, "What type of medication/substance was involved?")
        self.assertEqual(inst.group.group[1].group[0].question[0].type, "open-choice")
        self.assertEqual(inst.group.group[1].group[0].question[1].linkId, "74080-3/74072-0")
        self.assertTrue(inst.group.group[1].group[0].question[1].required)
        self.assertEqual(inst.group.group[1].group[0].question[1].text, "Which of the following best characterizes the event?")
        self.assertEqual(inst.group.group[1].group[0].question[1].type, "open-choice")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[0].linkId, "74080-3/74071-2/A1275")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[0].question[0].linkId, "74080-3/74070-4")
        self.assertTrue(inst.group.group[1].group[0].question[2].group[0].question[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].group[0].question[0].text, "Which best describes the incorrect dose(s)?")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[0].question[0].type, "open-choice")
        self.assertFalse(inst.group.group[1].group[0].question[2].group[0].repeats)
        self.assertFalse(inst.group.group[1].group[0].question[2].group[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].group[1].linkId, "74080-3/74071-2/LA20313-5")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[1].question[0].linkId, "Medication/74069-6")
        self.assertTrue(inst.group.group[1].group[0].question[2].group[1].question[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].group[1].question[0].text, "Which best describes the incorrect timing?")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[1].question[0].type, "open-choice")
        self.assertFalse(inst.group.group[1].group[0].question[2].group[1].repeats)
        self.assertFalse(inst.group.group[1].group[0].question[2].group[1].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].group[2].linkId, "74080-3/74071-2/LA20306-9")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[2].question[0].linkId, "74080-3/74068-8")
        self.assertTrue(inst.group.group[1].group[0].question[2].group[2].question[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].group[2].question[0].text, "Which best describes the incorrect rate?")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[2].question[0].type, "open-choice")
        self.assertFalse(inst.group.group[1].group[0].question[2].group[2].repeats)
        self.assertFalse(inst.group.group[1].group[0].question[2].group[2].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].group[3].linkId, "74080-3/74071-2/LA20309-3")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[3].question[0].linkId, "Medication/74067-0")
        self.assertTrue(inst.group.group[1].group[0].question[2].group[3].question[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].group[3].question[0].text, "Which best describes the incorrect strength or concentration?")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[3].question[0].type, "open-choice")
        self.assertFalse(inst.group.group[1].group[0].question[2].group[3].repeats)
        self.assertFalse(inst.group.group[1].group[0].question[2].group[3].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].group[4].linkId, "74080-3/74071-2/LA20311-9")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[4].question[0].linkId, "Medication/74066-2")
        self.assertTrue(inst.group.group[1].group[0].question[2].group[4].question[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].group[4].question[0].text, "What was the expiration date?")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[4].question[0].type, "string")
        self.assertFalse(inst.group.group[1].group[0].question[2].group[4].repeats)
        self.assertFalse(inst.group.group[1].group[0].question[2].group[4].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].group[5].linkId, "74080-3/74071-2/LA20312-7")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[5].question[0].linkId, "Medication/74065-4")
        self.assertTrue(inst.group.group[1].group[0].question[2].group[5].question[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].group[5].question[0].text, "Was there a documented history of allergies or sensitivities to the medication/substance                      administered?")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[5].question[0].type, "open-choice")
        self.assertFalse(inst.group.group[1].group[0].question[2].group[5].repeats)
        self.assertFalse(inst.group.group[1].group[0].question[2].group[5].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].group[6].linkId, "74080-3/74071-2/LA20345-7")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[6].question[0].linkId, "Medication/74064-7")
        self.assertTrue(inst.group.group[1].group[0].question[2].group[6].question[0].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].group[6].question[0].text, "What was the contraindication (potential or actual interaction)?")
        self.assertEqual(inst.group.group[1].group[0].question[2].group[6].question[0].type, "open-choice")
        self.assertFalse(inst.group.group[1].group[0].question[2].group[6].repeats)
        self.assertFalse(inst.group.group[1].group[0].question[2].group[6].required)
        self.assertEqual(inst.group.group[1].group[0].question[2].linkId, "74080-3/74071-2")
        self.assertEqual(inst.group.group[1].group[0].question[2].text, "What was the incorrect action?")
        self.assertEqual(inst.group.group[1].group[0].question[2].type, "open-choice")
        self.assertEqual(inst.group.group[1].group[0].question[3].linkId, "74080-3/74063-9")
        self.assertTrue(inst.group.group[1].group[0].question[3].required)
        self.assertEqual(inst.group.group[1].group[0].question[3].text, "At what stage in the process did the event originate, regardless of the stage at which                  it was discovered?")
        self.assertEqual(inst.group.group[1].group[0].question[3].type, "open-choice")
        self.assertTrue(inst.group.group[1].group[0].required)
        self.assertEqual(inst.group.group[1].group[1].extension[0].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxOccurs")
        self.assertEqual(inst.group.group[1].group[1].extension[0].valueInteger, 5)
        self.assertEqual(inst.group.group[1].group[1].linkId, "74080-3/74078-7")
        self.assertEqual(inst.group.group[1].group[1].question[0].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[1].group[1].question[0].extension[0].valueInteger, 0)
        self.assertEqual(inst.group.group[1].group[1].question[0].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[1].group[1].question[0].extension[1].valueInteger, 65)
        self.assertEqual(inst.group.group[1].group[1].question[0].linkId, "74080-3/74078-7/74062-1")
        self.assertEqual(inst.group.group[1].group[1].question[0].text, "Generic name or investigational drug name")
        self.assertEqual(inst.group.group[1].group[1].question[0].type, "string")
        self.assertEqual(inst.group.group[1].group[1].question[1].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[1].group[1].question[1].extension[0].valueInteger, 0)
        self.assertEqual(inst.group.group[1].group[1].question[1].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[1].group[1].question[1].extension[1].valueInteger, 65)
        self.assertEqual(inst.group.group[1].group[1].question[1].linkId, "74080-3/74078-7/74061-3")
        self.assertEqual(inst.group.group[1].group[1].question[1].text, "Ingredient RXCUI (if known)")
        self.assertEqual(inst.group.group[1].group[1].question[1].type, "string")
        self.assertEqual(inst.group.group[1].group[1].question[2].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[1].group[1].question[2].extension[0].valueInteger, 0)
        self.assertEqual(inst.group.group[1].group[1].question[2].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[1].group[1].question[2].extension[1].valueInteger, 65)
        self.assertEqual(inst.group.group[1].group[1].question[2].linkId, "74080-3/74078-7/74060-5")
        self.assertEqual(inst.group.group[1].group[1].question[2].text, "Brand name (if known)")
        self.assertEqual(inst.group.group[1].group[1].question[2].type, "string")
        self.assertEqual(inst.group.group[1].group[1].question[3].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[1].group[1].question[3].extension[0].valueInteger, 0)
        self.assertEqual(inst.group.group[1].group[1].question[3].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[1].group[1].question[3].extension[1].valueInteger, 65)
        self.assertEqual(inst.group.group[1].group[1].question[3].linkId, "74080-3/74078-7/74059-7")
        self.assertEqual(inst.group.group[1].group[1].question[3].text, "Brand name RXCUI (if known)")
        self.assertEqual(inst.group.group[1].group[1].question[3].type, "string")
        self.assertEqual(inst.group.group[1].group[1].question[4].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[1].group[1].question[4].extension[0].valueInteger, 0)
        self.assertEqual(inst.group.group[1].group[1].question[4].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[1].group[1].question[4].extension[1].valueInteger, 65)
        self.assertEqual(inst.group.group[1].group[1].question[4].linkId, "74080-3/74078-7/74058-9")
        self.assertEqual(inst.group.group[1].group[1].question[4].text, "Manufacturer (if known)")
        self.assertEqual(inst.group.group[1].group[1].question[4].type, "string")
        self.assertEqual(inst.group.group[1].group[1].question[5].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[1].group[1].question[5].extension[0].valueInteger, 0)
        self.assertEqual(inst.group.group[1].group[1].question[5].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[1].group[1].question[5].extension[1].valueInteger, 65)
        self.assertEqual(inst.group.group[1].group[1].question[5].linkId, "74080-3/74078-7/74057-1")
        self.assertEqual(inst.group.group[1].group[1].question[5].text, "Strength or concentration of product")
        self.assertEqual(inst.group.group[1].group[1].question[5].type, "string")
        self.assertEqual(inst.group.group[1].group[1].question[6].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[1].group[1].question[6].extension[0].valueInteger, 0)
        self.assertEqual(inst.group.group[1].group[1].question[6].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[1].group[1].question[6].extension[1].valueInteger, 65)
        self.assertEqual(inst.group.group[1].group[1].question[6].linkId, "74080-3/74078-7/74056-3")
        self.assertEqual(inst.group.group[1].group[1].question[6].text, "Clinical drug component RXCUI (if known)")
        self.assertEqual(inst.group.group[1].group[1].question[6].type, "string")
        self.assertEqual(inst.group.group[1].group[1].question[7].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[1].group[1].question[7].extension[0].valueInteger, 0)
        self.assertEqual(inst.group.group[1].group[1].question[7].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[1].group[1].question[7].extension[1].valueInteger, 65)
        self.assertEqual(inst.group.group[1].group[1].question[7].linkId, "74080-3/74078-7/74055-5")
        self.assertEqual(inst.group.group[1].group[1].question[7].text, "Dosage form of Product")
        self.assertEqual(inst.group.group[1].group[1].question[7].type, "string")
        self.assertEqual(inst.group.group[1].group[1].question[8].extension[0].url, "http://hl7.org/fhir/StructureDefinition/minLength")
        self.assertEqual(inst.group.group[1].group[1].question[8].extension[0].valueInteger, 0)
        self.assertEqual(inst.group.group[1].group[1].question[8].extension[1].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-maxLength")
        self.assertEqual(inst.group.group[1].group[1].question[8].extension[1].valueInteger, 65)
        self.assertEqual(inst.group.group[1].group[1].question[8].linkId, "74080-3/74078-7/74054-8")
        self.assertEqual(inst.group.group[1].group[1].question[8].text, "Dose form RXCUI (if known)")
        self.assertEqual(inst.group.group[1].group[1].question[8].type, "string")
        self.assertEqual(inst.group.group[1].group[1].question[9].linkId, "74080-3/74078-7/74053-0")
        self.assertTrue(inst.group.group[1].group[1].question[9].required)
        self.assertEqual(inst.group.group[1].group[1].question[9].text, "Was this medication/substance prescribed for this patient?")
        self.assertEqual(inst.group.group[1].group[1].question[9].type, "open-choice")
        self.assertTrue(inst.group.group[1].group[1].repeats)
        self.assertEqual(inst.group.group[1].group[1].text, "Please provide the following medication details for any medications or other substances                directly involved in the event.")
        self.assertEqual(inst.group.group[1].group[2].linkId, "Medication/SEC03")
        self.assertEqual(inst.group.group[1].group[2].question[0].linkId, "74080-3/74051-4")
        self.assertTrue(inst.group.group[1].group[2].question[0].required)
        self.assertEqual(inst.group.group[1].group[2].question[0].text, "What was the intended route of administration?")
        self.assertEqual(inst.group.group[1].group[2].question[0].type, "open-choice")
        self.assertEqual(inst.group.group[1].group[2].question[1].linkId, "74080-3/74050-6")
        self.assertTrue(inst.group.group[1].group[2].question[1].required)
        self.assertEqual(inst.group.group[1].group[2].question[1].text, "What was the actual route of administration (attempted or completed)?")
        self.assertEqual(inst.group.group[1].group[2].question[1].type, "open-choice")
        self.assertEqual(inst.group.group[1].group[3].linkId, "Medication/SEC04")
        self.assertEqual(inst.group.group[1].group[3].text, "The form is complete.")
        self.assertEqual(inst.group.group[1].group[3].title, "STOP")
        self.assertEqual(inst.group.group[1].group[4].linkId, "Medication/SEC05")
        self.assertEqual(inst.group.group[1].group[4].title, "Thank you for completing these questions.")
        self.assertEqual(inst.group.group[1].linkId, "Medication/SEC00")
        self.assertEqual(inst.group.group[1].title, "Medication or Other Substance")
        self.assertEqual(inst.group.group[2].extension[0].url, "http://hl7.org/fhir/StructureDefinition/questionnaire-sdc-specialGroup")
        self.assertEqual(inst.group.group[2].extension[0].valueCode, "footer")
        self.assertEqual(inst.group.group[2].linkId, "Medication/footer")
        self.assertEqual(inst.group.group[2].text, "AHRQ Common Formats - Hospital Version 1.2 - 2012 Medication or Other Substance")
        self.assertEqual(inst.group.linkId, "root")
        self.assertEqual(inst.group.title, "Medication or Other Substance")
        self.assertEqual(inst.id, "sdc-loinc")
        self.assertEqual(inst.identifier[0].system, "http://loinc.org/vs")
        self.assertEqual(inst.identifier[0].value, "74080-3")
        self.assertEqual(inst.publisher, "Agency for Healthcare Research and Quality (AHRQ)")
        self.assertEqual(inst.status, "published")
        self.assertEqual(inst.text.div, "<div>Todo</div>")
        self.assertEqual(inst.text.status, "generated")

