Skip to content

OpenConceptLab/ocl_issues#1791 Add support for importing NPM packages #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN chown -R ocl:ocl $APP_HOME /temp /staticfiles

WORKDIR $APP_HOME

RUN apk update && apk upgrade && apk add --no-cache libpq bash curl
RUN apk update && apk upgrade && apk add --no-cache libpq bash curl busybox-extras

RUN pip install --upgrade pip

Expand Down
52 changes: 52 additions & 0 deletions core/code_systems/converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from fhir.resources.codesystem import CodeSystem

from core.settings import DEFAULT_LOCALE
from core.sources.models import Source


class CodeSystemConverter:
"""It is intended as a replacement for serializers"""

@staticmethod
def can_convert_from_fhir(obj):
return isinstance(obj, CodeSystem) or (isinstance(obj, dict) and obj.get('resourceType') == 'CodeSystem')

@staticmethod
def can_convert_to_fhir(obj):
return isinstance(obj, Source) or (isinstance(obj, dict) and obj.get('type') == 'Source')

@staticmethod
def to_fhir(source):
if isinstance(source, dict):
res = source
res_type = res.pop('type')
source = Source(**res)
res.update({'type', res_type})

code_system = {
'id': source.mnemonic,
'status': 'retired' if source.retired else 'active' if source.released else 'draft',
'content': source.content_type if source.content_type else 'complete',
'url': source.canonical_url,
'title': source.name,
'language': source.default_locale,
'count': source.active_concepts,
}
return CodeSystem(**code_system).dict()

@staticmethod
def from_fhir(code_system):
if isinstance(code_system, dict):
code_system = CodeSystem(**code_system)

source = {
'type': 'Source',
'mnemonic': code_system.id,
'canonical_url': code_system.url,
'name': code_system.title,
'default_locale': code_system.language if code_system.language else DEFAULT_LOCALE,
'content_type': code_system.content,
'retired': code_system.status == 'retired',
'released': code_system.status == 'active',
}
return source
18 changes: 18 additions & 0 deletions core/code_systems/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import json

import responses
from fhir.resources.codesystem import CodeSystem
from rest_framework.test import APIClient

from core.code_systems.converter import CodeSystemConverter
from core.code_systems.serializers import CodeSystemDetailSerializer
from core.code_systems.views import CodeSystemLookupNotFoundError
from core.common.tests import OCLTestCase
Expand Down Expand Up @@ -589,3 +592,18 @@ def test_unable_to_represent_as_fhir(self):
self.assertDictEqual(serialized, {
'resourceType': 'OperationOutcome',
'issue': [{'severity': 'error', 'details': 'Failed to represent "/invalid/uri" as CodeSystem'}]})

def test_conversion_from_fhir(self):
code_system = CodeSystem(**{
'resourceType': 'CodeSystem',
'id': 'test',
'content': 'complete',
'status': 'draft'
})
source = CodeSystemConverter.from_fhir(code_system)
self.assertEqual(source['mnemonic'], 'test')

def test_conversion_to_fhir(self):
source = OrganizationSourceFactory.build(mnemonic='test')
code_system = CodeSystemConverter.to_fhir(source)
self.assertEqual(code_system['id'], 'test')
4 changes: 2 additions & 2 deletions core/common/errbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ def xml_raw(self, etype, value, trace, limit=None, file=None):
original_print_exception = traceback.print_exception


def print_exception_with_errbit_logging(etype, value, tb, limit=None, file=None):
def print_exception_with_errbit_logging(etype, value, tb, limit=None, file=None, chain=True):
if not (etype == KeyError and str(value) == "'cid'"):
message = ERRBIT_LOGGER.xml_raw(etype, value, tb)
ERRBIT_LOGGER.send_message(message.encode('utf-8'))
original_print_exception(etype, value, tb, limit=None, file=None)
original_print_exception(etype, value, tb, limit=limit, file=file, chain=chain)


traceback.print_exception = print_exception_with_errbit_logging
17 changes: 17 additions & 0 deletions core/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,23 @@ def bulk_import_inline(to_import, username, update_if_exists):
return BulkImportInline(content=to_import, username=username, update_if_exists=update_if_exists).run()


@app.task(base=QueueOnce, retry_kwargs={'max_retries': 0})
def bulk_import_new(path, username, owner_type, owner, import_type='default'):
from core.importers.importer import Importer
return Importer(path, username, owner_type, owner, import_type).run()


@app.task(retry_kwargs={'max_retries': 0})
def bulk_import_subtask(path, username, owner_type, owner, resource_type, files):
from core.importers.importer import ImporterSubtask
return ImporterSubtask(path, username, owner_type, owner, resource_type, files).run()

@app.task
def chordfinisher(*args, **kwargs):
"""Used for waiting for all results of a group of tasks. See Importer.run()"""
return "Done!"


@app.task(bind=True, retry_kwargs={'max_retries': 0})
def bulk_import_parts_inline(self, input_list, username, update_if_exists):
from core.importers.models import BulkImportInline
Expand Down
Loading