001
002package ca.uhn.fhir.jpa.rp.r4;
003
004import java.util.*;
005
006import org.apache.commons.lang3.StringUtils;
007
008import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
009import ca.uhn.fhir.model.api.Include;
010import ca.uhn.fhir.model.api.annotation.*;
011import org.hl7.fhir.r4.model.*;
012import ca.uhn.fhir.rest.annotation.*;
013import ca.uhn.fhir.rest.param.*;
014import ca.uhn.fhir.rest.api.SortSpec;
015import ca.uhn.fhir.rest.api.SummaryEnum;
016import ca.uhn.fhir.rest.api.SearchTotalModeEnum;
017import ca.uhn.fhir.rest.api.SearchContainedModeEnum;
018
019public class MedicationResourceProvider extends 
020        ca.uhn.fhir.jpa.provider.BaseJpaResourceProvider<Medication>
021        {
022
023        @Override
024        public Class<Medication> getResourceType() {
025                return Medication.class;
026        }
027
028        @Search(allowUnknownParams=true)
029        public ca.uhn.fhir.rest.api.server.IBundleProvider search(
030                        jakarta.servlet.http.HttpServletRequest theServletRequest,
031                        jakarta.servlet.http.HttpServletResponse theServletResponse,
032
033                        ca.uhn.fhir.rest.api.server.RequestDetails theRequestDetails,
034
035                        @Description(shortDefinition="Search the contents of the resource's data using a filter")
036                        @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_FILTER)
037                        StringAndListParam theFtFilter,
038
039                        @Description(shortDefinition="Search the contents of the resource's data using a fulltext search")
040                        @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_CONTENT)
041                        StringAndListParam theFtContent, 
042
043                        @Description(shortDefinition="Search the contents of the resource's narrative using a fulltext search")
044                        @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_TEXT)
045                        StringAndListParam theFtText, 
046
047                        @Description(shortDefinition="Search for resources which have the given tag")
048                        @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_TAG)
049                        TokenAndListParam theSearchForTag, 
050
051                        @Description(shortDefinition="Search for resources which have the given security labels")
052                        @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_SECURITY)
053                        TokenAndListParam theSearchForSecurity, 
054  
055                        @Description(shortDefinition="Search for resources which have the given profile")
056                        @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_PROFILE)
057                        UriAndListParam theSearchForProfile,
058
059                        @Description(shortDefinition="Search the contents of the resource's data using a list")
060                        @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_LIST)
061                        StringAndListParam theList,
062
063
064                        @Description(shortDefinition="Search for resources which have the given source value (Resource.meta.source)")
065                        @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_SOURCE)
066                        UriAndListParam theSearchForSource,
067
068                        @Description(shortDefinition="Return resources linked to by the given target")
069                        @OptionalParam(name="_has")
070                        HasAndListParam theHas, 
071
072   
073
074                        @Description(shortDefinition="The ID of the resource")
075                        @OptionalParam(name="_id")
076                        TokenAndListParam the_id,
077   
078
079                        @Description(shortDefinition="Returns medications for a specific code")
080                        @OptionalParam(name="code")
081                        TokenAndListParam theCode,
082   
083
084                        @Description(shortDefinition="Returns medications in a batch with this expiration date")
085                        @OptionalParam(name="expiration-date")
086                        DateRangeParam theExpiration_date, 
087   
088
089                        @Description(shortDefinition="Returns medications for a specific dose form")
090                        @OptionalParam(name="form")
091                        TokenAndListParam theForm,
092   
093
094                        @Description(shortDefinition="Returns medications with this external identifier")
095                        @OptionalParam(name="identifier")
096                        TokenAndListParam theIdentifier,
097   
098
099                        @Description(shortDefinition="Returns medications for this ingredient reference")
100                        @OptionalParam(name="ingredient", targetTypes={  } )
101                        ReferenceAndListParam theIngredient, 
102   
103
104                        @Description(shortDefinition="Returns medications for this ingredient code")
105                        @OptionalParam(name="ingredient-code")
106                        TokenAndListParam theIngredient_code,
107   
108
109                        @Description(shortDefinition="Returns medications in a batch with this lot number")
110                        @OptionalParam(name="lot-number")
111                        TokenAndListParam theLot_number,
112   
113
114                        @Description(shortDefinition="Returns medications made or sold for this manufacturer")
115                        @OptionalParam(name="manufacturer", targetTypes={  } )
116                        ReferenceAndListParam theManufacturer, 
117   
118
119                        @Description(shortDefinition="Returns medications for this status")
120                        @OptionalParam(name="status")
121                        TokenAndListParam theStatus,
122
123                        @RawParam
124                        Map<String, List<String>> theAdditionalRawParams,
125
126                        @Description(shortDefinition="Only return resources which were last updated as specified by the given range")
127                        @OptionalParam(name="_lastUpdated")
128                        DateRangeParam theLastUpdated, 
129
130                        @IncludeParam
131                        Set<Include> theIncludes,
132
133                        @IncludeParam(reverse=true)
134                        Set<Include> theRevIncludes,
135
136                        @Sort
137                        SortSpec theSort,
138                        
139                        @ca.uhn.fhir.rest.annotation.Count
140                        Integer theCount,
141
142                        @ca.uhn.fhir.rest.annotation.Offset
143                        Integer theOffset,
144
145                        SummaryEnum theSummaryMode,
146
147                        SearchTotalModeEnum theSearchTotalMode,
148
149                        SearchContainedModeEnum theSearchContainedMode
150
151                        ) {
152                startRequest(theServletRequest);
153                try {
154                        SearchParameterMap paramMap = new SearchParameterMap();
155                        paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_FILTER, theFtFilter);
156                        paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_CONTENT, theFtContent);
157                        paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_TEXT, theFtText);
158                        paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_TAG, theSearchForTag);
159                        paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_SECURITY, theSearchForSecurity);
160                        paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_PROFILE, theSearchForProfile);
161                        paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_SOURCE, theSearchForSource);
162                        paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_LIST, theList);
163                        paramMap.add("_has", theHas);
164                        paramMap.add("_id", the_id);
165                        paramMap.add("code", theCode);
166                        paramMap.add("expiration-date", theExpiration_date);
167                        paramMap.add("form", theForm);
168                        paramMap.add("identifier", theIdentifier);
169                        paramMap.add("ingredient", theIngredient);
170                        paramMap.add("ingredient-code", theIngredient_code);
171                        paramMap.add("lot-number", theLot_number);
172                        paramMap.add("manufacturer", theManufacturer);
173                        paramMap.add("status", theStatus);
174                        paramMap.setRevIncludes(theRevIncludes);
175                        paramMap.setLastUpdated(theLastUpdated);
176                        paramMap.setIncludes(theIncludes);
177                        paramMap.setSort(theSort);
178                        paramMap.setCount(theCount);
179                        paramMap.setOffset(theOffset);
180                        paramMap.setSummaryMode(theSummaryMode);
181                        paramMap.setSearchTotalMode(theSearchTotalMode);
182                        paramMap.setSearchContainedMode(theSearchContainedMode);
183
184                        getDao().translateRawParameters(theAdditionalRawParams, paramMap);
185
186                        ca.uhn.fhir.rest.api.server.IBundleProvider retVal = getDao().search(paramMap, theRequestDetails, theServletResponse);
187                        return retVal;
188                } finally {
189                        endRequest(theServletRequest);
190                }
191        }
192
193}