Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shanoir-issue#2112-2: get sc policy during import to update front #2456

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,18 @@ export abstract class AbstractClinicalContextComponent implements OnDestroy, OnI
if (this.reloading) {
this.fetchStudies(false).then(() => {
this.reloadSavedData().finally(() => this.reloading = false);
this.getStudyCardPolicy(this.study).then(policy => {
this.study.studyCardPolicy = policy;
})
}).catch(error => {
throw new ShanoirError({error: {message: 'the study list failed loading', details: error}});
});
} else {
this.fetchStudies(true);
this.fetchStudies(true).then( () => {
this.getStudyCardPolicy(this.study).then(policy => {
this.study.studyCardPolicy = policy;
})
});
}
}

Expand Down Expand Up @@ -297,6 +304,21 @@ export abstract class AbstractClinicalContextComponent implements OnDestroy, OnI
}
}

private getStudyCardPolicy(study: Study): Promise<string> {
if (study && study.id) {
return this.studyService.get(study.id).then(study => {
if (study.studyCardPolicy == 'MANDATORY') {
this.useStudyCard = true;
} else {
this.useStudyCard = false;
}
return study.studyCardPolicy;
})
} else {
return Promise.resolve('MANDATORY');
}
}

private selectDefaultCenter(options: Option<Center>[]): Promise<void> {
let founded = options?.find(option => option.compatible)?.value;
if (founded) {
Expand Down Expand Up @@ -355,24 +377,28 @@ export abstract class AbstractClinicalContextComponent implements OnDestroy, OnI
this.computeIsAdminOfStudy(this.study?.id);
this.studycard = this.center = this.acquisitionEquipment = this.subject = this.examination = null;

let studycardsOrCentersPromise: Promise<void>;
if (this.useStudyCard) {
studycardsOrCentersPromise = this.getStudyCardOptions(this.study).then(options => {
this.studycardOptions = options;
return this.selectDefaultStudyCard(options);
});
} else {
studycardsOrCentersPromise = this.getCenterOptions(this.study).then(options => {
this.centerOptions = options;
return this.selectDefaultCenter(options);
});
}
return this.getStudyCardPolicy(this.study).then(policy => {
this.study.studyCardPolicy = policy;

let subjectsPromise: Promise<void> = this.getSubjectList(this.study?.id).then(subjects => {
this.subjects = subjects ? subjects : [];
let studycardsOrCentersPromise: Promise<void>;
if (this.useStudyCard) {
studycardsOrCentersPromise = this.getStudyCardOptions(this.study).then(options => {
this.studycardOptions = options;
return this.selectDefaultStudyCard(options);
});
} else {
studycardsOrCentersPromise = this.getCenterOptions(this.study).then(options => {
this.centerOptions = options;
return this.selectDefaultCenter(options);
});
}

let subjectsPromise: Promise<void> = this.getSubjectList(this.study?.id).then(subjects => {
this.subjects = subjects ? subjects : [];
});
return Promise.all([studycardsOrCentersPromise, subjectsPromise]).finally(() => this.loading--)
.then(() => this.onContextChange());
});
return Promise.all([studycardsOrCentersPromise, subjectsPromise]).finally(() => this.loading--)
.then(() => this.onContextChange());
}

public onSelectStudyCard(): Promise<any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ <h2 class="header command-zone" i18n="Create study|Title@@studyDetailCreateTitle
</ng-template>
<ng-template ngSwitchDefault>
<input type="radio" [(ngModel)]="study.studyCardPolicy" formControlName="studyCardPolicy" value="MANDATORY"/>Mandatory
<input type="radio" [(ngModel)]="study.studyCardPolicy" formControlName="studyCardPolicy" value="OPTIONAL"/>Optional
<input type="radio" [(ngModel)]="study.studyCardPolicy" formControlName="studyCardPolicy" value="DISABLED"/>Disabled
</ng-template>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@ public enum StudyCardPolicy {
*/
MANDATORY(1),

/**
* Study card is optional during import
*/
OPTIONAL(2),

/**
* Study card is disabled during import
*/
DISABLED(3);
DISABLED(2);

private int id;

Expand Down
Loading