001/*- 002 * #%L 003 * Smile CDR - CDR 004 * %% 005 * Copyright (C) 2016 - 2024 Smile CDR, Inc. 006 * %% 007 * All rights reserved. 008 * #L% 009 */ 010package ca.cdr.api.fhirgw.model; 011 012import org.apache.commons.lang3.StringUtils; 013import org.hl7.fhir.instance.model.api.IBaseParameters; 014 015import java.util.ArrayList; 016import java.util.List; 017 018/** 019 * This class represents a FHIR Gateway Operation request 020 */ 021public class OperationRequest extends BaseRequest<OperationRequest> { 022 private String myResourceId; 023 private final String myOperationName; 024 private IBaseParameters myParameters; 025 private boolean myIsPaged; 026 027 /** 028 * Constructor 029 * @param theOperationName 030 */ 031 public OperationRequest(String theOperationName) { 032 // nothing 033 myOperationName = theOperationName; 034 } 035 036 /** 037 * Copy constructor 038 */ 039 public OperationRequest(OperationRequest theRequest) { 040 super(theRequest); 041 myResourceId = theRequest.getResourceId(); 042 myOperationName = theRequest.getOperationName(); 043 myParameters = theRequest.getParameters(); 044 } 045 046 public String getResourceId() { 047 return myResourceId; 048 } 049 050 public OperationRequest setResourceId(String theResourceId) { 051 myResourceId = theResourceId; 052 return this; 053 } 054 055 public IBaseParameters getParameters() { 056 return myParameters; 057 } 058 059 public OperationRequest setParameters(IBaseParameters theParameters) { 060 myParameters = theParameters; 061 return this; 062 } 063 064 public String getOperationName() { 065 return myOperationName; 066 } 067 068 public boolean isInstanceRequest() { 069 return myResourceId != null; 070 } 071 072 public boolean isTypeRequest() { 073 return !isInstanceRequest() && getResourceType() != null; 074 } 075 076 public boolean isSystemRequest() { 077 return !isInstanceRequest() && !isTypeRequest(); 078 } 079 080 public String getDescription() { 081 List<String> operations = new ArrayList<>(); 082 if (isSystemRequest()) { 083 operations.add("/" + myOperationName); 084 } 085 if (isTypeRequest()) { 086 operations.add(getResourceType() + "/" + myOperationName); 087 } 088 if (isInstanceRequest()) { 089 operations.add(getResourceId() + "/" + myOperationName); 090 } 091 return StringUtils.join(operations, ","); 092 } 093 094 public boolean isPaged() { 095 return myIsPaged; 096 } 097 098 public void setPaged(boolean thePaged) { 099 myIsPaged = thePaged; 100 } 101}