def createDefaultInsuree(cls, audit_user_id):
     imis_insuree = Insuree()
     imis_insuree.head = GeneralConfiguration.get_default_value_of_patient_head_attribute(
     )
     imis_insuree.card_issued = GeneralConfiguration.get_default_value_of_patient_card_issued_attribute(
     )
     imis_insuree.validity_from = TimeUtils.now()
     imis_insuree.audit_user_id = audit_user_id
     return imis_insuree
 def createDefaultInsuree(cls, audit_user_id):
     imis_hf = HealthFacility()
     # TODO legalForm isn't covered because that value is missing in the model (value need to be nullable in DB)
     # TODO LocationId isn't covered because that value is missing in the model (value need to be nullable in DB)
     imis_hf.offline = GeneralConfiguration.get_default_value_of_location_offline_attribute(
     )
     imis_hf.care_type = GeneralConfiguration.get_default_value_of_location_care_type(
     )
     imis_hf.validity_from = TimeUtils.now()
     imis_hf.audit_user_id = audit_user_id
     return imis_hf
 def build_fhir_gender(cls, fhir_patient, imis_insuree):
     if imis_insuree.gender is not None:
         code = imis_insuree.gender.code
         if code == GeneralConfiguration.get_male_gender_code():
             fhir_patient.gender = AdministrativeGender.MALE.value
         elif code == GeneralConfiguration.get_female_gender_code():
             fhir_patient.gender = AdministrativeGender.FEMALE.value
         elif code == GeneralConfiguration.get_other_gender_code():
             fhir_patient.gender = AdministrativeGender.OTHER.value
     else:
         fhir_patient.gender = AdministrativeGender.UNKNOWN.value
 def build_imis_gender(cls, imis_insuree, fhir_patient):
     gender = fhir_patient.gender
     if gender is not None:
         imis_gender_code = None
         if gender == AdministrativeGender.MALE.value:
             imis_gender_code = GeneralConfiguration.get_male_gender_code()
         elif gender == AdministrativeGender.FEMALE.value:
             imis_gender_code = GeneralConfiguration.get_female_gender_code(
             )
         elif gender == AdministrativeGender.OTHER.value:
             imis_gender_code = GeneralConfiguration.get_other_gender_code()
         if imis_gender_code is not None:
             imis_insuree.gender = Gender.objects.get(pk=imis_gender_code)
Beispiel #5
0
 def build_fhir_contact_point(cls, value, contact_point_system, contact_point_use):
     contact_point = ContactPoint()
     if GeneralConfiguration.show_system():
         contact_point.system = contact_point_system
     contact_point.use = contact_point_use
     contact_point.value = value
     return contact_point
Beispiel #6
0
 def get_audit_user_id(self):
     request = self.context.get("request")
     # Taking the audit_user_id from the query doesn't seem wise but there might be a use for it
     # audit_user_id = request.query_params.get('auditUserId', None)
     audit_user_id = request.user.id_for_audit if request.user else None
     if audit_user_id is None:
         audit_user_id = GeneralConfiguration.get_default_audit_user_id()
     return audit_user_id
Beispiel #7
0
 def build_codeable_concept(cls, code, system=None, text=None):
     codeable_concept = CodeableConcept()
     if code or system:
         coding = Coding()
         if GeneralConfiguration.show_system():
             coding.system = system
         if not isinstance(code, str):
             code = str(code)
         coding.code = code
         codeable_concept.coding = [coding]
     codeable_concept.text = text
     return codeable_concept
Beispiel #8
0
 def build_configuration(cls, cfg):
     GeneralConfiguration.build_configuration(cfg)
     cls.get_r4().build_configuration(cfg)
     cls.configure_api_error_handler()
Beispiel #9
0
class FhirBundleResultsSetPagination(PageNumberPagination):

    page_size = GeneralConfiguration.get_default_response_page_size()
    page_query_param = 'page-offset'
    page_size_query_param = '_count'

    def get_paginated_response(self, data):
        return Response(self.build_bundle_set(data).toDict())

    def build_bundle_set(self, data):
        bundle = Bundle()
        bundle.type = BundleType.SEARCHSET.value
        bundle.total = self.page.paginator.count
        self.build_bundle_links(bundle)
        self.build_bundle_entry(bundle, data)
        return bundle

    def build_bundle_links(self, bundle):
        self.build_bundle_link(bundle, BundleLinkRelation.SELF.value,
                               self.request.build_absolute_uri())
        next_link = self.get_next_link()
        if next_link:
            self.build_bundle_link(bundle, BundleLinkRelation.NEXT.value,
                                   next_link)
        previous_link = self.get_previous_link()
        if previous_link:
            self.build_bundle_link(bundle, BundleLinkRelation.PREVIOUS.value,
                                   previous_link)

    def build_bundle_link(self, bundle, relation, url):
        self_link = BundleLink()
        self_link.relation = relation
        self_link.url = url
        bundle.link.append(self_link)

    def build_bundle_entry(self, bundle, data):
        for obj in data:
            entry = BundleEntry()
            entry.fullUrl = self.build_full_url_for_resource(obj)
            entry.resource = obj
            bundle.entry.append(entry)

    def build_full_url_for_resource(self, fhir_object):
        url = None
        resource_pk = self.get_object_pk(fhir_object)
        if resource_pk:
            url = self.request.build_absolute_uri()
            url = self.exclude_query_parameter_from_url(url)
            url = url + resource_pk
        return url

    def get_object_pk(self, fhir_object):
        pk_id = None
        if isinstance(fhir_object, dict):
            pk_id = fhir_object.get('id')
        return str(pk_id) if pk_id else None

    def exclude_query_parameter_from_url(self, url):
        try:
            from urllib.parse import urlparse  # Python 3
        except ImportError:
            from urlparse import urlparse  # Python 2
        o = urlparse(url)
        return o._replace(query=None).geturl()

    def paginate_queryset(self, queryset, *args, **kwargs):
        if hasattr(queryset, 'count'):
            queryset = CachedCountQueryset(queryset)
        return super().paginate_queryset(queryset, *args, **kwargs)