示例#1
0
def babyInfo(id):
    form = BabyForm()
    session['currentBaby'] = id
    if form.validate_on_submit():
        return render_template('baby1.html', form=form, baby=id)

    if request.method == "GET":
        if form.validate() == False:
            form.preload(id)
            #print(form.labels)
            #print(form.labels['birth_weight_grams_label'])
            #print(form.newborn_first_name)
            if form.mother_id == None:
                raise ValidationError
            return render_template('baby1.html', form=form, baby=id)
        else:
            #print(bornWithDays.data)
            #bornWithDays = form.bornWithDays.data
            #babies = GetPatientInfo.getRecentBabies(bornInDays=bornWithDays)
            #print("bornWithDays: %s" % bornWithDays)
            #return render_template('babylist.html', babies=babies, bornWithinDays=bornWithDays)
            return render_template('baby1.html', form=form, baby=id)
    if request.method == 'POST':
        print("Getting form for baby")
        #print(request.form["birth_weight_grams"])
        #print(form.birth_weight_grams)
        #print(request.form.birth_weight_grams)
        if not validateBabyWeightInputs(form):
            easygui.msgbox(
                "Inconsistent weight grams vs weight pounds and ounces!\nPlease correct the weight"
            )
            return render_template('baby1.html', form=form, baby=id)
        print(form.birth_weight_grams)
        print(form.birth_weight_lbs)
        print(form.birth_weight_ozs)
        print(request.form)

        CODEFILE = "FHIR_resource_codes_1.txt"
        codes = GetPatientInfo.getCODETABLE(file=CODEFILE, page='baby')
        currentInformation = mapUDOHvaribleName(request.form, codes)
        session['currentInformation'] = currentInformation
        babyInformation = json.dumps(currentInformation,
                                     indent=4,
                                     sort_keys=True)
        #print("baby result form is a ", type(request.form))
        #print("Dumpint baby info")
        #print(babyInformation)
        easygui.msgbox(babyInformation)
        print("The mother id", request.form['mother_id'])
        if request.form['mother_id'] == None or request.form['mother_id'] == '':
            easygui.msgbox("Mother ID required!")
            return redirect('baby/' + session.get('currentBaby'))
        return redirect('motherinfo/' + request.form['mother_id'])
    def preload(self, pid):
        """
        codes = GetPatientInfo.getCODETABLE(page='baby')
        self.labels = {}
        values = {}
        for code in codes.values():
            datatype = code['datatype']
            if datatype == 'text':
                self.labels[code['name']] = code['desc']
            else:
                values[code['name']] = datatype

        self.newborn_family_name_value = StringField()
        self.newborn_first_name_value = StringField()
        self.apgar1m_score_value = IntegerField()
        self.apgar5m_score_value = IntegerField()
        self.apgar10m_score_value = IntegerField()
        self.birth_weight_grams_value = DecimalField()
        self.birth_weight_lbs_value = DecimalField()
        self.birth_weight_ozs_value = DecimalField()
        """


        self.mother_id.data = GetPatientInfo.getMotherID(pid)

        baby, medInfo = GetPatientInfo.getPatientMedical(pid=pid, codes=self.codes)
        if baby == None:
            return
        if baby.name[0].family != None:
            self.newborn_family_name.data = baby.name[0].family
            #self.values['newborn_family_name_value.data'] = baby.name[0].family
        if baby.name[0].given[0] != None:
            self.newborn_first_name.data = baby.name[0].given[0]

        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "apgar1m_score")
        if value != None:
            self.apgar1m_score.data = value
        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "apgar5m_score")
        if value != None:
            self.apgar5m_score.data = value
        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "apgar10m_score")
        if value != None:
            self.apgar10m_score.data = value

        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "birth_weight")
        if value != None:
            vGrams, vLbs, vOzs = convertWeight(float(value), unit)
            self.birth_weight_grams.data = vGrams
            self.birth_weight_lbs.data = vLbs
            self.birth_weight_ozs.data = vOzs

        #self.motherid = GetPatientInfo.getMotherID(pid)
        #self.mother_id = '<input type="hidden" name="mother_id" value="%s">' %self.motherid
        self.mother_id.data = GetPatientInfo.getMotherID(pid)
示例#3
0
def motherResult():
    if request.method == 'POST':
        CODEFILE = "FHIR_resource_codes_1.txt"
        codes = GetPatientInfo.getCODETABLE(file=CODEFILE, page='mother')
        motherInformation = mapUDOHvaribleName(request.form, codes)
        currentInformation = session.get('currentInformation')
        #print("*****", currentInformation)
        currentInformation.update(motherInformation)
        motherInformation = json.dumps(currentInformation,
                                       indent=4,
                                       sort_keys=True)
        #print("mother result form is a ", type(request.form))
        #print("Dumpint mother info")
        #print(motherInformation)
        easygui.msgbox(motherInformation)
        return redirect('select')
示例#4
0
def select():
    form = SelectBabyForm()
    bornWithDays = form.bornWithDays

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('selectbaby.html', form=form)
        else:
            print(bornWithDays.data)
            bornWithDays = form.bornWithDays.data
            babies = GetPatientInfo.getRecentBabies(bornInDays=bornWithDays)
            print("bornWithDays: %s" % bornWithDays)
            return render_template('babylist.html',
                                   babies=babies,
                                   bornWithinDays=bornWithDays)
    if request.method == 'GET':
        return render_template('selectbaby.html', form=form)
示例#5
0
def babyResult():
    if request.method == 'POST':
        CODEFILE = "FHIR_resource_codes_1.txt"
        codes = GetPatientInfo.getCODETABLE(file=CODEFILE, page='baby')
        currentInformation = mapUDOHvaribleName(request.form, codes)
        session['currentInformation'] = currentInformation
        babyInformation = json.dumps(currentInformation,
                                     indent=4,
                                     sort_keys=True)
        #print("baby result form is a ", type(request.form))
        #print("Dumpint baby info")
        #print(babyInformation)
        easygui.msgbox(babyInformation)
        print("The mother id", request.form['mother_id'])
        if request.form['mother_id'] == None or request.form['mother_id'] == '':
            easygui.msgbox("Mother ID required!")
            return redirect('baby/' + session.get('currentBaby'))
        return redirect('motherinfo/' + request.form['mother_id'])
class BabyForm(FlaskForm):
    #values = {}
    #values['newborn_family_name_value'] = StringField()
    CODEFILE = "FHIR_resource_codes_1.txt"
    codes = GetPatientInfo.getCODETABLE(file=CODEFILE, page='baby')

    submit = SubmitField("Save and Next")

    fields = ['newborn_family_name',
              'newborn_first_name',
              'birth_weight',
              'birth_weight_grams',
              'birth_weight_lbs',
              'birth_weight_ozs',
              'apgar10m_score',
              'apgar5m_score',
              'apgar1m_score']

    for f in fields:
        field = codes[f]
        comm = f + " = "
        if field['datatype'].lower() == 'int':
            comm += "IntegerField('%s')" % field['desc']
        elif field['datatype'].lower() == 'string':
            comm += "StringField('%s')" % field['desc']
        elif field['datatype'].lower() == 'float':
            comm += "DecimalField('%s')" % field['desc']
        elif field['datatype'].lower() == 'boolean':
            comm += "BooleanField('%s')" % field['desc']
        print("Executing command: " + comm)
        exec (comm)

    mother_id = StringField("Mother ID", [validators.DataRequired()])


    def preload(self, pid):
        """
        codes = GetPatientInfo.getCODETABLE(page='baby')
        self.labels = {}
        values = {}
        for code in codes.values():
            datatype = code['datatype']
            if datatype == 'text':
                self.labels[code['name']] = code['desc']
            else:
                values[code['name']] = datatype

        self.newborn_family_name_value = StringField()
        self.newborn_first_name_value = StringField()
        self.apgar1m_score_value = IntegerField()
        self.apgar5m_score_value = IntegerField()
        self.apgar10m_score_value = IntegerField()
        self.birth_weight_grams_value = DecimalField()
        self.birth_weight_lbs_value = DecimalField()
        self.birth_weight_ozs_value = DecimalField()
        """


        self.mother_id.data = GetPatientInfo.getMotherID(pid)

        baby, medInfo = GetPatientInfo.getPatientMedical(pid=pid, codes=self.codes)
        if baby == None:
            return
        if baby.name[0].family != None:
            self.newborn_family_name.data = baby.name[0].family
            #self.values['newborn_family_name_value.data'] = baby.name[0].family
        if baby.name[0].given[0] != None:
            self.newborn_first_name.data = baby.name[0].given[0]

        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "apgar1m_score")
        if value != None:
            self.apgar1m_score.data = value
        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "apgar5m_score")
        if value != None:
            self.apgar5m_score.data = value
        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "apgar10m_score")
        if value != None:
            self.apgar10m_score.data = value

        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "birth_weight")
        if value != None:
            vGrams, vLbs, vOzs = convertWeight(float(value), unit)
            self.birth_weight_grams.data = vGrams
            self.birth_weight_lbs.data = vLbs
            self.birth_weight_ozs.data = vOzs

        #self.motherid = GetPatientInfo.getMotherID(pid)
        #self.mother_id = '<input type="hidden" name="mother_id" value="%s">' %self.motherid
        self.mother_id.data = GetPatientInfo.getMotherID(pid)
示例#7
0
    def preload(self, pid):

        mother, medInfo = GetPatientInfo.getPatientMedical(pid=pid,
                                                           codes=self.codes)
        if mother.name[0].family != None:
            self.mother_family_name.data = mother.name[0].family
            #self.values['newborn_family_name_value.data'] = mother.name[0].family
        if mother.name[0].given[0] != None:
            self.mother_first_name.data = mother.name[0].given[0]

        print(json.dumps(medInfo, indent=4))
        print(self.codes['pre_weight'])
        '''
        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "apgar1m_score_value")
        if value != None:
            self.apgar1m_score_value.data = value
        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "apgar5m_score_value")
        if value != None:
            self.apgar5m_score_value.data = value
        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "apgar10m_score_value")
        if value != None:
            self.apgar10m_score_value.data = value
        '''

        value1, unit = GetPatientInfo.getMedInfoValue(medInfo, "pre_weight")
        print(value1, unit)
        if value1 != None:
            vGrams, vLbs, vOzs = convertWeight(float(value1), unit)
            self.pre_weight_grams.data = vGrams
            self.pre_weight_lbs.data = vLbs
            self.pre_weight_ozs.data = vOzs

        value2, unit = GetPatientInfo.getMedInfoValue(medInfo,
                                                      "delivery_weight")
        print(value2, unit)
        if value2 != None:
            vGrams, vLbs, vOzs = convertWeight(float(value2), unit)
            self.delivery_weight_grams.data = vGrams
            self.delivery_weight_lbs.data = vLbs
            self.delivery_weight_ozs.data = vOzs

        if value1 != None and value2 != None:
            (vG, vL, vO) = weightDifference(self.pre_weight_grams.data,
                                            self.pre_weight_lbs.data,
                                            self.pre_weight_ozs.data,
                                            self.delivery_weight_grams.data,
                                            self.delivery_weight_lbs.data,
                                            self.delivery_weight_ozs.data)
            self.weight_gain_grams.data = vG
            self.weight_gain_lbs.data = vL
            self.weight_gain_ozs.data = vO

        value, unit = GetPatientInfo.getMedInfoValue(medInfo,
                                                     "pre_hypertension")
        if value != None:
            print(value, unit)
            self.pre_hypertension.data = value

        value, unit = GetPatientInfo.getMedInfoValue(
            medInfo, "gestational_hypertension")
        if value != None:
            print(value, unit)
            self.gestational_hypertension.data = value

        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "eclampsia")
        if value != None:
            print(value, unit)
            self.eclampsia.data = value

        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "pre_diabetes")
        if value != None:
            print(value, unit)
            self.pre_diabetes.data = value

        value, unit = GetPatientInfo.getMedInfoValue(medInfo,
                                                     "gestational_diabetes")
        if value != None:
            print(value, unit)
            self.gestational_diabetes.data = value
示例#8
0
class MotherForm(FlaskForm):
    #values = {}
    #values['newborn_family_name_value'] = StringField()
    CODEFILE = "FHIR_resource_codes_1.txt"
    codes = GetPatientInfo.getCODETABLE(file=CODEFILE, page='mother')

    temp = BooleanField('Hi')

    #print(json.dumps(codes, indent=4))
    submit = SubmitField("Save and Report")

    fields = [
        'mother_family_name', 'mother_first_name', 'pre_weight',
        'pre_weight_grams', 'pre_weight_lbs', 'pre_weight_ozs',
        'delivery_weight', 'delivery_weight_grams', 'delivery_weight_lbs',
        'delivery_weight_ozs', 'weight_gain', 'weight_gain_grams',
        'weight_gain_lbs', 'weight_gain_ozs', 'pre_hypertension',
        'gestational_hypertension', 'eclampsia', 'pre_diabetes',
        'gestational_diabetes'
    ]

    for f in fields:
        field = codes[f]
        comm = f + " = "
        if field['datatype'].lower() == 'int':
            comm += "IntegerField('%s')" % field['desc']
        elif field['datatype'].lower() == 'string':
            comm += "StringField('%s')" % field['desc']
        elif field['datatype'].lower() == 'float':
            comm += "DecimalField('%s', [validateWeightInputs])" % field['desc']
        elif field['datatype'].lower() == 'boolean':
            comm += "BooleanField('%s')" % field['desc']
        print("Executing command: " + comm)
        exec(comm)

    def preload(self, pid):

        mother, medInfo = GetPatientInfo.getPatientMedical(pid=pid,
                                                           codes=self.codes)
        if mother.name[0].family != None:
            self.mother_family_name.data = mother.name[0].family
            #self.values['newborn_family_name_value.data'] = mother.name[0].family
        if mother.name[0].given[0] != None:
            self.mother_first_name.data = mother.name[0].given[0]

        print(json.dumps(medInfo, indent=4))
        print(self.codes['pre_weight'])
        '''
        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "apgar1m_score_value")
        if value != None:
            self.apgar1m_score_value.data = value
        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "apgar5m_score_value")
        if value != None:
            self.apgar5m_score_value.data = value
        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "apgar10m_score_value")
        if value != None:
            self.apgar10m_score_value.data = value
        '''

        value1, unit = GetPatientInfo.getMedInfoValue(medInfo, "pre_weight")
        print(value1, unit)
        if value1 != None:
            vGrams, vLbs, vOzs = convertWeight(float(value1), unit)
            self.pre_weight_grams.data = vGrams
            self.pre_weight_lbs.data = vLbs
            self.pre_weight_ozs.data = vOzs

        value2, unit = GetPatientInfo.getMedInfoValue(medInfo,
                                                      "delivery_weight")
        print(value2, unit)
        if value2 != None:
            vGrams, vLbs, vOzs = convertWeight(float(value2), unit)
            self.delivery_weight_grams.data = vGrams
            self.delivery_weight_lbs.data = vLbs
            self.delivery_weight_ozs.data = vOzs

        if value1 != None and value2 != None:
            (vG, vL, vO) = weightDifference(self.pre_weight_grams.data,
                                            self.pre_weight_lbs.data,
                                            self.pre_weight_ozs.data,
                                            self.delivery_weight_grams.data,
                                            self.delivery_weight_lbs.data,
                                            self.delivery_weight_ozs.data)
            self.weight_gain_grams.data = vG
            self.weight_gain_lbs.data = vL
            self.weight_gain_ozs.data = vO

        value, unit = GetPatientInfo.getMedInfoValue(medInfo,
                                                     "pre_hypertension")
        if value != None:
            print(value, unit)
            self.pre_hypertension.data = value

        value, unit = GetPatientInfo.getMedInfoValue(
            medInfo, "gestational_hypertension")
        if value != None:
            print(value, unit)
            self.gestational_hypertension.data = value

        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "eclampsia")
        if value != None:
            print(value, unit)
            self.eclampsia.data = value

        value, unit = GetPatientInfo.getMedInfoValue(medInfo, "pre_diabetes")
        if value != None:
            print(value, unit)
            self.pre_diabetes.data = value

        value, unit = GetPatientInfo.getMedInfoValue(medInfo,
                                                     "gestational_diabetes")
        if value != None:
            print(value, unit)
            self.gestational_diabetes.data = value

    def validateWeightInputs(form, field):
        """
        Try to validate weight inputs, but seems not working for
        :param field:
        :return:
        """
        return validWeight(form.pre_weight_grams.data, form_pre_weight_lbs.data, form.pre_weight_ozs.data) and \
               validWeight(form.delivery_weight_grams.data, form_delivery_weight_lbs.data, form.delivery_weight_ozs.data) and \
               validWeight(form.weight_gain_grams.data, form_weight_gain_lbs.data, form.weight_gain_ozs.data)