public List<RecordWeb> findEntitiesByIdentifier(EntityWeb entityModel, IdentifierWeb identferWeb)
      throws Exception {
    log.debug(
        "Received request to retrieve a list of entity instance records that match the entity specified as a parameter.");

    authenticateCaller();
    try {
      RecordQueryService entityInstanceService = Context.getRecordQueryService();
      EntityDefinitionManagerService entityDefService = Context.getEntityDefinitionManagerService();
      Entity entityDef = entityDefService.loadEntity(entityModel.getEntityVersionId());

      org.openhie.openempi.model.Identifier identifier =
          ModelTransformer.map(identferWeb, org.openhie.openempi.model.Identifier.class);

      List<Record> records = entityInstanceService.findRecordsByIdentifier(entityDef, identifier);

      List<RecordWeb> dtos = new java.util.ArrayList<RecordWeb>(records.size());
      for (Record record : records) {
        RecordWeb dto = ModelTransformer.mapToRecord(record, RecordWeb.class);
        dtos.add(dto);
      }

      return dtos;
    } catch (Throwable t) {
      log.error("Failed to execute: " + t.getMessage(), t);
      throw new RuntimeException(t);
    }
  }
  public RecordListWeb findEntitiesByIdentifier(RecordSearchCriteriaWeb searchCriteria)
      throws Exception {
    log.debug("Received entity records by identifier.");

    authenticateCaller();
    try {
      RecordQueryService entityInstanceService = Context.getRecordQueryService();
      EntityDefinitionManagerService entityDefService = Context.getEntityDefinitionManagerService();

      EntityWeb entityModel = searchCriteria.getEntityModel();
      Entity entityDef = entityDefService.loadEntity(entityModel.getEntityVersionId());

      IdentifierWeb identifierWeb = searchCriteria.getIdentifier();
      int offset = searchCriteria.getFirstResult();
      int pageSize = searchCriteria.getMaxResults();

      org.openhie.openempi.model.Identifier identifier =
          ModelTransformer.map(identifierWeb, org.openhie.openempi.model.Identifier.class);

      // Get total count
      Long totalCount = searchCriteria.getTotalCount();
      if (totalCount == 0) {
        totalCount = entityInstanceService.getRecordCount(entityDef, identifier);
      }

      // get List of Record
      List<Record> records =
          entityInstanceService.findRecordsByIdentifier(entityDef, identifier, offset, pageSize);

      List<RecordWeb> dtos = new java.util.ArrayList<RecordWeb>(records.size());
      for (Record record : records) {
        RecordWeb dto = ModelTransformer.mapToRecord(record, RecordWeb.class);
        dtos.add(dto);
      }

      RecordListWeb recordList = new RecordListWeb();
      recordList.setTotalCount(totalCount);
      recordList.setRecords(dtos);

      return recordList;
    } catch (Throwable t) {
      log.error("Failed to execute: " + t.getMessage(), t);
      throw new RuntimeException(t);
    }
  }