Example #1
0
    def testRelativeReference(self):
        with open(os.path.join(cwd, 'test_relative_reference.json')) as h:
            data = json.load(h)
        q = questionnaire.Questionnaire(data)
        self.assertIsNotNone(q, "Must instantiate Questionnaire")
        self.assertEqual('Questionnaire', q.resource_type)
        q._server = MockServer()

        group = q.item[0].item[0]
        self.assertEqual('Observation.subject', group.linkId)
        question = group.item[0]
        self.assertEqual('Observation.subject._type', question.linkId)
        self.assertIsNotNone(question.answerOption)
        with self.assertRaises(Exception):
            question.answerOption[0].valueReference.resolved()
        reference = question.answerOption[0].valueReference

        # resolve relative resource
        relative = reference.resolved(valueset.ValueSet)
        self.assertIsNotNone(relative, "Must resolve relative ValueSet")
        self.assertEqual('ValueSet', relative.resource_type)
        self.assertEqual('Type options for Observation.subject', relative.name)

        # 2nd resolve, should pull from cache
        relative = reference.resolved(medication.Medication)
        self.assertIsNone(relative,
                          "Must not resolve on resource type mismatch")
        relative = reference.resolved(resource.Resource)
        self.assertIsNotNone(
            relative,
            "Must resolve relative ValueSet even if requesting `Resource`")
Example #2
0
def createQuestionnaire(name):
    questionnaire = q.Questionnaire()
    questionnaire.status = "draft"
    questionnaire.name = name
    items = []

    ph_patients = get_patients()
    date_dict = generate_start_dict(ph_patients)
    cur_dates = date_dict["2"]

    if name == "MADRS":
        form_data = repo.generate_patient_MADRS(cur_dates)
        questionnaire.title = "Montgomery And Åsberg Depression Rating Scale"
    elif name == "PHQ9":
        form_data = repo.generate_patient_PHQ9(cur_dates)
        questionnaire.title = "Patient Health Questionnaire"
    measurement = next(iter(form_data.items()))
    categories = measurement[1]

    for i, (key, val) in enumerate(categories.items()):
        questionnaire_item = q.QuestionnaireItem()
        questionnaire_item.text = key
        questionnaire_item.linkId = str(i)
        questionnaire_item.type = "integer"
        items.append(questionnaire_item)

    questionnaire.item = items

    print(pretty(questionnaire.as_json()))

    result = questionnaire.create(smart.server)
    print(result)
Example #3
0
def main():
    # set up questionnaire structure from model
    q = questionnaire.Questionnaire()
    root_group = questionnaire.QuestionnaireGroup()
    q.group = root_group
    # root group can be either a group of groups or questions

    # complete required fields for q level
    q.identifier = [{
        'value': 'questionnaire-healthy-habit-goal-status'
    }]  # used by response to link to questionnaire
    q.status = 'draft'  #	draft | published | retired

    # complete other fields for q level
    q.publisher = 'GT CS8903 HOC Team'
    q.date = str(datetime.date.today())

    # complete required fields for root group level
    root_group.linkId = 'root'
    root_group.title = 'Healthy Habits Goal Status'

    # root group can be either a group of groups or questions
    questions_group = []
    root_group.group = questions_group

    # for each status question, create a QuestionnaireGroup obj to add to the list
    # then for each QuestionnaireGroup obj, assign the question to a list of QuestionnaireGroupQuestion objects
    for i, st_question_tuple in enumerate(ST_QUESTIONS):
        q_group = questionnaire.QuestionnaireGroup()
        grp_text, question_details = st_question_tuple
        q_group.text = grp_text
        q_group.linkId = str(i + 1)
        questions_group.append(q_group)

        questions = []
        q_group.question = questions
        for j, sub_q_truple in enumerate(question_details):
            q_question = questionnaire.QuestionnaireGroupQuestion()
            q_question.linkId = str(i) + "." + str(j)
            q_question.text, q_question.type, option, q_question.linkId, q_question.repeats,\
            q_question.required, extension = sub_q_truple
            if option is not None: q_question.option = option
            if extension is not None: q_question.extension = extension
            questions.append(q_question)

    with open('questionnaire-healthy-habit-goal-status.json', 'w') as f:
        print(json.dumps(OrderedDict(q.as_json()),
                         indent=4,
                         separators=(',', ': ')),
              file=f)
Example #4
0
def get_q(request):
    form_url = request.form['options']
    session['form_url'] = form_url
    application.logger.info('form_url = {} '.format(form_url ))
    application.logger.info('get cache = {} '.format(cache.get(form_url)))
    if not cache.get(form_url):  # cache value is empty
        r = requests.get(form_url, headers=f.headers, params={})
        q =Q.Questionnaire(r.json())
        set_cache(form_url,q)  # get questionnaire from server as json and display create a link to the main menu how to return to main menu
        # q = translate_res(q,request.form.get('translate', None)) # translate q to the language in translate code. not available in 3.4 for AWS deployment
        q = get_options(cache.get(form_url))  # if options from external or contained VS then need to fetch valuesets and populate option.coding with the values...
        set_cache('{}_wq'.format(form_url), q)  # get questionnaire from server as json and display create a link to the main menu how to return to main menu
    # application.logger.info('=================\n q = {} \n============='.format(q.as_json()))
    # application.logger.info('title = {} and qs = {}'.format(q.title, q.item))
    # bp()  # this is a break
    return()
Example #5
0
    def testContainedResourceDetection(self):
        with open(os.path.join(cwd, 'test_contained_resource.json')) as h:
            data = json.load(h)
        q = questionnaire.Questionnaire(data)
        self.assertIsNotNone(q, "Must instantiate Questionnaire")
        self.assertEqual('Questionnaire', q.resource_type)

        group = q.item[0].item[3]
        self.assertEqual('Observation.subject', group.linkId)
        question = group.item[0]
        self.assertEqual('Observation.subject._type', question.linkId)
        self.assertIsNotNone(question.answerOption)
        with self.assertRaises(Exception):
            question.answerOption[0].valueReference.resolved()
        reference = question.answerOption[0].valueReference
        # 1st resolve, extracting from contained resources
        contained = reference.resolved(medication.Medication)
        self.assertIsNone(contained,
                          "Must not resolve on resource type mismatch")
        contained = reference.resolved(valueset.ValueSet)
        self.assertIsNotNone(contained, "Must resolve contained ValueSet")
        self.assertEqual('ValueSet', contained.resource_type)
        self.assertEqual('Type options for Observation.subject',
                         contained.name)

        # 2nd resolve, should pull from cache
        contained = reference.resolved(medication.Medication)
        self.assertIsNone(contained,
                          "Must not resolve on resource type mismatch")
        contained = reference.resolved(resource.Resource)
        self.assertIsNotNone(
            contained,
            "Must resolve contained ValueSet even if requesting `Resource`")
        contained = reference.resolved(valueset.ValueSet)
        self.assertIsNotNone(contained, "Must resolve contained ValueSet")
        self.assertEqual('ValueSet', contained.resource_type)
Example #6
0
def main():
    # set up questionnaire structure from model
    q = questionnaire.Questionnaire()
    root_group = questionnaire.QuestionnaireGroup()
    q.group = root_group
    # root group can be either a group of groups or questions
    questions = []
    root_group.question = questions

    # complete required fields for q level
    q.identifier = [{
        'value': 'questionnaire-healthy-habit-goals'
    }]  # used by response to link to questionnaire
    q.status = 'draft'  #	draft | published | retired

    # complete other fields for q level
    q.publisher = 'GT CS8903 HOC Team'
    q.date = str(datetime.date.today())
    # complete required fields for root group level
    root_group.linkId = 'root'
    root_group.title = 'Healthy Habits Goal Questionnaire'

    # add goal choice question
    item = questionnaire.QuestionnaireGroupQuestion()
    item.linkId = "1"
    item.text = "Today's Healthy Habit Goal Set: (choose one)"
    item.type = "integer"
    item.required = True
    item.repeats = False
    # ordered upper left, upper right, lower left, lower right; codes match codes used in HHA questionnaire
    item.option = [
        {
            "code": "1",
            "display": "Make half your plate fruits and veggies"
        },
        {
            "code": "2",
            "display": "Be active"
        },
        {
            "code": "4",
            "display": "Drink more water & limit sugary drinks"
        },
        {
            "code": "3",
            "display": "Limit screen time"
        },
    ]
    questions.append(item)

    # fill in specific data for questions
    for i in range(len(GOAL_QUESTIONS)):
        item = questionnaire.QuestionnaireGroupQuestion()
        item.linkId = str(i + 2)
        item.text = GOAL_QUESTIONS[i]
        item.type = 'string'
        item.required = True
        item.repeats = False
        questions.append(item)

    with open('questionnaire-healthy-habit-goals.json', 'w') as f:
        print(json.dumps(OrderedDict(q.as_json()),
                         indent=4,
                         separators=(',', ': ')),
              file=f)
from __future__ import print_function
import json
from collections import OrderedDict
from fhirclient.models import questionnaire, fhirdate
import datetime
from questionnaire_commons import *
CDC_QUESTIONS = [
    "In the last year, did you worry that your food would run out before you got money or Food Stamps to buy more?",
    "In the last year, did the food you bought just not last and you didn't have money to get more?",
]

if __name__ == '__main__':
    # set up questionnaire structure from model
    q = questionnaire.Questionnaire()
    root_group = questionnaire.QuestionnaireGroup()
    q.group = root_group
    # root group can be either a group of groups or questions
    questions = []
    root_group.question = questions

    # complete required fields for q level
    q.identifier = [{
        'value': 'questionnaire-food-insecurity'
    }]  # used by response to link to questionnaire
    q.status = 'draft'  #	draft | published | retired

    # complete other fields for q level
    q.publisher = 'GT CS8903 HOC Team'
    q.date = str(datetime.date.today())
    # complete required fields for root group level
    root_group.linkId = 'root'