RSS Git Download  Clone
Raw Blame History
package RequestForm::Test;

# imports lib paths, Modern::Perl, etc into t/ scripts

use Modern::Perl;

use Import::Into;
use YAML::Tiny;
use Exporter ();
use FindBin; # warn $FindBin::Bin;

use lib (
    '/home/raj/perl-lib', # MooX::Types
    $FindBin::Bin . '/../../HILIS4/lib', # LLU
);
use LIMS::Local::Utils;

open my $fh, '>' . $FindBin::Bin . '/mech.htm' or die $!;

sub print_output {
    my $response = shift;
    print $fh $response->{content};
}

sub form_tokens {
    my $key = LIMS::Local::Utils::today->ymd;
    my $enc = sub { LIMS::Local::Utils::encrypt(shift, $key) };
    return sprintf 'c=%s;u=%s', &$enc('test'), &$enc('test');
}

sub patient_data {
    my $patient = YAML::Tiny->read( 'src/patients.conf' ) or die $!; # ddp $patient;
    # don't call PDS, and attempt is fatal anyway somewhere in patient_demographic_service()
    $_->{_skip_pds} ||= 1 for @$patient; # dpp $patient;
    return $patient;
}

sub test_schema { _schema() }

our @EXPORT = qw(print_output form_tokens patient_data test_schema);

sub import {
  Modern::Perl->import::into(1);
  Local::DB->import::into(1);
  Data::Dumper->import::into(1);
  Data::Printer->import::into(1);
  goto &Exporter::import;
}

1;

sub _schema {
    return (
        q{
            CREATE TABLE users(
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                username TEXT
            )
        },
        q{
            INSERT INTO users(username) VALUES('test')
        },
        q{
            CREATE TABLE patients (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                last_name TEXT,
                first_name TEXT,
                dob TEXT,
                gender TEXT,
                nhs_number INT
            )
        },
        q{
            CREATE TABLE referral_sources (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                display_name TEXT,
                organisation_code TEXT,
                referral_type_id INT,
                is_active TEXT
            )
        },
        q{
            INSERT INTO referral_sources
                (display_name, organisation_code, referral_type_id, is_active)
                VALUES('Newtown General Infirmary', 'ABC01', 1, 'yes')
        },
        q{
            CREATE TABLE referral_types (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                description TEXT
            )
        },
        q{
            INSERT INTO referral_types(description) VALUES('hospital')
        },
        q{
            CREATE TABLE request_form(
                id TEXT,
                last_name TEXT,
                first_name TEXT,
                dob TEXT,
                gender TEXT,
                nhs_number INTEGER,
                patient_number TEXT,
                location_name TEXT,
                location_id INTEGER,
                referrer TEXT,
                pds_code TEXT,
                user_id INTEGER,
                created TEXT,
                imported TEXT
            )
        },
    );
}