Skip to content

Commit

Permalink
Added Support for Questionnaire
Browse files Browse the repository at this point in the history
  • Loading branch information
icrc-loliveira committed Jun 21, 2024
1 parent 3b983de commit f53ac5a
Showing 1 changed file with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hibernate.Criteria;
import org.openmrs.Form;
import org.openmrs.api.FormService;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.dao.FhirQuestionnaireDao;
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap;
import org.openmrs.module.fhir2.api.util.FormResourceAuditable;
Expand All @@ -29,31 +30,31 @@
@Component
@Setter(AccessLevel.PACKAGE)
public class FhirQuestionnaireDaoImpl extends BaseFhirDao<FormResourceAuditable> implements FhirQuestionnaireDao {
@Autowired
private FormService formService;
@Override
public FormResourceAuditable get(@Nonnull String uuid) {
Form form = formService.getFormByUuid(uuid);
return new FormResourceAuditable(formService.getFormResource(form, "JSON schema"));
}
@Override
protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams) {
criteria.add(eq("set", true));
theParams.getParameters().forEach(entry -> {
switch (entry.getKey()) {
case TITLE_SEARCH_HANDLER:
entry.getValue().forEach(param -> handleTitle(criteria, (StringAndListParam) param.getParam()));
break;
}
});
}
protected void handleTitle(Criteria criteria, StringAndListParam titlePattern) {
criteria.createAlias("names", "cn");
handleAndListParam(titlePattern, (title) -> propertyLike("cn.name", title)).ifPresent(criteria::add);
}

@Autowired
private FormService formService;

@Override
public FormResourceAuditable get(@Nonnull String uuid) {
Form form = formService.getFormByUuid(uuid);
return new FormResourceAuditable(formService.getFormResource(form, FhirConstants.FHIR_QUESTIONNAIRE_TYPE));
}

@Override
protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams) {
criteria.add(eq("set", true));
theParams.getParameters().forEach(entry -> {
switch (entry.getKey()) {
case TITLE_SEARCH_HANDLER:
entry.getValue().forEach(param -> handleTitle(criteria, (StringAndListParam) param.getParam()));
break;
}
});
}

protected void handleTitle(Criteria criteria, StringAndListParam titlePattern) {
criteria.createAlias("names", "cn");
handleAndListParam(titlePattern, (title) -> propertyLike("cn.name", title)).ifPresent(criteria::add);
}

}

0 comments on commit f53ac5a

Please sign in to comment.