/ark-study/src/main/java/au/org/theark/study/service/IStudyService.java

https://gitlab.com/gecgooden/ark · Java · 520 lines · 203 code · 143 blank · 174 comment · 0 complexity · 5d58ada6ece631cb833f58f06948947a MD5 · raw file

  1. /*******************************************************************************
  2. * Copyright (c) 2011 University of Western Australia. All rights reserved.
  3. *
  4. * This file is part of The Ark.
  5. *
  6. * The Ark is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 3
  9. * of the License, or (at your option) any later version.
  10. *
  11. * The Ark is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. ******************************************************************************/
  19. package au.org.theark.study.service;
  20. import java.io.FileNotFoundException;
  21. import java.io.InputStream;
  22. import java.util.Collection;
  23. import java.util.List;
  24. import java.util.Set;
  25. import org.apache.wicket.util.file.File;
  26. import au.org.theark.core.exception.ArkFileNotFoundException;
  27. import au.org.theark.core.exception.ArkSubjectInsertException;
  28. import au.org.theark.core.exception.ArkSystemException;
  29. import au.org.theark.core.exception.ArkUniqueException;
  30. import au.org.theark.core.exception.CannotRemoveArkModuleException;
  31. import au.org.theark.core.exception.EntityCannotBeRemoved;
  32. import au.org.theark.core.exception.EntityExistsException;
  33. import au.org.theark.core.exception.EntityNotFoundException;
  34. import au.org.theark.core.exception.StatusNotAvailableException;
  35. import au.org.theark.core.exception.UnAuthorizedOperation;
  36. import au.org.theark.core.model.audit.entity.ConsentHistory;
  37. import au.org.theark.core.model.audit.entity.LssConsentHistory;
  38. import au.org.theark.core.model.study.entity.Address;
  39. import au.org.theark.core.model.study.entity.AddressStatus;
  40. import au.org.theark.core.model.study.entity.AddressType;
  41. import au.org.theark.core.model.study.entity.ArkFunction;
  42. import au.org.theark.core.model.study.entity.ArkUser;
  43. import au.org.theark.core.model.study.entity.Consent;
  44. import au.org.theark.core.model.study.entity.ConsentFile;
  45. import au.org.theark.core.model.study.entity.ConsentOption;
  46. import au.org.theark.core.model.study.entity.ConsentStatus;
  47. import au.org.theark.core.model.study.entity.ConsentType;
  48. import au.org.theark.core.model.study.entity.CorrespondenceDirectionType;
  49. import au.org.theark.core.model.study.entity.CorrespondenceModeType;
  50. import au.org.theark.core.model.study.entity.CorrespondenceOutcomeType;
  51. import au.org.theark.core.model.study.entity.Correspondences;
  52. import au.org.theark.core.model.study.entity.CustomField;
  53. import au.org.theark.core.model.study.entity.CustomFieldCategory;
  54. import au.org.theark.core.model.study.entity.CustomFieldType;
  55. import au.org.theark.core.model.study.entity.EmailStatus;
  56. import au.org.theark.core.model.study.entity.FamilyCustomFieldData;
  57. import au.org.theark.core.model.study.entity.GenderType;
  58. import au.org.theark.core.model.study.entity.ICustomFieldData;
  59. import au.org.theark.core.model.study.entity.LinkStudySubstudy;
  60. import au.org.theark.core.model.study.entity.LinkSubjectPedigree;
  61. import au.org.theark.core.model.study.entity.LinkSubjectStudy;
  62. import au.org.theark.core.model.study.entity.LinkSubjectTwin;
  63. import au.org.theark.core.model.study.entity.MaritalStatus;
  64. import au.org.theark.core.model.study.entity.OtherID;
  65. import au.org.theark.core.model.study.entity.Person;
  66. import au.org.theark.core.model.study.entity.PersonLastnameHistory;
  67. import au.org.theark.core.model.study.entity.Phone;
  68. import au.org.theark.core.model.study.entity.PhoneStatus;
  69. import au.org.theark.core.model.study.entity.PhoneType;
  70. import au.org.theark.core.model.study.entity.Study;
  71. import au.org.theark.core.model.study.entity.StudyCalendar;
  72. import au.org.theark.core.model.study.entity.StudyComp;
  73. import au.org.theark.core.model.study.entity.StudyPedigreeConfiguration;
  74. import au.org.theark.core.model.study.entity.SubjectCustomFieldData;
  75. import au.org.theark.core.model.study.entity.SubjectFile;
  76. import au.org.theark.core.model.study.entity.SubjectStatus;
  77. import au.org.theark.core.model.study.entity.TitleType;
  78. import au.org.theark.core.model.study.entity.TwinType;
  79. import au.org.theark.core.model.study.entity.Upload;
  80. import au.org.theark.core.model.study.entity.VitalStatus;
  81. import au.org.theark.core.vo.ArkUserVO;
  82. import au.org.theark.core.vo.ConsentVO;
  83. import au.org.theark.core.vo.StudyModelVO;
  84. import au.org.theark.core.vo.SubjectVO;
  85. import au.org.theark.core.vo.UploadVO;
  86. import au.org.theark.study.model.capsule.ArkRelativeCapsule;
  87. import au.org.theark.study.model.capsule.RelativeCapsule;
  88. import au.org.theark.study.model.vo.RelationshipVo;
  89. import au.org.theark.study.model.vo.StudyCalendarVo;
  90. import au.org.theark.study.util.SubjectUploadValidator;
  91. public interface IStudyService {
  92. //public long countNumberOfUniqueSubjects(Study study, List subjects);
  93. /**
  94. *
  95. * @param studyModelVo
  96. */
  97. public void createStudy(StudyModelVO studyModelVo);
  98. /**
  99. * Create a new study and assign the specified user
  100. *
  101. * @param studyModelVo
  102. * @param arkUserVo
  103. */
  104. public void createStudy(StudyModelVO studyModelVo, ArkUserVO arkUserVo);
  105. public void updateStudy(StudyModelVO studyModelVo) throws CannotRemoveArkModuleException;
  106. public void archiveStudy(Study studyEntity) throws UnAuthorizedOperation, StatusNotAvailableException, ArkSystemException;
  107. /**
  108. * Search for Study components with a certain criteria.
  109. *
  110. * @param studyCompCriteria
  111. * @return
  112. */
  113. public List<StudyComp> searchStudyComp(StudyComp studyCompCriteria) throws ArkSystemException;
  114. public void create(StudyComp sc) throws UnAuthorizedOperation, ArkSystemException, EntityExistsException;
  115. public void update(StudyComp studyComponent) throws UnAuthorizedOperation, ArkSystemException, EntityExistsException;
  116. public void create(Phone phone) throws ArkSystemException, ArkUniqueException;
  117. public void update(Phone phone) throws ArkSystemException, ArkUniqueException;
  118. public void delete(Phone phone) throws ArkSystemException;
  119. /**
  120. * A method to create a Subject.
  121. *
  122. * @param subjectVO
  123. * @throws ArkUniqueException
  124. * , ArkSubjectInsertException
  125. */
  126. public void createSubject(SubjectVO subjectVO) throws ArkUniqueException, ArkUniqueException, ArkSubjectInsertException;
  127. public void updateSubject(SubjectVO subjectVO) throws ArkUniqueException,EntityNotFoundException;
  128. /**
  129. * Look up a Person based on the supplied Long ID that represents a Person primary key. This id is the primary key of the Person table that can
  130. * represent a subject or contact.
  131. *
  132. * @param personId
  133. * @return
  134. * @throws EntityNotFoundException
  135. * @throws ArkSystemException
  136. */
  137. public Person getPerson(Long personId) throws EntityNotFoundException, ArkSystemException;
  138. /**
  139. * Look up the phones connected with the person(subject or contact)
  140. *
  141. * @param personId
  142. * @return List<Phone>
  143. * @throws ArkSystemException
  144. */
  145. public List<Phone> getPersonPhoneList(Long personId) throws ArkSystemException;
  146. /**
  147. * Looks up the phones linked to a person and applies any filter supplied with the phone object.Used in Search Phone functionality. One can look up
  148. * base don area code, phone type, phone number
  149. *
  150. * @param personId
  151. * @param phone
  152. * @return
  153. * @throws ArkSystemException
  154. */
  155. public List<Phone> getPersonPhoneList(Long personId, Phone phone) throws ArkSystemException;
  156. /**
  157. * Looks up the addresses linked to a person and applies any filter supplied with the address object.Used in Search Address functionality.
  158. *
  159. * @param personId
  160. * @param address
  161. * @return
  162. * @throws ArkSystemException
  163. */
  164. public List<Address> getPersonAddressList(Long personId, Address address) throws ArkSystemException;
  165. public void create(Address address) throws ArkSystemException;
  166. public void update(Address address) throws ArkSystemException;
  167. public void delete(Address address) throws ArkSystemException;
  168. public void create(Consent consent) throws ArkSystemException;
  169. public void update(Consent consent) throws ArkSystemException, EntityNotFoundException;
  170. public void update(Consent consent,boolean consentFile) throws ArkSystemException, EntityNotFoundException;
  171. public void delete(Consent consent) throws ArkSystemException, EntityNotFoundException;
  172. public Consent getConsent(Long id) throws ArkSystemException;
  173. /**
  174. * for simplification's sake. true is yes, false is no. todo...look at whether booleans or something else are more appropriate in many of the situations
  175. * @param trueOrFalse
  176. * @return
  177. * @throws ArkSystemException
  178. */
  179. public ConsentOption getConsentOptionForBoolean(boolean trueForYesOrFalseForNo) throws ArkSystemException;
  180. public List<Consent> searchConsent(Consent consent) throws EntityNotFoundException, ArkSystemException;
  181. public List<Consent> searchConsent(ConsentVO consentVO) throws EntityNotFoundException, ArkSystemException;
  182. /**
  183. *
  184. * @param consentFile
  185. * @throws ArkSystemException
  186. */
  187. public void create(ConsentFile consentFile) throws ArkSystemException;
  188. public void update(ConsentFile consentFile) throws ArkSystemException, EntityNotFoundException;
  189. public void delete(ConsentFile consentFile) throws ArkSystemException, EntityNotFoundException;
  190. public List<ConsentFile> searchConsentFile(ConsentFile consentFile) throws EntityNotFoundException, ArkSystemException;
  191. public void create(Correspondences correspondence) throws ArkSystemException;
  192. public void update(Correspondences correspondence) throws ArkSystemException, EntityNotFoundException;
  193. public void update(Correspondences correspondence, String checksum) throws ArkSystemException, EntityNotFoundException,ArkFileNotFoundException;
  194. public void delete(Correspondences correspondence) throws ArkSystemException, EntityNotFoundException;
  195. /**
  196. *
  197. * @param personId
  198. * @param correspondence
  199. * @return a list of correspondence for person. if empty, returns an empty list
  200. * @throws ArkSystemException
  201. */
  202. public List<Correspondences> getCorrespondenceList(LinkSubjectStudy lss, Correspondences correspondence) throws ArkSystemException;
  203. public List<CorrespondenceModeType> getCorrespondenceModeTypes();
  204. public List<CorrespondenceDirectionType> getCorrespondenceDirectionTypes();
  205. public List<CorrespondenceOutcomeType> getCorrespondenceOutcomeTypes();
  206. // public void createPersonLastnameHistory(Person person);
  207. // public void updatePersonLastnameHistory(Person person);
  208. public PersonLastnameHistory getPreviousSurnameHistory(PersonLastnameHistory personSurnameHistory);
  209. public String getPreviousLastname(Person person);
  210. // public String getCurrentLastname(Person person);
  211. public List<PersonLastnameHistory> getLastnameHistory(Person person);
  212. public boolean personHasPreferredMailingAddress(Person person, Long currentAddressId);
  213. /**
  214. *
  215. * @param subjectFile
  216. * @throws ArkSystemException
  217. */
  218. public void create(SubjectFile subjectFile, String directoryType) throws ArkSystemException;
  219. public void update(SubjectFile subjectFile) throws ArkSystemException, EntityNotFoundException;
  220. public void update(SubjectFile subjectFile, String checksum) throws ArkSystemException, EntityNotFoundException,ArkFileNotFoundException;
  221. public void delete(SubjectFile subjectFile,String directoryType) throws ArkSystemException, EntityNotFoundException,ArkFileNotFoundException;
  222. public List<SubjectFile> searchSubjectFile(SubjectFile subjectFile) throws EntityNotFoundException, ArkSystemException;
  223. public void delete(StudyComp studyComp) throws ArkSystemException, EntityCannotBeRemoved, UnAuthorizedOperation;
  224. public SubjectUploadValidator validateSubjectFileFormat(File file, String fileFormat, char delimChar);
  225. public SubjectUploadValidator validateSubjectFileFormat(InputStream inputStream, String fileFormat, char delimChar);
  226. public SubjectUploadValidator validateSubjectFileFormat(UploadVO uploadVo);
  227. public SubjectUploadValidator validateSubjectFileData(InputStream inputStream, String fileFormat, char delimChar, List<String> referenceOfListStringsToUpdate);
  228. public SubjectUploadValidator validateSubjectFileData(UploadVO uploadVo, List<String> referenceOfListStringsToUpdate);
  229. public StringBuffer uploadAndReportMatrixSubjectFile(File file, String fileFormat, char delimChar, List<String> listOfUIDsToUpdate);
  230. public StringBuffer uploadAndReportMatrixSubjectFile(InputStream inputStream, long size, String fileFormat, char delimChar, long studyId, List<String> listOfUIDsToUpdate);
  231. public StringBuffer uploadAndReportCustomDataFile(InputStream inputStream, long size, String fileFormat, char delimChar, long studyId,
  232. List<String> listOfUIDsToUpdate,String customFieldType,UploadVO uploadVO);
  233. //TODO Trav Deprecated public void batchInsertSubjects(Collection<SubjectVO> subjectVoCollection) throws ArkUniqueException, ArkSubjectInsertException;
  234. // public void batchInsertSubjects(List<LinkSubjectStudy> subjectList, Study study) throws ArkUniqueException, ArkSubjectInsertException;
  235. //public void batchUpdateSubjects(List<LinkSubjectStudy> subjectList) throws ArkUniqueException, ArkSubjectInsertException;
  236. /**
  237. * Returns a Collection of ArkUser entities from the backend for users who are linked to the passed in study.
  238. *
  239. * @param study
  240. * @return Collection<ArkUser>
  241. */
  242. public Collection<ArkUser> lookupArkUser(Study study);
  243. public LinkSubjectStudy getSubjectLinkedToStudy(Long personId, Study study) throws EntityNotFoundException, ArkSystemException;
  244. //public List<SubjectCustomFieldData> getSubjectCustomFieldDataList(LinkSubjectStudy linkSubjectStudyCriteria, ArkFunction arkFunction, int first, int count);
  245. public long getSubjectCustomFieldDataCount(LinkSubjectStudy criteria, ArkFunction arkFunction);
  246. public long getFamilyCustomFieldDataCount(LinkSubjectStudy linkSubjectStudyCriteria, ArkFunction arkFunction);
  247. /**
  248. * Allows to Save(Insert) or Update SubjectCustomFieldData. If there are SubjectCustomFieldData with no data value then it will discard it from the
  249. * save/update process.
  250. *
  251. * @param subjectCustomFieldDataList
  252. */
  253. public List<SubjectCustomFieldData> createOrUpdateSubjectCustomFieldData(List<SubjectCustomFieldData> subjectCustomFieldDataList);
  254. public List<FamilyCustomFieldData> createOrUpdateFamilyCustomFieldData(List<FamilyCustomFieldData> familyCustomFieldDataList);
  255. /**
  256. * Checks if the given component(study) is or has attachments linked to it
  257. *
  258. * @param studyComp
  259. * @return
  260. */
  261. public boolean isStudyComponentHasAttachments(StudyComp studyComp);
  262. public void cloneSubjectForSubStudy(LinkSubjectStudy linkSubjectStudy);
  263. public LinkStudySubstudy isSubStudy(Study study);
  264. /**
  265. * Gets the list of child studies for the specifed parent Study
  266. *
  267. * @param study
  268. * the parent study
  269. * @return
  270. */
  271. public List<Study> getChildStudyListOfParent(Study study);
  272. /**
  273. * Return a list of LinkSubjectStudy ConsentHistory entities
  274. *
  275. * @param linkSubjectStudy
  276. * @return
  277. */
  278. public List<LssConsentHistory> getLssConsentHistoryList(LinkSubjectStudy linkSubjectStudy);
  279. /**
  280. * Return a list of ConsentHistory entities
  281. *
  282. * @param consent
  283. * @return
  284. */
  285. public List<ConsentHistory> getConsentHistoryList(Consent consent);
  286. /**
  287. * Return the upload for the given id
  288. *
  289. * @param consent
  290. * @return
  291. */
  292. public Upload getUpload(Long id);
  293. /**
  294. * Refresh this entity with latest from db
  295. *
  296. * @param consent
  297. * @return
  298. */
  299. public Upload refreshUpload(Upload upload);
  300. public SubjectStatus getDefaultSubjectStatus();
  301. public TitleType getDefaultTitleType();
  302. public GenderType getDefaultGenderType();
  303. public VitalStatus getDefaultVitalStatus();
  304. public MaritalStatus getDefaultMaritalStatus();
  305. public ConsentStatus getConsentStatusByName(String string);
  306. public ConsentType getConsentTypeByName(String string);
  307. public void setPreferredMailingAdressToFalse(Person person);
  308. public void processBatch(List<LinkSubjectStudy> subjectsToInsert, Study study, List<LinkSubjectStudy> subjectsToUpdate);
  309. public void processFieldsBatch(List<? extends ICustomFieldData> fieldDataList, Study study, List<? extends ICustomFieldData> fieldDataToInsert);
  310. /**
  311. * Process the given {@link Consent} lists separately and persist the changes to the table.
  312. * @param updateConsentList
  313. * @param insertConsentList
  314. * @throws ArkSystemException
  315. * @throws EntityNotFoundException
  316. */
  317. public void processSubjectConsentBatch(List<Consent> updateConsentList, List<Consent> insertConsentList) throws ArkSystemException,EntityNotFoundException;
  318. /**
  319. * Insert the given {@link LinkSubjectPedigree} list.
  320. * @param parentsToInsert
  321. * @param twinsToInsert
  322. * @throws ArkSystemException
  323. * @throws EntityNotFoundException
  324. */
  325. public void processPedigreeBatch(List<LinkSubjectPedigree> parentsToInsert,List<LinkSubjectTwin> twinsToInsert) throws ArkSystemException,EntityNotFoundException;
  326. /**
  327. * Insert the given {@link SubjectFile} list
  328. * @param subjectFiles
  329. * @throws ArkSystemException
  330. * @throws EntityNotFoundException
  331. */
  332. public void processSubjectAttachmentBatch(List<SubjectFile> subjectFiles)throws ArkSystemException,EntityNotFoundException;
  333. public AddressType getDefaultAddressType();
  334. public AddressStatus getDefaultAddressStatus();
  335. public PhoneType getDefaultPhoneType();
  336. public PhoneStatus getDefaultPhoneStatus();
  337. public EmailStatus getDefaultEmailStatus();
  338. public List<ConsentOption> getConsentOptions();
  339. public List<ConsentStatus> getConsentStatus();
  340. public List<ConsentType> getConsentType();
  341. public StringBuffer uploadAndReportSubjectConsentDataFile(InputStream inputStream, long size, String fileFormat, char delimChar, long studyId);
  342. public StringBuffer uploadAndReportPedigreeDataFile(InputStream inputStream, long size, String fileFormat, char delimChar, long studyId);
  343. public StringBuffer uploadAndReportSubjectAttachmentDataFile(InputStream inputStream, long size, String fileFormat, char delimChar, long studyId, String user_id);
  344. public RelativeCapsule[] generateSubjectPedigreeImageList(final String subjectUID,final Long studyId);
  345. public RelativeCapsule[] generateSubjectPedigreeExportList(final String subjectUID,final Long studyId);
  346. public List<RelationshipVo> generateSubjectPedigreeRelativeList(final String subjectUID,final Long studyId);
  347. public void deleteRelationship(final LinkSubjectPedigree relationship);
  348. public void create(LinkSubjectPedigree pedigree);
  349. public List<RelationshipVo> getSubjectPedigreeTwinList(final String subjectUID,final Long studyId);
  350. public void processPedigreeTwinRelationship(final RelationshipVo relationshipVo, final String subjectUid, final Long studyId);
  351. public List<TwinType> getTwinTypes();
  352. public long getRelationshipCount(final String subjectUID,final Long studyId);
  353. public List<LinkSubjectTwin> getTwins(final Set<String> subjectUids,final Long studyId);
  354. public ArkRelativeCapsule[] generateSubjectArkPedigreeExportList(final String subjectUID,final Long studyId);
  355. public List<CustomField> getBinaryCustomFieldsForPedigreeRelativesList(Long studyId);
  356. public StudyPedigreeConfiguration getStudyPedigreeConfiguration(Long studyId);
  357. public void saveOrUpdateStudyPedigreeConfiguration(StudyPedigreeConfiguration config);
  358. public List<Phone> pageablePersonPhoneList(Long personId,Phone phoneCriteria, int first, int count);
  359. public List<Address> pageablePersonAddressList(Long personId,Address addressCriteria, int first, int count);
  360. public List<CustomField> getFamilyUIdCustomFieldsForPedigreeRelativesList(Long studyId);
  361. public List<FamilyCustomFieldData> getFamilyCustomFieldDataList(LinkSubjectStudy linkSubjectStudyCriteria, ArkFunction arkFunction,CustomFieldCategory customFieldCategory,CustomFieldType customFieldType, int first, int count);
  362. public String getSubjectFamilyId(Long studyId, String subjectUID);
  363. public List<SubjectCustomFieldData> getSubjectCustomFieldDataList(LinkSubjectStudy linkSubjectStudyCriteria, ArkFunction arkFunction,CustomFieldCategory customFieldCategory,CustomFieldType customFieldType, int first, int count);
  364. public void setPreferredPhoneNumberToFalse(Person person);
  365. public void saveOrUpdate(StudyCalendar studyCalendar);
  366. public void delete(StudyCalendar studyCalendar);
  367. public List<StudyCalendar> searchStudyCalenderList(StudyCalendar studyCalendar);
  368. public List<CustomField> getStudySubjectCustomFieldList(Long studyId);
  369. public void saveOrUpdate(StudyCalendarVo studyCalendarVo);
  370. public List<CustomField> getSelectedCalendarCustomFieldList(StudyCalendar studyCalendar);
  371. public List<RelationshipVo> getSubjectChildren(String subjectUID, long studyId);
  372. public void delete(OtherID otherID);
  373. public boolean isStudyComponentBeingUsedInConsent(StudyComp studyComp);
  374. public List<CorrespondenceOutcomeType> getCorrespondenceOutcomeTypesForModeAndDirection(CorrespondenceModeType correspondenceModeType,CorrespondenceDirectionType correspondenceDirectionType);
  375. public boolean isAlreadyHasFileAttached(LinkSubjectStudy linkSubjectStudy,StudyComp studyComp);
  376. public SubjectFile getSubjectFileParticularConsent(LinkSubjectStudy linkSubjectStudy, StudyComp studyComp);
  377. }