#!/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 observation
from .fhirdate import FHIRDate


class ObservationTests(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("Observation", js["resourceType"])
        return observation.Observation(js)
    
    def testObservation1(self):
        inst = self.instantiate_from("obs-genetics-example1-somatic.json")
        self.assertIsNotNone(inst, "Must have instantiated a Observation instance")
        self.implObservation1(inst)
        
        js = inst.as_json()
        self.assertEqual("Observation", js["resourceType"])
        inst2 = observation.Observation(js)
        self.implObservation1(inst2)
    
    def implObservation1(self, inst):
        self.assertEqual(inst.code.coding[0].code, "21665-5")
        self.assertEqual(inst.code.coding[0].display, "EGFR gene mutation analysis")
        self.assertEqual(inst.code.coding[0].system, "http://loinc.org")
        self.assertEqual(inst.comments, "The EGFR p.L858R mutation has been associated with response to anti-EGFR therapy")
        self.assertEqual(inst.extension[0].url, "http://hl7.org/fhir/StructureDefinition/geneticsGenomeBuild")
        self.assertEqual(inst.extension[0].valueString, "GRCh 37")
        self.assertEqual(inst.extension[1].url, "http://hl7.org/fhir/StructureDefinition/geneticsChromosome")
        self.assertEqual(inst.extension[1].valueString, "7")
        self.assertEqual(inst.extension[2].url, "http://hl7.org/fhir/StructureDefinition/geneticsGenomicReferenceSequenceId")
        self.assertEqual(inst.extension[2].valueCode, "NC_000007.13")
        self.assertEqual(inst.extension[3].url, "http://hl7.org/fhir/StructureDefinition/geneticsGenomicStart")
        self.assertEqual(inst.extension[3].valueInteger, 55259515)
        self.assertEqual(inst.extension[4].url, "http://hl7.org/fhir/StructureDefinition/geneticsGenomicStop")
        self.assertEqual(inst.extension[4].valueInteger, 55259515)
        self.assertEqual(inst.extension[5].url, "http://hl7.org/fhir/StructureDefinition/geneticsReferenceAllele")
        self.assertEqual(inst.extension[5].valueString, "T")
        self.assertEqual(inst.extension[6].url, "http://hl7.org/fhir/StructureDefinition/geneticsObservedAllele")
        self.assertEqual(inst.extension[6].valueString, "G")
        self.assertEqual(inst.extension[7].url, "http://hl7.org/fhir/StructureDefinition/geneticsGeneId")
        self.assertEqual(inst.extension[7].valueCodeableConcept.coding[0].code, "3236")
        self.assertEqual(inst.extension[7].valueCodeableConcept.coding[0].display, "EGFR")
        self.assertEqual(inst.extension[7].valueCodeableConcept.coding[0].system, "http://www.genenames.org")
        self.assertEqual(inst.extension[8].url, "http://hl7.org/fhir/StructureDefinition/geneticsTranscriptReferenceSequenseId")
        self.assertEqual(inst.extension[8].valueCode, "ENSESTT00000085772.1")
        self.assertEqual(inst.extension[9].url, "http://hl7.org/fhir/StructureDefinition/geneticsDNASequenceVariation")
        self.assertEqual(inst.extension[9].valueString, "c.2573T>G")
        self.assertEqual(inst.id, "genetics-example1-somatic")
        self.assertEqual(inst.status, "final")
        self.assertEqual(inst.text.status, "generated")
    
    def testObservation2(self):
        inst = self.instantiate_from("obs-genetics-example2-germline.json")
        self.assertIsNotNone(inst, "Must have instantiated a Observation instance")
        self.implObservation2(inst)
        
        js = inst.as_json()
        self.assertEqual("Observation", js["resourceType"])
        inst2 = observation.Observation(js)
        self.implObservation2(inst2)
    
    def implObservation2(self, inst):
        self.assertEqual(inst.code.coding[0].code, "21636-6")
        self.assertEqual(inst.code.coding[0].display, "BRCA1 gene mutation analysis")
        self.assertEqual(inst.code.coding[0].system, "http://loinc.org")
        self.assertEqual(inst.extension[0].url, "http://hl7.org/fhir/StructureDefinition/geneticsGenomeBuild")
        self.assertEqual(inst.extension[0].valueString, "GRCh 37")
        self.assertEqual(inst.extension[1].url, "http://hl7.org/fhir/StructureDefinition/geneticsChromosome")
        self.assertEqual(inst.extension[1].valueString, "17")
        self.assertEqual(inst.extension[2].url, "http://hl7.org/fhir/StructureDefinition/geneticsGenomicReferenceSequenceId")
        self.assertEqual(inst.extension[2].valueCode, "NC_000017.10")
        self.assertEqual(inst.extension[3].url, "http://hl7.org/fhir/StructureDefinition/geneticsGenomicStart")
        self.assertEqual(inst.extension[3].valueInteger, 41258504)
        self.assertEqual(inst.extension[4].url, "http://hl7.org/fhir/StructureDefinition/geneticsGenomicStop")
        self.assertEqual(inst.extension[4].valueInteger, 41258504)
        self.assertEqual(inst.extension[5].url, "http://hl7.org/fhir/StructureDefinition/geneticsReferenceAllele")
        self.assertEqual(inst.extension[5].valueString, "A")
        self.assertEqual(inst.extension[6].url, "http://hl7.org/fhir/StructureDefinition/geneticsObservedAllele")
        self.assertEqual(inst.extension[6].valueString, "C")
        self.assertEqual(inst.extension[7].url, "http://hl7.org/fhir/StructureDefinition/geneticsGeneId")
        self.assertEqual(inst.extension[7].valueCodeableConcept.coding[0].code, "1100")
        self.assertEqual(inst.extension[7].valueCodeableConcept.coding[0].display, "BRCA1")
        self.assertEqual(inst.extension[7].valueCodeableConcept.coding[0].system, "http://www.genenames.org")
        self.assertEqual(inst.extension[8].url, "http://hl7.org/fhir/StructureDefinition/geneticsTranscriptReferenceSequenseId")
        self.assertEqual(inst.extension[8].valueCode, "NM_007294.3")
        self.assertEqual(inst.extension[9].url, "http://hl7.org/fhir/StructureDefinition/geneticsDNASequenceVariation")
        self.assertEqual(inst.extension[9].valueString, "c.181T>G")
        self.assertEqual(inst.id, "genetics-example2-germline")
        self.assertEqual(inst.status, "final")
        self.assertEqual(inst.text.status, "generated")
    
    def testObservation3(self):
        inst = self.instantiate_from("obs-uslab-example1.json")
        self.assertIsNotNone(inst, "Must have instantiated a Observation instance")
        self.implObservation3(inst)
        
        js = inst.as_json()
        self.assertEqual("Observation", js["resourceType"])
        inst2 = observation.Observation(js)
        self.implObservation3(inst2)
    
    def implObservation3(self, inst):
        self.assertEqual(inst.appliesDateTime.date, FHIRDate("2014-12-03").date)
        self.assertEqual(inst.appliesDateTime.as_json(), "2014-12-03")
        self.assertEqual(inst.code.coding[0].code, "10368-9")
        self.assertEqual(inst.code.coding[0].system, "http://loinc.org")
        self.assertEqual(inst.code.coding[1].code, "CAPLD")
        self.assertEqual(inst.code.coding[1].display, "Blood Lead, Capillary")
        self.assertEqual(inst.code.coding[1].system, "urn:oid:2.16.840.1.113883.3.72.5.24")
        self.assertEqual(inst.code.text, "Capillary Blood Lead Screen")
        self.assertEqual(inst.extension[0].url, "http://hl7.org/fhir/StructureDefinition/uslabobservationkind")
        self.assertEqual(inst.extension[0].valueCode, "result")
        self.assertEqual(inst.id, "uslab-example1")
        self.assertEqual(inst.identifier[0].system, "http://lis.acmelabs.org/identifiers/labtestresult")
        self.assertEqual(inst.identifier[0].type.text, "lab test result ID")
        self.assertEqual(inst.identifier[0].use, "official")
        self.assertEqual(inst.identifier[0].value, "1234")
        self.assertEqual(inst.interpretation.coding[0].code, "H")
        self.assertEqual(inst.interpretation.coding[0].system, "http://hl7.org/fhir/v2/0078")
        self.assertEqual(inst.issued.date, FHIRDate("2014-12-04T15:42:15-08:00").date)
        self.assertEqual(inst.issued.as_json(), "2014-12-04T15:42:15-08:00")
        self.assertEqual(inst.referenceRange[0].high.code, "ug/dL")
        self.assertEqual(inst.referenceRange[0].high.system, "http://unitsofmeasure.org")
        self.assertEqual(inst.referenceRange[0].high.units, "microgram per deciliter")
        self.assertEqual(inst.referenceRange[0].high.value, 5.0)
        self.assertEqual(inst.status, "final")
        self.assertEqual(inst.text.status, "generated")
        self.assertEqual(inst.valueQuantity.code, "ug/dL")
        self.assertEqual(inst.valueQuantity.system, "http://unitsofmeasure.org")
        self.assertEqual(inst.valueQuantity.units, "microgram per deciliter")
        self.assertEqual(inst.valueQuantity.value, 65)
    
    def testObservation4(self):
        inst = self.instantiate_from("obs-uslab-example2.json")
        self.assertIsNotNone(inst, "Must have instantiated a Observation instance")
        self.implObservation4(inst)
        
        js = inst.as_json()
        self.assertEqual("Observation", js["resourceType"])
        inst2 = observation.Observation(js)
        self.implObservation4(inst2)
    
    def implObservation4(self, inst):
        self.assertEqual(inst.appliesDateTime.date, FHIRDate("2014-12-05").date)
        self.assertEqual(inst.appliesDateTime.as_json(), "2014-12-05")
        self.assertEqual(inst.code.coding[0].code, "43305-2")
        self.assertEqual(inst.code.coding[0].display, "Neisseria gonorrhoeae rRNA [Presence] in Unspecified specimen by Probe and target amplification method")
        self.assertEqual(inst.code.coding[0].system, "http://loinc.org")
        self.assertEqual(inst.code.coding[1].code, "GCPCR")
        self.assertEqual(inst.code.coding[1].display, "APTIMA GC")
        self.assertEqual(inst.code.coding[1].system, "urn:oid:2.16.840.1.113883.3.72.5.24")
        self.assertEqual(inst.code.text, "Neisseria gonorrhoeae by PCR")
        self.assertEqual(inst.extension[0].url, "http://hl7.org/fhir/StructureDefinition/uslabobservationkind")
        self.assertEqual(inst.extension[0].valueCode, "result")
        self.assertEqual(inst.id, "uslab-example2")
        self.assertEqual(inst.identifier[0].system, "http://lis.acmelabs.org/identifiers/labtestresult")
        self.assertEqual(inst.identifier[0].type.text, "lab test result ID")
        self.assertEqual(inst.identifier[0].use, "official")
        self.assertEqual(inst.identifier[0].value, "2345")
        self.assertEqual(inst.interpretation.coding[0].code, "A")
        self.assertEqual(inst.interpretation.coding[0].system, "http://hl7.org/fhir/v2/0078")
        self.assertEqual(inst.issued.date, FHIRDate("2014-12-06T15:42:15-08:00").date)
        self.assertEqual(inst.issued.as_json(), "2014-12-06T15:42:15-08:00")
        self.assertEqual(inst.status, "final")
        self.assertEqual(inst.text.status, "generated")
        self.assertEqual(inst.valueCodeableConcept.coding[0].code, "10828004")
        self.assertEqual(inst.valueCodeableConcept.coding[0].display, "Positive")
        self.assertEqual(inst.valueCodeableConcept.coding[0].system, "http://snomed.info/sct")
        self.assertEqual(inst.valueCodeableConcept.coding[1].code, "POS")
        self.assertEqual(inst.valueCodeableConcept.coding[1].display, "Positive")
        self.assertEqual(inst.valueCodeableConcept.coding[1].system, "urn:oid:2.16.840.1.113883.3.72.5.24")
        self.assertEqual(inst.valueCodeableConcept.text, "Positive for Neisseira gonorrheoea rRNA")
    
    def testObservation5(self):
        inst = self.instantiate_from("obs-uslab-example3.json")
        self.assertIsNotNone(inst, "Must have instantiated a Observation instance")
        self.implObservation5(inst)
        
        js = inst.as_json()
        self.assertEqual("Observation", js["resourceType"])
        inst2 = observation.Observation(js)
        self.implObservation5(inst2)
    
    def implObservation5(self, inst):
        self.assertEqual(inst.appliesDateTime.date, FHIRDate("2014-12-05").date)
        self.assertEqual(inst.appliesDateTime.as_json(), "2014-12-05")
        self.assertEqual(inst.code.coding[0].code, "6463-4")
        self.assertEqual(inst.code.coding[0].display, "Bacteria identified in Unspecified specimen by Culture")
        self.assertEqual(inst.code.coding[0].system, "http://loinc.org")
        self.assertEqual(inst.code.coding[1].code, "MSCBACT")
        self.assertEqual(inst.code.coding[1].display, "Misc Culture")
        self.assertEqual(inst.code.coding[1].system, "urn:oid:2.16.840.1.113883.3.72.5.24")
        self.assertEqual(inst.code.text, "Miscellaneous Culture")
        self.assertEqual(inst.extension[0].url, "http://hl7.org/fhir/StructureDefinition/uslabobservationkind")
        self.assertEqual(inst.extension[0].valueCode, "result")
        self.assertEqual(inst.id, "uslab-example3")
        self.assertEqual(inst.identifier[0].system, "http://lis.acmelabs.org/identifiers/labtestresult")
        self.assertEqual(inst.identifier[0].type.text, "lab test result ID")
        self.assertEqual(inst.identifier[0].use, "official")
        self.assertEqual(inst.identifier[0].value, "3456")
        self.assertEqual(inst.interpretation.coding[0].code, "A")
        self.assertEqual(inst.interpretation.coding[0].system, "http://hl7.org/fhir/v2/0078")
        self.assertEqual(inst.issued.date, FHIRDate("2014-12-06T15:42:15-08:00").date)
        self.assertEqual(inst.issued.as_json(), "2014-12-06T15:42:15-08:00")
        self.assertEqual(inst.status, "final")
        self.assertEqual(inst.text.status, "generated")
        self.assertEqual(inst.valueString, "Moderate Growth of gram-positive cocci bacteria")
    
    def testObservation6(self):
        inst = self.instantiate_from("obs-uslab-example4.json")
        self.assertIsNotNone(inst, "Must have instantiated a Observation instance")
        self.implObservation6(inst)
        
        js = inst.as_json()
        self.assertEqual("Observation", js["resourceType"])
        inst2 = observation.Observation(js)
        self.implObservation6(inst2)
    
    def implObservation6(self, inst):
        self.assertEqual(inst.appliesDateTime.date, FHIRDate("2014-12-05").date)
        self.assertEqual(inst.appliesDateTime.as_json(), "2014-12-05")
        self.assertEqual(inst.code.coding[0].code, "6812-2")
        self.assertEqual(inst.code.coding[0].display, "Dengue virus IgM Ab [Titer] in Serum")
        self.assertEqual(inst.code.coding[0].system, "http://loinc.org")
        self.assertEqual(inst.code.coding[1].code, "DGIGM")
        self.assertEqual(inst.code.coding[1].display, "Dengue IgM QN")
        self.assertEqual(inst.code.coding[1].system, "urn:oid:2.16.840.1.113883.3.72.5.24")
        self.assertEqual(inst.code.text, "Dengue IgM Titer")
        self.assertEqual(inst.extension[0].url, "http://hl7.org/fhir/StructureDefinition/uslabobservationkind")
        self.assertEqual(inst.extension[0].valueCode, "result")
        self.assertEqual(inst.id, "uslab-example4")
        self.assertEqual(inst.identifier[0].system, "http://lis.acmelabs.org/identifiers/labtestresult")
        self.assertEqual(inst.identifier[0].type.text, "lab test result ID")
        self.assertEqual(inst.identifier[0].use, "official")
        self.assertEqual(inst.identifier[0].value, "4567")
        self.assertEqual(inst.interpretation.coding[0].code, "H")
        self.assertEqual(inst.interpretation.coding[0].system, "http://hl7.org/fhir/v2/0078")
        self.assertEqual(inst.issued.date, FHIRDate("2014-12-06T15:42:15-08:00").date)
        self.assertEqual(inst.issued.as_json(), "2014-12-06T15:42:15-08:00")
        self.assertEqual(inst.referenceRange[0].text, "<1:64")
        self.assertEqual(inst.status, "final")
        self.assertEqual(inst.text.status, "generated")
        self.assertEqual(inst.valueRatio.denominator.value, 256)
        self.assertEqual(inst.valueRatio.numerator.value, 1)
    
    def testObservation7(self):
        inst = self.instantiate_from("obs-uslab-example5.json")
        self.assertIsNotNone(inst, "Must have instantiated a Observation instance")
        self.implObservation7(inst)
        
        js = inst.as_json()
        self.assertEqual("Observation", js["resourceType"])
        inst2 = observation.Observation(js)
        self.implObservation7(inst2)
    
    def implObservation7(self, inst):
        self.assertEqual(inst.appliesDateTime.date, FHIRDate("2014-12-05").date)
        self.assertEqual(inst.appliesDateTime.as_json(), "2014-12-05")
        self.assertEqual(inst.code.coding[0].code, "5671-3")
        self.assertEqual(inst.code.coding[0].display, "Lead [Mass/volume] in Blood")
        self.assertEqual(inst.code.coding[0].system, "http://loinc.org")
        self.assertEqual(inst.code.coding[1].code, "BLDLD")
        self.assertEqual(inst.code.coding[1].display, "Blood Lead")
        self.assertEqual(inst.code.coding[1].system, "urn:oid:2.16.840.1.113883.3.72.5.24")
        self.assertEqual(inst.code.text, "Blood Lead")
        self.assertEqual(inst.extension[0].url, "http://hl7.org/fhir/StructureDefinition/uslabobservationkind")
        self.assertEqual(inst.extension[0].valueCode, "result")
        self.assertEqual(inst.id, "uslab-example5")
        self.assertEqual(inst.identifier[0].system, "http://lis.acmelabs.org/identifiers/labtestresult")
        self.assertEqual(inst.identifier[0].type.text, "lab test result ID")
        self.assertEqual(inst.identifier[0].use, "official")
        self.assertEqual(inst.identifier[0].value, "1234")
        self.assertEqual(inst.interpretation.coding[0].code, "H")
        self.assertEqual(inst.interpretation.coding[0].system, "http://hl7.org/fhir/v2/0078")
        self.assertEqual(inst.issued.date, FHIRDate("2014-12-06T15:42:15-08:00").date)
        self.assertEqual(inst.issued.as_json(), "2014-12-06T15:42:15-08:00")
        self.assertEqual(inst.referenceRange[0].high.code, "ug/dL")
        self.assertEqual(inst.referenceRange[0].high.system, "http://unitsofmeasure.org")
        self.assertEqual(inst.referenceRange[0].high.units, "microgram per deciliter")
        self.assertEqual(inst.referenceRange[0].high.value, 5.0)
        self.assertEqual(inst.status, "final")
        self.assertEqual(inst.text.status, "generated")
        self.assertEqual(inst.valueQuantity.code, "ug/dL")
        self.assertEqual(inst.valueQuantity.system, "http://unitsofmeasure.org")
        self.assertEqual(inst.valueQuantity.units, "microgram per deciliter")
        self.assertEqual(inst.valueQuantity.value, 65)
    
    def testObservation8(self):
        inst = self.instantiate_from("obs-uslab-example6.json")
        self.assertIsNotNone(inst, "Must have instantiated a Observation instance")
        self.implObservation8(inst)
        
        js = inst.as_json()
        self.assertEqual("Observation", js["resourceType"])
        inst2 = observation.Observation(js)
        self.implObservation8(inst2)
    
    def implObservation8(self, inst):
        self.assertEqual(inst.appliesDateTime.date, FHIRDate("2014-12-05").date)
        self.assertEqual(inst.appliesDateTime.as_json(), "2014-12-05")
        self.assertEqual(inst.code.coding[0].code, "64017-7")
        self.assertEqual(inst.code.coding[0].display, "Chlamydia trachomatis and Neisseria gonorrhoeae rRNA panel - Unspecified specimen by Probe and target amplification method")
        self.assertEqual(inst.code.coding[0].system, "http://loinc.org")
        self.assertEqual(inst.code.coding[1].code, "GCCTPCR")
        self.assertEqual(inst.code.coding[1].display, "GC CT PCR")
        self.assertEqual(inst.code.coding[1].system, "urn:oid:2.16.840.1.113883.3.72.5.24")
        self.assertEqual(inst.code.text, "GC CT RNA Panel")
        self.assertEqual(inst.extension[0].url, "http://hl7.org/fhir/StructureDefinition/uslabobservationkind")
        self.assertEqual(inst.extension[0].valueCode, "result")
        self.assertEqual(inst.id, "uslab-example6")
        self.assertEqual(inst.identifier[0].system, "http://lis.acmelabs.org/identifiers/labtestresult")
        self.assertEqual(inst.identifier[0].type.text, "lab test result ID")
        self.assertEqual(inst.identifier[0].use, "official")
        self.assertEqual(inst.identifier[0].value, "8901")
        self.assertEqual(inst.issued.date, FHIRDate("2014-12-06T15:42:15-08:00").date)
        self.assertEqual(inst.issued.as_json(), "2014-12-06T15:42:15-08:00")
        self.assertEqual(inst.related[0].type, "has-component")
        self.assertEqual(inst.related[1].type, "has-component")
        self.assertEqual(inst.status, "final")
        self.assertEqual(inst.text.status, "generated")
    
    def testObservation9(self):
        inst = self.instantiate_from("obs-uslab-example7.json")
        self.assertIsNotNone(inst, "Must have instantiated a Observation instance")
        self.implObservation9(inst)
        
        js = inst.as_json()
        self.assertEqual("Observation", js["resourceType"])
        inst2 = observation.Observation(js)
        self.implObservation9(inst2)
    
    def implObservation9(self, inst):
        self.assertEqual(inst.appliesDateTime.date, FHIRDate("2014-12-05").date)
        self.assertEqual(inst.appliesDateTime.as_json(), "2014-12-05")
        self.assertEqual(inst.code.coding[0].code, "43304-5")
        self.assertEqual(inst.code.coding[0].display, "Chlamydia trachomatis rRNA [Presence] in Unspecified specimen by Probe and target amplification method")
        self.assertEqual(inst.code.coding[0].system, "http://loinc.org")
        self.assertEqual(inst.code.coding[1].code, "CTPCR")
        self.assertEqual(inst.code.coding[1].display, "APTIMA CT")
        self.assertEqual(inst.code.coding[1].system, "urn:oid:2.16.840.1.113883.3.72.5.24")
        self.assertEqual(inst.code.text, "Chlamydia trachomatis by PCR")
        self.assertEqual(inst.extension[0].url, "http://hl7.org/fhir/StructureDefinition/uslabobservationkind")
        self.assertEqual(inst.extension[0].valueCode, "result")
        self.assertEqual(inst.id, "uslab-example7")
        self.assertEqual(inst.identifier[0].system, "http://lis.acmelabs.org/identifiers/labtestresult")
        self.assertEqual(inst.identifier[0].type.text, "lab test result ID")
        self.assertEqual(inst.identifier[0].use, "official")
        self.assertEqual(inst.identifier[0].value, "9012")
        self.assertEqual(inst.interpretation.coding[0].code, "N")
        self.assertEqual(inst.interpretation.coding[0].system, "http://hl7.org/fhir/v2/0078")
        self.assertEqual(inst.issued.date, FHIRDate("2014-12-06T15:42:15-08:00").date)
        self.assertEqual(inst.issued.as_json(), "2014-12-06T15:42:15-08:00")
        self.assertEqual(inst.status, "final")
        self.assertEqual(inst.text.status, "generated")
        self.assertEqual(inst.valueCodeableConcept.coding[0].code, "260385009")
        self.assertEqual(inst.valueCodeableConcept.coding[0].display, "Negative")
        self.assertEqual(inst.valueCodeableConcept.coding[0].system, "http://snomed.info/sct")
        self.assertEqual(inst.valueCodeableConcept.coding[1].code, "NEG")
        self.assertEqual(inst.valueCodeableConcept.coding[1].display, "Negative")
        self.assertEqual(inst.valueCodeableConcept.coding[1].system, "urn:oid:2.16.840.1.113883.3.72.5.24")
        self.assertEqual(inst.valueCodeableConcept.text, "Negative for Chlamydia Trachomatis rRNA")
    
    def testObservation10(self):
        inst = self.instantiate_from("obs-uslab-example8.json")
        self.assertIsNotNone(inst, "Must have instantiated a Observation instance")
        self.implObservation10(inst)
        
        js = inst.as_json()
        self.assertEqual("Observation", js["resourceType"])
        inst2 = observation.Observation(js)
        self.implObservation10(inst2)
    
    def implObservation10(self, inst):
        self.assertEqual(inst.appliesDateTime.date, FHIRDate("2014-12-03").date)
        self.assertEqual(inst.appliesDateTime.as_json(), "2014-12-03")
        self.assertEqual(inst.code.coding[0].code, "5821-4")
        self.assertEqual(inst.code.coding[0].system, "http://loinc.org")
        self.assertEqual(inst.code.coding[1].code, "WBCFLD")
        self.assertEqual(inst.code.coding[1].display, "White blood cells (WBC) in urine ")
        self.assertEqual(inst.code.coding[1].system, "urn:oid:2.16.840.1.113883.3.72.5.24")
        self.assertEqual(inst.code.text, "White blood cells (WBC) in urine")
        self.assertEqual(inst.extension[0].url, "http://hl7.org/fhir/StructureDefinition/uslabobservationkind")
        self.assertEqual(inst.extension[0].valueCode, "result")
        self.assertEqual(inst.id, "uslab-example8")
        self.assertEqual(inst.identifier[0].system, "http://lis.acmelabs.org/identifiers/labtestresult")
        self.assertEqual(inst.identifier[0].type.text, "lab test result ID")
        self.assertEqual(inst.identifier[0].use, "official")
        self.assertEqual(inst.identifier[0].value, "9099")
        self.assertEqual(inst.interpretation.coding[0].code, "H")
        self.assertEqual(inst.interpretation.coding[0].system, "http://hl7.org/fhir/v2/0078")
        self.assertEqual(inst.issued.date, FHIRDate("2014-12-04T15:42:15-08:00").date)
        self.assertEqual(inst.issued.as_json(), "2014-12-04T15:42:15-08:00")
        self.assertEqual(inst.referenceRange[0].high.code, "/[HPF]")
        self.assertEqual(inst.referenceRange[0].high.system, "http://unitsofmeasure.org")
        self.assertEqual(inst.referenceRange[0].high.units, "WBC/HPF")
        self.assertEqual(inst.referenceRange[0].high.value, 5)
        self.assertEqual(inst.referenceRange[0].low.code, "/[HPF]")
        self.assertEqual(inst.referenceRange[0].low.system, "http://unitsofmeasure.org")
        self.assertEqual(inst.referenceRange[0].low.units, "WBC/HPF")
        self.assertEqual(inst.referenceRange[0].low.value, 0)
        self.assertEqual(inst.status, "final")
        self.assertEqual(inst.text.status, "generated")
        self.assertEqual(inst.valueRange.high.units, "WBC/HPF")
        self.assertEqual(inst.valueRange.high.value, 20)
        self.assertEqual(inst.valueRange.low.units, "WBC/HPF")
        self.assertEqual(inst.valueRange.low.value, 10)

