FlowG

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

FlowG: Seamless Lab Data Integration

FlowG is a Go package that facilitates the connection between data files from lab equipment and GLIMS, a Laboratory Information System developed by CliniSys. It streamlines common FlowG-related tasks by automatically monitoring lab equipment upload folders and converting data into the FlowG file format.

For detailed documentation, visit pkg.go.dev.

Key Features

  • Folder Monitoring: Automatically monitors lab equipment upload directories for new data files.
  • FlowG File Generation: Converts lab data into FlowG-compatible files for GLIMS integration.
  • Error Handling and Logging: Provides configurable directories for processed data, error handling, and log management.

Installation

To use FlowG in your Go project, import the package in your source code:

import "github.com/bas-dehaan/FlowG"

Configuration

FlowG requires some initial configuration to set up folder paths and logging preferences. Use the SetConfig function to define these parameters.

Configuration Parameters
  • glimsDir: The directory where lab equipment uploads new data files.
  • processedDir: The directory to store successfully processed data files for archival purposes.
  • errorDir: The directory to move files that fail to process correctly.
  • logDir: The directory for storing log files.
  • logLvl: The log level to control the verbosity of log messages. Options include DEBUG, INFO, WARNING, ERROR, and CRITICAL.
Watching for New Files

Once configuration is complete, use the FileWatch() function to monitor the glimsDir for new files. When a new file is detected, FlowG will call your custom processing function.

Processing Function

Your processing function should load all data into a slice of SampleStruct. Then, you can call GlimsOutput() to generate the FlowG file

Example implementation

package main

import (
    "github.com/bas-dehaan/FlowG"
    "path/filepath"
)

func main() {
    err := FlowG.SetConfig("glimsDir", "path/to/upload/folder")
    err = FlowG.SetConfig("processedDir", "processed/data/archival")
    err = FlowG.SetConfig("errorDir", "data/failed/to/process")
    err = FlowG.SetConfig("logDir", "log/storage/folder")
    err = FlowG.SetConfig("logLvl", FlowG.WARNING)
    if err != nil {
        panic(err)
    }
    
    FlowG.FileWatch(yourProcessingFunction)
}

func yourProcessingFunction(filePath string) bool {
    var samples []FlowG.SampleStruct
    filename := filepath.Base(filePath)
    
    // Your file processing, specific to your input filetype...
    
    ok := FlowG.GlimsOutput(filename, samples)
    return ok
}

Documentation

For more detailed usage instructions, please visit the pkg.go.dev documentation.

Documentation

Index

Constants

View Source
const (
	DEBUG    = uint8(0)
	INFO     = uint8(1)
	WARNING  = uint8(2)
	ERROR    = uint8(3)
	CRITICAL = uint8(4)
)

Constants for log levels

Variables

This section is empty.

Functions

func FileMove

func FileMove(path string, ok bool)

FileMove moves a file from the given path to a processed or error directory based on the status flag (ok).

func FileWatch

func FileWatch(callback func(string) bool)

FileWatch continuously watches the directory specified in config.glimsDir for new file creation events. When a new file is detected, it waits for 1 second before executing the provided callback function with the file path as an argument. If the callback returns true, the file is moved to the processed directory; otherwise, it is moved to the error directory. Logging is performed for critical errors during the process.

func GetConfig

func GetConfig(key string) (interface{}, error)

GetConfig retrieves the configuration value associated with the given key. Available keys are: 'glimsDir', 'importDir', 'processedDir', 'errorDir', 'logDir', 'logLvl'. Returns the configuration value and a nil error if the key is found, otherwise returns nil and an error indicating that the key is unknown.

func GetLogLvLID

func GetLogLvLID(name string) (uint8, bool)

GetLogLvLID returns the ID of the log level associated with the given name, along with a boolean indicating existence.

func GlimsOutput

func GlimsOutput(FileName string, SampleList []SampleStruct) bool

GlimsOutput processes a list of samples and outputs them to a CSV file with the provided filename according to the FlowG standard.

func Logging

func Logging(msg string, lvl uint8)

Logging logs a message with a specified severity level. Messages are written to a log file specific to the current date.

func SetConfig

func SetConfig(key string, value interface{}) error

SetConfig sets the specified configuration key to the provided value, performing type-checking and validation. Available keys are: 'glimsDir', 'processedDir', 'errorDir', 'logDir', 'logLvl'.

Types

type SampleStruct

type SampleStruct struct {
	Barcode           string
	TestName          string
	IsolationSequence string
	Result            *float64
	ResultINT         *float64
	ResultCT          *float64
	InstrumentID      string
}

Jump to

Keyboard shortcuts

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