{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.ComprehendMedical.InferRxNorm
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- InferRxNorm detects medications as entities listed in a patient record
-- and links to the normalized concept identifiers in the RxNorm database
-- from the National Library of Medicine. Amazon Comprehend Medical only
-- detects medical entities in English language texts.
module Amazonka.ComprehendMedical.InferRxNorm
  ( -- * Creating a Request
    InferRxNorm (..),
    newInferRxNorm,

    -- * Request Lenses
    inferRxNorm_text,

    -- * Destructuring the Response
    InferRxNormResponse (..),
    newInferRxNormResponse,

    -- * Response Lenses
    inferRxNormResponse_paginationToken,
    inferRxNormResponse_modelVersion,
    inferRxNormResponse_httpStatus,
    inferRxNormResponse_entities,
  )
where

import Amazonka.ComprehendMedical.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newInferRxNorm' smart constructor.
data InferRxNorm = InferRxNorm'
  { -- | The input text used for analysis. The input for InferRxNorm is a string
    -- from 1 to 10000 characters.
    InferRxNorm -> Text
text :: Prelude.Text
  }
  deriving (InferRxNorm -> InferRxNorm -> Bool
(InferRxNorm -> InferRxNorm -> Bool)
-> (InferRxNorm -> InferRxNorm -> Bool) -> Eq InferRxNorm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InferRxNorm -> InferRxNorm -> Bool
$c/= :: InferRxNorm -> InferRxNorm -> Bool
== :: InferRxNorm -> InferRxNorm -> Bool
$c== :: InferRxNorm -> InferRxNorm -> Bool
Prelude.Eq, ReadPrec [InferRxNorm]
ReadPrec InferRxNorm
Int -> ReadS InferRxNorm
ReadS [InferRxNorm]
(Int -> ReadS InferRxNorm)
-> ReadS [InferRxNorm]
-> ReadPrec InferRxNorm
-> ReadPrec [InferRxNorm]
-> Read InferRxNorm
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InferRxNorm]
$creadListPrec :: ReadPrec [InferRxNorm]
readPrec :: ReadPrec InferRxNorm
$creadPrec :: ReadPrec InferRxNorm
readList :: ReadS [InferRxNorm]
$creadList :: ReadS [InferRxNorm]
readsPrec :: Int -> ReadS InferRxNorm
$creadsPrec :: Int -> ReadS InferRxNorm
Prelude.Read, Int -> InferRxNorm -> ShowS
[InferRxNorm] -> ShowS
InferRxNorm -> String
(Int -> InferRxNorm -> ShowS)
-> (InferRxNorm -> String)
-> ([InferRxNorm] -> ShowS)
-> Show InferRxNorm
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InferRxNorm] -> ShowS
$cshowList :: [InferRxNorm] -> ShowS
show :: InferRxNorm -> String
$cshow :: InferRxNorm -> String
showsPrec :: Int -> InferRxNorm -> ShowS
$cshowsPrec :: Int -> InferRxNorm -> ShowS
Prelude.Show, (forall x. InferRxNorm -> Rep InferRxNorm x)
-> (forall x. Rep InferRxNorm x -> InferRxNorm)
-> Generic InferRxNorm
forall x. Rep InferRxNorm x -> InferRxNorm
forall x. InferRxNorm -> Rep InferRxNorm x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InferRxNorm x -> InferRxNorm
$cfrom :: forall x. InferRxNorm -> Rep InferRxNorm x
Prelude.Generic)

-- |
-- Create a value of 'InferRxNorm' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'text', 'inferRxNorm_text' - The input text used for analysis. The input for InferRxNorm is a string
-- from 1 to 10000 characters.
newInferRxNorm ::
  -- | 'text'
  Prelude.Text ->
  InferRxNorm
newInferRxNorm :: Text -> InferRxNorm
newInferRxNorm Text
pText_ = InferRxNorm' :: Text -> InferRxNorm
InferRxNorm' {$sel:text:InferRxNorm' :: Text
text = Text
pText_}

-- | The input text used for analysis. The input for InferRxNorm is a string
-- from 1 to 10000 characters.
inferRxNorm_text :: Lens.Lens' InferRxNorm Prelude.Text
inferRxNorm_text :: (Text -> f Text) -> InferRxNorm -> f InferRxNorm
inferRxNorm_text = (InferRxNorm -> Text)
-> (InferRxNorm -> Text -> InferRxNorm)
-> Lens InferRxNorm InferRxNorm Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InferRxNorm' {Text
text :: Text
$sel:text:InferRxNorm' :: InferRxNorm -> Text
text} -> Text
text) (\s :: InferRxNorm
s@InferRxNorm' {} Text
a -> InferRxNorm
s {$sel:text:InferRxNorm' :: Text
text = Text
a} :: InferRxNorm)

instance Core.AWSRequest InferRxNorm where
  type AWSResponse InferRxNorm = InferRxNormResponse
  request :: InferRxNorm -> Request InferRxNorm
request = Service -> InferRxNorm -> Request InferRxNorm
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy InferRxNorm
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse InferRxNorm)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse InferRxNorm))
-> Logger
-> Service
-> Proxy InferRxNorm
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse InferRxNorm)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text
-> Maybe Text -> Int -> [RxNormEntity] -> InferRxNormResponse
InferRxNormResponse'
            (Maybe Text
 -> Maybe Text -> Int -> [RxNormEntity] -> InferRxNormResponse)
-> Either String (Maybe Text)
-> Either
     String (Maybe Text -> Int -> [RxNormEntity] -> InferRxNormResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"PaginationToken")
            Either
  String (Maybe Text -> Int -> [RxNormEntity] -> InferRxNormResponse)
-> Either String (Maybe Text)
-> Either String (Int -> [RxNormEntity] -> InferRxNormResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"ModelVersion")
            Either String (Int -> [RxNormEntity] -> InferRxNormResponse)
-> Either String Int
-> Either String ([RxNormEntity] -> InferRxNormResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either String ([RxNormEntity] -> InferRxNormResponse)
-> Either String [RxNormEntity]
-> Either String InferRxNormResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe [RxNormEntity])
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Entities" Either String (Maybe [RxNormEntity])
-> [RxNormEntity] -> Either String [RxNormEntity]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [RxNormEntity]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable InferRxNorm

instance Prelude.NFData InferRxNorm

instance Core.ToHeaders InferRxNorm where
  toHeaders :: InferRxNorm -> ResponseHeaders
toHeaders =
    ResponseHeaders -> InferRxNorm -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"ComprehendMedical_20181030.InferRxNorm" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON InferRxNorm where
  toJSON :: InferRxNorm -> Value
toJSON InferRxNorm' {Text
text :: Text
$sel:text:InferRxNorm' :: InferRxNorm -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Text" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
text)]
      )

instance Core.ToPath InferRxNorm where
  toPath :: InferRxNorm -> ByteString
toPath = ByteString -> InferRxNorm -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery InferRxNorm where
  toQuery :: InferRxNorm -> QueryString
toQuery = QueryString -> InferRxNorm -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newInferRxNormResponse' smart constructor.
data InferRxNormResponse = InferRxNormResponse'
  { -- | If the result of the previous request to @InferRxNorm@ was truncated,
    -- include the @PaginationToken@ to fetch the next page of medication
    -- entities.
    InferRxNormResponse -> Maybe Text
paginationToken :: Prelude.Maybe Prelude.Text,
    -- | The version of the model used to analyze the documents, in the format
    -- /n/./n/./n/ You can use this information to track the model used for a
    -- particular batch of documents.
    InferRxNormResponse -> Maybe Text
modelVersion :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    InferRxNormResponse -> Int
httpStatus :: Prelude.Int,
    -- | The medication entities detected in the text linked to RxNorm concepts.
    -- If the action is successful, the service sends back an HTTP 200
    -- response, as well as the entities detected.
    InferRxNormResponse -> [RxNormEntity]
entities :: [RxNormEntity]
  }
  deriving (InferRxNormResponse -> InferRxNormResponse -> Bool
(InferRxNormResponse -> InferRxNormResponse -> Bool)
-> (InferRxNormResponse -> InferRxNormResponse -> Bool)
-> Eq InferRxNormResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InferRxNormResponse -> InferRxNormResponse -> Bool
$c/= :: InferRxNormResponse -> InferRxNormResponse -> Bool
== :: InferRxNormResponse -> InferRxNormResponse -> Bool
$c== :: InferRxNormResponse -> InferRxNormResponse -> Bool
Prelude.Eq, ReadPrec [InferRxNormResponse]
ReadPrec InferRxNormResponse
Int -> ReadS InferRxNormResponse
ReadS [InferRxNormResponse]
(Int -> ReadS InferRxNormResponse)
-> ReadS [InferRxNormResponse]
-> ReadPrec InferRxNormResponse
-> ReadPrec [InferRxNormResponse]
-> Read InferRxNormResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InferRxNormResponse]
$creadListPrec :: ReadPrec [InferRxNormResponse]
readPrec :: ReadPrec InferRxNormResponse
$creadPrec :: ReadPrec InferRxNormResponse
readList :: ReadS [InferRxNormResponse]
$creadList :: ReadS [InferRxNormResponse]
readsPrec :: Int -> ReadS InferRxNormResponse
$creadsPrec :: Int -> ReadS InferRxNormResponse
Prelude.Read, Int -> InferRxNormResponse -> ShowS
[InferRxNormResponse] -> ShowS
InferRxNormResponse -> String
(Int -> InferRxNormResponse -> ShowS)
-> (InferRxNormResponse -> String)
-> ([InferRxNormResponse] -> ShowS)
-> Show InferRxNormResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InferRxNormResponse] -> ShowS
$cshowList :: [InferRxNormResponse] -> ShowS
show :: InferRxNormResponse -> String
$cshow :: InferRxNormResponse -> String
showsPrec :: Int -> InferRxNormResponse -> ShowS
$cshowsPrec :: Int -> InferRxNormResponse -> ShowS
Prelude.Show, (forall x. InferRxNormResponse -> Rep InferRxNormResponse x)
-> (forall x. Rep InferRxNormResponse x -> InferRxNormResponse)
-> Generic InferRxNormResponse
forall x. Rep InferRxNormResponse x -> InferRxNormResponse
forall x. InferRxNormResponse -> Rep InferRxNormResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InferRxNormResponse x -> InferRxNormResponse
$cfrom :: forall x. InferRxNormResponse -> Rep InferRxNormResponse x
Prelude.Generic)

-- |
-- Create a value of 'InferRxNormResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'paginationToken', 'inferRxNormResponse_paginationToken' - If the result of the previous request to @InferRxNorm@ was truncated,
-- include the @PaginationToken@ to fetch the next page of medication
-- entities.
--
-- 'modelVersion', 'inferRxNormResponse_modelVersion' - The version of the model used to analyze the documents, in the format
-- /n/./n/./n/ You can use this information to track the model used for a
-- particular batch of documents.
--
-- 'httpStatus', 'inferRxNormResponse_httpStatus' - The response's http status code.
--
-- 'entities', 'inferRxNormResponse_entities' - The medication entities detected in the text linked to RxNorm concepts.
-- If the action is successful, the service sends back an HTTP 200
-- response, as well as the entities detected.
newInferRxNormResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  InferRxNormResponse
newInferRxNormResponse :: Int -> InferRxNormResponse
newInferRxNormResponse Int
pHttpStatus_ =
  InferRxNormResponse' :: Maybe Text
-> Maybe Text -> Int -> [RxNormEntity] -> InferRxNormResponse
InferRxNormResponse'
    { $sel:paginationToken:InferRxNormResponse' :: Maybe Text
paginationToken =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:modelVersion:InferRxNormResponse' :: Maybe Text
modelVersion = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:InferRxNormResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:entities:InferRxNormResponse' :: [RxNormEntity]
entities = [RxNormEntity]
forall a. Monoid a => a
Prelude.mempty
    }

-- | If the result of the previous request to @InferRxNorm@ was truncated,
-- include the @PaginationToken@ to fetch the next page of medication
-- entities.
inferRxNormResponse_paginationToken :: Lens.Lens' InferRxNormResponse (Prelude.Maybe Prelude.Text)
inferRxNormResponse_paginationToken :: (Maybe Text -> f (Maybe Text))
-> InferRxNormResponse -> f InferRxNormResponse
inferRxNormResponse_paginationToken = (InferRxNormResponse -> Maybe Text)
-> (InferRxNormResponse -> Maybe Text -> InferRxNormResponse)
-> Lens
     InferRxNormResponse InferRxNormResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InferRxNormResponse' {Maybe Text
paginationToken :: Maybe Text
$sel:paginationToken:InferRxNormResponse' :: InferRxNormResponse -> Maybe Text
paginationToken} -> Maybe Text
paginationToken) (\s :: InferRxNormResponse
s@InferRxNormResponse' {} Maybe Text
a -> InferRxNormResponse
s {$sel:paginationToken:InferRxNormResponse' :: Maybe Text
paginationToken = Maybe Text
a} :: InferRxNormResponse)

-- | The version of the model used to analyze the documents, in the format
-- /n/./n/./n/ You can use this information to track the model used for a
-- particular batch of documents.
inferRxNormResponse_modelVersion :: Lens.Lens' InferRxNormResponse (Prelude.Maybe Prelude.Text)
inferRxNormResponse_modelVersion :: (Maybe Text -> f (Maybe Text))
-> InferRxNormResponse -> f InferRxNormResponse
inferRxNormResponse_modelVersion = (InferRxNormResponse -> Maybe Text)
-> (InferRxNormResponse -> Maybe Text -> InferRxNormResponse)
-> Lens
     InferRxNormResponse InferRxNormResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InferRxNormResponse' {Maybe Text
modelVersion :: Maybe Text
$sel:modelVersion:InferRxNormResponse' :: InferRxNormResponse -> Maybe Text
modelVersion} -> Maybe Text
modelVersion) (\s :: InferRxNormResponse
s@InferRxNormResponse' {} Maybe Text
a -> InferRxNormResponse
s {$sel:modelVersion:InferRxNormResponse' :: Maybe Text
modelVersion = Maybe Text
a} :: InferRxNormResponse)

-- | The response's http status code.
inferRxNormResponse_httpStatus :: Lens.Lens' InferRxNormResponse Prelude.Int
inferRxNormResponse_httpStatus :: (Int -> f Int) -> InferRxNormResponse -> f InferRxNormResponse
inferRxNormResponse_httpStatus = (InferRxNormResponse -> Int)
-> (InferRxNormResponse -> Int -> InferRxNormResponse)
-> Lens InferRxNormResponse InferRxNormResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InferRxNormResponse' {Int
httpStatus :: Int
$sel:httpStatus:InferRxNormResponse' :: InferRxNormResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: InferRxNormResponse
s@InferRxNormResponse' {} Int
a -> InferRxNormResponse
s {$sel:httpStatus:InferRxNormResponse' :: Int
httpStatus = Int
a} :: InferRxNormResponse)

-- | The medication entities detected in the text linked to RxNorm concepts.
-- If the action is successful, the service sends back an HTTP 200
-- response, as well as the entities detected.
inferRxNormResponse_entities :: Lens.Lens' InferRxNormResponse [RxNormEntity]
inferRxNormResponse_entities :: ([RxNormEntity] -> f [RxNormEntity])
-> InferRxNormResponse -> f InferRxNormResponse
inferRxNormResponse_entities = (InferRxNormResponse -> [RxNormEntity])
-> (InferRxNormResponse -> [RxNormEntity] -> InferRxNormResponse)
-> Lens
     InferRxNormResponse
     InferRxNormResponse
     [RxNormEntity]
     [RxNormEntity]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InferRxNormResponse' {[RxNormEntity]
entities :: [RxNormEntity]
$sel:entities:InferRxNormResponse' :: InferRxNormResponse -> [RxNormEntity]
entities} -> [RxNormEntity]
entities) (\s :: InferRxNormResponse
s@InferRxNormResponse' {} [RxNormEntity]
a -> InferRxNormResponse
s {$sel:entities:InferRxNormResponse' :: [RxNormEntity]
entities = [RxNormEntity]
a} :: InferRxNormResponse) (([RxNormEntity] -> f [RxNormEntity])
 -> InferRxNormResponse -> f InferRxNormResponse)
-> (([RxNormEntity] -> f [RxNormEntity])
    -> [RxNormEntity] -> f [RxNormEntity])
-> ([RxNormEntity] -> f [RxNormEntity])
-> InferRxNormResponse
-> f InferRxNormResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([RxNormEntity] -> f [RxNormEntity])
-> [RxNormEntity] -> f [RxNormEntity]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData InferRxNormResponse