ccd

package
v0.0.0-...-56e66a6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2020 License: MIT Imports: 9 Imported by: 0

README

CCD

Decodes Continuity of Care documents. Very preliminary right now. The API is constantly changing.

This library will try not to fail. The medical industry a lot of times fails to follow specifications perfectly, so there is a lot of hackish code to parse what I can. It can't help serious XML errors though.

Documentation

Index

Constants

View Source
const (
	// Found both these formats in the wild
	TimeDecidingIndex = 14
	TimeFormat        = "20060102150405-0700"
	TimeFormat2       = "20060102150405.000-0700"
)
View Source
const (
	// represents a single point in time
	TIME_SINGLE TimeType = "TS"
	// interval of time
	TIME_INTERVAL = "IVL_TS"
	// periodic interval of time
	TIME_PERIODIC = "PIVL_TS"
	// event based time interval
	TIME_EVENT = "EIVL_TS"
	// represents an probabilistic time interval and is used to represent dosing frequencies like q4-6h
	TIME_PROBABILISTIC = "PIVL_PPD_TS"
	// represents a parenthetical set of time expressions
	TIME_PARENTHETICAL = "SXPR_TS"
)

Variables

View Source
var (
	AllergiesTid = []string{"2.16.840.1.113883.10.20.1.2", "2.16.840.1.113883.10.20.22.2.6.1"}

	AllergiesParser = Parser{
		Type:     PARSE_SECTION,
		Values:   AllergiesTid,
		Priority: 0,
		Func:     parseAllergies,
	}
)
View Source
var (
	TidEncounters    = []string{"2.16.840.1.113883.10.20.22.2.22.1", "2.16.840.1.113883.10.20.22.4.49"}
	EncountersParser = Parser{
		Type:     PARSE_SECTION,
		Values:   TidEncounters,
		Priority: 0,
		Func:     parseEncounters,
	}
	//The following TemplateID constants are used to find specific sections inside of an encounter.
	TidSDL         = "2.16.840.1.113883.10.20.22.4.32" //TemplateID of the Service Delivery Location
	TidEncounterDx = "2.16.840.1.113883.10.20.22.4.80" //TemplateID of the Encounter Diagnosis
	TidIndication  = "2.16.840.1.113883.10.20.22.4.19"
)
View Source
var (
	ImmunizationsTid = []string{"2.16.840.1.113883.10.20.1.6", "2.16.840.1.113883.10.20.22.2.2.1"}

	ImmunizationsParser = Parser{
		Type:     PARSE_SECTION,
		Values:   ImmunizationsTid,
		Priority: 0,
		Func:     parseImmunizations,
	}
)
View Source
var (
	MedicationsTid = []string{"2.16.840.1.113883.10.20.1.8", "2.16.840.1.113883.10.20.22.2.1.1"}

	MedicationsParser = Parser{
		Type:     PARSE_SECTION,
		Values:   MedicationsTid,
		Priority: 0,
		Func:     parseMedications,
	}
)
View Source
var (
	ProblemsTid = []string{"2.16.840.1.113883.10.20.1.11", "2.16.840.1.113883.10.20.22.2.5.1"}

	ProblemsParser = Parser{
		Type:     PARSE_SECTION,
		Values:   ProblemsTid,
		Priority: 0,
		Func:     parseProblems,
	}
)
View Source
var (
	ResultsTid = []string{"2.16.840.1.113883.10.20.1.14", "2.16.840.1.113883.10.20.22.2.3.1"}

	ResultsParser = Parser{
		Type:     PARSE_SECTION,
		Values:   ResultsTid,
		Priority: 0,
		Func:     parseResults,
	}

	RANGE_SPLIT_RE = regexp.MustCompile(`\s*(;|,|\|)\s*`)
	RANGE_RE       = regexp.MustCompile(`(?P<text>[a-zA-Z\s]*?)\s*\(?(?P<low>[\d.]+)\s*[-–]\s*(?P<high>[\d.]+).*?\)?`)
	RANGE_MATH_RE  = regexp.MustCompile(`(?P<text>[a-zA-Z\s]*?)\s*\(?(?P<symbol>[<>=]+)\s*(?P<value>[\d.]+).*?\)?`)
)
View Source
var (
	SocialHistoryTid = []string{"2.16.840.1.113883.10.20.1.15", "2.16.840.1.113883.10.20.22.2.17"}

	SocialHistoryParser = Parser{
		Type:     PARSE_SECTION,
		Values:   SocialHistoryTid,
		Priority: 0,
		Func:     parseSocialHistory,
	}
)
View Source
var (
	VitalSignsTid = []string{"2.16.840.1.113883.10.20.1.16", "2.16.840.1.113883.10.20.22.2.4.1"}

	VitalSignsParser = Parser{
		Type:     PARSE_SECTION,
		Values:   VitalSignsTid,
		Priority: 0,
		Func:     parseVitalSigns,
	}
)
View Source
var (
	PatientParser = Parser{
		Type:     PARSE_DOC,
		Priority: 0,
		Func:     parsePatient,
	}
)

Functions

func Nget

func Nget(node *xmlx.Node, args ...string) *xmlx.Node

Node get. helper function to continually transverse down the xml nodes in args, and return the last one.

func Nsget

func Nsget(node *xmlx.Node, args ...string) *xmlx.Node

Node Safe get. just like Nget, but returns a node no matter what.

func ParseHL7Time

func ParseHL7Time(value string) (time.Time, error)

Dates and times in a CCD can be partial. Meaning they can be:

2006, 200601, 20060102, etc...

This function helps us parse all cases.

Types

type Address

type Address struct {
	Line1   string
	Line2   string
	City    string
	County  string
	State   string
	Zip     string
	Country string
	Use     string // H or HP = home, TMP = temporary, WP = work/office
}

func (Address) IsZero

func (a Address) IsZero() bool

type Allergy

type Allergy struct {
	Name         string
	Reaction     string
	Status       string
	SeverityCode string
	SeverityText string

	Type      Code
	Substance Code
	Severity  Code
}

type CCD

type CCD struct {
	Patient       Patient
	Immunizations []Immunization
	Medications   []Medication
	Problems      []Problem
	Results       []Result
	VitalSigns    []VitalSign
	Allergies     []Allergy
	SocialHistory []SocialHistory
	Encounters    []Encounter
	// contains filtered or unexported fields
}

func NewCCD

func NewCCD() *CCD

New CCD object with no parsers. Use NewDefaultCCD() or add your own parsers with AddParsers() if you want to actually parse anything.

func NewDefaultCCD

func NewDefaultCCD() *CCD

New CCD object with all the default parsers

func (*CCD) AddParsers

func (c *CCD) AddParsers(parsers ...Parser)

func (*CCD) Parse

func (c *CCD) Parse(data []byte) error

func (*CCD) ParseDoc

func (c *CCD) ParseDoc(doc *xmlx.Document) error

Parses a CCD into a CCD struct.

func (*CCD) ParseFile

func (c *CCD) ParseFile(filename string) error

func (*CCD) ParseStream

func (c *CCD) ParseStream(r io.Reader) error

type Code

type Code struct {
	CodeSystemName string
	Type           string
	CodeSystem     string
	Code           string
	DisplayName    string
	OriginalText   string
	Translations   []Code
	Qualifiers     []Code
}

Code is a "Coded With Equivalents Value" there are many similar types that inherit from "Concept Descriptor", this tries to support all of them. See https://www.hl7.org/documentcenter/public_temp_950A80AE-1C23-BA17-0C003CDA0019BD2E/wg/inm/datatypes-its-xml20050714.htm#dtimpl-CE

type Diagnosis

type Diagnosis struct {
	Code    Code
	Status  string
	Problem Problem
}

type Encounter

type Encounter struct {
	Performers []Performer
	Code       Code
	Time       Time

	//CCD calls this a 'participant', but we only use it for Service Delivery Locations
	Locations []Location

	/*List of problems found as a result of this visit*/
	Diagnosis []Diagnosis

	/*List of problems that caused the visit to happen*/
	Indications []Problem
}

Encounter describes any interaction with the patient and healthcare provider. See: http://www.cdatools.org/infocenter/index.jsp?topic=%2Forg.openhealthtools.mdht.uml.cda.consol.doc%2Fclasses%2FEncounterDiagnosis.html

type Immunization

type Immunization struct {
	Name           string
	Administration string
	Date           time.Time
	Status         string
}

type Location

type Location struct {
	Name    string
	Code    Code
	Address Address
	Telecom Telecom
}

type Medication

type Medication struct {
	Name           string
	Administration string
	Dose           MedicationDose
	// Active, On Hold, Prior History, No Longer Active
	// http://motorcycleguy.blogspot.com/2011/03/medication-status-in-ccd.html
	Status string
	// Document HL7 ActStatus: aborted / active / cancelled / completed / held / new / suspended
	StatusCode string
	StartDate  time.Time
	StopDate   time.Time
	Period     time.Duration
	Code       Code
	Reason     *MedicationReason
}

type MedicationDose

type MedicationDose struct {
	LowValue  string
	LowUnit   string
	HighValue string
	HighUnit  string
}

func (MedicationDose) String

func (m MedicationDose) String() string

func (MedicationDose) ValueUnit

func (m MedicationDose) ValueUnit() (string, string)

type MedicationReason

type MedicationReason struct {
	Value Code
	Date  time.Time
}

type Name

type Name struct {
	Last     string
	First    string
	Middle   string
	Suffix   string
	Prefix   string // title
	Type     string // L = legal name, PN = patient name (not sure)
	NickName string
}

func (Name) IsZero

func (n Name) IsZero() bool

type ParseFunc

type ParseFunc func(root *xmlx.Node, ccd *CCD) []error

type ParseType

type ParseType int
const (
	PARSE_DOC ParseType = iota
	PARSE_SECTION
)

type Parser

type Parser struct {
	Type         ParseType
	Values       []string
	Organization string
	Priority     int
	Func         ParseFunc
}

type Parsers

type Parsers []Parser

type Patient

type Patient struct {
	Name          Name
	Dob           time.Time
	Addresses     []Address
	Telecoms      []Telecom
	LanguageCode  string
	Gender        Code
	MaritalStatus Code
	Race          Code
	Ethnicity     Code
	Religion      Code
}

type Performer

type Performer struct {
	Address Address
	Telecom Telecom
	Name    Name
	Code    Code
}

type Problem

type Problem struct {
	Name string
	Time Time
	// Duration time.Duration
	Status      string
	ProblemType string
	Code        Code
}

Problem represents an Observation Problem (templateId: 2.16.840.1.113883.10.20.22.4.4)

type Result

type Result struct {
	Date         time.Time
	Code         Code
	Observations []ResultObservation
}

type ResultObservation

type ResultObservation struct {
	Date                time.Time
	Code                Code
	Value               ResultValue
	InterpretationCodes []string
	Ranges              []ResultRange
}

type ResultRange

type ResultRange struct {
	Gender       *string // M or F
	AgeLow       *float64
	AgeHigh      *float64
	Low          *float64
	High         *float64
	Text         *string
	OriginalText string
}

func (ResultRange) IsZero

func (r ResultRange) IsZero() bool

type ResultRanges

type ResultRanges []ResultRange

func (*ResultRanges) Parse

func (r *ResultRanges) Parse(s string)

type ResultValue

type ResultValue struct {
	Type  string
	Value string
	Unit  string
}

type SocialHistory

type SocialHistory struct {
	Code      Code
	Value     Code
	StartDate time.Time
	StopDate  time.Time
}

type Telecom

type Telecom struct {
	Type          string
	Use           string
	Value         string
	OriginalValue string
}

type Time

type Time struct {
	Type   TimeType
	Low    time.Time
	High   time.Time
	Value  time.Time
	Period time.Duration // s, min, h, d, wk and mo
}

func (*Time) IsZero

func (t *Time) IsZero() bool

type TimeType

type TimeType string

type VitalSign

type VitalSign struct {
	Date         time.Time
	Observations []VitalSignObservation
}

type VitalSignObservation

type VitalSignObservation struct {
	Date   time.Time
	Code   Code
	Result VitalSignResult
}

type VitalSignResult

type VitalSignResult struct {
	Type  string
	Value string
	Unit  string
}

Directories

Path Synopsis
parsers

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL