@Override public RecordListWeb getEntityRecordsBySearch(RecordSearchCriteriaWeb searchCriteria) throws Exception { log.debug("Get Entity Records By Search"); authenticateCaller(); try { RecordQueryService entityInstanceService = Context.getRecordQueryService(); EntityDefinitionManagerService entityDefService = Context.getEntityDefinitionManagerService(); EntityWeb entityModel = searchCriteria.getEntityModel(); Entity entityDef = entityDefService.loadEntity(entityModel.getEntityVersionId()); RecordWeb entity = searchCriteria.getRecord(); int offset = searchCriteria.getFirstResult(); int pageSize = searchCriteria.getMaxResults(); org.openhie.openempi.model.Record recordForMatch = ModelTransformer.mapToRecordForSearch(entityDef, entity, Record.class); // Get total count Long totalCount = searchCriteria.getTotalCount(); if (totalCount == 0) { totalCount = entityInstanceService.getRecordCount(entityDef, recordForMatch); } // get List of Record List<Record> records = entityInstanceService.findRecordsByAttributes( entityDef, recordForMatch, 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 (Exception e) { log.error("Failed while trying to get audit events: " + e, e); } return null; }
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); } }