__all__ = ['process_pmc']

import logging
import requests

from .processor import RlimspProcessor


logger = logging.getLogger(__name__)


RLIMSP_URL = 'https://research.bioinformatics.udel.edu/itextmine/api/data/rlims/pmc'


class RLIMSP_Error(Exception):
    pass


def process_pmc(pmcid, with_grounding=True):
    """Get an output from RLIMS-p for the given pmic id.

    Parameters
    ----------
    pmcid : str
        A PMCID, with the prefix PMC, of the paper to be "read".
    with_grounding : bool
        The RLIMS-P web service provides two endpoints, one pre-grounded, the
        other not so much. The grounded endpoint returns far less content, and
        may perform some grounding that can be handled by the grounding mapper.
    """
    if with_grounding:
        resp = requests.get(RLIMSP_URL + '.normed/pmcid/%s' % pmcid)
    else:
        resp = requests.get(RLIMSP_URL + '/pmcid/%s' % pmcid)

    if resp.status_code != 200:
        raise RLIMSP_Error("Bad status code: %d - %s"
                           % (resp.status_code, resp.reason))

    rp = RlimspProcessor(resp.json())

    return rp

@@ -13,19 +13,31 @@
 process_
-pmc
+from_webservice
 '%5D%0A%0Aimpo
@@ -224,19 +224,16 @@
 a/rlims/
-pmc
 '%0A%0A%0Aclas
@@ -286,18 +286,90 @@
 ess_
-pmc(pmcid,
+from_webservice(id_val, id_type='pmcid', source='pmc',%0A                           
  wit
@@ -479,21 +479,22 @@
 ---%0A    
-pmcid
+id_val
  : str%0A 
@@ -529,16 +529,41 @@
 fix PMC,
+ or pmid, with no prefix,
  of the 
@@ -570,16 +570,24 @@
 paper to
+%0A       
  be %22rea
@@ -590,16 +590,204 @@
 %22read%22.%0A
+    id_type : str%0A        Either 'pmid' or 'pmcid'. The default is 'pmcid'.%0A    source : str%0A        Either 'pmc' or 'medline', whether you want pmc fulltext or medline%0A        abstracts.%0A
     with
@@ -1084,83 +1084,68 @@
     
-resp = requests.get(RLIMSP_URL + '.normed/pmcid/%25s' %25 pmcid)%0A    else:%0A    
+fmt = '%25s.normed/%25s/%25s'%0A    else:%0A        fmt = '%25s/%25s/%25s'%0A%0A
     
@@ -1181,27 +1181,39 @@
 L + 
-'/pmcid/%25s' %25 pmcid
+fmt %25 (source, id_type, id_val)
 )%0A%0A 

Add capability to read pmids and get medline.