public without sharing class LexSearchHospitalController {
    @AuraEnabled
    public static Results init() {
        Results results = new Results();
        try {
            User useracc = [SELECT accountid, UserPro_Type__c FROM user WHERE id = :UserInfo.getUserId()];
            String accountId = Useracc.accountid;
            String soql = 'SELECT id,Name,State_Master__c,State_Master__r.Name,Address__c FROM Account';
            soql += ' where id in (SELECT Hospital__c FROM hospitalprice__c WHERE account__c = :accountId) ';
            soql += ' order by Name desc limit 100';
            results.attList = Database.query(soql);
            results.result = 'Success';
        } catch (Exception e) {
            results.result = 'Fail';
            results.errorMsg = e.getLineNumber() + '---' + e.getMessage();
        }
        return results;
    }

    @AuraEnabled
    public static Results searchHospital(String searchName, String accountId) {
        Results results = new Results();
        try {
            results.attList = Database.query(makeSoql(searchName, accountId));
            results.result = 'Success';
        } catch (Exception e) {
            results.result = 'Fail';
            results.errorMsg = e.getLineNumber() + '---' + e.getMessage();
        }
        return results;
    }

    private static String makeSoql(String searchName, String accountId) {
        String soql = 'SELECT id,Name,State_Master__c,State_Master__r.Name,Address__c FROM Account';
        soql += ' where id in (SELECT Hospital__c FROM hospitalprice__c WHERE account__c = :accountId) ';
        if (String.isNotBlank(searchName)) {
            soql += ' AND Name like \'%' + searchName + '%\'';
        }
        soql += ' order by Name desc limit 100';
        return soql;
    }

    public class Results {
        @AuraEnabled
        public String result;
        @AuraEnabled
        public String errorMsg;
        @AuraEnabled
        public List<Account> attList;
    }
}