Skip to content

Commit

Permalink
Implement create prescription
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiserZZK committed Dec 4, 2023
1 parent 3fdd687 commit a4178ec
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 24 deletions.
2 changes: 1 addition & 1 deletion health_portal/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const routes: Routes = [
{ path: 'view-profile/:profileId', component: ViewProfileComponent },
{ path: 'update-profile/:profileId', component: UpdateProfileComponent },
{ path: 'list-prescription/:profileId', component: ListPrescriptionComponent },
{ path: 'create-prescription', component: CreatePrescriptionComponent },
{ path: 'create-prescription/:profileId', component: CreatePrescriptionComponent },
{ path: 'view-prescription/:profileId/:prescriptionId', component: ViewPrescriptionComponent },
{ path: 'update-prescription/:profileId/:prescriptionId', component: UpdatePrescriptionComponent },
{ path: 'health-advice/:profileId', component: HealthAdviceComponent },
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
<p>create-prescription works!</p>
<h3>Create Prescription</h3>
<div [hidden]="submitted" style="width: 400px;">

<form (ngSubmit)="onSubmit()">

<thead>
<tr class="text-uppercase table-dark">
<th scope="col">Rx Number</th>
<th scope="col">Rx Provider</th>
<th scope="col">Rx Name</th>
<th scope="col">Refills</th>
<th scope="col">Quantity</th>
</tr>
</thead>

<div>
<label for="rxNumber">Rx Number</label>
<input type="text" class="form-control" id="rxNumber" required [(ngModel)]="prescription.rxNumber" name="rxNumber">
</div>

<div>
<label for="rxProvider">Rx Provider</label>
<input type="text" class="form-control" id="rxProvider" required [(ngModel)]="prescription.rxProvider" name="rxProvider">
</div>

<div>
<label for="rxName">Rx Name</label>
<input type="text" class="form-control" id="rxName" required [(ngModel)]="prescription.rxName" name="rxName">
</div>

<div>
<label for="refills">Refills</label>
<input type="number" class="form-control" id="refills" required [(ngModel)]="prescription.refills" name="refills">
</div>

<div>
<label for="quantity">Quantity</label>
<input type="number" class="form-control" id="quantity" required [(ngModel)]="prescription.quantity" name="quantity">
</div>


<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>

<button (click)="gotoList(prescription.profileId)" class="btn btn-info" style="margin-left: 10px">Cancel</button>


<div [hidden]="!submitted">
<h4>You submitted successfully!</h4>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Component } from '@angular/core';
import { Prescription } from "./../../../documents/prescription";
import { PrescriptionService } from "./../../../service/prescription.service";
import { Router, ActivatedRoute } from '@angular/router';
import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';

@Component({
selector: 'app-create-prescription',
Expand All @@ -7,4 +11,44 @@ import { Component } from '@angular/core';
})
export class CreatePrescriptionComponent {

}
prescription: Prescription = new Prescription();
submitted = false;
profileId: string;
prescriptionId: string;

constructor(
private route: ActivatedRoute,
private prescriptionService: PrescriptionService,
private router: Router,
private fb: FormBuilder
) {
}

ngOnInit() {
this.profileId = this.route.snapshot.paramMap.get('profileId');
}

newProfile(): void {
this.submitted = false;
this.prescription = new Prescription();
}

save() {
this.prescription.profileId = this.profileId;
this.prescriptionService.createPrescription(this.prescription)
.subscribe(data => console.log(data), error => console.log(error));
this.prescription = new Prescription();
alert("Prescription created successfully!");
this.gotoList(this.profileId);
}

onSubmit() {
this.submitted = true;
this.save();
}

gotoList(profileId: String) {
this.router.navigate(['list-prescription', profileId]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h1> You're now viewing your prescription list</h1>
<div class="panel-heading">
<h2>Prescription List</h2>
</div>
<button type="button" routerLink="/create-prescription">Create New Prescription (implementing)</button>
<button (click)="createPrescription()" class="btn btn-info" style="margin-left: 10px">Create New Profile</button>
<div class="panel-body">
<table class="table table-striped">
<thead>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export class ListPrescriptionComponent {
// this.router.navigate(['view-prescription', prescriptionId]);
// }

createPrescription() {
this.router.navigate(['create-prescription', this.profileId]);
}

updatePrescription(profileId: String, prescriptionId: String) {
this.router.navigate(['update-prescription', profileId, prescriptionId]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3>Update Profile</h3>
<h3>Update Prescription</h3>
<div [hidden]="submitted" style="width: 400px;">

<form (ngSubmit)="onSubmit()">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,6 @@ export class UpdatePrescriptionComponent {
)
}

// createFormGroup(medicalHistory?: MedicalHistory): FormGroup {
// return this.fb.group({
// diseaseName: [medicalHistory ? medicalHistory.diseaseName : '',[Validators.required]],
// diagnosedAt: [medicalHistory ? medicalHistory.diagnosedAt : '',[Validators.required]],
// treatment:[medicalHistory ? medicalHistory.treatment : ''],
// });
// }

// get getFormControls() {
// const control = this.medicalHistoryForm.get('tableRows') as FormArray;
// return control;
// }

// addRow(medicalHistory?: MedicalHistory) {
// const control = this.medicalHistoryForm.get('tableRows') as FormArray;
// control.push(this.createFormGroup(medicalHistory));
// }

newPrescription(): void {
this.submitted = false;
this.prescription = new Prescription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class UpdateProfileComponent {
this.profileService.createProfile(this.profile)
.subscribe(data => console.log(data), error => console.log(error));
this.profile = new Profile();
alert("Profile created successfully!");
alert("Profile updated successfully!");
this.gotoList();
}

Expand Down

0 comments on commit a4178ec

Please sign in to comment.