from __future__ import absolute_import
from __future__ import unicode_literals

from django import forms
from django.utils.translation import ugettext_lazy as _
import json

class JsonForm(forms.Form):
    json = forms.CharField(label='JSON body', max_length=10000, widget=forms.Textarea,
            help_text =_("This field must contain a JSON object e.g. {}"))

    required_css_class = 'required'


    def clean_json(self):
        jsonf = self.cleaned_data.get('json')

        try:
            j = json.loads(jsonf)
            if type (j) != type({}):
                msg=_("The field does not contain a valid JSON object.")
                raise forms.ValidationError(msg)
            
        except ValueError:  
            msg=_("The field does not contain valid JSON.")
            raise forms.ValidationError(msg)
        
        return jsonf
        
    
@@ -165,16 +165,53 @@
 ort json
+%0Afrom pdt import %0Afrom pdt import pdt
 %0A%0Aclass 
@@ -712,28 +712,16 @@
 or(msg)%0A
-            
 %0A       
@@ -739,18 +739,16 @@
 ueError:
-  
 %0A       
@@ -845,25 +845,17 @@
 or(msg)%0A
-        
 %0A
+
         
@@ -871,17 +871,1740 @@
 onf%0A
-        %0A    
+%0Aclass PractitionerForm(forms.Form):%0A    json = forms.CharField(label='JSON body', max_length=10000, widget=forms.Textarea,%0A            help_text =_(%22This field must contain a Practitioner FHIR JSON object e.g. %7B%7D%22))%0A%0A    required_css_class = 'required'%0A%0A%0A    def clean_json(self):%0A        jsonf  = self.cleaned_data.get('json')%0A%0A        try:%0A            j = json.loads(jsonf)%0A            json_pract_result = pdt.json_schema_check.json_schema_check(pdt.fhir_json_schema.fhir_practitioner_schema.json,j)%0A            if json_pract_result%5B'errors'%5D != %5B%5D:%0A                msg=_(%22The field does not contain a valid FHIR Practitioner JSON object: %22, json_pract_result)%0A                raise forms.ValidationError(msg)%0A%0A        except ValueError:%0A            msg=_(%22The field does not contain valid JSON.%22)%0A            raise forms.ValidationError(msg)%0A%0A        return jsonf%0A%0Aclass OrganizationForm(forms.Form):%0A    json = forms.CharField(label='JSON body', max_length=10000, widget=forms.Textarea,%0A            help_text =_(%22This field must contain an Organization FHIR JSON object e.g. %7B%7D%22))%0A%0A    required_css_class = 'required'%0A%0A%0A    def clean_json(self):%0A        jsonf = self.cleaned_data.get('json')%0A%0A        try:%0A            j = json.loads(jsonf)%0A            json_pract_result = pdt.json_schema_check.json_schema_check(pdt.fhir_json_schema.fhir_organization_schema.json,j)%0A            if json_pract_result%5B'errors'%5D != %5B%5D:%0A                msg=_(%22The field does not contain a valid FHIR Organization JSON object: %22, json_pract_result)%0A                raise forms.ValidationError(msg)%0A%0A        except ValueError:%0A            msg=_(%22The field does not contain valid JSON.%22)%0A            raise forms.ValidationError(msg)%0A%0A        return jsonf%0A

Add functionality for fhir organization and practitioner