<commit_before>"use strict";

var chakram     = require("chakram"),
    Q           = require("q"),
    curry       = require("curry"),
    auth        = require("../common/auth.js"),
    patients    = require("../patients/common.js"),
    doctors     = require("../doctors/common.js"),
    pharmacies  = require("../pharmacies/common.js"),
    common      = require("../common/chakram.js");
var expect = chakram.expect;

// we validate child schemata, but success shouldn't be present on a doctor
// object here
var doctorSchema = JSON.parse(JSON.stringify(doctors.schema));
doctorSchema.required.splice(doctorSchema.required.indexOf("success"));
delete doctorSchema.properties.success;

// we validate child schemata, but success shouldn't be present on a pharmacy
// object here
var pharmacySchema = JSON.parse(JSON.stringify(pharmacies.schema));
pharmacySchema.required.splice(pharmacySchema.required.indexOf("success"));
delete pharmacySchema.properties.success;

// verify successful responses
/*eslint-disable key-spacing */
var medicationSchema = module.exports.schema = {
    required: ["id", "name", "rx_norm", "ndc", "dose", "route", "form", "rx_number",
                "quantity", "type", "schedule", "fill_date", "number_left", "access_anyone",
                "access_family", "access_prime", "success"],
    properties: {
        success:        { type: "boolean" },
        id:             { type: "number" },
        name:           { type: "string" },
        rx_norm:        { type: "string" },
        ndc:            { type: "string" },
        dose:           {
            type:           ["object", "null"],
            required:       ["quantity", "unit"],
            properties:     {
                quantity:       { type: "number" },
                unit:           { type: "string" }
            }
        },
        route:          { type: "string" },
        form:           { type: "string" },
        rx_number:      { type: "string" },
        fill_date:      { type: ["string", "null"] },
        number_left:    { type: ["number", "null"] },
        quantity:       { type: "number" },
        type:           { type: "string" },
        schedule:       { type: "object" }, // TODO: full schedule schema here
        access_anyone:  { type: "string" },
        access_family:  { type: "string" },
        access_prime:   { type: "string" }
    },
    definitions: {
        doctor: doctorSchema,
        pharmacy: pharmacySchema
    },
    additionalProperties: false
};
/*eslint-enable key-spacing */
var medicationViewSchema = JSON.parse(JSON.stringify(medicationSchema)); // easy deep copy
<commit_msg>Add schedule JSON schema<commit_after>"use strict";

var chakram     = require("chakram"),
    Q           = require("q"),
    curry       = require("curry"),
    auth        = require("../common/auth.js"),
    patients    = require("../patients/common.js"),
    doctors     = require("../doctors/common.js"),
    pharmacies  = require("../pharmacies/common.js"),
    common      = require("../common/chakram.js");
var expect = chakram.expect;

// we validate child schemata, but success shouldn't be present on a doctor
// object here
var doctorSchema = JSON.parse(JSON.stringify(doctors.schema));
doctorSchema.required.splice(doctorSchema.required.indexOf("success"));
delete doctorSchema.properties.success;

// we validate child schemata, but success shouldn't be present on a pharmacy
// object here
var pharmacySchema = JSON.parse(JSON.stringify(pharmacies.schema));
pharmacySchema.required.splice(pharmacySchema.required.indexOf("success"));
delete pharmacySchema.properties.success;

// verify successful responses
/*eslint-disable key-spacing */
var medicationSchema = module.exports.schema = {
    required: ["id", "name", "rx_norm", "ndc", "dose", "route", "form", "rx_number",
                "quantity", "type", "schedule", "fill_date", "number_left", "access_anyone",
                "access_family", "access_prime", "success"],
    properties: {
        success:        { type: "boolean" },
        id:             { type: "number" },
        name:           { type: "string" },
        rx_norm:        { type: "string" },
        ndc:            { type: "string" },
        dose:           {
            type:           ["object", "null"],
            required:       ["quantity", "unit"],
            properties:     {
                quantity:       { type: "number" },
                unit:           { type: "string" }
            }
        },
        route:          { type: "string" },
        form:           { type: "string" },
        rx_number:      { type: "string" },
        fill_date:      { type: ["string", "null"] },
        number_left:    { type: ["number", "null"] },
        quantity:       { type: "number" },
        type:           { type: "string" },
        schedule:       {
            type:           "object",
            required:       ["as_needed", "regularly"],
            properties:     {
                as_needed:  { type: "boolean" },
                regularly:  { type: "boolean" },
                until:      {
                    type:       "object",
                    required:   ["type"],
                    properties: {
                        type:   { type: "string" },
                        stop:   { type: ["number", "string"] }
                    }
                },
                frequency: {
                    type:       "object",
                    required:   ["n", "unit"],
                    properties: {
                        n:          { type: "number" },
                        unit:       { type: "string" },
                        exclude:    {
                            type:       "object",
                            required:   ["exclude", "repeat"],
                            properties: {
                                exclude: {
                                    type:   "array",
                                    items: { type: "number" }
                                },
                                repeat: { type: "number" }
                            }
                        },
                        start:      { type: "string" }
                    }
                },
                times: {
                    type:   "array",
                    items:  {
                        type:       "object",
                        required:   ["type"],
                        properties: {
                            type:   { type: "string" },
                            time:   { type: "string" },
                            event:  { type: "string" },
                            when:   { type: "string" }
                        }
                    }
                },
                take_with_food: { type: ["boolean", "null"] },
                take_with_medications: {
                    type: "array",
                    items: { type: "number" }
                },
                take_without_medications: {
                    type: "array",
                    items: { type: "number" }
                }
            },
            additionalProperties: false
        },
        access_anyone:  { type: "string" },
        access_family:  { type: "string" },
        access_prime:   { type: "string" }
    },
    definitions: {
        doctor: doctorSchema,
        pharmacy: pharmacySchema
    },
    additionalProperties: false
};
/*eslint-enable key-spacing */
var medicationViewSchema = JSON.parse(JSON.stringify(medicationSchema)); // easy deep copy

{'fraction_non_alphanumeric': 0.13612911760814922, 'fraction_numerical': 0.0, 'mean_word_length': 1.4076433121019107, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5256498', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1906, 'n_words': 438}